1 ! (c)2010 Joe Groff bsd license
2 USING: byte-arrays io.encodings.8-bit.koi8-r
3 io.encodings.8-bit.latin1 io.encodings.binary
4 io.encodings.detect io.encodings.utf16 io.encodings.utf32
5 io.encodings.utf8 namespaces tools.test ;
6 IN: io.encodings.detect.tests
8 ! UTF encodings with BOMs
9 { utf16be } [ B{ 0xFE 0xFF 0x00 0x31 0x00 0x32 0x00 0x33 } detect-byte-array ] unit-test
10 { utf16le } [ B{ 0xFF 0xFE 0x31 0x00 0x32 0x00 0x33 0x00 } detect-byte-array ] unit-test
11 { utf32be } [ B{ 0x00 0x00 0xFE 0xFF 0x00 0x00 0x00 0x31 0x00 0x00 0x00 0x32 0x00 0x00 0x00 0x33 } detect-byte-array ] unit-test
12 { utf32le } [ B{ 0xFF 0xFE 0x00 0x00 0x31 0x00 0x00 0x00 0x32 0x00 0x00 0x00 0x33 0x00 0x00 0x00 } detect-byte-array ] unit-test
13 { utf8 } [ B{ 0xEF 0xBB 0xBF 0x31 0x32 0x33 } detect-byte-array ] unit-test
17 [ "<?xml version=\"1.0\"?>" >byte-array detect-byte-array ]
21 [ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" >byte-array detect-byte-array ]
25 [ "<?xml version='1.0' encoding='ISO-8859-1'?>" >byte-array detect-byte-array ]
29 [ "<?xml version='1.0' encoding=\"ISO-8859-1\" " >byte-array detect-byte-array ]
32 ! Default to utf8 if decoding succeeds and there are no nulls
33 { utf8 } [ B{ } detect-byte-array ] unit-test
34 { utf8 } [ B{ 0x31 0x32 0x33 } detect-byte-array ] unit-test
35 { utf8 } [ B{ 0x31 0x32 0xC2 0xA0 0x33 } detect-byte-array ] unit-test
36 { latin1 } [ B{ 0x31 0x32 0xA0 0x33 } detect-byte-array ] unit-test
38 koi8-r default-8bit-encoding [
39 B{ 0x31 0x32 0xA0 0x33 } detect-byte-array
43 { binary } [ B{ 0x31 0x32 0x33 0xC2 0xA0 0x00 } detect-byte-array ] unit-test
44 { binary } [ B{ 0x31 0x32 0x33 0xC2 0xA0 0x00 0x30 } detect-byte-array ] unit-test