1 USING: arrays continuations io.streams.null kernel
2 kernel.private literals make math math.order memory namespaces
3 prettyprint sbufs sequences strings strings.private tools.test
6 { CHAR: b } [ 1 >bignum "abc" nth ] unit-test
8 { } [ 10 [ [ -1000000 <sbuf> ] ignore-errors ] times ] unit-test
10 { "abc" } [ [ "a" "b" "c" ] [ [ % ] each ] "" make ] unit-test
12 { "abc" } [ "ab" "c" append ] unit-test
13 { "abc" } [ "a" "b" "c" 3append ] unit-test
15 { 3 } [ "a" "hola" subseq-start ] unit-test
16 { f } [ "x" "hola" subseq-start ] unit-test
17 { 0 } [ "" "a" subseq-start ] unit-test
18 { 0 } [ "" "" subseq-start ] unit-test
19 { 0 } [ "hola" "hola" subseq-start ] unit-test
20 { 1 } [ "ol" "hola" subseq-start ] unit-test
21 { f } [ "amigo" "hola" subseq-start ] unit-test
22 { f } [ "holaa" "hola" subseq-start ] unit-test
24 { 3 } [ "hola" "a" subseq-index ] unit-test
25 { f } [ "hola" "x" subseq-index ] unit-test
26 { 0 } [ "a" "" subseq-index ] unit-test
27 { 0 } [ "" "" subseq-index ] unit-test
28 { 0 } [ "hola" "hola" subseq-index ] unit-test
29 { 1 } [ "hola" "ol" subseq-index ] unit-test
30 { f } [ "hola" "amigo" subseq-index ] unit-test
31 { f } [ "hola" "holaa" subseq-index ] unit-test
33 { "Beginning" } [ "Beginning and end" 9 head ] unit-test
35 { f } [ CHAR: I "team" member? ] unit-test
36 { t } [ "ea" "team" subseq? ] unit-test
37 { f } [ "actore" "Factor" subseq? ] unit-test
38 { t } [ "team" "ea" subseq-index? ] unit-test
39 { f } [ "Factor" "actore" subseq-index? ] unit-test
41 { "end" } [ "Beginning and end" 14 tail ] unit-test
43 { t } [ "abc" "abd" before? ] unit-test
44 { t } [ "z" "abd" after? ] unit-test
45 { "abc" } [ "abc" "abd" min ] unit-test
46 { "z" } [ "z" "abd" max ] unit-test
48 [ 0 10 "hello" subseq ] must-fail
50 { "Replacing+spaces+with+plus" }
52 "Replacing spaces with plus"
53 [ dup CHAR: \s = [ drop CHAR: + ] when ] map
57 { "05" } [ "5" 2 CHAR: 0 pad-head ] unit-test
58 { "666" } [ "666" 2 CHAR: 0 pad-head ] unit-test
60 [ 1 "" nth ] must-fail
61 [ -6 "hello" nth ] must-fail
63 { t } [ "hello world" dup >vector >string = ] unit-test
65 { "ab" } [ 2 "abc" resize-string ] unit-test
66 { "abc\0\0\0" } [ 6 "abc" resize-string ] unit-test
68 { "\u001234b" } [ 2 "\u001234bc" resize-string ] unit-test
69 { "\u001234bc\0\0\0" } [ 6 "\u001234bc" resize-string ] unit-test
71 ! Random tester found this
72 [ 2 -7 resize-string ]
73 [ ${ KERNEL-ERROR ERROR-TYPE 11 -7 } = ] must-fail-with
75 ! Make sure 24-bit strings work
78 { } [ 0x1234 1 "s" get set-nth ] unit-test
79 { 0x1234 } [ 1 "s" get nth ] unit-test
81 { } [ 0x4321 3 "s" get set-nth ] unit-test
82 { 0x4321 } [ 3 "s" get nth ] unit-test
84 { } [ 0x654321 5 "s" get set-nth ] unit-test
85 { 0x654321 } [ 5 "s" get nth ] unit-test
105 ! Make sure string initialization works
106 { 0x123456 } [ 100 0x123456 <string> first ] unit-test
108 ! Make sure we clear aux vector when storing octets
109 { "\u123456hi" } [ "ih\u123456" clone reverse! ] unit-test
111 ! Make sure aux vector is not shared
114 CHAR: \u123456 over clone set-first
121 100 [ "obdurak" clone ] replicate
124 1234 0 rot set-string-nth
137 300 100 CHAR: \u123456
138 [ <string> clone resize-string first ] keep =
143 { } [ 0x100,0000 0 "s" get set-nth ] unit-test
144 { 0 } [ 0 "s" get nth ] unit-test
146 { } [ -1 0 "s" get set-nth ] unit-test
147 { 0x7fffff } [ 0 "s" get nth ] unit-test