109
|
1 |
"{ Package: 'stx:goodies/xtreams/transforms/tests' }"!
|
10
|
2 |
|
|
3 |
!Xtreams::CollectionReadingWritingTest methodsFor:'tests - transforming'!
|
|
4 |
|
|
5 |
testReadRejecting
|
109
|
6 |
self output write: #[ 1 2 3 4 5 6 7 8 9 ].
|
|
7 |
self assert: ((self input rejecting: [ :e | e even ]) read: 5) = #[ 1 3 5 7 9 ]
|
10
|
8 |
! !
|
109
|
9 |
|
10
|
10 |
!Xtreams::CollectionReadingWritingTest methodsFor:'tests - transforming'!
|
|
11 |
|
|
12 |
testReadSelecting
|
109
|
13 |
self output write: #[ 1 2 3 4 5 6 7 8 9 ].
|
|
14 |
self assert: ((self input selecting: [ :e | e even ]) read: 4) = #[ 2 4 6 8 ]
|
10
|
15 |
! !
|
109
|
16 |
|
10
|
17 |
!Xtreams::CollectionReadingWritingTest methodsFor:'tests - transforming'!
|
|
18 |
|
|
19 |
testWriteRejecting
|
109
|
20 |
(self output rejecting: [ :e | e even ] ) write: #[ 1 2 3 4 5 6 7 8 9 ]; close.
|
|
21 |
self assert: (self input read: 5) = #[ 1 3 5 7 9 ]
|
10
|
22 |
! !
|
109
|
23 |
|
10
|
24 |
!Xtreams::CollectionReadingWritingTest methodsFor:'tests - transforming'!
|
|
25 |
|
|
26 |
testWriteSelecting
|
109
|
27 |
(self output selecting: [ :e | e even]) write: #[ 1 2 3 4 5 6 7 8 9 ]; close.
|
|
28 |
self assert: (self input read: 4) = #[ 2 4 6 8 ]
|
10
|
29 |
! !
|
109
|
30 |
|
10
|
31 |
!Xtreams::CollectionReadingWritingTest methodsFor:'tests - transforming'!
|
|
32 |
|
|
33 |
testWriteTransformHexToByte
|
|
34 |
| hex2Byte decoder result |
|
|
35 |
decoder := [ :char | ('0123456789ABCDEF' indexOf: char asUppercase) - 1 ].
|
109
|
36 |
hex2Byte :=
|
10
|
37 |
self output transforming: [ :in :out |
|
|
38 |
out put: (((decoder value: in get) bitShift: 4) + (decoder value: in get)) ].
|
|
39 |
hex2Byte buffer: (ElasticBuffer on: (ByteString new: 16)).
|
|
40 |
hex2Byte write: 'ab'.
|
|
41 |
hex2Byte write: 'cdef'.
|
|
42 |
hex2Byte close.
|
|
43 |
self assert: self input get = 16rAB.
|
|
44 |
result := self input read: 2.
|
|
45 |
self assert: result = #[16rcd 16ref].
|
|
46 |
! !
|
109
|
47 |
|
73
|
48 |
!Xtreams::FiniteReadingWritingTests methodsFor:'tests - interpreting'!
|
40
|
49 |
|
73
|
50 |
testInterpretingDoubles
|
109
|
51 |
| doubles result |
|
|
52 |
doubles := (1 to: 10) reading collect: [ :i | i reciprocal asDouble ].
|
|
53 |
(self output interpreting: #double) write: doubles; close.
|
|
54 |
result := (self input interpreting: #double) rest.
|
|
55 |
self assert: result = doubles asArray
|
73
|
56 |
! !
|
109
|
57 |
|
10
|
58 |
!Xtreams::FiniteReadingWritingTests methodsFor:'tests - transforming'!
|
|
59 |
|
|
60 |
testWriteTransformingOverLimitingPastEnd
|
|
61 |
|
|
62 |
| limited transferred |
|
|
63 |
limited := (self output limiting: 10) transforming: [ :in :out | out put: in get ].
|
|
64 |
self assert: (
|
109
|
65 |
[ limited write: (ByteArray withAll: (1 to: 20)).
|
10
|
66 |
false
|
|
67 |
] on: Incomplete do: [ :ex | ex count = 11 ] ).
|
|
68 |
transferred := self input read: 10.
|
|
69 |
self assert: transferred = (ByteArray withAll: (1 to: 10))
|
|
70 |
! !
|
109
|
71 |
|
10
|
72 |
!Xtreams::FiniteReadingWritingTests methodsFor:'tests - transforming'!
|
|
73 |
|
|
74 |
testWriteTransformingPastEnd
|
|
75 |
| count transformed |
|
|
76 |
count := 1.
|
|
77 |
transformed := self output transforming: [:in :out |
|
|
78 |
count = 2 ifTrue: [Incomplete zero raise].
|
|
79 |
out put: in get.
|
|
80 |
count := count + 1].
|
|
81 |
self assert: (
|
109
|
82 |
[ transformed write: #[ 1 2 3 ].
|
10
|
83 |
false
|
|
84 |
] on: Incomplete do: [ :ex | ex count = 1 ]).
|
|
85 |
transformed close.
|
|
86 |
self assert: self input get = 1.
|
|
87 |
self should: [self input get] raise: Incomplete.
|
|
88 |
self should: [self input get] raise: Incomplete
|
|
89 |
! !
|
109
|
90 |
|
73
|
91 |
!Xtreams::ReadingWritingTest methodsFor:'tests - transforming'!
|
10
|
92 |
|
115
|
93 |
testCharacters
|
|
94 |
(self output encoding: #ascii)
|
|
95 |
setLineEndTransparent;
|
|
96 |
backspace; bell; cr; delete; ff; lf; q; qq; space; tab; vtab; escape;
|
|
97 |
close.
|
|
98 |
self assert: (self input read: 12) = #[8 7 13 127 12 10 39 34 32 9 11 27]
|
|
99 |
! !
|
|
100 |
|
|
101 |
!Xtreams::ReadingWritingTest methodsFor:'tests - transforming'!
|
|
102 |
|
73
|
103 |
testDoing
|
|
104 |
| outing inning |
|
|
105 |
outing := ByteArray new writing.
|
|
106 |
(self output doing: [:each | outing put: each]) write: #[ 1 2 3 4 5 ].
|
|
107 |
self assert: outing contents = #[ 1 2 3 4 5 ].
|
|
108 |
|
|
109 |
inning := ByteArray new writing.
|
|
110 |
self assert: ((self input doing: [:each | inning put: each]) read: 5) = #[ 1 2 3 4 5 ].
|
|
111 |
self assert: inning contents = #[ 1 2 3 4 5 ]
|
|
112 |
! !
|
109
|
113 |
|
73
|
114 |
!Xtreams::ReadingWritingTest methodsFor:'tests - interpreting'!
|
|
115 |
|
|
116 |
testInterpretingPoints
|
|
117 |
|
|
118 |
| points result |
|
|
119 |
points := (Random new reading transforming: [ :in :out | out put: in get @ in get ]) read: 5.
|
|
120 |
(self output interpreting: [ :b :i :o | b doubleAt: i put: o x. b doubleAt: i + 8 put: o y ] size: 16 )
|
|
121 |
write: points;
|
|
122 |
close.
|
|
123 |
result := (self input interpreting: [ :b :i | (b doubleAt: i) @ (b doubleAt: i + 8) ] size: 16 cacheSize: 5) read: points size.
|
|
124 |
self assert: points = result
|
|
125 |
! !
|
109
|
126 |
|
73
|
127 |
!Xtreams::ReadingWritingTest methodsFor:'tests - interpreting'!
|
|
128 |
|
|
129 |
testMarshaling
|
|
130 |
| object result in out |
|
|
131 |
object := Object new.
|
|
132 |
out := self output marshaling.
|
|
133 |
in := self input marshaling.
|
109
|
134 |
2 timesRepeat:
|
73
|
135 |
[out put: ((1 to: 11) collect: [:each | (1 to: 11) collect: [:ea | object]]).
|
|
136 |
result := in get.
|
|
137 |
self assert: result size = 11.
|
|
138 |
self assert: (result allSatisfy: [:each | each allSatisfy: [:ea | ea == result first first]])]
|
|
139 |
! !
|
109
|
140 |
|
73
|
141 |
!Xtreams::ReadingWritingTest methodsFor:'tests - transforming'!
|
|
142 |
|
|
143 |
testReadCollecting
|
|
144 |
| data |
|
|
145 |
data := #[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ].
|
|
146 |
self output write: data.
|
|
147 |
self assert: ((self input collecting: [:e | e * e]) read: data size) = (ByteArray withAll: (data collect: [:e | e * e]))
|
|
148 |
! !
|
109
|
149 |
|
73
|
150 |
!Xtreams::ReadingWritingTest methodsFor:'tests - transforming'!
|
|
151 |
|
|
152 |
testReadCollectingContentsSpeciesChanged
|
|
153 |
| data result |
|
|
154 |
data := ByteArray withAll: ((1 to: 16) collect: [:index | 65]).
|
|
155 |
self output write: data.
|
|
156 |
result :=
|
|
157 |
(self input collecting: [:e | Character codePoint: e])
|
|
158 |
contentsSpecies: String;
|
|
159 |
read: data size.
|
|
160 |
self assert: result = (String withAll: (data asArray collect: [:e | Character codePoint: e]))
|
|
161 |
! !
|
109
|
162 |
|
10
|
163 |
!Xtreams::ReadingWritingTest methodsFor:'tests - encoding'!
|
|
164 |
|
|
165 |
testReadDecodingBase64
|
|
166 |
(self output encoding: #ascii)
|
109
|
167 |
write:
|
10
|
168 |
'TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz
|
|
169 |
IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg
|
|
170 |
dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu
|
|
171 |
dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo
|
|
172 |
ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=';
|
|
173 |
close.
|
|
174 |
self assert: (((self input encoding: #ascii) encodingBase64 encoding: #ascii) read: 269) = 'Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.'
|
|
175 |
! !
|
109
|
176 |
|
10
|
177 |
!Xtreams::ReadingWritingTest methodsFor:'tests - encoding'!
|
|
178 |
|
|
179 |
testReadDecodingCRLF
|
|
180 |
|
|
181 |
| result |
|
|
182 |
self output write: #[104 101 108 108 111 13 10 119 111 114 108 100 10 13 13 10 10 ]; close.
|
|
183 |
result := (self input encoding: #ascii) read: 15.
|
|
184 |
self assert: result = 'hello\world\\\\' withCRs
|
|
185 |
! !
|
109
|
186 |
|
10
|
187 |
!Xtreams::ReadingWritingTest methodsFor:'tests - encoding'!
|
|
188 |
|
|
189 |
testReadDecodingTransparent
|
|
190 |
|
|
191 |
| result bytes |
|
|
192 |
bytes := #[104 101 108 108 111 13 10 119 111 114 108 100 13 10 13 10 13 10 ].
|
|
193 |
self output write: bytes; close.
|
|
194 |
result := (self input encoding: #ascii) setLineEndTransparent read: bytes size.
|
109
|
195 |
self assert: result = (String withAll: (bytes asArray collect: [ :e | e asCharacter ]))
|
10
|
196 |
! !
|
109
|
197 |
|
10
|
198 |
!Xtreams::ReadingWritingTest methodsFor:'tests - encoding'!
|
|
199 |
|
|
200 |
testReadDecodingUTF16
|
|
201 |
|
|
202 |
| result bytes |
|
|
203 |
bytes := #[0 72 0 101 0 108 0 108 0 111 0 32 0 87 0 111 0 114 0 108 0 100 0 33].
|
|
204 |
self output write: bytes; close.
|
|
205 |
result := (self input encoding: #utf16) read: 12.
|
|
206 |
self assert: result = 'Hello World!!'
|
|
207 |
! !
|
109
|
208 |
|
10
|
209 |
!Xtreams::ReadingWritingTest methodsFor:'tests - encoding'!
|
|
210 |
|
|
211 |
testReadDecodingUTF8
|
|
212 |
|
91
|
213 |
| result bytes text |
|
|
214 |
text := 'Příliš žluťoučký kůň úpěl ďábelské ódy'.
|
|
215 |
bytes := #[80 197 153 195 173 108 105 197 161 32 197 190 108 117 197 165 111 117 196 141 107 195 189 32 107 197 175 197 136 32 195 186 112 196 155 108 32 196 143 195 161 98 101 108 115 107 195 169 32 195 179 100 121].
|
|
216 |
self output write: bytes; close.
|
|
217 |
result := (self input encoding: #utf8) read: 38.
|
|
218 |
self assert: result = text
|
10
|
219 |
! !
|
109
|
220 |
|
73
|
221 |
!Xtreams::ReadingWritingTest methodsFor:'tests - transforming'!
|
10
|
222 |
|
73
|
223 |
testReadDuplicating
|
|
224 |
|
|
225 |
| copy contents |
|
|
226 |
contents := Array withAll: (0 to: 15).
|
|
227 |
copy := Array new writing.
|
|
228 |
self assert: (contents reading duplicating: copy) rest = contents.
|
|
229 |
self assert: copy conclusion = contents
|
|
230 |
! !
|
109
|
231 |
|
73
|
232 |
!Xtreams::ReadingWritingTest methodsFor:'tests - transforming'!
|
|
233 |
|
|
234 |
testReadInjecting
|
|
235 |
self output write: #[ 1 2 3 4 ].
|
|
236 |
self assert: ((self input injecting: 0 into: [:all :each | all + each]) read: 4) = #[ 1 3 6 10 ]
|
|
237 |
! !
|
109
|
238 |
|
73
|
239 |
!Xtreams::ReadingWritingTest methodsFor:'tests - transforming'!
|
|
240 |
|
|
241 |
testReadRejecting
|
|
242 |
self output write: #[ 1 2 3 4 5 6 7 8 9 ].
|
|
243 |
self assert: ((self input rejecting: #even) read: 5) = #[ 1 3 5 7 9 ]
|
|
244 |
! !
|
109
|
245 |
|
73
|
246 |
!Xtreams::ReadingWritingTest methodsFor:'tests - transforming'!
|
|
247 |
|
|
248 |
testReadSelecting
|
|
249 |
self output write: #[ 1 2 3 4 5 6 7 8 9 ].
|
|
250 |
self assert: ((self input selecting: #even) read: 4) = #[ 2 4 6 8 ]
|
|
251 |
! !
|
109
|
252 |
|
73
|
253 |
!Xtreams::ReadingWritingTest methodsFor:'tests - transforming'!
|
|
254 |
|
|
255 |
testReadTransforming1into2
|
|
256 |
| result |
|
|
257 |
self output write: #[ 1 2 3 ].
|
|
258 |
result :=
|
|
259 |
(self input transforming: [:in :out | | x | x := in get. out put: x; put: x])
|
|
260 |
read: 6.
|
|
261 |
self assert: result = #[ 1 1 2 2 3 3 ]
|
|
262 |
! !
|
109
|
263 |
|
73
|
264 |
!Xtreams::ReadingWritingTest methodsFor:'tests - transforming'!
|
|
265 |
|
|
266 |
testReadTransforming2into1
|
|
267 |
| result |
|
|
268 |
self output write: #[ 1 2 3 4 ].
|
|
269 |
result :=
|
|
270 |
(self input transforming: [:in :out | in get. out put: in get])
|
|
271 |
read: 2.
|
|
272 |
self assert: result = #[ 2 4 ]
|
|
273 |
! !
|
109
|
274 |
|
73
|
275 |
!Xtreams::ReadingWritingTest methodsFor:'tests - transforming'!
|
|
276 |
|
|
277 |
testReadTransformingPastEnd
|
|
278 |
| count transformed |
|
|
279 |
count := 1.
|
|
280 |
self output write: #[ 1 2 3 ]; close.
|
|
281 |
transformed := self input transforming: [:in :out |
|
|
282 |
count = 2 ifTrue: [Incomplete zero raise].
|
|
283 |
out put: in get.
|
|
284 |
count := count + 1].
|
|
285 |
self assert: transformed get = 1.
|
|
286 |
self should: [transformed get] raise: Incomplete.
|
|
287 |
self should: [transformed get] raise: Incomplete
|
|
288 |
! !
|
109
|
289 |
|
73
|
290 |
!Xtreams::ReadingWritingTest methodsFor:'tests - interpreting'!
|
|
291 |
|
|
292 |
testReadUnsignedShortEndianness
|
|
293 |
|
|
294 |
self output write: #[ 16rFF 16r00 16rFF 00]; close.
|
|
295 |
self assert: (self input interpreting: #unsignedShort_le) get = 16rFF.
|
|
296 |
self assert: (self input interpreting: #unsignedShort_be) get = 16rFF00.
|
|
297 |
! !
|
109
|
298 |
|
73
|
299 |
!Xtreams::ReadingWritingTest methodsFor:'tests - transforming'!
|
|
300 |
|
|
301 |
testWriteCollecting
|
|
302 |
| data |
|
|
303 |
data := 1 to: 15.
|
|
304 |
(self output collecting: [:e | e * e]) write: data.
|
|
305 |
self assert: (self input read: data size) = (ByteArray withAll: (data collect: [:e | e * e]))
|
|
306 |
! !
|
109
|
307 |
|
73
|
308 |
!Xtreams::ReadingWritingTest methodsFor:'tests - transforming'!
|
|
309 |
|
|
310 |
testWriteCollectingIncompatibleContentSpecies
|
|
311 |
| data |
|
|
312 |
data := (1 to: 15) collect: [ :x | x @ 0 ].
|
|
313 |
(self output collecting: [:e | e x ]) write: data.
|
|
314 |
self assert: (self input read: data size) = (ByteArray withAll: (data collect: [:e | e x]))
|
|
315 |
! !
|
109
|
316 |
|
73
|
317 |
!Xtreams::ReadingWritingTest methodsFor:'tests - transforming'!
|
|
318 |
|
|
319 |
testWriteCollectingMultipleBufferSize
|
|
320 |
| data |
|
|
321 |
data := (1 to: DefaultBufferSize + 500) collect: [ :i | i \\ 16 ].
|
|
322 |
self timeout: 1 seconds
|
|
323 |
server:
|
|
324 |
[(self output collecting: [:e | e * e])
|
|
325 |
write: data;
|
|
326 |
close.
|
|
327 |
true]
|
|
328 |
client: [(self input read: data size) = (ByteArray withAll: (data collect: [:e | e * e]))]
|
|
329 |
! !
|
109
|
330 |
|
73
|
331 |
!Xtreams::ReadingWritingTest methodsFor:'tests - transforming'!
|
|
332 |
|
|
333 |
testWriteDuplicating
|
|
334 |
|
|
335 |
| original copy contents |
|
|
336 |
contents := Array withAll: (0 to: 15).
|
|
337 |
original := Array new writing.
|
|
338 |
copy := Array new writing.
|
|
339 |
(original duplicating: copy) write: contents.
|
|
340 |
self assert: original conclusion = contents.
|
|
341 |
self assert: copy conclusion = contents
|
|
342 |
! !
|
109
|
343 |
|
10
|
344 |
!Xtreams::ReadingWritingTest methodsFor:'tests - encoding'!
|
|
345 |
|
|
346 |
testWriteEncodingBase64
|
|
347 |
((self output encoding: #ascii) encodingBase64 encoding: #ascii)
|
|
348 |
write: 'Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.';
|
|
349 |
close.
|
|
350 |
self assert: ((self input encoding: #ascii) read: 360) = 'TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4='
|
|
351 |
! !
|
109
|
352 |
|
10
|
353 |
!Xtreams::ReadingWritingTest methodsFor:'tests - encoding'!
|
|
354 |
|
|
355 |
testWriteEncodingCRLF
|
|
356 |
|
115
|
357 |
| result isCRLF |
|
|
358 |
(self output encoding: #ascii)
|
|
359 |
write: 'hello\world\\\' withCRs;
|
|
360 |
close.
|
|
361 |
isCRLF := OperatingSystem isMSWINDOWSlike.
|
|
362 |
result := self input read: (isCRLF ifTrue: [18] ifFalse: [14]).
|
109
|
363 |
|
115
|
364 |
self assert: result = (isCRLF
|
|
365 |
ifTrue: [#[104 101 108 108 111 13 10 119 111 114 108 100 13 10 13 10 13 10 ] ]
|
|
366 |
ifFalse: [#[104 101 108 108 111 10 119 111 114 108 100 10 10 10 ] ])
|
10
|
367 |
! !
|
109
|
368 |
|
10
|
369 |
!Xtreams::ReadingWritingTest methodsFor:'tests - encoding'!
|
|
370 |
|
|
371 |
testWriteEncodingTransparent
|
|
372 |
|
|
373 |
| data result bytes |
|
|
374 |
bytes := #[104 101 108 108 111 13 10 119 111 114 108 100 13 10 13 10 13 10 ].
|
109
|
375 |
data := String withAll: (bytes asArray collect: [ :e | e asCharacter ]).
|
10
|
376 |
(self output encoding: #ascii)
|
|
377 |
setLineEndTransparent;
|
|
378 |
write: data;
|
|
379 |
close.
|
|
380 |
result := self input read: data size.
|
|
381 |
self assert: result = bytes
|
|
382 |
! !
|
109
|
383 |
|
10
|
384 |
!Xtreams::ReadingWritingTest methodsFor:'tests - encoding'!
|
|
385 |
|
|
386 |
testWriteEncodingUTF16
|
|
387 |
|
|
388 |
| result bytes |
|
|
389 |
bytes := #[0 72 0 101 0 108 0 108 0 111 0 32 0 87 0 111 0 114 0 108 0 100 0 33].
|
|
390 |
(self output encoding: #utf16) write: 'Hello World!!'; close.
|
|
391 |
result := self input read: 24.
|
|
392 |
self assert: result = bytes
|
|
393 |
! !
|
109
|
394 |
|
10
|
395 |
!Xtreams::ReadingWritingTest methodsFor:'tests - encoding'!
|
|
396 |
|
|
397 |
testWriteEncodingUTF8
|
|
398 |
|
109
|
399 |
| result bytes text |
|
|
400 |
text := 'Příliš žluťoučký kůň úpěl ďábelské ódy'.
|
|
401 |
bytes := #[80 197 153 195 173 108 105 197 161 32 197 190 108 117 197 165 111 117 196 141 107 195 189 32 107 197 175 197 136 32 195 186 112 196 155 108 32 196 143 195 161 98 101 108 115 107 195 169 32 195 179 100 121].
|
|
402 |
(self output encoding: #utf8) write: text; close.
|
|
403 |
result := self input read: bytes size.
|
|
404 |
self assert: result = bytes
|
10
|
405 |
! !
|
109
|
406 |
|
10
|
407 |
!Xtreams::ReadingWritingTest methodsFor:'tests - transforming'!
|
|
408 |
|
|
409 |
testWriteInjecting
|
|
410 |
(self output injecting: 0 into: [:all :each | all + each])
|
|
411 |
write: #[ 1 2 3 4 ]; close.
|
|
412 |
self assert: (self input read: 4) = #[ 1 3 6 10 ]
|
|
413 |
! !
|
109
|
414 |
|
10
|
415 |
!Xtreams::ReadingWritingTest methodsFor:'tests - transforming'!
|
|
416 |
|
|
417 |
testWriteRejecting
|
|
418 |
(self output rejecting: #even) write: #[ 1 2 3 4 5 6 7 8 9 ]; close.
|
|
419 |
self assert: (self input read: 5) = #[ 1 3 5 7 9 ]
|
|
420 |
! !
|
109
|
421 |
|
10
|
422 |
!Xtreams::ReadingWritingTest methodsFor:'tests - transforming'!
|
|
423 |
|
|
424 |
testWriteSelecting
|
|
425 |
(self output selecting: #even) write: #[ 1 2 3 4 5 6 7 8 9 ]; close.
|
|
426 |
self assert: (self input read: 4) = #[ 2 4 6 8 ]
|
|
427 |
! !
|
109
|
428 |
|
10
|
429 |
!Xtreams::ReadingWritingTest methodsFor:'tests - transforming'!
|
|
430 |
|
|
431 |
testWriteTransformHexToByte
|
123
|
432 |
| hex2Byte decoder result |
|
|
433 |
decoder := [ :char | ('0123456789ABCDEF' indexOf: char asUppercase) - 1 ].
|
|
434 |
hex2Byte :=
|
|
435 |
self output transforming: [ :in :out |
|
|
436 |
out put: (((decoder value: in get) bitShift: 4) + (decoder value: in get)) ].
|
|
437 |
hex2Byte buffer: (ElasticBuffer on: (String new: 16)).
|
|
438 |
hex2Byte write: 'ab'.
|
|
439 |
self assert: self input get = 16rAB.
|
|
440 |
hex2Byte write: 'cdef'.
|
|
441 |
hex2Byte close.
|
|
442 |
result := self input read: 2.
|
|
443 |
self assert: result = #[16rcd 16ref].
|
10
|
444 |
! !
|
109
|
445 |
|
10
|
446 |
!Xtreams::ReadingWritingTest methodsFor:'tests - transforming'!
|
|
447 |
|
|
448 |
testWriteTransforming1into2
|
|
449 |
| result |
|
|
450 |
(self output transforming: [:in :out | | x | x := in get. out put: x; put: x])
|
|
451 |
write: #[ 1 2 3 ];
|
|
452 |
close.
|
|
453 |
result := (self input read: 6).
|
|
454 |
self assert: result = #[ 1 1 2 2 3 3 ]
|
|
455 |
! !
|
109
|
456 |
|
10
|
457 |
!Xtreams::ReadingWritingTest methodsFor:'tests - transforming'!
|
|
458 |
|
|
459 |
testWriteTransforming2into1
|
|
460 |
| result |
|
|
461 |
(self output transforming: [:in :out | in get. out put: in get])
|
|
462 |
write: #[ 1 2 3 4 ];
|
|
463 |
close.
|
|
464 |
result := self input read: 2.
|
|
465 |
self assert: result = #[ 2 4 ]
|
|
466 |
! !
|
109
|
467 |
|
73
|
468 |
!Xtreams::ReadingWritingTest methodsFor:'tests - interpreting'!
|
10
|
469 |
|
73
|
470 |
testWriteUnsignedShortEndianness
|
|
471 |
|
|
472 |
(self output interpreting: #unsignedShort_le) put: 16rFF.
|
|
473 |
(self output interpreting: #unsignedShort_be) put: 16rFF00.
|
|
474 |
self output close.
|
|
475 |
self assert: (self input read: 4) = #[ 16rFF 16r00 16rFF 00]
|
|
476 |
! !
|
109
|
477 |
|
73
|
478 |
!stx_goodies_xtreams_transforms_tests class methodsFor:'documentation'!
|
|
479 |
|
109
|
480 |
extensionsVersion_HG
|
|
481 |
|
|
482 |
^ '$Changeset: <not expanded> $'
|
|
483 |
! ! |