]> gitweb.factorcode.org Git - factor.git/blob - basis/unicode/normalize/normalize-tests.factor
Add vocab: for vocab-relative paths
[factor.git] / basis / unicode / normalize / normalize-tests.factor
1 USING: unicode.normalize kernel tools.test sequences
2 unicode.data io.encodings.utf8 io.files splitting math.parser
3 locals math quotations assocs combinators unicode.normalize.private ;
4 IN: unicode.normalize.tests
5
6 { nfc nfkc nfd nfkd } [ must-infer ] each
7
8 [ "ab\u000323\u000302cd" ] [ "ab\u000302" "\u000323cd" string-append ] unit-test
9
10 [ "ab\u00064b\u000347\u00034e\u00034d\u000346" ] [ "ab\u000346\u000347\u00064b\u00034e\u00034d" dup reorder ] unit-test
11 [ "hello" "hello" ] [ "hello" [ nfd ] keep nfkd ] unit-test
12 [ "\u00FB012\u002075\u00017F\u000323\u000307" "fi25s\u000323\u000307" ]
13 [ "\u00FB012\u002075\u001E9B\u000323" [ nfd ] keep nfkd ] unit-test
14
15 [ "\u001E69" "s\u000323\u000307" ] [ "\u001E69" [ nfc ] keep nfd ] unit-test
16 [ "\u001E0D\u000307" ] [ "\u001E0B\u000323" nfc ] unit-test
17
18 [ 54620 ] [ 4370 4449 4523 jamo>hangul ] unit-test
19 [ 4370 4449 4523 ] [ 54620 hangul>jamo first3 ] unit-test
20 [ t ] [ 54620 hangul? ] unit-test
21 [ f ] [ 0 hangul? ] unit-test
22 [ "\u001112\u001161\u0011ab" ] [ "\u00d55c" nfd ] unit-test
23 [ "\u00d55c" ] [ "\u001112\u001161\u0011ab" nfc ] unit-test
24
25 : parse-test ( -- tests )
26     "vocab:unicode/normalize/NormalizationTest.txt"
27     utf8 file-lines filter-comments
28     [ ";" split 5 head [ " " split [ hex> ] "" map-as ] map ] map ;
29
30 :: assert= ( test spec quot -- )
31     spec [
32         [
33             [ 1- test nth ] bi@
34             [ 1quotation ] [ quot curry ] bi* unit-test
35         ] with each
36     ] assoc-each ;
37
38 : run-line ( test -- )
39     {
40         [ { { 2 { 1 2 3 } } { 4 { 4 5 } } } [ nfc ] assert= ]
41         [ { { 3 { 1 2 3 } } { 5 { 4 5 } } } [ nfd ] assert= ]
42         [ { { 4 { 1 2 3 4 5 } } } [ nfkc ] assert= ]
43         [ { { 5 { 1 2 3 4 5 } } } [ nfkd ] assert= ]
44     } cleave ;
45
46 parse-test [ run-line ] each