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