This repository has been archived by the owner on Jan 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
053string.test
228 lines (172 loc) · 4.61 KB
/
053string.test
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
(test "len works on strings"
:valueof (len "abcdefgh")
:should be 8)
(test "strings work in function position"
:valueof ("abcd" 2)
:should be "c")
(test "strings can index final char"
:valueof ("abcd" 3)
:should be "d")
(test "strings can index past final char"
:valueof ("abcd" 4)
:should be_false)
(test "strings can take negative indices"
:valueof ("abcd" -3)
:should be "b")
(test "strings can take slices"
:valueof ("abcd" 1 3)
:should be "bc")
(test "strings can take slices - 2"
:valueof ("abcd" 1 -1)
:should be "bc")
(test "strings can take slices - explicit nil"
:valueof ("abcd" 1 nil)
:should be "bcd")
(test "strings can take slices - overflow"
:valueof ("abcd" 1 10)
:should be "bcd")
(test "string indices can be assigned to"
:valueof (ret s "abc"
(s.1 <- "z"))
:should be "azc")
(test "string indices can be assigned to - 2"
:valueof (ret s "abc"
(s.-1 <- "z"))
:should be "abz")
(test "string slices can be assigned to"
:valueof (ret s "abcdefgh"
((s 1 5) <- "xy"))
:should be "axyfgh")
(test "string slices can be assigned to - 2"
:valueof (ret s "abcdefgh"
((s -4 -1) <- "xy"))
:should be "abcdxyh")
(test "string slices can be assigned to - explicit nil"
:valueof (ret s "abcdefgh"
((s -4 nil) <- "xy"))
:should be "abcdxy")
(test "string slices can be assigned to - explicit nil var"
:valueof (ret s "abcdefgh"
(let x nil
((s -4 x) <- "xy")))
:should be "abcdxy")
(test "string index can be reset"
:valueof (ret l "abc"
(l.1 <- nil))
:should be "ac")
(test "each works on literal strings"
:valueof (ret ans nil
(each c "abc"
(push! c ans)))
:should be '("c" "b" "a"))
(test "each works on strings"
:valueof (ret ans nil
(let s "abc"
(each c s
(push! c ans))))
:should be '("c" "b" "a"))
(test "string works with multiple args"
:valueof (string 'a 43)
:should be "a43")
(test "string works with nil"
:valueof string.nil
:should be "")
(test "string coerces to list"
:valueof (as list "abc")
:should be '("a" "b" "c"))
(test "list coerces to string"
:valueof (as string '("a" "b" "c"))
:should be "abc")
(test "join works on strings"
:valueof (join "a" 'b nil)
:should be "ab")
(test "pos works on strings"
:valueof (pos "ab" "abc")
:should be 0)
(test "pos works on strings - 2"
:valueof (pos "b" "abc")
:should be 1)
(test "pos works on strings - 3"
:valueof (pos "ba" "abc")
:should be_false)
(test "< works on strings"
:valueof ("a" < "b")
:should be_true)
(test "< works on strings - 2"
:valueof ("b" < "a")
:should be_false)
(test "< works on strings - 3"
:valueof ("a" < "a")
:should be_false)
(test "< works on strings - 4"
:valueof (< "a" "b" "c")
:should be_true)
(test "< works on strings - 5"
:valueof (< "a" "b" "a")
:should be_false)
(test "< works on strings - 6"
:valueof ("a" < "b" < "c")
:should be_true)
(test "< works on strings - 7"
:valueof ("a" < "b" < "a")
:should be_false)
(test "> works on strings"
:valueof ("a" > "b")
:should be_false)
(test "> works on strings - 2"
:valueof ("b" > "a")
:should be_true)
(test "> works on strings - 3"
:valueof (> "c" "b" "d")
:should be_false)
(test "> works on strings - 4"
:valueof (> "c" "b" "a")
:should be_true)
(test "> works on strings - 5"
:valueof (> "a" "b" "a")
:should be_false)
(test "> works on strings - 6"
:valueof ("a" > "a")
:should be_false)
(test "> works on strings - 7"
:valueof (> "c" "b" "a")
:should be_true)
(test "> works on strings - 8"
:valueof (> "c" "b" "c")
:should be_false)
(test "> works on strings - 9"
:valueof ("c" > "b" > "a")
:should be_true)
(test "> works on strings - 7"
:valueof ("c" > "b" > "c")
:should be_false)
(test "<= works on strings"
:valueof ("a" <= "b")
:should be_true)
(test "<= works on strings - 2"
:valueof ("b" <= "a")
:should be_false)
(test "<= works on strings - 3"
:valueof ("a" <= "a")
:should be_true)
(test "<= works on strings - 4"
:valueof (nil <= "a")
:should be_false)
(test "<= works on strings - 5"
:valueof ("z" <= nil)
:should be_false)
(test ">= works on strings"
:valueof ("a" >= "b")
:should be_false)
(test ">= works on strings - 2"
:valueof ("b" >= "a")
:should be_true)
(test ">= works on strings - 4"
:valueof ("a" >= "a")
:should be_true)
(test "range checks work on strings"
:valueof ("a" <= "a" <= "b")
:should be_true)
(test "range checks work on strings - 2"
:valueof ("c" >= "b" > "b")
:should be_false)