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
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
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
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
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
26 { { "This" "is" "a" "split" "sentence" } }
27 [ "This is a split sentence" " " split ]
31 [ "OneWord" " " split ]
34 { { "a" "b" "c" "d" "e" "f" } }
35 [ "aXbYcXdYeXf" "XY" split ] unit-test
38 [ " " " " split ] unit-test
41 [ "hey" " " split ] unit-test
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
48 { { } } [ "" string-lines ] unit-test
49 { { "" } } [ "\n" string-lines ] unit-test
50 { { "" } } [ "\r" string-lines ] unit-test
51 { { "" } } [ "\r\n" string-lines ] unit-test
52 { { "hello" } } [ "hello" string-lines ] unit-test
53 { { "hello" } } [ "hello\n" string-lines ] unit-test
54 { { "hello" } } [ "hello\r" string-lines ] unit-test
55 { { "hello" } } [ "hello\r\n" string-lines ] unit-test
56 { { "hello" "hi" } } [ "hello\nhi" string-lines ] unit-test
57 { { "hello" "hi" } } [ "hello\rhi" string-lines ] unit-test
58 { { "hello" "hi" } } [ "hello\r\nhi" string-lines ] unit-test
59 { { "hello" "" "" } } [ "hello\n\n\n" string-lines ] unit-test
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 { { "hello" "" "" } } [ SBUF" hello\n\n\n" string-lines ] unit-test
74 { { "hey" "world" "what's" "happening" } }
75 [ "heyAworldBwhat'sChappening" [ LETTER? ] split-when ] unit-test
76 { { { 2 } { 3 } { 5 1 } { 7 } } } [
78 [ dupd = dup [ [ 1 + ] dip ] when ] split-when nip
81 { { "hey" "world" "what's" "happening" } }
83 "heyAworldBwhat'sChappening" [ LETTER? ] split-when-slice
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
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
96 [ "afoobfooc" "foo" "bar" replace ] unit-test
99 [ "afoobfooc" "foo" "" replace ] unit-test
102 [ "afoobfooc" "" "bar" replace ] unit-test
105 [ "afoobfooc" "" "" replace ] unit-test
107 { "" } [ "" "" "" replace ] unit-test
109 { { "Thi" "s " "i" "s a sequence" } } [
110 "This is a sequence" { 3 5 6 } split-indices
114 "This" { 0 } split-indices