-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstring.test.fs
130 lines (101 loc) · 3.11 KB
/
string.test.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
require string.fs
require list.fs
also list.fs
also string.fs
: between ( a b c -- t )
rot dup >r
swap <=
swap r> swap >=
and
;
: must-equal <> if abort" " else ." OK" then ;
variable str
variable tokens
: run-test
." string:print -> "
s" Hello, world! " string:create string:print ." visually assert: Hello, world!" cr
." string:to-number -> "
s" 123" string:create string:to-number drop 123 must-equal cr
." string:tokenize -> "
s" A,BC,DEF,GHIJ" string:create str !
[char] , str @ string:tokenize tokens !
tokens @ list:length 4 must-equal cr
." string:for-each -> "
tokens @ [: ." Token: " string:print space ;] swap list:for-each ." visually assert: A,BC,DEF,GHIJ" cr
." string:nth -> "
s" Hello, world" string:create 4 string:nth [char] o must-equal cr
." string:compare -> "
s" foo" string:create
s" bar" string:create
string:compare false must-equal cr
." string:compare -> "
s" foo" string:create
s" barz" string:create
string:compare false must-equal cr
." string:compare -> "
s" foo" string:create
s" foo" string:create
string:compare true must-equal cr
." string:append -> "
s" foo" string:create s" bar" string:create string:append s" foobar" string:create string:compare true must-equal cr
." string:from-char -> "
[char] x string:from-char s" x" string:create string:compare true must-equal cr
." string:substring -> "
s" aabbbb" string:create 2 6 string:substring s" bbbb" string:create string:compare true must-equal cr
." string:substring -> "
s" aabbbbaaaaaaaaaaa" string:create 2 6 string:substring s" bbbb" string:create string:compare true must-equal cr
." string:index-of -> "
s" foobar" string:create
s" bar" string:create
string:index-of 3 must-equal cr
." string:index-of -> "
s" foobar" string:create
s" xxx" string:create
string:index-of -1 must-equal cr
." string:replace -> "
s" foobarbuzz" string:create
s" bar" string:create
s" xxx" string:create
string:replace
s" fooxxxbuzz" string:create string:compare true must-equal cr
." string:replace -> "
s" foobarbuzz" string:create
s" 123" string:create
s" xxx" string:create
string:replace
s" foobarbuzz" string:create string:compare true must-equal cr
." string:some -> "
s" fooxbar" string:create
[: [char] x = ;]
string:some true must-equal cr
." string:some -> "
s" fooxbar" string:create
[: [char] y = ;]
string:some false must-equal cr
." string:every -> "
s" 0123456789" string:create
[: [char] 0 [char] 9 between ;]
string:every true must-equal cr
." string:every -> "
s" 0123456789a" string:create
[: [char] 0 [char] 9 between ;]
string:every false must-equal cr
." string:ends-with -> "
s" 158cm" string:create
s" cm" string:create
string:ends-with true must-equal cr
." string:ends-with -> "
s" foobar" string:create
s" bar" string:create
string:ends-with true must-equal cr
." string:ends-with -> "
s" foobar" string:create
s" ba" string:create
string:ends-with false must-equal cr
." string:reduce -> "
s" 1234" string:create
0
[: [char] 0 - + ;]
string:reduce 10 must-equal cr
;
run-test