]> gitweb.factorcode.org Git - factor.git/blob - core/io/streams/byte-array/byte-array-tests.factor
1fe296f90a739f8c589ccf0745300bae5f11c9c7
[factor.git] / core / io / streams / byte-array / byte-array-tests.factor
1 USING: alien.c-types alien.data arrays io io.encodings.ascii
2 io.encodings.binary io.encodings.utf8 io.streams.byte-array
3 kernel math specialized-arrays strings tools.test ;
4 SPECIALIZED-ARRAY: int
5
6 { B{ } } [ B{ } binary [ contents ] with-byte-reader ] unit-test
7
8 ! Issue #70 github
9 { f } [ B{ } binary [ 0 read ] with-byte-reader ] unit-test
10 { f } [ B{ } binary [ 1 read ] with-byte-reader ] unit-test
11 { f } [ B{ } ascii [ 0 read ] with-byte-reader ] unit-test
12 { f } [ B{ } ascii [ readln ] with-byte-reader ] unit-test
13 { f f } [ B{ } ascii [ "a" read-until ] with-byte-reader ] unit-test
14 { f f } [ B{ } binary [ { 2 } read-until ] with-byte-reader ] unit-test
15
16
17 { B{ 1 2 3 } } [ binary [ B{ 1 2 3 } write ] with-byte-writer ] unit-test
18 { B{ 1 2 3 4 5 6 } } [ binary [ B{ 1 2 3 } write B{ 4 5 6 } write ] with-byte-writer ] unit-test
19 { B{ 1 2 3 } } [ { 1 2 3 } binary [ 3 read ] with-byte-reader ] unit-test
20
21 { B{ 0b11110101 0b10111111 0b10000000 0b10111111 0b11101111 0b10000000 0b10111111 0b11011111 0b10000000 CHAR: x } }
22 [ { 0b101111111000000111111 0b1111000000111111 0b11111000000 CHAR: x } >string utf8 [ write ] with-byte-writer ] unit-test
23 { { 0b1111111000000111111 } t } [ { 0b11110001 0b10111111 0b10000000 0b10111111 } utf8 <byte-reader> stream-contents dup >array swap string? ] unit-test
24
25 { B{ 121 120 } 0 } [
26     B{ 0 121 120 0 0 0 0 0 0 } binary
27     [ 1 read drop "\0" read-until ] with-byte-reader
28 ] unit-test
29
30
31 { B{ } 1 } [
32     B{ 1 2 3 } binary [ B{ 1 } read-until ] with-byte-reader
33 ] unit-test
34
35 { f f } [
36     B{ } binary [ B{ 0 } read-until ] with-byte-reader
37 ] unit-test
38
39 { 1 1 4 11 f } [
40     B{ 1 2 3 4 5 6 7 8 9 10 11 12 } binary
41     [
42         read1
43         0 seek-absolute seek-input
44         read1
45         2 seek-relative seek-input
46         read1
47         -2 seek-end seek-input
48         read1
49         0 seek-end seek-input
50         read1
51     ] with-byte-reader
52 ] unit-test
53
54 { 0 } [
55     B{ 1 2 3 4 5 6 7 8 9 10 11 12 } binary [ tell-input ] with-byte-reader
56 ] unit-test
57
58 ! Overly aggressive compiler optimizations
59 { B{ 123 } } [
60     binary [ 123 >bignum write1 ] with-byte-writer
61 ] unit-test
62
63 ! Writing specialized arrays to byte writers
64 { int-array{ 1 2 3 } } [
65     binary [ int-array{ 1 2 3 } write ] with-byte-writer
66     int cast-array
67 ] unit-test