]> gitweb.factorcode.org Git - factor.git/blob - core/io/encodings/utf8/utf8-tests.factor
More changes for encodings
[factor.git] / core / io / encodings / utf8 / utf8-tests.factor
1 USING: io.encodings.utf8 tools.test sbufs kernel io io.encodings
2 sequences strings arrays unicode ;
3
4 : decode-utf8-w/stream ( array -- newarray )
5     >sbuf dup reverse-here utf8 <decoded> contents ;
6
7 : encode-utf8-w/stream ( array -- newarray )
8     SBUF" " clone tuck utf8 <encoded> stream-write >array ;
9
10 [ { CHAR: replacement-character } ] [ { BIN: 11110101 BIN: 10111111 BIN: 10000000 BIN: 11111111 } decode-utf8-w/stream >array ] unit-test
11
12 [ { BIN: 101111111000000111111 } ] [ { BIN: 11110101 BIN: 10111111 BIN: 10000000 BIN: 10111111 } decode-utf8-w/stream >array ] unit-test
13
14 [ "x" ] [ "x" decode-utf8-w/stream >string ] unit-test
15
16 [ { BIN: 11111000000 } ] [ { BIN: 11011111 BIN: 10000000 } decode-utf8-w/stream >array ] unit-test
17
18 [ { CHAR: replacement-character } ] [ { BIN: 10000000 } decode-utf8-w/stream >array ] unit-test
19
20 [ { BIN: 1111000000111111 } ] [ { BIN: 11101111 BIN: 10000000 BIN: 10111111 } decode-utf8-w/stream >array ] unit-test
21
22 [ { BIN: 11110101 BIN: 10111111 BIN: 10000000 BIN: 10111111 BIN: 11101111 BIN: 10000000 BIN: 10111111 BIN: 11011111 BIN: 10000000 CHAR: x } ]
23 [ { BIN: 101111111000000111111 BIN: 1111000000111111 BIN: 11111000000 CHAR: x } encode-utf8-w/stream ] unit-test