]> gitweb.factorcode.org Git - factor.git/blob - core/splitting/splitting-tests.factor
c44df593e1c588b1607c40c611b01bb88c6f77d6
[factor.git] / core / splitting / splitting-tests.factor
1 USING: splitting tools.test kernel sequences arrays strings ascii math ;
2 IN: splitting.tests
3
4 [ "hello" "world ." ] [ "hello world ." " " split1 ] unit-test
5 [ "hello" "world-+." ] [ "hello-+world-+." "-+" split1 ] unit-test
6 [ "goodbye" f ] [ "goodbye" " " split1 ] unit-test
7 [ "" "" ] [ "great" "great" split1 ] unit-test
8
9 [ "hello world" "." ] [ "hello world ." " " split1-last ] unit-test
10 [ "hello-+world" "." ] [ "hello-+world-+." "-+" split1-last ] unit-test
11 [ "goodbye" f ] [ "goodbye" " " split1-last ] unit-test
12 [ "" "" ] [ "great" "great" split1-last ] unit-test
13
14 [ "hello world" "." ] [ "hello world ." " " split1-last-slice [ >string ] bi@ ] unit-test
15 [ "hello-+world" "." ] [ "hello-+world-+." "-+" split1-last-slice [ >string ] bi@ ] unit-test
16 [ "goodbye" f ] [ "goodbye" " " split1-last-slice [ >string ] dip ] unit-test
17 [ "" f ] [ "great" "great" split1-last-slice [ >string ] dip ] unit-test
18
19 [ "and end" t ] [ "Beginning and end" "Beginning " ?head ] unit-test
20 [ "Beginning and end" f ] [ "Beginning and end" "Beginning x" ?head ] unit-test
21 [ "Beginning and end" f ] [ "Beginning and end" "eginning " ?head ] unit-test
22
23 [ "Beginning" t ] [ "Beginning and end" " and end" ?tail ] unit-test
24 [ "Beginning and end" f ] [ "Beginning and end" "Beginning x" ?tail ] unit-test
25 [ "Beginning and end" f ] [ "Beginning and end" "eginning " ?tail ] unit-test
26
27 [ { "This" "is" "a" "split" "sentence" } ]
28 [ "This is a split sentence" " " split ]
29 unit-test
30
31 [ { "OneWord" } ]
32 [ "OneWord" " " split ]
33 unit-test
34
35 [ { "a" "b" "c" "d" "e" "f" } ]
36 [ "aXbYcXdYeXf" "XY" split ] unit-test
37
38 [ { "" "" } ]
39 [ " " " " split ] unit-test
40
41 [ { "hey" } ]
42 [ "hey" " " split ] unit-test
43
44 [ "Hello world" t ] [ "Hello world\n" "\n" ?tail ] unit-test
45 [ "Hello world" f ] [ "Hello world" "\n" ?tail ] unit-test
46 [ "" t ] [ "\n" "\n" ?tail ] unit-test
47 [ "" f ] [ "" "\n" ?tail ] unit-test
48
49 [ { "" } ] [ "" string-lines ] unit-test
50 [ { "" "" } ] [ "\n" string-lines ] unit-test
51 [ { "" "" } ] [ "\r" string-lines ] unit-test
52 [ { "" "" } ] [ "\r\n" string-lines ] unit-test
53 [ { "hello" } ] [ "hello" string-lines ] unit-test
54 [ { "hello" "" } ] [ "hello\n" string-lines ] unit-test
55 [ { "hello" "" } ] [ "hello\r" string-lines ] unit-test
56 [ { "hello" "" } ] [ "hello\r\n" string-lines ] unit-test
57 [ { "hello" "hi" } ] [ "hello\nhi" string-lines ] unit-test
58 [ { "hello" "hi" } ] [ "hello\rhi" string-lines ] unit-test
59 [ { "hello" "hi" } ] [ "hello\r\nhi" string-lines ] unit-test
60
61 [ { "" } ] [ SBUF" " string-lines ] unit-test
62 [ { "" "" } ] [ SBUF" \n" string-lines ] unit-test
63 [ { "" "" } ] [ SBUF" \r" string-lines ] unit-test
64 [ { "" "" } ] [ SBUF" \r\n" string-lines ] unit-test
65 [ { "hello" } ] [ SBUF" hello" string-lines ] unit-test
66 [ { "hello" "" } ] [ SBUF" hello\n" string-lines ] unit-test
67 [ { "hello" "" } ] [ SBUF" hello\r" string-lines ] unit-test
68 [ { "hello" "" } ] [ SBUF" hello\r\n" string-lines ] unit-test
69 [ { "hello" "hi" } ] [ SBUF" hello\nhi" string-lines ] unit-test
70 [ { "hello" "hi" } ] [ SBUF" hello\rhi" string-lines ] unit-test
71 [ { "hello" "hi" } ] [ SBUF" hello\r\nhi" string-lines ] unit-test
72
73 [ { "hey" "world" "what's" "happening" } ]
74 [ "heyAworldBwhat'sChappening" [ LETTER? ] split-when ] unit-test
75 { { { 2 } { 3 } { 5 1 } { 7 } } } [
76     1 { 2 1 3 2 5 1 3 7 }
77     [ dupd = dup [ [ 1 + ] dip ] when ] split-when nip
78 ] unit-test
79
80 [ { "hey" "world" "what's" "happening" } ]
81 [
82     "heyAworldBwhat'sChappening" [ LETTER? ] split-when-slice
83     [ >string ] map
84 ] unit-test
85
86 [ "" f ] [ "" [ blank? ] split1-when ] unit-test
87 [ "" "ABC" ] [ " ABC" [ blank? ] split1-when ] unit-test
88 [ "a" " bc" ] [ "a  bc" [ blank? ] split1-when ] unit-test
89
90 [ "" f ] [ "" [ blank? ] split1-when-slice ] unit-test
91 [ "" "ABC" ] [ " ABC" [ blank? ] split1-when-slice [ >string ] bi@ ] unit-test
92 [ "a" " bc" ] [ "a  bc" [ blank? ] split1-when-slice [ >string ] bi@ ] unit-test
93
94 { "abarbbarc" }
95 [ "afoobfooc" "foo" "bar" replace ] unit-test
96
97 { "abc" }
98 [ "afoobfooc" "foo" "" replace ] unit-test
99
100 { "afoobfooc" }
101 [ "afoobfooc" "" "bar" replace ] unit-test
102
103 { "afoobfooc" }
104 [ "afoobfooc" "" "" replace ] unit-test
105
106 { "" } [ "" "" "" replace ] unit-test
107
108 { { "Thi" "s " "i" "s a sequence" } } [
109     "This is a sequence" { 3 5 6 } split-indices
110 ] unit-test
111
112 { { "" "This" } } [
113     "This" { 0 } split-indices
114 ] unit-test