1 USING: tools.test io.streams.byte-array io.encodings.binary
2 io.encodings.utf8 io kernel arrays strings namespaces math
3 specialized-arrays alien.c-types alien.data io.encodings.ascii ;
5 IN: io.streams.byte-array.tests
7 [ B{ } ] [ B{ } binary [ contents ] with-byte-reader ] unit-test
10 [ f ] [ B{ } binary [ 0 read ] with-byte-reader ] unit-test
11 [ f ] [ B{ } binary [ 1 read ] with-byte-reader ] unit-test
12 [ f ] [ B{ } ascii [ 0 read ] with-byte-reader ] unit-test
13 [ f ] [ B{ } ascii [ readln ] with-byte-reader ] unit-test
14 [ f f ] [ B{ } ascii [ "a" read-until ] with-byte-reader ] unit-test
15 [ f f ] [ B{ } binary [ { 2 } read-until ] with-byte-reader ] unit-test
18 [ B{ 1 2 3 } ] [ binary [ B{ 1 2 3 } write ] with-byte-writer ] unit-test
19 [ B{ 1 2 3 4 5 6 } ] [ binary [ B{ 1 2 3 } write B{ 4 5 6 } write ] with-byte-writer ] unit-test
20 [ B{ 1 2 3 } ] [ { 1 2 3 } binary [ 3 read ] with-byte-reader ] unit-test
22 [ B{ 0b11110101 0b10111111 0b10000000 0b10111111 0b11101111 0b10000000 0b10111111 0b11011111 0b10000000 CHAR: x } ]
23 [ { 0b101111111000000111111 0b1111000000111111 0b11111000000 CHAR: x } >string utf8 [ write ] with-byte-writer ] unit-test
24 [ { 0b1111111000000111111 } t ] [ { 0b11110001 0b10111111 0b10000000 0b10111111 } utf8 <byte-reader> stream-contents dup >array swap string? ] unit-test
27 B{ 0 121 120 0 0 0 0 0 0 } binary
28 [ 1 read drop "\0" read-until ] with-byte-reader
32 B{ 1 2 3 4 5 6 7 8 9 10 11 12 } binary
35 0 seek-absolute input-stream get stream-seek
37 2 seek-relative input-stream get stream-seek
39 -2 seek-end input-stream get stream-seek
41 0 seek-end input-stream get stream-seek
47 B{ 1 2 3 4 5 6 7 8 9 10 11 12 } binary [ tell-input ] with-byte-reader
50 ! Overly aggressive compiler optimizations
52 binary [ 123 >bignum write1 ] with-byte-writer
55 ! Writing specialized arrays to byte writers
56 [ int-array{ 1 2 3 } ] [
57 binary [ int-array{ 1 2 3 } write ] with-byte-writer