Skip to content

Commit 466b6d0

Browse files
authored
Fix test_roundtrip_write (#233)
1 parent 76543ed commit 466b6d0

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name = "TranscodingStreams"
22
uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
33
license = "MIT"
44
authors = ["Kenta Sato <[email protected]>"]
5-
version = "0.11.0"
5+
version = "0.11.1"
66

77
[deps]
88
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

ext/TestExt.jl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,25 @@ function TranscodingStreams.test_roundtrip_read(encoder, decoder)
1919
end
2020
end
2121

22+
# flush all nested streams and return final data
23+
function take_all(stream)
24+
if stream isa Base.GenericIOBuffer
25+
seekstart(stream)
26+
read(stream)
27+
else
28+
write(stream, TranscodingStreams.TOKEN_END)
29+
flush(stream)
30+
take_all(stream.stream)
31+
end
32+
end
33+
2234
function TranscodingStreams.test_roundtrip_write(encoder, decoder)
2335
seed!(TEST_RANDOM_SEED)
2436
for n in vcat(0:30, sort!(rand(500:100_000, 30))), alpha in (0x00:0xff, 0x00:0x0f)
2537
data = rand(alpha, n)
26-
file = IOBuffer()
27-
stream = encoder(decoder(file))
28-
write(stream, data, TOKEN_END); flush(stream)
29-
Test.@test hash(take!(file)) == hash(data)
38+
stream = encoder(decoder(IOBuffer()))
39+
write(stream, data)
40+
Test.@test take_all(stream) == data
3041
close(stream)
3142
end
3243
end

0 commit comments

Comments
 (0)