]> gitweb.factorcode.org Git - factor.git/blob - core/io/streams/byte-array/byte-array-tests.factor
use radix literals
[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 [ 1 1 4 11 f ] [
32     B{ 1 2 3 4 5 6 7 8 9 10 11 12 } binary
33     [
34         read1
35         0 seek-absolute input-stream get stream-seek
36         read1
37         2 seek-relative input-stream get stream-seek
38         read1
39         -2 seek-end input-stream get stream-seek
40         read1
41         0 seek-end input-stream get stream-seek
42         read1
43     ] with-byte-reader
44 ] unit-test
45
46 [ 0 ] [
47     B{ 1 2 3 4 5 6 7 8 9 10 11 12 } binary [ tell-input ] with-byte-reader
48 ] unit-test
49
50 ! Overly aggressive compiler optimizations
51 [ B{ 123 } ] [
52     binary [ 123 >bignum write1 ] with-byte-writer
53 ] unit-test
54
55 ! Writing specialized arrays to byte writers
56 [ int-array{ 1 2 3 } ] [
57     binary [ int-array{ 1 2 3 } write ] with-byte-writer
58     int cast-array
59 ] unit-test