]> gitweb.factorcode.org Git - factor.git/blob - core/io/encodings/utf8/utf8-tests.factor
088131acf9e0a0ba6c90a0ed2d99efc7b5509cc1
[factor.git] / core / io / encodings / utf8 / utf8-tests.factor
1 USING: io.encodings.utf8 tools.test io.encodings.string strings arrays
2 bootstrap.unicode kernel sequences ;
3 IN: io.encodings.utf8.tests
4
5 : decode-utf8-w/stream ( array -- newarray )
6     utf8 decode >array ;
7
8 : encode-utf8-w/stream ( array -- newarray )
9     >string utf8 encode >array ;
10
11 [ { CHAR: replacement-character } ] [ { BIN: 11110101 BIN: 10111111 BIN: 10000000 BIN: 11111111 } decode-utf8-w/stream ] unit-test
12
13 [ { BIN: 101111111000000111111 } ] [ { BIN: 11110101 BIN: 10111111 BIN: 10000000 BIN: 10111111 } decode-utf8-w/stream ] unit-test
14
15 [ "x" ] [ "x" decode-utf8-w/stream >string ] unit-test
16
17 [ { BIN: 11111000000 } ] [ { BIN: 11011111 BIN: 10000000 } decode-utf8-w/stream >array ] unit-test
18
19 [ { CHAR: replacement-character } ] [ { BIN: 10000000 } decode-utf8-w/stream ] unit-test
20
21 [ { BIN: 1111000000111111 } ] [ { BIN: 11101111 BIN: 10000000 BIN: 10111111 } decode-utf8-w/stream >array ] unit-test
22
23 [ { BIN: 11110101 BIN: 10111111 BIN: 10000000 BIN: 10111111 BIN: 11101111 BIN: 10000000 BIN: 10111111 BIN: 11011111 BIN: 10000000 CHAR: x } ]
24 [ { BIN: 101111111000000111111 BIN: 1111000000111111 BIN: 11111000000 CHAR: x } encode-utf8-w/stream ] unit-test
25
26 [ 3 ] [ 1 "日本語" >utf8-index ] unit-test
27 [ 3 ] [ 9 "日本語" utf8-index> ] unit-test
28
29 [ 3 ] [ 2 "lápis" >utf8-index ] unit-test
30
31 [ V{ } ] [ 100000 [ [ code-point-length ] [ 1string utf8 encode length ] bi = not ] filter ] unit-test