1 USING: ascii kernel math sequences splitting strings tools.test ;
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
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
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
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
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
28 { { "This" "is" "a" "split" "sentence" } }
29 [ "This is a split sentence" split-words ]
33 [ "OneWord" split-words ]
36 { { "a" "b" "c" "d" "e" "f" } }
37 [ "aXbYcXdYeXf" "XY" split ] unit-test
40 [ " " split-words ] unit-test
43 [ "hey" split-words ] unit-test
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
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
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
76 { { "hey" "world" "what's" "happening" } }
77 [ "heyAworldBwhat'sChappening" [ LETTER? ] split-when ] unit-test
78 { { { 2 } { 3 } { 5 1 } { 7 } } } [
80 [ dupd = dup [ [ 1 + ] dip ] when ] split-when nip
83 { { "hey" "world" "what's" "happening" } }
85 "heyAworldBwhat'sChappening" [ LETTER? ] split-when-slice
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
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
98 [ "afoobfooc" "foo" "bar" replace ] unit-test
101 [ "afoobfooc" "foo" "" replace ] unit-test
104 [ "afoobfooc" "" "bar" replace ] unit-test
107 [ "afoobfooc" "" "" replace ] unit-test
109 { "" } [ "" "" "" replace ] unit-test
111 { { "Thi" "s " "i" "s a sequence" } } [
112 "This is a sequence" { 3 5 6 } split-indices
116 "This" { 0 } split-indices