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
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 : grapheme-break-test ( -- filename )
21 "vocab:unicode/breaks/GraphemeBreakTest.txt" ;
23 : word-break-test ( -- filename )
24 "vocab:unicode/breaks/WordBreakTest.txt" ;
26 : parse-test-file ( file-name -- tests )
28 [ "#" split1 drop ] map harvest [
32 [ [ blank? ] trim hex> ] map
33 [ { f 0 } member? ] reject
39 :: test ( tests quot -- )
42 [ concat [ quot call [ "" like ] map ] curry ] bi unit-test
45 : grapheme-test ( tests -- )
48 [ concat [ >graphemes [ "" like ] map ] curry ] bi unit-test
51 grapheme-break-test parse-test-file [ >graphemes ] test
52 word-break-test parse-test-file [ >words ] test
54 { { t f t t f t } } [ 6 <iota> [ "as df" word-break-at? ] map ] unit-test