1
1
using TranscodingStreams
2
- using TranscodingStreams. CodecIdentity
3
2
using Base. Test
4
3
5
4
@testset " Memory" begin
@@ -31,34 +30,33 @@ using Base.Test
31
30
@test mem. size == sizeof (data)
32
31
end
33
32
34
- @testset " Identity Codec" begin
33
+ @testset " Noop Codec" begin
35
34
source = IOBuffer (" " )
36
- stream = TranscodingStream (Identity (), source)
35
+ stream = TranscodingStream (Noop (), source)
37
36
@test eof (stream)
38
37
@test read (stream) == UInt8[]
39
38
@test contains (repr (stream), " mode=read" )
40
- close (stream)
41
39
42
40
source = IOBuffer (" foo" )
43
- stream = TranscodingStream (Identity (), source)
41
+ stream = TranscodingStream (Noop (), source)
44
42
@test ! eof (stream)
45
43
@test read (stream) == b " foo"
46
44
close (stream)
47
45
48
46
data = rand (UInt8, 100_000 )
49
47
source = IOBuffer (data)
50
- stream = TranscodingStream (Identity (), source)
48
+ stream = TranscodingStream (Noop (), source)
51
49
@test ! eof (stream)
52
50
@test read (stream) == data
53
51
close (stream)
54
52
55
- stream = TranscodingStream (Identity (), IOBuffer ())
53
+ stream = TranscodingStream (Noop (), IOBuffer ())
56
54
@test_throws EOFError read (stream, UInt8)
57
55
@test_throws EOFError unsafe_read (stream, pointer (Vector {UInt8} (3 )), 3 )
58
56
close (stream)
59
57
60
58
sink = IOBuffer ()
61
- stream = TranscodingStream (Identity (), sink)
59
+ stream = TranscodingStream (Noop (), sink)
62
60
@test write (stream, " foo" ) === 3
63
61
@test contains (repr (stream), " mode=write" )
64
62
flush (stream)
67
65
68
66
data = rand (UInt8, 100_000 )
69
67
sink = IOBuffer ()
70
- stream = TranscodingStream (Identity (), sink)
68
+ stream = TranscodingStream (Noop (), sink)
71
69
for i in 1 : 10_000
72
70
@assert write (stream, data[10 (i- 1 )+ 1 : 10 i]) == 10
73
71
end
76
74
close (stream)
77
75
78
76
data = collect (0x00 : 0x0f )
79
- stream = TranscodingStream (Identity (), IOBuffer (data))
77
+ stream = TranscodingStream (Noop (), IOBuffer (data))
80
78
@test ! ismarked (stream)
81
79
mark (stream)
82
80
@test ismarked (stream)
91
89
close (stream)
92
90
93
91
data = collect (0x00 : 0x0f )
94
- stream = TranscodingStream (Identity (), IOBuffer (data))
92
+ stream = TranscodingStream (Noop (), IOBuffer (data))
95
93
@test read (stream, UInt8) == data[1 ]
96
94
skip (stream, 1 )
97
95
@test read (stream, UInt8) == data[3 ]
103
101
104
102
# skip offset > bufsize
105
103
data = collect (0x00 : 0x0f )
106
- stream = TranscodingStream (Identity (), IOBuffer (data), bufsize= 2 )
104
+ stream = TranscodingStream (Noop (), IOBuffer (data), bufsize= 2 )
107
105
@test read (stream, UInt8) == data[1 ]
108
106
skip (stream, 4 )
109
107
@test read (stream, UInt8) == data[6 ]
@@ -113,14 +111,14 @@ end
113
111
@test eof (stream)
114
112
close (stream)
115
113
116
- stream = TranscodingStream (Identity (), IOBuffer (" foo" ))
114
+ stream = TranscodingStream (Noop (), IOBuffer (" foo" ))
117
115
out = zeros (UInt8, 3 )
118
116
@test nb_available (stream) == 0
119
117
@test TranscodingStreams. unsafe_read (stream, pointer (out), 10 ) == 3
120
118
@test out == b " foo"
121
119
close (stream)
122
120
123
- s = TranscodingStream (Identity (), IOBuffer (b " baz" ))
121
+ s = TranscodingStream (Noop (), IOBuffer (b " baz" ))
124
122
@test endof (s. state. buffer1) == 0
125
123
read (s, UInt8)
126
124
@test endof (s. state. buffer1) == 2
@@ -130,46 +128,39 @@ end
130
128
@test_throws BoundsError s. state. buffer1[0 ]
131
129
@test_throws BoundsError s. state. buffer1[3 ]
132
130
@test_throws BoundsError s. state. buffer1[3 : 4 ]
131
+ close (s)
133
132
134
133
data = rand (UInt8, 1999 )
135
134
# unmarked
136
- stream = TranscodingStream (Identity (), IOBuffer (data), bufsize= 7 )
135
+ stream = TranscodingStream (Noop (), IOBuffer (data), bufsize= 7 )
137
136
@test hash (read (stream)) == hash (data)
138
137
@test length (stream. state. buffer1) == 7
139
138
# marked
140
- stream = TranscodingStream (Identity (), IOBuffer (data), bufsize= 7 )
139
+ stream = TranscodingStream (Noop (), IOBuffer (data), bufsize= 7 )
141
140
mark (stream)
142
141
@test hash (read (stream)) == hash (data)
143
142
@test hash (stream. state. buffer1. data[1 : length (data)]) == hash (data)
143
+ close (stream)
144
144
145
- stream = TranscodingStream (Identity (), IOBuffer (b " foobar" ))
145
+ #= FIXME : restore these tests
146
+ stream = TranscodingStream(Noop(), IOBuffer(b"foobar"))
146
147
@test TranscodingStreams.total_in(stream) === Int64(0)
147
148
@test TranscodingStreams.total_out(stream) === Int64(0)
148
149
read(stream)
149
150
@test TranscodingStreams.total_in(stream) === Int64(6)
150
151
@test TranscodingStreams.total_out(stream) === Int64(6)
152
+ close(stream)
151
153
152
- stream = TranscodingStream (Identity (), IOBuffer ())
154
+ stream = TranscodingStream(Noop (), IOBuffer())
153
155
@test TranscodingStreams.total_in(stream) === Int64(0)
154
156
@test TranscodingStreams.total_out(stream) === Int64(0)
155
157
write(stream, b"foobar")
156
158
flush(stream)
157
159
@test TranscodingStreams.total_in(stream) === Int64(6)
158
160
@test TranscodingStreams.total_out(stream) === Int64(6)
161
+ close(stream)
162
+ =#
159
163
160
- # transcode
161
- @test transcode (Identity (), b "" ) == b ""
162
- @test transcode (Identity (), b " foo" ) == b " foo"
163
- TranscodingStreams. test_roundtrip_transcode (Identity, Identity)
164
-
165
- TranscodingStreams. test_roundtrip_read (IdentityStream, IdentityStream)
166
- TranscodingStreams. test_roundtrip_write (IdentityStream, IdentityStream)
167
- TranscodingStreams. test_roundtrip_lines (IdentityStream, IdentityStream)
168
-
169
- @test_throws ArgumentError TranscodingStream (Identity (), IOBuffer (), bufsize= 0 )
170
- end
171
-
172
- @testset " Noop Codec" begin
173
164
stream = NoopStream (IOBuffer (" foobar" ))
174
165
@test nb_available (stream) === 0
175
166
@test readavailable (stream) == b ""
178
169
@test readavailable (stream) == b " oobar"
179
170
close (stream)
180
171
172
+ data = b ""
173
+ @test transcode (Noop (), data) == data
174
+ @test transcode (Noop (), data) != = data
181
175
data = b " foo"
176
+ @test transcode (Noop (), data) == data
182
177
@test transcode (Noop (), data) != = data
178
+
183
179
TranscodingStreams. test_roundtrip_transcode (Noop, Noop)
184
180
TranscodingStreams. test_roundtrip_read (NoopStream, NoopStream)
185
181
TranscodingStreams. test_roundtrip_write (NoopStream, NoopStream)
237
233
stream = NoopStream (IOBuffer (" foobar" ))
238
234
@test_throws ArgumentError TranscodingStreams. unsafe_unread (stream, pointer (b " foo" ), - 1 )
239
235
close (stream)
236
+
237
+ @test_throws ArgumentError NoopStream (IOBuffer (), bufsize= 0 )
238
+ @test_throws ArgumentError TranscodingStream (Noop (), IOBuffer (), bufsize= 0 )
240
239
end
241
240
242
241
# This does not implement necessary interface methods.
@@ -276,6 +275,15 @@ TranscodingStreams.minoutsize(::QuadrupleCodec, ::Memory) = 4
276
275
@test (@allocated transcode (QuadrupleCodec (), data)) < sizeof (data) * 5
277
276
end
278
277
278
+ # TODO : Remove this in the future.
279
+ using TranscodingStreams. CodecIdentity
280
+ @testset " Identity Codec (deprecated)" begin
281
+ TranscodingStreams. test_roundtrip_transcode (Identity, Identity)
282
+ TranscodingStreams. test_roundtrip_read (IdentityStream, IdentityStream)
283
+ TranscodingStreams. test_roundtrip_write (IdentityStream, IdentityStream)
284
+ TranscodingStreams. test_roundtrip_lines (IdentityStream, IdentityStream)
285
+ end
286
+
279
287
for pkg in [" CodecZlib" , " CodecBzip2" , " CodecXz" , " CodecZstd" , " CodecBase" ]
280
288
Pkg. test (pkg)
281
289
end
0 commit comments