@@ -269,16 +269,33 @@ const encodings = [
269269 @test YAML. load (IOBuffer (data)) == " test"
270270end
271271
272- @testset " multi_doc_bom" begin
273- iterable = YAML. load_all ("""
272+ const multidoc_contents = """
274273\u feff---\r
275274test: 1
276275\u feff---
277276test: 2
278277
279278\u feff---
280279test: 3
281- """ )
280+ """
281+
282+ @testset " multi_doc_bom" begin
283+ iterable = YAML. load_all (multidoc_contents)
284+ (val, state) = iterate (iterable)
285+ @test equivalent (val, Dict (" test" => 1 ))
286+ (val, state) = iterate (iterable, state)
287+ @test equivalent (val, Dict (" test" => 2 ))
288+ (val, state) = iterate (iterable, state)
289+ @test equivalent (val, Dict (" test" => 3 ))
290+ @test iterate (iterable, state) === nothing
291+ end
292+
293+ @testset " multi_doc_file" begin
294+ fname = tempname () # cleanup=true, file will be deleted on process exit
295+ open (fname, " w" ) do f
296+ write (f, multidoc_contents)
297+ end
298+ iterable = YAML. load_all_file (fname)
282299 (val, state) = iterate (iterable)
283300 @test equivalent (val, Dict (" test" => 1 ))
284301 (val, state) = iterate (iterable, state)
@@ -288,6 +305,18 @@ test: 3
288305 @test iterate (iterable, state) === nothing
289306end
290307
308+ @testset " multi_doc_iteration_protocol" begin
309+ fname = tempname () # cleanup=true, file will be deleted on process exit
310+ open (fname, " w" ) do f
311+ write (f, multidoc_contents)
312+ end
313+ iterable = YAML. load_all_file (fname)
314+ @test Base. IteratorSize (YAML. YAMLDocIterator) == Base. SizeUnknown ()
315+ @test Base. IteratorEltype (YAML. YAMLDocIterator) == Base. HasEltype ()
316+ @test eltype (iterable) == Dict{Any, Any}
317+ @test length (collect (iterable)) == 3
318+ end
319+
291320# test that an OrderedDict is written in the correct order
292321using OrderedCollections, DataStructures
293322@test strip (YAML. yaml (OrderedDict (:c => 3 , :b => 2 , :a => 1 ))) == join ([" c: 3" , " b: 2" , " a: 1" ], " \n " )
0 commit comments