factor/basis/unicode/breaks/breaks-tests.factor

55 lines
1.7 KiB
Factor
Raw Normal View History

2009-01-06 11:19:19 -05:00
USING: tools.test unicode.breaks sequences math kernel splitting
unicode.categories io.pathnames io.encodings.utf8 io.files
2009-01-07 13:23:07 -05:00
strings quotations math.parser locals ;
2009-01-06 11:19:19 -05:00
IN: unicode.breaks.tests
2007-09-20 18:09:08 -04:00
{ "\u001112\u001161\u0011abA\u000300a\r\r\n" }
[ "\r\n\raA\u000300\u001112\u001161\u0011ab" string-reverse ] unit-test
{ "dcba" } [ "abcd" string-reverse ] unit-test
{ 3 } [ "\u001112\u001161\u0011abA\u000300a"
dup last-grapheme head last-grapheme ] unit-test
2009-01-06 11:19:19 -05:00
{ 3 } [ 2 "hello" first-grapheme-from ] unit-test
{ 1 } [ 2 "hello" last-grapheme-from ] unit-test
{ 4 } [ 2 "what am I saying" first-word-from ] unit-test
{ 0 } [ 2 "what am I saying" last-word-from ] unit-test
{ 16 } [ 11 "what am I saying" first-word-from ] unit-test
{ 10 } [ 11 "what am I saying" last-word-from ] unit-test
2009-01-06 11:19:19 -05:00
: grapheme-break-test ( -- filename )
2009-02-15 20:53:21 -05:00
"vocab:unicode/breaks/GraphemeBreakTest.txt" ;
2009-01-06 11:19:19 -05:00
2009-01-07 13:23:07 -05:00
: word-break-test ( -- filename )
2009-02-15 20:53:21 -05:00
"vocab:unicode/breaks/WordBreakTest.txt" ;
2009-01-07 13:23:07 -05:00
: parse-test-file ( file-name -- tests )
utf8 file-lines
2009-01-06 11:19:19 -05:00
[ "#" split1 drop ] map harvest [
"÷" split
2010-01-14 10:10:13 -05:00
[
"×" split
[ [ blank? ] trim hex> ] map
[ { f 0 } member? ] reject
2010-01-14 10:10:13 -05:00
>string
] map
2009-01-06 11:19:19 -05:00
harvest
] map ;
2009-01-07 13:23:07 -05:00
:: test ( tests quot -- )
tests [
[ 1quotation ]
[ concat [ quot call [ "" like ] map ] curry ] bi unit-test
] each ;
2009-04-22 08:05:00 -04:00
: grapheme-test ( tests -- )
2009-01-06 11:19:19 -05:00
[
[ 1quotation ]
[ concat [ >graphemes [ "" like ] map ] curry ] bi unit-test
] each ;
2009-01-07 13:23:07 -05:00
grapheme-break-test parse-test-file [ >graphemes ] test
2009-01-07 16:08:08 -05:00
word-break-test parse-test-file [ >words ] test
2009-03-11 16:51:54 -04:00
{ { t f t t f t } } [ 6 iota [ "as df" word-break-at? ] map ] unit-test