Skip to content

Commit 6289baa

Browse files
committed
Add more iteration tests
1 parent 0fdd8d0 commit 6289baa

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

test/runtests.jl

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,33 @@ const encodings = [
269269
@test YAML.load(IOBuffer(data)) == "test"
270270
end
271271

272-
@testset "multi_doc_bom" begin
273-
iterable = YAML.load_all("""
272+
const multidoc_contents = """
274273
\ufeff---\r
275274
test: 1
276275
\ufeff---
277276
test: 2
278277
279278
\ufeff---
280279
test: 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
289306
end
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
292321
using 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

Comments
 (0)