]> gitweb.factorcode.org Git - factor.git/blob - core/io/streams/byte-array/byte-array-tests.factor
factor: Retrying on the unit tests. Also normalize some syntax with FUNCTION:.
[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 alien.data io.encodings.ascii ;
4 SPECIALIZED-ARRAY: int
5 IN: io.streams.byte-array.tests
6
7 { B{ } } [ B{ } binary [ contents ] with-byte-reader ] unit-test
8
9 ! Issue #70 github
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
16
17
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
21
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
25
26 { B{ 121 120 } 0 } [
27     B{ 0 121 120 0 0 0 0 0 0 } binary
28     [ 1 read drop "\0" read-until ] with-byte-reader
29 ] unit-test
30
31
32 { B{ } 1 } [
33     B{ 1 2 3 } binary [ B{ 1 } read-until ] with-byte-reader
34 ] unit-test
35
36 { f f } [
37     B{ } binary [ B{ 0 } read-until ] with-byte-reader
38 ] unit-test
39
40 { 1 1 4 11 f } [
41     B{ 1 2 3 4 5 6 7 8 9 10 11 12 } binary
42     [
43         read1
44         0 seek-absolute seek-input
45         read1
46         2 seek-relative seek-input
47         read1
48         -2 seek-end seek-input
49         read1
50         0 seek-end seek-input
51         read1
52     ] with-byte-reader
53 ] unit-test
54
55 { 0 } [
56     B{ 1 2 3 4 5 6 7 8 9 10 11 12 } binary [ tell-input ] with-byte-reader
57 ] unit-test
58
59 ! Overly aggressive compiler optimizations
60 { B{ 123 } } [
61     binary [ 123 >bignum write1 ] with-byte-writer
62 ] unit-test
63
64 ! Writing specialized arrays to byte writers
65 { int-array{ 1 2 3 } } [
66     binary [ int-array{ 1 2 3 } write ] with-byte-writer
67     int cast-array
68 ] unit-test