]> gitweb.factorcode.org Git - factor.git/blob - basis/unicode/breaks/breaks-tests.factor
unicode: Update to 11.0
[factor.git] / basis / unicode / breaks / breaks-tests.factor
1 USING: tools.test unicode sequences math kernel splitting
2 unicode.categories io.pathnames io.encodings.utf8 io.files
3 strings quotations math.parser locals ;
4 IN: unicode.breaks.tests
5
6 { "\u001112\u001161\u0011abA\u000300a\r\r\n" }
7 [ "\r\n\raA\u000300\u001112\u001161\u0011ab" string-reverse ] unit-test
8 { "dcba" } [ "abcd" string-reverse ] unit-test
9 { 3 } [ "\u001112\u001161\u0011abA\u000300a"
10         dup last-grapheme head last-grapheme ] unit-test
11
12 { 3 } [ 2 "hello" first-grapheme-from ] unit-test
13 { 1 } [ 2 "hello" last-grapheme-from ] unit-test
14
15 { 4 } [ 2 "what am I saying" first-word-from ] unit-test
16 { 0 } [ 2 "what am I saying" last-word-from ] unit-test
17 { 16 } [ 11 "what am I saying" first-word-from ] unit-test
18 { 10 } [ 11 "what am I saying" last-word-from ] unit-test
19
20 { { t f t t f t } } [ 6 <iota> [ "as df" word-break-at? ] map ] unit-test
21
22 : grapheme-break-test ( -- filename )
23     "vocab:unicode/UCD/auxiliary/GraphemeBreakTest.txt" ;
24
25 : word-break-test ( -- filename )
26     "vocab:unicode/UCD/auxiliary/WordBreakTest.txt" ;
27
28 : parse-test-file ( file-name -- tests )
29     utf8 file-lines
30     [ "#" split1 drop ] map harvest [
31         "÷" split
32         [
33             "×" split
34             [ [ blank? ] trim hex> ] map
35             [ { f 0 } member? ] reject
36             >string
37         ] map
38         harvest
39     ] map ;
40
41 :: test-unicode-breaks ( tests quot -- )
42     tests [
43         [ 1quotation ]
44         [ concat [ quot call [ "" like ] map ] curry ] bi unit-test
45     ] each ;
46
47 ! XXX: not used?
48 : grapheme-test ( tests -- )
49     [
50         [ 1quotation ]
51         [ concat [ >graphemes [ "" like ] map ] curry ] bi unit-test
52     ] each ;
53
54 : run-grapheme-break-tests ( -- )
55     grapheme-break-test parse-test-file [ >graphemes ] test-unicode-breaks ;
56
57 : run-word-break-tests ( -- )
58     word-break-test parse-test-file [ >words ] test-unicode-breaks ;