]> gitweb.factorcode.org Git - factor.git/blob - core/io/streams/byte-array/byte-array-tests.factor
2a7de28b8b26780f8843ce0b8df5653ac4a6975d
[factor.git] / core / io / streams / byte-array / byte-array-tests.factor
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 ;
4 SPECIALIZED-ARRAY: int
5 IN: io.streams.byte-array.tests
6
7 [ B{ } ] [ B{ } binary [ contents ] with-byte-reader ] unit-test
8 [ B{ 1 2 3 } ] [ binary [ B{ 1 2 3 } write ] with-byte-writer ] unit-test
9 [ B{ 1 2 3 4 5 6 } ] [ binary [ B{ 1 2 3 } write B{ 4 5 6 } write ] with-byte-writer ] unit-test
10 [ B{ 1 2 3 } ] [ { 1 2 3 } binary [ 3 read ] with-byte-reader ] unit-test
11 [ B{ 1 2 } ] [ B{ 1 2 3 4 } binary [ 2 peek ] with-byte-reader ] unit-test
12
13 [ B{ BIN: 11110101 BIN: 10111111 BIN: 10000000 BIN: 10111111 BIN: 11101111 BIN: 10000000 BIN: 10111111 BIN: 11011111 BIN: 10000000 CHAR: x } ]
14 [ { BIN: 101111111000000111111 BIN: 1111000000111111 BIN: 11111000000 CHAR: x } >string utf8 [ write ] with-byte-writer ] unit-test
15 [ { BIN: 1111111000000111111 } t ] [ { BIN: 11110001 BIN: 10111111 BIN: 10000000 BIN: 10111111 } utf8 <byte-reader> stream-contents dup >array swap string? ] unit-test
16
17 [ B{ 121 120 } 0 ] [
18     B{ 0 121 120 0 0 0 0 0 0 } binary
19     [ 1 read drop "\0" read-until ] with-byte-reader
20 ] unit-test
21
22 [ 1 1 4 11 f ] [
23     B{ 1 2 3 4 5 6 7 8 9 10 11 12 } binary
24     [
25         read1
26         0 seek-absolute input-stream get stream-seek
27         read1
28         2 seek-relative input-stream get stream-seek
29         read1
30         -2 seek-end input-stream get stream-seek
31         read1
32         0 seek-end input-stream get stream-seek
33         read1
34     ] with-byte-reader
35 ] unit-test
36
37 [ 0 ] [
38     B{ 1 2 3 4 5 6 7 8 9 10 11 12 } binary [ tell-input ] with-byte-reader
39 ] unit-test
40
41 ! Overly aggressive compiler optimizations
42 [ B{ 123 } ] [
43     binary [ 123 >bignum write1 ] with-byte-writer
44 ] unit-test
45
46 ! Writing specialized arrays to byte writers
47 [ int-array{ 1 2 3 } ] [
48     binary [ int-array{ 1 2 3 } write ] with-byte-writer
49     int-array-cast
50 ] unit-test