1 USING: http.download io.encodings.utf8 io.files io.files.temp
2 kernel math.parser quotations sequences splitting strings
4 IN: unicode.breaks.tests
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
12 { 3 } [ 2 "hello" first-grapheme-from ] unit-test
13 { 1 } [ 2 "hello" last-grapheme-from ] unit-test
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
20 { { t f t t f t } } [ 6 <iota> [ "as df" word-break-at? ] map ] unit-test
22 : grapheme-break-test ( -- filename )
23 "https://downloads.factorcode.org/misc/UCD/15.1.0/auxiliary/GraphemeBreakTest.txt"
24 "GraphemeBreakTest-15.1.0.txt" cache-file download-to ;
26 : word-break-test ( -- filename )
27 "https://downloads.factorcode.org/misc/UCD/15.1.0/auxiliary/WordBreakTest.txt"
28 "WordBreakTest-15.1.0.txt" cache-file download-to ;
30 : parse-test-file ( file-name -- tests )
32 [ "#" split1 drop ] map harvest [
36 [ [ blank? ] trim hex> ] map
37 [ { f 0 } member? ] reject
43 :: test-unicode-breaks ( tests quot -- )
46 [ concat [ quot call [ "" like ] map ] curry ] bi unit-test
50 : grapheme-test ( tests -- )
53 [ concat [ >graphemes [ "" like ] map ] curry ] bi unit-test
56 : run-grapheme-break-tests ( -- )
57 grapheme-break-test parse-test-file [ >graphemes ] test-unicode-breaks ;
59 : run-word-break-tests ( -- )
60 word-break-test parse-test-file [ >words ] test-unicode-breaks ;