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