Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nhz2 committed Mar 3, 2024
1 parent ad34bab commit 6217a90
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
25 changes: 16 additions & 9 deletions test/codecnoop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@
end
end

@testset "seekstart doesn't delete data" begin
@testset "seek doesn't delete data" begin
sink = IOBuffer()
stream = NoopStream(sink, bufsize=16)
write(stream, "x")
Expand All @@ -344,13 +344,20 @@
@test take!(sink) == b"x"
close(stream)

sink = IOBuffer()
stream = NoopStream(sink, bufsize=16)
write(stream, "abc")
seekstart(stream)
write(stream, "d")
flush(stream)
@test take!(sink) == b"dbc"
close(stream)
op_expected = [
(seekstart, b"dbc"),
(seekend, b"abcd"),
(Base.Fix2(seek, 1), b"adc"),
]
@testset "$op" for (op, expected) in op_expected
sink = IOBuffer()
stream = NoopStream(sink, bufsize=16)
write(stream, "abc")
@test op(stream) === stream
write(stream, "d")
flush(stream)
@test take!(sink) == expected
close(stream)
end
end
end
38 changes: 16 additions & 22 deletions test/codecquadruple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,28 +124,22 @@ end
end

@testset "seekstart doesn't delete data" begin
sink = IOBuffer()
stream = TranscodingStream(QuadrupleCodec(), sink, bufsize=16)
write(stream, "x")
# seekstart must not delete user data even if it errors.
@test_throws ArgumentError seekstart(stream)
write(stream, TranscodingStreams.TOKEN_END)
flush(stream)
@test take!(sink) == b"xxxx"
close(stream)
end

@testset "seekstart doesn't delete data in a NoopStream wrapped TranscodingStream" begin
sink = IOBuffer()
stream1 = TranscodingStream(QuadrupleCodec(), sink, bufsize=16)
stream2 = NoopStream(stream1, bufsize=16)
write(stream2, "x")
# seekstart must not delete user data even if it errors.
@test_throws ArgumentError seekstart(stream2)
write(stream2, TranscodingStreams.TOKEN_END)
flush(stream2)
@test take!(sink) == b"xxxx"
close(stream2)
for n in 0:3
sink = IOBuffer()
# wrap stream in NoopStream n times.
stream = foldl(
(s,_) -> NoopStream(s),
1:n;
init=TranscodingStream(QuadrupleCodec(), sink, bufsize=16)
)
write(stream, "x")
# seekstart must not delete user data even if it errors.
@test_throws ArgumentError seekstart(stream)
write(stream, TranscodingStreams.TOKEN_END)
flush(stream)
@test take!(sink) == b"xxxx"
close(stream)
end
end

@testset "eof is true after write" begin
Expand Down

0 comments on commit 6217a90

Please sign in to comment.