Skip to content

Commit 034d5b3

Browse files
committed
adds some tests for loadstreaming and savestreaming
1 parent 6c8e1fb commit 034d5b3

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

test/loadsave.jl

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function DummyReader(stream, ownstream)
7272
DummyReader(stream, ownstream, read(stream, Int64))
7373
end
7474

75-
function Base.read(stream::DummyReader, n)
75+
function Base.read(stream::DummyReader, n=stream.bytesleft)
7676
toread = min(n, stream.bytesleft)
7777
buf = read(stream.stream, toread)
7878
stream.bytesleft -= length(buf)
@@ -217,6 +217,38 @@ add_saver(format"DUMMY", :Dummy)
217217
end
218218
rm(fn)
219219

220+
# streaming I/O with filenames
221+
fn = string(tempname(), ".dmy")
222+
save(fn, a)
223+
loadstreaming(fn) do reader
224+
@test read(reader) == a
225+
end
226+
rm(fn)
227+
savestreaming(fn) do writer
228+
write(writer, a)
229+
end
230+
@test load(fn) == a
231+
rm(fn)
232+
233+
# streaming I/O with streams
234+
save(fn, a)
235+
open(fn) do io
236+
loadstreaming(io) do reader
237+
@test read(reader) == a
238+
end
239+
@test isopen(io)
240+
end
241+
rm(fn)
242+
open(fn, "w") do io
243+
savestreaming(format"DUMMY", io) do writer
244+
write(writer, a)
245+
end
246+
@test isopen(io)
247+
end
248+
@test load(fn) == a
249+
rm(fn)
250+
251+
220252
@test_throws Exception save("missing.fmt",5)
221253
end
222254

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

272304
rm(fn)
305+
del_format(format"AmbigExt1")
306+
del_format(format"AmbigExt2")
273307
end
274308

275309
@testset "Absent file" begin

0 commit comments

Comments
 (0)