]> gitweb.factorcode.org Git - factor.git/blob - basis/unicode/breaks/breaks-tests.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / basis / unicode / breaks / breaks-tests.factor
1 USING: tools.test unicode.breaks 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 : grapheme-break-test ( -- filename )
13     "vocab:unicode/breaks/GraphemeBreakTest.txt" ;
14
15 : word-break-test ( -- filename )
16     "vocab:unicode/breaks/WordBreakTest.txt" ;
17
18 : parse-test-file ( file-name -- tests )
19     utf8 file-lines
20     [ "#" split1 drop ] map harvest [
21         "÷" split
22         [ "×" split [ [ blank? ] trim hex> ] map harvest >string ] map
23         harvest
24     ] map ;
25
26 :: test ( tests quot -- )
27     tests [
28         [ 1quotation ]
29         [ concat [ quot call [ "" like ] map ] curry ] bi unit-test
30     ] each ;
31
32 : grapheme-test ( tests quot -- )
33     [
34         [ 1quotation ]
35         [ concat [ >graphemes [ "" like ] map ] curry ] bi unit-test
36     ] each ;
37
38 grapheme-break-test parse-test-file [ >graphemes ] test
39 word-break-test parse-test-file [ >words ] test