]> gitweb.factorcode.org Git - factor.git/blob - basis/unicode/normalize/normalize-tests.factor
unicode: update to 15.1.0
[factor.git] / basis / unicode / normalize / normalize-tests.factor
1 USING: arrays assocs combinators combinators.short-circuit
2 grouping http.client io.encodings.utf8 io.files io.files.temp
3 io.streams.null kernel locals math math.parser quotations random
4 sequences splitting splitting.extras strings tools.test unicode
5 unicode.normalize.private ;
6 IN: unicode.normalize.tests
7
8 { "ab\u000323\u000302cd" } [ "ab\u000302" "\u000323cd" string-append ] unit-test
9
10 { "ab\u00064b\u000347\u00034e\u00034d\u000346" }
11 [ "ab\u000346\u000347\u00064b\u00034e\u00034d" dup reorder ] unit-test
12
13 { "hello" "hello" } [ "hello" [ nfd ] keep nfkd ] unit-test
14
15 { "\u00FB012\u002075\u00017F\u000323\u000307" "fi25s\u000323\u000307" }
16 [ "\u00FB012\u002075\u001E9B\u000323" [ nfd ] keep nfkd ] unit-test
17
18 { "\u001E69" "s\u000323\u000307" } [ "\u001E69" [ nfc ] keep nfd ] unit-test
19 { "\u001E0D\u000307" } [ "\u001E0B\u000323" nfc ] unit-test
20
21 { 54620 } [ 4370 4449 4523 jamo>hangul ] unit-test
22 { 4370 4449 4523 } [ 54620 hangul>jamo first3 ] unit-test
23 { t } [ 54620 hangul? ] unit-test
24 { f } [ 0 hangul? ] unit-test
25 { "\u001112\u001161\u0011ab" } [ "\u00d55c" nfd ] unit-test
26 { "\u00d55c" } [ "\u001112\u001161\u0011ab" nfc ] unit-test
27
28 ! Could use simple-flat-file after some cleanup
29 : parse-normalization-tests ( -- tests )
30     "https://downloads.factorcode.org/misc/UCD/15.1.0/NormalizationTest.txt"
31     "NormalizationTest-15.1.0.txt" cache-file [ ?download-to ] keep
32     utf8 file-lines [ "#" head? ] reject
33     [ "@" head? ] split*-when
34     2 <groups> [ first2 [ first ] dip 2array ] map
35     values [
36         [
37             "#@" split first [ CHAR: \s = ] trim-tail ";" split harvest
38             [ split-words [ hex> ] "" map-as ] map
39         ] map
40     ] map concat ;
41
42 :: check-normalization-test? ( test spec quot -- ? )
43     spec [
44         [
45             [ 1 - test nth ] bi@ quot call( str -- str' ) =
46         ] with all?
47     ] assoc-all? ;
48
49 { { } } [
50     parse-normalization-tests [
51         {
52             [ { { 2 { 1 2 3 } } { 4 { 4 5 } } } [ nfc ] check-normalization-test? ]
53             [ { { 3 { 1 2 3 } } { 5 { 4 5 } } } [ nfd ] check-normalization-test? ]
54             [ { { 4 { 1 2 3 4 5 } } } [ nfkc ] check-normalization-test? ]
55             [ { { 5 { 1 2 3 4 5 } } } [ nfkd ] check-normalization-test? ]
56         } 1&&
57     ] reject
58 ] unit-test
59
60 { { 4018 820 3953 3968 } }
61 [ { 3958 3953 820 } >string nfd >array ] unit-test