Skip to content

Commit

Permalink
adds some tests for loadstreaming and savestreaming
Browse files Browse the repository at this point in the history
  • Loading branch information
ssfrr committed Nov 25, 2017
1 parent defe2c1 commit d922a07
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion test/loadsave.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function DummyReader(stream, ownstream)
DummyReader(stream, ownstream, read(stream, Int64))
end

function Base.read(stream::DummyReader, n)
function Base.read(stream::DummyReader, n=stream.bytesleft)
toread = min(n, stream.bytesleft)
buf = read(stream.stream, toread)
stream.bytesleft -= length(buf)
Expand Down Expand Up @@ -217,6 +217,38 @@ add_saver(format"DUMMY", :Dummy)
end
rm(fn)

# streaming I/O with filenames
fn = string(tempname(), ".dmy")
save(fn, a)
loadstreaming(fn) do reader
@test read(reader) == a
end
rm(fn)
savestreaming(fn) do writer
write(writer, a)
end
@test load(fn) == a
rm(fn)

# streaming I/O with streams
save(fn, a)
open(fn) do io
loadstreaming(io) do reader
@test read(reader) == a
end
@test isopen(io)
end
rm(fn)
open(fn, "w") do io
savestreaming(format"DUMMY", io) do writer
write(writer, a)
end
@test isopen(io)
end
@test load(fn) == a
rm(fn)


@test_throws Exception save("missing.fmt",5)
end

Expand Down Expand Up @@ -270,6 +302,8 @@ end
@test typeof(query(fn)) == File{format"AmbigExt1"}

rm(fn)
del_format(format"AmbigExt1")
del_format(format"AmbigExt2")
end

@testset "Absent file" begin
Expand Down

0 comments on commit d922a07

Please sign in to comment.