]> gitweb.factorcode.org Git - factor.git/blob - core/io/streams/byte-array/byte-array-tests.factor
Merge branch 'master' of git://factorcode.org/git/factor
[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 ;
3
4 [ B{ 1 2 3 } ] [ binary [ B{ 1 2 3 } write ] with-byte-writer ] unit-test
5 [ B{ 1 2 3 } ] [ { 1 2 3 } binary [ 3 read ] with-byte-reader ] unit-test
6
7 [ B{ BIN: 11110101 BIN: 10111111 BIN: 10000000 BIN: 10111111 BIN: 11101111 BIN: 10000000 BIN: 10111111 BIN: 11011111 BIN: 10000000 CHAR: x } ]
8 [ { BIN: 101111111000000111111 BIN: 1111000000111111 BIN: 11111000000 CHAR: x } >string utf8 [ write ] with-byte-writer ] unit-test
9 [ { BIN: 101111111000000111111 } t ] [ { BIN: 11110101 BIN: 10111111 BIN: 10000000 BIN: 10111111 } utf8 <byte-reader> stream-contents dup >array swap string? ] unit-test
10
11 [ B{ 121 120 } 0 ] [
12     B{ 0 121 120 0 0 0 0 0 0 } binary
13     [ 1 read drop "\0" read-until ] with-byte-reader
14 ] unit-test
15
16 [ 1 1 4 11 f ] [
17     B{ 1 2 3 4 5 6 7 8 9 10 11 12 } binary
18     [
19         read1
20         0 seek-absolute input-stream get stream-seek
21         read1
22         2 seek-relative input-stream get stream-seek
23         read1
24         -2 seek-end input-stream get stream-seek
25         read1
26         0 seek-end input-stream get stream-seek
27         read1
28     ] with-byte-reader
29 ] unit-test