]> gitweb.factorcode.org Git - factor.git/blob - extra/io/encodings/detect/detect-tests.factor
78c8b1a55b85730093c5ea4e314e8173c4ab98fa
[factor.git] / extra / io / encodings / detect / detect-tests.factor
1 ! Copyright (C) 2010 Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: byte-arrays io.encodings.8-bit io.encodings.binary
4 io.encodings.detect io.encodings.latin1 io.encodings.utf16
5 io.encodings.utf32 io.encodings.utf8 namespaces tools.test ;
6
7 ! UTF encodings with BOMs
8 { utf16be } [ B{ 0xFE 0xFF 0x00 0x31 0x00 0x32 0x00 0x33 } detect-byte-array ] unit-test
9 { utf16le } [ B{ 0xFF 0xFE 0x31 0x00 0x32 0x00 0x33 0x00 } detect-byte-array ] unit-test
10 { utf32be } [ B{ 0x00 0x00 0xFE 0xFF 0x00 0x00 0x00 0x31 0x00 0x00 0x00 0x32 0x00 0x00 0x00 0x33 } detect-byte-array ] unit-test
11 { utf32le } [ B{ 0xFF 0xFE 0x00 0x00 0x31 0x00 0x00 0x00 0x32 0x00 0x00 0x00 0x33 0x00 0x00 0x00 } detect-byte-array ] unit-test
12 { utf8 } [ B{ 0xEF 0xBB 0xBF 0x31 0x32 0x33 } detect-byte-array ] unit-test
13
14 ! XML prolog
15 { utf8 }
16 [ "<?xml version=\"1.0\"?>" >byte-array detect-byte-array ]
17 unit-test
18
19 { utf8 }
20 [ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" >byte-array detect-byte-array ]
21 unit-test
22
23 { latin1 }
24 [ "<?xml version='1.0' encoding='ISO-8859-1'?>" >byte-array detect-byte-array ]
25 unit-test
26
27 { latin1 }
28 [ "<?xml version='1.0' encoding=\"ISO-8859-1\" " >byte-array detect-byte-array ]
29 unit-test
30
31 ! Default to utf8 if decoding succeeds and there are no nulls
32 { utf8 } [ B{ } detect-byte-array ] unit-test
33 { utf8 } [ B{ 0x31 0x32 0x33 } detect-byte-array ] unit-test
34 { utf8 } [ B{ 0x31 0x32 0xC2 0xA0 0x33 } detect-byte-array ] unit-test
35 { latin1 } [ B{ 0x31 0x32 0xA0 0x33 } detect-byte-array ] unit-test
36 { koi8-r } [
37     koi8-r default-encoding [
38         B{ 0x31 0x32 0xA0 0x33 } detect-byte-array
39     ] with-variable
40 ] unit-test
41
42 { binary } [ B{ 0x31 0x32 0x33 0xC2 0xA0 0x00 } detect-byte-array ] unit-test
43 { binary } [ B{ 0x31 0x32 0x33 0xC2 0xA0 0x00 0x30 } detect-byte-array ] unit-test