]> gitweb.factorcode.org Git - factor.git/blob - basis/unicode/breaks/breaks-tests.factor
Merge branch 'master' of git://factorcode.org/git/factor into clean-linux-x86-32
[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 [ 3 ] [ 2 "hello" first-grapheme-from ] unit-test
13 [ 1 ] [ 2 "hello" last-grapheme-from ] unit-test
14
15 : grapheme-break-test ( -- filename )
16     "vocab:unicode/breaks/GraphemeBreakTest.txt" ;
17
18 : word-break-test ( -- filename )
19     "vocab:unicode/breaks/WordBreakTest.txt" ;
20
21 : parse-test-file ( file-name -- tests )
22     utf8 file-lines
23     [ "#" split1 drop ] map harvest [
24         "÷" split
25         [ "×" split [ [ blank? ] trim hex> ] map harvest >string ] map
26         harvest
27     ] map ;
28
29 :: test ( tests quot -- )
30     tests [
31         [ 1quotation ]
32         [ concat [ quot call [ "" like ] map ] curry ] bi unit-test
33     ] each ;
34
35 : grapheme-test ( tests -- )
36     [
37         [ 1quotation ]
38         [ concat [ >graphemes [ "" like ] map ] curry ] bi unit-test
39     ] each ;
40
41 grapheme-break-test parse-test-file [ >graphemes ] test
42 word-break-test parse-test-file [ >words ] test
43
44 [ { t f t t f t } ] [ 6 [ "as df" word-break-at? ] map ] unit-test