author | Claus Gittinger <cg@exept.de> |
Sat, 25 May 2019 09:05:06 +0200 | |
changeset 2241 | 748bb1185b08 |
parent 2212 | 80b766225587 |
child 2242 | 6ed9be004635 |
permissions | -rw-r--r-- |
1990 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1447 | 3 |
"{ Package: 'stx:goodies/regression' }" |
283 | 4 |
|
5 |
"{ NameSpace: RegressionTests }" |
|
6 |
||
7 |
TestCase subclass:#StringTests |
|
1421 | 8 |
instanceVariableNames:'' |
9 |
classVariableNames:'' |
|
10 |
poolDictionaries:'' |
|
11 |
category:'tests-Regression-Collections' |
|
283 | 12 |
! |
13 |
||
14 |
||
1425 | 15 |
!StringTests class methodsFor:'queries'! |
16 |
||
17 |
coveredClassNames |
|
18 |
"should be redefined to return a collection of classes which are tested by |
|
1447 | 19 |
this suite/case. |
1425 | 20 |
If not redefined, coveredPackageNames should be. |
21 |
||
22 |
These classes can be instrumented for coverage analysis, |
|
23 |
before running the suite to provide coverage analysis/report" |
|
24 |
||
25 |
^ #( String CharacterArray ) |
|
26 |
||
27 |
"Created: / 06-07-2011 / 21:27:03 / cg" |
|
28 |
! ! |
|
29 |
||
288 | 30 |
!StringTests methodsFor:'helpers'! |
284 | 31 |
|
288 | 32 |
runAccessTestsOnInstancesOf:aStringClass |
874
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
33 |
|str s0 s1 s2 s3 s4 t| |
284 | 34 |
|
35 |
0 to:33 do:[:l | |
|
1447 | 36 |
str := aStringClass new:l. |
37 |
str atAllPut:(Character space). |
|
38 |
self assert:( str isBlank ). |
|
284 | 39 |
|
1447 | 40 |
1 to:l do:[:pos | |
41 |
str at:pos put:$a. |
|
42 |
self assert:( str isBlank not ). |
|
43 |
str at:pos put:(Character space). |
|
44 |
]. |
|
284 | 45 |
]. |
46 |
||
288 | 47 |
s0 := aStringClass new:0. |
287 | 48 |
self assert:s0 isEmpty. |
49 |
self assert:s0 isEmptyOrNil. |
|
50 |
self assert:s0 size == 0. |
|
51 |
||
288 | 52 |
s1 := (aStringClass new:5) replaceFrom:1 with:'hello'. |
53 |
s2 := (aStringClass new:6) replaceFrom:1 with:' world'. |
|
285 | 54 |
self assert:(s1 , s2) size == 11. |
288 | 55 |
self assert:(s1 , s2) class == aStringClass. |
285 | 56 |
self assert:(s1 = 'hello'). |
57 |
self assert:(s2 = ' world'). |
|
58 |
self assert:(s1 size == 5). |
|
59 |
self assert:(s2 size == 6). |
|
288 | 60 |
|
285 | 61 |
self assert:(s1 = 'hello'). |
62 |
self assert:(s1 asSymbol == #'hello'). |
|
63 |
self assert:(s1 copyFrom:1) = 'hello'. |
|
288 | 64 |
self assert:(s1 copyFrom:1) class == aStringClass. |
285 | 65 |
self assert:(s1 copyFrom:1 to:3) = 'hel'. |
288 | 66 |
self assert:(s1 copyFrom:1 to:3) class == aStringClass. |
285 | 67 |
self assert:(s1 copyWith:$X) = 'helloX'. |
288 | 68 |
self assert:(s1 copyWith:$X) class == aStringClass. |
285 | 69 |
self assert:(s1 endsWith:'llo'). |
70 |
self assert:(s1 startsWith:'hel'). |
|
286 | 71 |
|
702
4c5fb5598e9e
changed: #runAccessTestsOnInstancesOf:
Claus Gittinger <cg@exept.de>
parents:
635
diff
changeset
|
72 |
self assert:(t := s1 identityIndexOf:$h) == 1 description:('identityIndex is %1 (should be 1)' bindWith:t). |
4c5fb5598e9e
changed: #runAccessTestsOnInstancesOf:
Claus Gittinger <cg@exept.de>
parents:
635
diff
changeset
|
73 |
self assert:(t := s1 identityIndexOf:$l) == 3 description:('identityIndex is %1 (should be 3)' bindWith:t). |
4c5fb5598e9e
changed: #runAccessTestsOnInstancesOf:
Claus Gittinger <cg@exept.de>
parents:
635
diff
changeset
|
74 |
self assert:(t := s1 identityIndexOf:$L) == 0 description:('identityIndex is %1 (should be 0)' bindWith:t). |
288 | 75 |
|
76 |
self assert:(s1 identityIndexOf:$h startingAt:1) == 1. |
|
77 |
self assert:(s1 identityIndexOf:$h startingAt:2) == 0. |
|
78 |
self assert:(s1 identityIndexOf:$e startingAt:1) == 2. |
|
79 |
self assert:(s1 identityIndexOf:$e startingAt:2) == 2. |
|
80 |
self assert:(s1 identityIndexOf:$l startingAt:1) == 3. |
|
81 |
self assert:(s1 identityIndexOf:$l startingAt:2) == 3. |
|
82 |
self assert:(s1 identityIndexOf:$l startingAt:3) == 3. |
|
83 |
self assert:(s1 identityIndexOf:$l startingAt:4) == 4. |
|
84 |
self assert:(s1 identityIndexOf:$l startingAt:5) == 0. |
|
85 |
self assert:(s1 identityIndexOf:$l startingAt:6) == 0. |
|
86 |
||
286 | 87 |
self assert:(s1 indexOf:$h) == 1. |
88 |
self assert:(s1 indexOf:$l) == 3. |
|
287 | 89 |
self assert:(s1 indexOf:$L) == 0. |
874
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
90 |
self assert:(s1 indexOf:$A) == 0. |
288 | 91 |
|
286 | 92 |
self assert:(s1 indexOf:$h startingAt:1) == 1. |
93 |
self assert:(s1 indexOf:$h startingAt:2) == 0. |
|
94 |
self assert:(s1 indexOf:$e startingAt:1) == 2. |
|
95 |
self assert:(s1 indexOf:$e startingAt:2) == 2. |
|
96 |
self assert:(s1 indexOf:$l startingAt:1) == 3. |
|
97 |
self assert:(s1 indexOf:$l startingAt:2) == 3. |
|
98 |
self assert:(s1 indexOf:$l startingAt:3) == 3. |
|
99 |
self assert:(s1 indexOf:$l startingAt:4) == 4. |
|
100 |
self assert:(s1 indexOf:$l startingAt:5) == 0. |
|
101 |
self assert:(s1 indexOf:$l startingAt:6) == 0. |
|
288 | 102 |
|
286 | 103 |
self assert:(s1 includes:$l). |
104 |
self assert:(s1 includes:$L) not. |
|
288 | 105 |
|
287 | 106 |
self assert:(s1 includesAny:'a') not. |
107 |
self assert:(s1 includesAny:'ab') not. |
|
108 |
self assert:(s1 includesAny:'abc') not. |
|
109 |
self assert:(s1 includesAny:'abcd') not. |
|
110 |
self assert:(s1 includesAny:'abcde'). |
|
111 |
self assert:(s1 includesAny:'e'). |
|
112 |
self assert:(s1 includesAny:'ae'). |
|
113 |
self assert:(s1 includesAny:'ea'). |
|
114 |
self assert:(s1 includesAny:'abe'). |
|
115 |
self assert:(s1 includesAny:'eab'). |
|
116 |
self assert:(s1 includesAny:'aeb'). |
|
117 |
self assert:(s1 includesAny:'abce'). |
|
118 |
self assert:(s1 includesAny:'eabc'). |
|
119 |
self assert:(s1 includesAny:'aebc'). |
|
120 |
self assert:(s1 includesAny:'abec'). |
|
121 |
self assert:(s1 includesAny:'abcde'). |
|
1447 | 122 |
" 12345678901234567890 " |
288 | 123 |
s3 := (aStringClass new:20) replaceFrom:1 with:'12 45,78;01.34-67+90'. |
124 |
t := s3 asCollectionOfSubstringsSeparatedBy:$,. |
|
125 |
self assert:(t size = 2). |
|
126 |
self assert:(t first = '12 45'). |
|
127 |
self assert:(t second = '78;01.34-67+90'). |
|
128 |
||
129 |
t := s3 asCollectionOfSubstringsSeparatedByAny:',;. '. |
|
130 |
self assert:(t size = 5). |
|
131 |
self assert:(t first = '12'). |
|
132 |
self assert:(t second = '45'). |
|
133 |
self assert:(t third = '78'). |
|
134 |
self assert:(t fourth = '01'). |
|
135 |
self assert:(t fifth = '34-67+90'). |
|
874
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
136 |
|
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
137 |
s4 := (aStringClass new:10) replaceFrom:1 with:'123',Character tab,'567',Character cr,'90'. |
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
138 |
self assert:(s4 size = 10). |
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
139 |
self assert:(s4 indexOfSeparatorStartingAt:1) = 4. |
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
140 |
self assert:(s4 indexOfSeparatorStartingAt:3) = 4. |
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
141 |
self assert:(s4 indexOfSeparatorStartingAt:4) = 4. |
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
142 |
self assert:(s4 indexOfSeparatorStartingAt:5) = 8. |
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
143 |
self assert:(s4 indexOfControlCharacterStartingAt:1) = 4. |
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
144 |
self assert:(s4 indexOfNonSeparatorStartingAt:1) = 1. |
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
145 |
self assert:(s4 indexOfNonSeparatorStartingAt:3) = 3. |
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
146 |
self assert:(s4 indexOfNonSeparatorStartingAt:4) = 5. |
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
147 |
self assert:(s4 indexOfNonSeparatorStartingAt:5) = 5. |
352 | 148 |
! ! |
149 |
||
150 |
!StringTests methodsFor:'tests'! |
|
288 | 151 |
|
152 |
test01_access |
|
153 |
0 to:33 do:[:l | |
|
1447 | 154 |
|str| |
288 | 155 |
|
1447 | 156 |
str := String new:l. |
157 |
str atAllPut:(Character space). |
|
158 |
self assert:( str isBlank ). |
|
159 |
self assert:((str size == 0) or: [(str first) == Character space.]). |
|
288 | 160 |
|
1447 | 161 |
1 to:l do:[:pos | |
162 |
str at:pos put:$a. |
|
163 |
self assert:( str isBlank not ). |
|
164 |
self assert:((str at:pos) == $a). |
|
165 |
str at:pos put:(Character space). |
|
166 |
]. |
|
288 | 167 |
]. |
168 |
self runAccessTestsOnInstancesOf:String |
|
169 |
||
170 |
" |
|
171 |
self new test01_access |
|
172 |
" |
|
173 |
! |
|
174 |
||
175 |
test02_subclassAccess |
|
176 |
|myStringClass s1| |
|
177 |
||
178 |
Class withoutUpdatingChangesDo:[ |
|
1421 | 179 |
myStringClass := String |
180 |
subclass:#'MyString' |
|
181 |
instanceVariableNames:'foo' |
|
182 |
classVariableNames:'' |
|
183 |
poolDictionaries:nil. |
|
184 |
myStringClass compile:'foo ^foo'. |
|
185 |
myStringClass compile:'foo:arg foo := arg'. |
|
288 | 186 |
]. |
187 |
||
188 |
s1 := (myStringClass new:5) replaceFrom:1 with:'hello'. |
|
189 |
self assert:(s1 foo isNil). |
|
190 |
self assert:(s1 size == 5). |
|
874
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
191 |
s1 foo:16r11413344. "/ ensure there is a $A inside (hex 41) |
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
192 |
self assert:(s1 foo == 16r11413344). |
288 | 193 |
self assert:(s1 = 'hello'). |
874
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
194 |
self assert:(s1 deepCopy foo == 16r11413344). |
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
195 |
|
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
196 |
self assert:((s1 indexOf:$A) == 0). "/ should not find the A |
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
197 |
self assert:((s1 identityIndexOf:$A) == 0). "/ should not find the A |
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
198 |
self assert:((s1 findFirst:[:ch | ch == $A]) == 0). "/ should not find the A |
288 | 199 |
|
200 |
self runAccessTestsOnInstancesOf:myStringClass. |
|
285 | 201 |
|
284 | 202 |
" |
203 |
self new test02_subclassAccess |
|
204 |
" |
|
205 |
! |
|
206 |
||
2209 | 207 |
test03a_unicode16 |
1693 | 208 |
|u s u2| |
209 |
||
210 |
u := 'hello' asUnicode16String. |
|
211 |
self assert:(u class == Unicode16String). |
|
212 |
self assert:(u size == 5). |
|
213 |
self assert:((u at:1) == $h). |
|
214 |
self assert:((u at:2) == $e). |
|
215 |
self assert:((u at:3) == $l). |
|
216 |
self assert:((u at:4) == $l). |
|
217 |
self assert:((u at:5) == $o). |
|
218 |
||
219 |
s := u asSingleByteString. |
|
220 |
self assert:(s class == String). |
|
221 |
self assert:(s size == 5). |
|
222 |
self assert:((s at:1) == $h). |
|
223 |
self assert:((s at:2) == $e). |
|
224 |
self assert:((s at:3) == $l). |
|
225 |
self assert:((s at:4) == $l). |
|
226 |
self assert:((s at:5) == $o). |
|
227 |
||
228 |
s := u asSingleByteStringIfPossible. |
|
229 |
self assert:(s class == String). |
|
230 |
self assert:(s size == 5). |
|
231 |
self assert:((s at:1) == $h). |
|
232 |
self assert:((s at:2) == $e). |
|
233 |
self assert:((s at:3) == $l). |
|
234 |
self assert:((s at:4) == $l). |
|
235 |
self assert:((s at:5) == $o). |
|
236 |
||
237 |
u2 := 'hello' asUnicode16String. |
|
238 |
u2 at:1 put:(Character codePoint:16r20AC). "/ euro character |
|
239 |
self assert:(u2 size == 5). |
|
240 |
self assert:((u2 at:1) = (Character codePoint:16r20AC)). |
|
241 |
self assert:((u2 at:2) == $e). |
|
242 |
self assert:((u2 at:3) == $l). |
|
243 |
self assert:((u2 at:4) == $l). |
|
244 |
self assert:((u2 at:5) == $o). |
|
245 |
||
246 |
s := u2 asSingleByteStringIfPossible. |
|
247 |
self assert:(s class == Unicode16String). |
|
248 |
self assert:(u2 == s). |
|
249 |
||
250 |
u := Unicode16String fromString:'hello'. |
|
251 |
self assert:(u class == Unicode16String). |
|
252 |
self assert:(u size == 5). |
|
253 |
self assert:((u at:1) == $h). |
|
254 |
self assert:((u at:2) == $e). |
|
255 |
self assert:((u at:3) == $l). |
|
256 |
self assert:((u at:4) == $l). |
|
257 |
self assert:((u at:5) == $o). |
|
258 |
||
259 |
u replaceFrom:1 to:5 with:'abcde' startingAt:1. |
|
260 |
self assert:(u class == Unicode16String). |
|
261 |
self assert:(u size == 5). |
|
262 |
self assert:((u at:1) == $a). |
|
263 |
self assert:((u at:2) == $b). |
|
264 |
self assert:((u at:3) == $c). |
|
265 |
self assert:((u at:4) == $d). |
|
266 |
self assert:((u at:5) == $e). |
|
267 |
||
268 |
" |
|
2209 | 269 |
self new test03a_unicode16 |
1693 | 270 |
" |
271 |
||
2209 | 272 |
"Created: / 02-04-2019 / 10:43:49 / Claus Gittinger" |
273 |
! |
|
274 |
||
275 |
test03b_unicode32 |
|
276 |
|u s u2| |
|
277 |
||
278 |
u := 'hello' asUnicode32String. |
|
279 |
self assert:(u class == Unicode32String). |
|
280 |
self assert:(u size == 5). |
|
281 |
self assert:((u at:1) == $h). |
|
282 |
self assert:((u at:2) == $e). |
|
283 |
self assert:((u at:3) == $l). |
|
284 |
self assert:((u at:4) == $l). |
|
285 |
self assert:((u at:5) == $o). |
|
286 |
||
287 |
s := u asSingleByteString. |
|
288 |
self assert:(s class == String). |
|
289 |
self assert:(s size == 5). |
|
290 |
self assert:((s at:1) == $h). |
|
291 |
self assert:((s at:2) == $e). |
|
292 |
self assert:((s at:3) == $l). |
|
293 |
self assert:((s at:4) == $l). |
|
294 |
self assert:((s at:5) == $o). |
|
295 |
||
296 |
s := u asSingleByteStringIfPossible. |
|
297 |
self assert:(s class == String). |
|
298 |
self assert:(s size == 5). |
|
299 |
self assert:((s at:1) == $h). |
|
300 |
self assert:((s at:2) == $e). |
|
301 |
self assert:((s at:3) == $l). |
|
302 |
self assert:((s at:4) == $l). |
|
303 |
self assert:((s at:5) == $o). |
|
304 |
||
305 |
u2 := 'hello' asUnicode32String. |
|
306 |
u2 at:1 put:(Character codePoint:16r20AC). "/ euro character |
|
307 |
self assert:(u2 size == 5). |
|
308 |
self assert:((u2 at:1) = (Character codePoint:16r20AC)). |
|
309 |
self assert:((u2 at:2) == $e). |
|
310 |
self assert:((u2 at:3) == $l). |
|
311 |
self assert:((u2 at:4) == $l). |
|
312 |
self assert:((u2 at:5) == $o). |
|
313 |
||
314 |
s := u2 asSingleByteStringIfPossible. |
|
315 |
self assert:(s class == Unicode32String). |
|
316 |
self assert:(u2 == s). |
|
317 |
||
318 |
u := Unicode32String fromString:'hello'. |
|
319 |
self assert:(u class == Unicode32String). |
|
320 |
self assert:(u size == 5). |
|
321 |
self assert:((u at:1) == $h). |
|
322 |
self assert:((u at:2) == $e). |
|
323 |
self assert:((u at:3) == $l). |
|
324 |
self assert:((u at:4) == $l). |
|
325 |
self assert:((u at:5) == $o). |
|
326 |
||
327 |
u replaceFrom:1 to:5 with:'abcde' startingAt:1. |
|
328 |
self assert:(u class == Unicode32String). |
|
329 |
self assert:(u size == 5). |
|
330 |
self assert:((u at:1) == $a). |
|
331 |
self assert:((u at:2) == $b). |
|
332 |
self assert:((u at:3) == $c). |
|
333 |
self assert:((u at:4) == $d). |
|
334 |
self assert:((u at:5) == $e). |
|
335 |
||
336 |
" |
|
337 |
self new test03b_unicode32 |
|
338 |
" |
|
339 |
||
340 |
"Created: / 02-04-2019 / 10:44:34 / Claus Gittinger" |
|
341 |
! |
|
342 |
||
343 |
test03c_unicodeStrings |
|
344 |
|u32 u16 u8| |
|
345 |
||
346 |
u32 := 'hello' asUnicode32String. |
|
347 |
u16 := 'hello' asUnicode16String. |
|
348 |
u8 := 'hello' asString. |
|
349 |
self assert:(u32 = u16). |
|
350 |
self assert:(u16 = u32). |
|
351 |
self assert:(u32 = u8). |
|
352 |
self assert:(u8 = u32). |
|
353 |
self assert:(u16 = u8). |
|
354 |
self assert:(u8 = u16). |
|
355 |
||
356 |
self assert:(u32 asDenseUnicodeString = u8). |
|
357 |
self assert:(u32 asDenseUnicodeString class == String). |
|
358 |
self assert:(u16 asDenseUnicodeString = u8). |
|
359 |
self assert:(u16 asDenseUnicodeString class == String). |
|
360 |
self assert:(u8 asDenseUnicodeString == u8). |
|
361 |
||
362 |
" |
|
363 |
self new test03c_unicodeStrings |
|
364 |
" |
|
365 |
||
366 |
"Created: / 02-04-2019 / 10:46:10 / Claus Gittinger" |
|
1693 | 367 |
! |
368 |
||
284 | 369 |
test10_Contains8BitCharacters |
288 | 370 |
0 to:65 do:[:l | |
1421 | 371 |
|str| |
283 | 372 |
|
1421 | 373 |
str := String new:l. |
374 |
str atAllPut:(Character value:16r7F). |
|
375 |
self assert:( str contains8BitCharacters not ). |
|
283 | 376 |
|
1421 | 377 |
1 to:l do:[:pos | |
378 |
str at:pos put:(Character value:16r80). |
|
379 |
self assert:( str contains8BitCharacters ). |
|
380 |
str at:pos put:(Character value:16r7F). |
|
381 |
]. |
|
283 | 382 |
]. |
383 |
||
384 |
" |
|
284 | 385 |
self new test10_Contains8BitCharacters |
283 | 386 |
" |
288 | 387 |
! |
388 |
||
1426 | 389 |
test11_IsEmpty |
390 |
|nul n| |
|
391 |
nul := 0 asCharacter. |
|
392 |
n := 1. |
|
393 |
self assert:('' isEmpty). |
|
394 |
self assert:(' ' isEmpty not). |
|
395 |
self assert:(nul asCharacter asString isEmpty not). |
|
396 |
self assert:(('' , nul) isEmpty not). |
|
397 |
self assert:((String new:0) isEmpty). |
|
398 |
self assert:((String new:17 withAll:nul) isEmpty not). |
|
399 |
||
1447 | 400 |
29 timesRepeat:[ |
401 |
|s| |
|
1426 | 402 |
|
1447 | 403 |
s := String new:(n + 17). |
404 |
self assert:(s isEmpty not). |
|
405 |
n := n * 2. |
|
1426 | 406 |
]. |
407 |
self assert:((String new:17 withAll:nul) isEmpty not). |
|
408 |
self assert:((String new:0 withAll:nul) isEmpty). |
|
409 |
" |
|
1429 | 410 |
self new test11_IsEmpty |
411 |
" |
|
1426 | 412 |
! |
413 |
||
414 |
test12_Comparison |
|
415 |
0 to: 255 do: [ :i | |
|
1447 | 416 |
|s t| |
1426 | 417 |
|
1447 | 418 |
1 to: 9 do: [ :j | |
419 |
s := String new:j withAll:(i asCharacter). |
|
420 |
t := s copy. |
|
1426 | 421 |
|
1447 | 422 |
self assert:(s notNil). |
423 |
self assert:(s = s). |
|
424 |
self assert:(s ~= s) not. |
|
425 |
self assert:(s < s) not. |
|
426 |
self assert:(s > s) not. |
|
427 |
self assert:(s = (s,s)) not. |
|
1426 | 428 |
|
1447 | 429 |
self assert:(t notNil). |
430 |
self assert:(s = t). |
|
431 |
self assert:(s ~= t) not. |
|
432 |
self assert:(s < t) not. |
|
433 |
self assert:(s > t) not. |
|
1426 | 434 |
|
1447 | 435 |
self assert:((s = nil) == ((s ~= nil) not)). |
436 |
self assert:((s = '') == ((s ~= '') not)). |
|
437 |
]. |
|
1426 | 438 |
|
1447 | 439 |
s := i asCharacter asString. |
440 |
0 to: 255 do: [ :j | |
|
441 |
t := j asCharacter asString. |
|
442 |
self assert:(t notNil). |
|
1426 | 443 |
|
1447 | 444 |
self assert:((s = t) == ((s ~= t) not)). |
445 |
] |
|
1426 | 446 |
]. |
447 |
||
448 |
" |
|
449 |
self new test12_Comparison |
|
450 |
" |
|
451 |
! |
|
452 |
||
1990 | 453 |
test13_startsWithEndsWithSameAs |
454 |
self assert:('hello' startsWith:''). |
|
455 |
self assert:('hello' startsWith:'h'). |
|
456 |
self assert:('hello' startsWith:'he'). |
|
457 |
self assert:('hello' startsWith:'hel'). |
|
458 |
self assert:('hello' startsWith:'hell'). |
|
459 |
self assert:('hello' startsWith:'hello'). |
|
460 |
self assert:('hello' startsWith:'hello world') not. |
|
461 |
"/ int size |
|
462 |
self assert:('1234' startsWith:'123'). |
|
463 |
self assert:('1234' startsWith:'1234'). |
|
464 |
self assert:('1234' startsWith:'12345') not. |
|
465 |
self assert:('12345678' startsWith:'123'). |
|
466 |
self assert:('12345678' startsWith:'1234'). |
|
467 |
self assert:('12345678' startsWith:'12345'). |
|
468 |
self assert:('12345678' startsWith:'123456'). |
|
469 |
self assert:('12345678' startsWith:'1234567'). |
|
470 |
self assert:('12345678' startsWith:'12345678'). |
|
471 |
self assert:('12345678' startsWith:'123456789') not. |
|
472 |
||
473 |
self assert:('1234' startsWith:'x23') not. |
|
474 |
self assert:('1234' startsWith:'x234') not. |
|
475 |
self assert:('1234' startsWith:'1x34') not. |
|
476 |
self assert:('1234' startsWith:'12x4') not. |
|
477 |
self assert:('1234' startsWith:'123x') not. |
|
478 |
self assert:('1234' startsWith:'12345') not. |
|
479 |
self assert:('12345678' startsWith:'x234') not. |
|
480 |
self assert:('12345678' startsWith:'1x34') not. |
|
481 |
self assert:('12345678' startsWith:'12x4') not. |
|
482 |
self assert:('12345678' startsWith:'123x') not. |
|
483 |
||
484 |
self assert:('hello' endsWith:''). |
|
485 |
self assert:('hello' endsWith:'o'). |
|
486 |
self assert:('hello' endsWith:'lo'). |
|
487 |
self assert:('hello' endsWith:'llo'). |
|
488 |
self assert:('hello' endsWith:'ello'). |
|
489 |
self assert:('hello' endsWith:'hello'). |
|
490 |
self assert:('hello' endsWith:'hello world') not. |
|
491 |
"/ int size |
|
492 |
self assert:('1234' endsWith:'234'). |
|
493 |
self assert:('1234' endsWith:'1234'). |
|
494 |
self assert:('1234' endsWith:'1235') not. |
|
495 |
self assert:('1234' endsWith:'12345') not. |
|
496 |
self assert:('12345678' endsWith:'678'). |
|
497 |
self assert:('12345678' endsWith:'5678'). |
|
498 |
self assert:('12345678' endsWith:'45678'). |
|
499 |
self assert:('12345678' endsWith:'345678'). |
|
500 |
self assert:('12345678' endsWith:'2345678'). |
|
501 |
self assert:('12345678' endsWith:'12345678'). |
|
502 |
self assert:('12345678' endsWith:'123456789') not. |
|
503 |
self assert:('12345678' endsWith:'012345678') not. |
|
504 |
||
505 |
self assert:('1234' endsWith:'x233') not. |
|
506 |
self assert:('1234' endsWith:'1x34') not. |
|
507 |
self assert:('1234' endsWith:'12x4') not. |
|
508 |
self assert:('1234' endsWith:'123x') not. |
|
509 |
self assert:('12345678' endsWith:'x2345678') not. |
|
510 |
self assert:('12345678' endsWith:'1x345678') not. |
|
511 |
self assert:('12345678' endsWith:'12x45678') not. |
|
512 |
self assert:('12345678' endsWith:'123x5678') not. |
|
513 |
self assert:('12345678' endsWith:'1234x678') not. |
|
514 |
self assert:('12345678' endsWith:'12345x78') not. |
|
515 |
self assert:('12345678' endsWith:'123456x8') not. |
|
516 |
self assert:('12345678' endsWith:'1234567x') not. |
|
517 |
||
518 |
self assert:('' sameAs:''). |
|
519 |
self assert:('' sameAs:'a') not. |
|
520 |
self assert:('a' sameAs:'') not. |
|
521 |
self assert:('a' sameAs:'a'). |
|
522 |
self assert:('a' sameAs:'A'). |
|
523 |
self assert:('A' sameAs:'A'). |
|
524 |
self assert:('A' sameAs:'a'). |
|
525 |
||
526 |
self assert:('a' sameAs:'1') not. |
|
527 |
self assert:('A' sameAs:'1') not. |
|
528 |
||
529 |
1 to:20 do:[:len | |
|
530 |
|s1 s2| |
|
531 |
||
532 |
s1 := ($a to:($a + len - 1)) asString. |
|
533 |
s2 := s1 copy. |
|
534 |
1 to:len do:[:idx | |
|
535 |
s2 at:idx put:(s2 at:idx) asUppercase. |
|
536 |
self assert:(s1 sameAs:s2). |
|
537 |
]. |
|
538 |
]. |
|
539 |
||
540 |
self assert:('Ä' sameAs:'ä'). |
|
541 |
self assert:('Ä' sameAs:'ä'). |
|
542 |
self assert:('ß' sameAs:'ÿ') not. |
|
543 |
self assert:('Ÿ' sameAs:'ÿ'). "/ single byte char ws. wide char |
|
544 |
self assert:('Ÿ' sameAs:'Ÿ'). "/ single byte char ws. wide char |
|
545 |
self assert:('ÿ' sameAs:'ÿ'). "/ single byte char ws. wide char |
|
546 |
||
547 |
" |
|
548 |
self new test13_startsWithEndsWithSameAs |
|
549 |
" |
|
550 |
||
551 |
"Created: / 19-07-2018 / 11:05:32 / Claus Gittinger" |
|
552 |
! |
|
553 |
||
1426 | 554 |
test15_CompareWithCollating |
555 |
| nul | |
|
556 |
||
557 |
nul := 0 asCharacter asString. |
|
558 |
self assert:('' compareWith:'' collating:true) == 0. |
|
559 |
self assert:('' compareWith:'' collating:false) == 0. |
|
1447 | 560 |
self assert:(nul compareWith:(255 asCharacter asString) collating:false) == -1. |
1426 | 561 |
self assert:((255 asCharacter asString) compareWith:nul collating:false) == 1. |
1433 | 562 |
"/ This will fail and is a WONTFIX |
563 |
"/ self assert:((('' compareWith:nul collating:false) == 0) == ('' = nul)). |
|
1426 | 564 |
|
565 |
0 to: 255 do: [ :i | |
|
1447 | 566 |
|s| |
1426 | 567 |
|
1447 | 568 |
s := i asCharacter asString. |
569 |
self assert:(s notNil). |
|
1426 | 570 |
|
1447 | 571 |
"/ This will fail and is a WONTFIX |
572 |
"/ self assert:('' compareWith:s collating:false) ~= 0. |
|
573 |
self assert:('' compareWith:s collating:false) == ((s compareWith:'' collating:false) negated). |
|
1426 | 574 |
|
1447 | 575 |
0 to: 255 do: [ :j | |
576 |
| t | |
|
577 |
t := j asCharacter asString. |
|
578 |
self assert:(t notNil). |
|
1426 | 579 |
|
1447 | 580 |
self assert:(((s compareWith:t collating:false) == -1) == (s < t)). |
581 |
self assert:(((s compareWith:t collating:false) == 0) == (s = t)). |
|
582 |
self assert:(((s compareWith:t collating:false) == 1) == (s > t)). |
|
583 |
self assert:(((s compareWith:t collating:true) == -1) == (s < t)). |
|
584 |
self assert:(((s compareWith:t collating:true) == 0) == (s = t)). |
|
585 |
self assert:(((s compareWith:t collating:true) == 1) == (s > t)). |
|
586 |
] |
|
1426 | 587 |
]. |
588 |
||
589 |
0 to: 9 do: [ :i | |
|
1447 | 590 |
0 to: 255 do: [ :j | |
591 |
|s t| |
|
592 |
s := String new:i withAll:(j asCharacter). |
|
593 |
t := s copy. |
|
1426 | 594 |
|
1447 | 595 |
self assert: (s compareWith:s collating:false) == 0. |
596 |
self assert: (s compareWith:s collating:true) == 0. |
|
597 |
self assert: (s compareWith:t collating:false) == 0. |
|
598 |
self assert: (s compareWith:t collating:true) == 0 |
|
599 |
] |
|
1426 | 600 |
]. |
601 |
||
602 |
" |
|
603 |
self new test15_CompareWithCollating |
|
604 |
" |
|
605 |
! |
|
606 |
||
288 | 607 |
test20_literalsAreReadonly |
605
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
608 |
|myClass s1 l2 s2 parserFlags compiler| |
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
609 |
|
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
610 |
parserFlags := Compiler new parserFlags copy. |
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
611 |
parserFlags stringsAreImmutable:true. |
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
612 |
parserFlags arraysAreImmutable:true. |
288 | 613 |
|
614 |
Class withoutUpdatingChangesDo:[ |
|
1421 | 615 |
myClass := Object |
616 |
subclass:#'MyClass' |
|
617 |
instanceVariableNames:'' |
|
618 |
classVariableNames:'' |
|
619 |
poolDictionaries:nil. |
|
605
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
620 |
|
1421 | 621 |
compiler := myClass compilerClass new. |
622 |
compiler parserFlags:parserFlags. |
|
623 |
compiler compile:'lit1 ^''hello''' forClass:myClass install:true. |
|
605
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
624 |
|
1421 | 625 |
compiler := myClass compilerClass new. |
626 |
compiler parserFlags:parserFlags. |
|
627 |
compiler compile:'lit2 ^#(''foo'' ''bar'' ''baz'')' forClass:myClass install:true. |
|
288 | 628 |
]. |
629 |
||
630 |
s1 := myClass new perform:#lit1. |
|
631 |
self assert:(s1 isString). |
|
632 |
self assert:(s1 class == ImmutableString). |
|
633 |
self should:[ s1 at:1 put:$H ] raise:Error. |
|
634 |
||
635 |
l2 := myClass new perform:#lit2. |
|
636 |
self assert:(l2 isArray). |
|
637 |
self assert:(l2 class == ImmutableArray). |
|
638 |
self should:[ l2 at:1 put:$H ] raise:Error. |
|
639 |
s2 := l2 at:1. |
|
640 |
self assert:(s2 isString). |
|
641 |
self assert:(s2 class == ImmutableString). |
|
642 |
self should:[ s2 at:1 put:$H ] raise:Error. |
|
643 |
||
644 |
" |
|
645 |
self new test20_literalsAreReadonly |
|
646 |
" |
|
605
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
647 |
|
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
648 |
"Modified: / 02-08-2011 / 19:30:53 / cg" |
352 | 649 |
! |
650 |
||
1418 | 651 |
test30_indexOfSubCollection |
352 | 652 |
|i| |
653 |
"/ 12345678901 |
|
654 |
i := 'hello world' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:true. |
|
655 |
self assert:(i == 7). |
|
656 |
i := 'hello wOrLd' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:true. |
|
657 |
self assert:(i == 0). |
|
658 |
i := 'hello wOrLd' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:false. |
|
659 |
self assert:(i == 7). |
|
660 |
i := 'hello wOrLd' indexOfSubCollection:'ll' startingAt:1 ifAbsent:0 caseSensitive:false. |
|
661 |
self assert:(i == 3). |
|
662 |
||
663 |
i := 'hello wOrLd yellow' indexOfSubCollection:'ll' startingAt:1 ifAbsent:0 caseSensitive:false. |
|
664 |
self assert:(i == 3). |
|
665 |
i := 'hello wOrLd yellow' indexOfSubCollection:'ll' startingAt:3 ifAbsent:0 caseSensitive:false. |
|
666 |
self assert:(i == 3). |
|
667 |
i := 'hello wOrLd yellow' indexOfSubCollection:'ll' startingAt:4 ifAbsent:0 caseSensitive:false. |
|
668 |
self assert:(i == 15). |
|
669 |
||
353 | 670 |
i := 'hello wOrLd yellow' indexOfSubCollection:'low' startingAt:1 ifAbsent:0 caseSensitive:false. |
671 |
self assert:(i == 16). |
|
672 |
i := 'hello wOrLd yellow' indexOfSubCollection:'low' startingAt:17 ifAbsent:0 caseSensitive:false. |
|
673 |
self assert:(i == 0). |
|
674 |
i := 'hello wOrLd yellow' indexOfSubCollection:'low' startingAt:18 ifAbsent:0 caseSensitive:false. |
|
675 |
self assert:(i == 0). |
|
676 |
||
2241 | 677 |
i := 'world' indexOfString:'world'. |
678 |
self assert:(i == 1). |
|
679 |
i := 'world' indexOfString:'world' startingAt:1. |
|
680 |
self assert:(i == 1). |
|
681 |
i := 'world' indexOfString:'world' startingAt:6. |
|
682 |
self assert:(i == 0). |
|
683 |
||
684 |
i := 'hello world' indexOfString:'world'. |
|
685 |
self assert:(i == 7). |
|
686 |
i := 'hello world' indexOfString:'world' startingAt:1. |
|
687 |
self assert:(i == 7). |
|
688 |
i := 'hello world' indexOfString:'world' startingAt:4. |
|
689 |
self assert:(i == 7). |
|
690 |
i := 'hello world' indexOfString:'world' startingAt:7. |
|
691 |
self assert:(i == 7). |
|
692 |
i := 'hello world' indexOfString:'world' startingAt:8. |
|
693 |
self assert:(i == 0). |
|
694 |
||
695 |
i := 'hello wOrLd' indexOfString:'world' startingAt:1. |
|
696 |
self assert:(i == 0). |
|
697 |
||
352 | 698 |
" |
1418 | 699 |
self new test30_indexOfSubCollection |
352 | 700 |
" |
2241 | 701 |
|
702 |
"Modified: / 25-05-2019 / 09:01:43 / Claus Gittinger" |
|
703 |
! |
|
704 |
||
705 |
test31_occurrencesOfString |
|
706 |
|n| |
|
707 |
"/ 12345678901 |
|
708 |
n := 'hello world' occurrencesOfString:'world'. |
|
709 |
self assert:(n == 1). |
|
710 |
||
711 |
n := 'hello wOrLd world' occurrencesOfString:'world'. |
|
712 |
self assert:(n == 1). |
|
713 |
||
714 |
n := 'hello world hello world' occurrencesOfString:'world'. |
|
715 |
self assert:(n == 2). |
|
716 |
||
717 |
n := '' occurrencesOfString:'aa'. |
|
718 |
self assert:(n == 0). |
|
719 |
||
720 |
n := 'a' occurrencesOfString:'aa'. |
|
721 |
self assert:(n == 0). |
|
722 |
||
723 |
n := 'aa' occurrencesOfString:'aa'. |
|
724 |
self assert:(n == 1). |
|
725 |
||
726 |
n := ' aa ' occurrencesOfString:'aa'. |
|
727 |
self assert:(n == 1). |
|
728 |
||
729 |
n := ' aa a' occurrencesOfString:'aa'. |
|
730 |
self assert:(n == 1). |
|
731 |
||
732 |
n := ' aaaa' occurrencesOfString:'aa'. |
|
733 |
self assert:(n == 2). |
|
734 |
||
735 |
n := ' aa aa ' occurrencesOfString:'aa'. |
|
736 |
self assert:(n == 2). |
|
737 |
||
738 |
n := ' aa bb ab ba aa ab' occurrencesOfString:'aa'. |
|
739 |
self assert:(n == 2). |
|
740 |
||
741 |
n := ' aa bb cc aa bb cc aa bb ' occurrencesOfString:'aa'. |
|
742 |
self assert:(n == 3). |
|
743 |
||
744 |
" |
|
745 |
self new test31_occurrencesOfString |
|
746 |
" |
|
747 |
||
748 |
"Created: / 25-05-2019 / 09:03:11 / Claus Gittinger" |
|
570 | 749 |
! |
750 |
||
751 |
test40_indexOfAny |
|
1426 | 752 |
|s i collection| |
570 | 753 |
|
754 |
s := 'Some Sample Generators (74035660-d1f6-11df-9ab3-00ff7b08316c)'. |
|
755 |
1 to:s size do:[:start | |
|
1447 | 756 |
i := s indexOfAny:'-' startingAt:start. |
757 |
self assert:(i == 0 or:[ i >= start]). |
|
758 |
(i ~~ 0) ifTrue:[ |
|
759 |
self assert:(s at:i) == $- |
|
760 |
]. |
|
1308 | 761 |
]. |
1447 | 762 |
"/ 123456789012 |
1308 | 763 |
s := 'bla bla 1234'. |
764 |
1 to:s size do:[:start | |
|
1447 | 765 |
i := s indexOfAny:'1234' startingAt:start. |
766 |
self assert:(i == 0 or:[ i >= start]). |
|
767 |
(i == 9) ifTrue:[ self assert:((s at:i) == $1) ]. |
|
768 |
(i == 10) ifTrue:[ self assert:((s at:i) == $2) ]. |
|
769 |
(i == 11) ifTrue:[ self assert:((s at:i) == $3) ]. |
|
770 |
(i == 12) ifTrue:[ self assert:((s at:i) == $4) ]. |
|
570 | 771 |
]. |
772 |
||
1426 | 773 |
collection := #($o, $l, $o). |
774 |
"/ 12345678901 |
|
775 |
i := 'hello world' indexOfAny:collection startingAt:1. |
|
776 |
self assert:(i == 3). |
|
777 |
i := 'hello world' indexOfAny:collection startingAt:2. |
|
778 |
self assert:(i == 3). |
|
779 |
i := 'hello world' indexOfAny:collection startingAt:3. |
|
1447 | 780 |
self assert:(i == 3). |
1426 | 781 |
i := 'hello world' indexOfAny:collection startingAt:4. |
1447 | 782 |
self assert:(i == 4). |
1426 | 783 |
i := 'hello world' indexOfAny:collection startingAt:5. |
1447 | 784 |
self assert:(i == 5). |
1426 | 785 |
i := 'hello world' indexOfAny:collection startingAt:6. |
1447 | 786 |
self assert:(i == 8). |
1426 | 787 |
i := 'hello world' indexOfAny:collection startingAt:7. |
788 |
self assert:(i == 8). |
|
789 |
i := 'hello world' indexOfAny:collection startingAt:8. |
|
1447 | 790 |
self assert:(i == 8). |
1426 | 791 |
i := 'hello world' indexOfAny:collection startingAt:9. |
1447 | 792 |
self assert:(i == 10). |
1426 | 793 |
i := 'hello world' indexOfAny:collection startingAt:10. |
1447 | 794 |
self assert:(i == 10). |
1426 | 795 |
i := 'hello world' indexOfAny:collection startingAt:11. |
796 |
self assert:(i == 0). |
|
797 |
i := 'hello world' indexOfAny:collection startingAt:12. |
|
798 |
self assert:(i == 0). |
|
799 |
i := 'hello world' indexOfAny:collection startingAt:10000. |
|
800 |
self assert:(i == 0). |
|
570 | 801 |
" |
802 |
self new test40_indexOfAny |
|
803 |
" |
|
804 |
||
805 |
"Created: / 29-10-2010 / 14:58:21 / cg" |
|
571 | 806 |
! |
807 |
||
1308 | 808 |
test41_contains |
809 |
|s| |
|
810 |
||
811 |
s := 'abcdefg'. |
|
812 |
self assert:(s contains:[:ch | ch == $a]). |
|
813 |
self assert:(s contains:[:ch | ch == $A]) not. |
|
814 |
self assert:(s contains:[:ch | ch == $1]) not. |
|
1426 | 815 |
self assert:(s contains:[:ch | ch == (0 asCharacter)]) not. |
1308 | 816 |
" |
817 |
self new test41_contains |
|
818 |
" |
|
819 |
! |
|
820 |
||
2211 | 821 |
test42a_includesAny |
1420 | 822 |
|s| |
823 |
||
824 |
1 to:20 do:[:na | |
|
2211 | 825 |
s := (String new:na withAll:$a),'bla bla 1234'. |
826 |
self assert:( s includesAny:'12'). |
|
827 |
self assert:( s includesAny:'21'). |
|
828 |
self assert:( s includesAny:'15'). |
|
829 |
self assert:( s includesAny:'51'). |
|
830 |
self assert:( s includesAny:'45'). |
|
831 |
self assert:( s includesAny:'54'). |
|
832 |
self assert:( s includesAny:'56') not. |
|
1420 | 833 |
]. |
1447 | 834 |
|
1420 | 835 |
" |
2211 | 836 |
self new test42a_includesAny |
837 |
" |
|
838 |
||
839 |
"Created: / 02-04-2019 / 11:03:13 / Claus Gittinger" |
|
840 |
! |
|
841 |
||
842 |
test42b_includesMatchCharacters |
|
843 |
self assert:('hello' includesMatchCharacters not). |
|
844 |
self assert:('he*llo' includesMatchCharacters). |
|
845 |
self assert:('h[eE]llo' includesMatchCharacters). |
|
846 |
self assert:('h#llo' includesMatchCharacters). |
|
847 |
||
848 |
" |
|
849 |
self new test42b_includesMatchCharacters |
|
1420 | 850 |
" |
2211 | 851 |
|
852 |
"Created: / 02-04-2019 / 11:03:46 / Claus Gittinger" |
|
853 |
! |
|
854 |
||
855 |
test42c_includesSeparator |
|
856 |
self assert:('hello' includesSeparator not). |
|
857 |
self assert:('he llo' includesSeparator). |
|
858 |
self assert:(' hello' includesSeparator). |
|
859 |
self assert:('hello ' includesSeparator). |
|
860 |
self assert:(' he llo ' includesSeparator). |
|
861 |
self assert:(c'h\nllo' includesSeparator). |
|
862 |
self assert:(c'h\tllo' includesSeparator). |
|
863 |
||
864 |
" |
|
865 |
self new test42c_includesSeparator |
|
866 |
" |
|
867 |
||
868 |
"Created: / 02-04-2019 / 11:05:39 / Claus Gittinger" |
|
1421 | 869 |
! |
1420 | 870 |
|
1421 | 871 |
test43_occurrencesOf |
1418 | 872 |
|s| |
873 |
||
874 |
"/ 12345678901 |
|
875 |
self assert:( 'hello world' occurrencesOf:$0 ) == 0. |
|
1447 | 876 |
self assert:( 'hello world' occurrencesOf:$l ) == 3. |
877 |
self assert:( 'hello world' occurrencesOf:$d ) == 1. |
|
1418 | 878 |
|
879 |
"/ how about 0-bytes in between |
|
880 |
self assert:( #[0 0 1 0 0] asString occurrencesOf:(Character value:1) ) == 1. |
|
881 |
self assert:( #[0 0 1 0 0] asString occurrencesOf:(Character value:0) ) == 4. |
|
882 |
||
883 |
1 to:10 do:[:nA | |
|
1447 | 884 |
1 to:10 do:[:nB | |
885 |
s := (String new:nA withAll:$a),(String new:nB withAll:$b). |
|
886 |
self assert:(s occurrencesOf:$a) == nA. |
|
887 |
self assert:(s occurrencesOf:$b) == nB. |
|
888 |
] |
|
889 |
]. |
|
1418 | 890 |
|
891 |
s := String new:1024. |
|
892 |
s atAllPut:$a. |
|
893 |
s at:512 put:(Character space). |
|
894 |
self assert:(s occurrencesOf:(Character space)) == 1. |
|
895 |
self assert:(s occurrencesOf:$a) == 1023. |
|
896 |
||
897 |
s := String new:1024. |
|
898 |
s atAllPut:$a. |
|
899 |
1 to:1024 by:2 do:[:i | s at:i put:$b]. |
|
900 |
self assert:(s occurrencesOf:$a) == 512. |
|
901 |
self assert:(s occurrencesOf:$b) == 512. |
|
1421 | 902 |
|
1418 | 903 |
" |
1421 | 904 |
self new test43_occurrencesOf |
1418 | 905 |
" |
906 |
! |
|
907 |
||
571 | 908 |
test50_indexOf |
909 |
|s i| |
|
910 |
||
911 |
s := 'Some Sample Generators (74035660-d1f6-11df-9ab3-00ff7b08316c)'. |
|
912 |
1 to:s size do:[:start | |
|
2211 | 913 |
i := s indexOf:$- startingAt:start. |
914 |
self assert:(i == 0 or:[ i >= start]). |
|
571 | 915 |
]. |
1418 | 916 |
"/ 12345678901 |
917 |
self assert:( 'hello world' indexOf:$0 startingAt:1 ) == 0. |
|
1447 | 918 |
self assert:( 'hello world' indexOf:$l startingAt:1 ) == 3. |
919 |
self assert:( 'hello world' indexOf:$l startingAt:5 ) == 10. |
|
920 |
self assert:( 'hello world' indexOf:$d startingAt:5 ) == 11. |
|
1418 | 921 |
|
1426 | 922 |
"/ 12345678901 |
923 |
self assert:(('hello world' indexOf:$o startingAt:1) == 5). |
|
924 |
self assert:(('hello world' indexOf:$o startingAt:2) == 5). |
|
925 |
self assert:(('hello world' indexOf:$o startingAt:3) == 5). |
|
926 |
self assert:(('hello world' indexOf:$o startingAt:4) == 5). |
|
927 |
self assert:(('hello world' indexOf:$o startingAt:5) == 5). |
|
928 |
self assert:(('hello world' indexOf:$o startingAt:6) == 8). |
|
929 |
self assert:(('hello world' indexOf:$o startingAt:7) == 8). |
|
930 |
self assert:(('hello world' indexOf:$o startingAt:8) == 8). |
|
931 |
self assert:(('hello world' indexOf:$o startingAt:9) == 0). |
|
932 |
self assert:(('hello world' indexOf:$o startingAt:10) == 0). |
|
933 |
self assert:(('hello world' indexOf:$o startingAt:11) == 0). |
|
934 |
self assert:(('hello world' indexOf:$o startingAt:12) == 0). |
|
935 |
self assert:(('hello world' indexOf:$o startingAt:10000) == 0). |
|
936 |
||
1418 | 937 |
"/ how about 0-bytes in between |
938 |
self assert:( #[0 0 1 0 0] asString indexOf:(Character value:1) startingAt:1 ) == 3. |
|
939 |
self assert:( #[0 0 1 0 0] asString indexOf:(Character value:0) startingAt:3 ) == 4. |
|
940 |
self assert:( #[0 0 1 1 0] asString indexOf:(Character value:0) startingAt:3 ) == 5. |
|
941 |
self assert:( #[0 1 0 1 0] asString indexOf:(Character value:1) startingAt:3 ) == 4. |
|
942 |
||
943 |
s := '12345678901234b'. |
|
944 |
self assert:(s indexOf:$x) == 0. |
|
945 |
self assert:(s indexOf:$1) == 1. |
|
946 |
self assert:(s indexOf:$2) == 2. |
|
947 |
self assert:(s indexOf:$3) == 3. |
|
948 |
self assert:(s indexOf:$4) == 4. |
|
949 |
self assert:(s indexOf:$5) == 5. |
|
950 |
self assert:(s indexOf:$0) == 10. |
|
951 |
self assert:(s indexOf:$b) == 15. |
|
952 |
||
953 |
s := ''. |
|
954 |
self assert:(s indexOf:$1) == 0. |
|
955 |
s := '1'. |
|
956 |
self assert:(s indexOf:$1) == 1. |
|
957 |
self assert:(s indexOf:$2) == 0. |
|
958 |
s := '12'. |
|
959 |
self assert:(s indexOf:$1) == 1. |
|
960 |
self assert:(s indexOf:$2) == 2. |
|
961 |
self assert:(s indexOf:$3) == 0. |
|
962 |
s := '123'. |
|
963 |
self assert:(s indexOf:$1) == 1. |
|
964 |
self assert:(s indexOf:$2) == 2. |
|
965 |
self assert:(s indexOf:$3) == 3. |
|
966 |
self assert:(s indexOf:$4) == 0. |
|
967 |
s := '1234'. |
|
968 |
self assert:(s indexOf:$1) == 1. |
|
969 |
self assert:(s indexOf:$2) == 2. |
|
970 |
self assert:(s indexOf:$3) == 3. |
|
971 |
self assert:(s indexOf:$4) == 4. |
|
972 |
self assert:(s indexOf:$5) == 0. |
|
973 |
s := '12345'. |
|
974 |
self assert:(s indexOf:$1) == 1. |
|
975 |
self assert:(s indexOf:$2) == 2. |
|
976 |
self assert:(s indexOf:$3) == 3. |
|
977 |
self assert:(s indexOf:$4) == 4. |
|
978 |
self assert:(s indexOf:$5) == 5. |
|
979 |
self assert:(s indexOf:$6) == 0. |
|
980 |
s := '123456'. |
|
981 |
self assert:(s indexOf:$1) == 1. |
|
982 |
self assert:(s indexOf:$2) == 2. |
|
983 |
self assert:(s indexOf:$3) == 3. |
|
984 |
self assert:(s indexOf:$4) == 4. |
|
985 |
self assert:(s indexOf:$5) == 5. |
|
986 |
self assert:(s indexOf:$6) == 6. |
|
987 |
self assert:(s indexOf:$7) == 0. |
|
988 |
s := '1234567'. |
|
989 |
self assert:(s indexOf:$1) == 1. |
|
990 |
self assert:(s indexOf:$2) == 2. |
|
991 |
self assert:(s indexOf:$3) == 3. |
|
992 |
self assert:(s indexOf:$4) == 4. |
|
993 |
self assert:(s indexOf:$5) == 5. |
|
994 |
self assert:(s indexOf:$6) == 6. |
|
995 |
self assert:(s indexOf:$7) == 7. |
|
996 |
self assert:(s indexOf:$8) == 0. |
|
997 |
s := '12345678'. |
|
998 |
self assert:(s indexOf:$1) == 1. |
|
999 |
self assert:(s indexOf:$2) == 2. |
|
1000 |
self assert:(s indexOf:$3) == 3. |
|
1001 |
self assert:(s indexOf:$4) == 4. |
|
1002 |
self assert:(s indexOf:$5) == 5. |
|
1003 |
self assert:(s indexOf:$6) == 6. |
|
1004 |
self assert:(s indexOf:$7) == 7. |
|
1005 |
self assert:(s indexOf:$8) == 8. |
|
1006 |
self assert:(s indexOf:$9) == 0. |
|
1007 |
s := '123456789'. |
|
1008 |
self assert:(s indexOf:$1) == 1. |
|
1009 |
self assert:(s indexOf:$2) == 2. |
|
1010 |
self assert:(s indexOf:$3) == 3. |
|
1011 |
self assert:(s indexOf:$4) == 4. |
|
1012 |
self assert:(s indexOf:$5) == 5. |
|
1013 |
self assert:(s indexOf:$6) == 6. |
|
1014 |
self assert:(s indexOf:$7) == 7. |
|
1015 |
self assert:(s indexOf:$8) == 8. |
|
1016 |
self assert:(s indexOf:$9) == 9. |
|
1017 |
||
1018 |
self assert:(s indexOf:$0) == 0. |
|
1019 |
self assert:(s indexOf:$b) == 0. |
|
1020 |
||
1021 |
s := String new:1024. |
|
1022 |
s atAllPut:$a. |
|
1023 |
s at:512 put:(Character space). |
|
1024 |
self assert:(s indexOf:(Character space)) == 512. |
|
1025 |
self assert:(s indexOf:(Character space) startingAt:1) == 512. |
|
1026 |
self assert:(s indexOf:(Character space) startingAt:2) == 512. |
|
1027 |
self assert:(s indexOf:(Character space) startingAt:3) == 512. |
|
1028 |
self assert:(s indexOf:(Character space) startingAt:4) == 512. |
|
1029 |
self assert:(s indexOf:(Character space) startingAt:5) == 512. |
|
1030 |
self assert:(s indexOf:(Character space) startingAt:6) == 512. |
|
1031 |
self assert:(s indexOf:(Character space) startingAt:7) == 512. |
|
1032 |
self assert:(s indexOf:(Character space) startingAt:8) == 512. |
|
1033 |
self assert:(s indexOf:(Character space) startingAt:9) == 512. |
|
1034 |
self assert:(s indexOf:(Character space) startingAt:511) == 512. |
|
1035 |
self assert:(s indexOf:(Character space) startingAt:512) == 512. |
|
1036 |
self assert:(s indexOf:(Character space) startingAt:513) == 0. |
|
571 | 1037 |
|
2211 | 1038 |
self assert:(s indexOfSeparator) == 512. |
1039 |
self assert:(s indexOfSeparatorStartingAt:1) == 512. |
|
1040 |
self assert:(s indexOfSeparatorStartingAt:2) == 512. |
|
1041 |
self assert:(s indexOfSeparatorStartingAt:3) == 512. |
|
1042 |
self assert:(s indexOfSeparatorStartingAt:4) == 512. |
|
1043 |
self assert:(s indexOfSeparatorStartingAt:5) == 512. |
|
1044 |
self assert:(s indexOfSeparatorStartingAt:6) == 512. |
|
1045 |
self assert:(s indexOfSeparatorStartingAt:7) == 512. |
|
1046 |
self assert:(s indexOfSeparatorStartingAt:8) == 512. |
|
1047 |
self assert:(s indexOfSeparatorStartingAt:9) == 512. |
|
1048 |
self assert:(s indexOfSeparatorStartingAt:511) == 512. |
|
1049 |
self assert:(s indexOfSeparatorStartingAt:512) == 512. |
|
1050 |
self assert:(s indexOfSeparatorStartingAt:513) == 0. |
|
1051 |
||
571 | 1052 |
" |
1053 |
self new test50_indexOf |
|
1054 |
" |
|
1055 |
||
1056 |
"Created: / 29-10-2010 / 14:58:21 / cg" |
|
2211 | 1057 |
"Modified: / 02-04-2019 / 11:06:52 / Claus Gittinger" |
751
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1058 |
! |
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1059 |
|
1373 | 1060 |
test51_substrings |
1061 |
self assert:('aaa/bbb/ccc' subStrings:'/') asArray = #('aaa' 'bbb' 'ccc'). |
|
1062 |
self assert:(('aaa/bbb/ccc' subStrings:'/') asStringWith:'/') = 'aaa/bbb/ccc'. |
|
1063 |
||
2083 | 1064 |
self assert:('aaa/bbb' withoutSuffix:'bbb') = 'aaa/'. |
1065 |
self assert:('aaa/bbb' withoutPrefix:'aaa') = '/bbb'. |
|
1066 |
||
1385 | 1067 |
"/ self assert:('/aaa/bbb/ccc' subStrings:'/') asArray = #('' 'aaa' 'bbb' 'ccc'). |
1068 |
"/ self assert:(('/aaa/bbb/ccc' subStrings:'/') asStringWith:'/') = '/aaa/bbb/ccc'. |
|
1069 |
"/ |
|
1070 |
"/ self assert:('aaa/bbb/ccc/' subStrings:'/') asArray = #('aaa' 'bbb' 'ccc' '' ). |
|
1071 |
"/ self assert:(('aaa/bbb/ccc/' subStrings:'/') asStringWith:'/') = '/aaa/bbb/ccc/'. |
|
1072 |
"/ |
|
1073 |
"/ self assert:('/aaa/bbb/ccc/' subStrings:'/') asArray = #('' 'aaa' 'bbb' 'ccc' ''). |
|
1074 |
"/ self assert:(('/aaa/bbb/ccc/' subStrings:'/') asStringWith:'/') = '/aaa/bbb/ccc'' '. |
|
1075 |
"/ |
|
1076 |
"/ self assert:('//aaa/bbb/ccc' subStrings:'/') asArray = #('' '' 'aaa' 'bbb' 'ccc'). |
|
1077 |
"/ self assert:(('//aaa/bbb/ccc' subStrings:'/') asStringWith:'/') = '//aaa/bbb/ccc'. |
|
1373 | 1078 |
|
1079 |
" |
|
1080 |
self new test51_substrings |
|
1081 |
" |
|
2083 | 1082 |
|
1083 |
"Modified: / 11-02-2019 / 23:57:03 / Claus Gittinger" |
|
1373 | 1084 |
! |
1085 |
||
1420 | 1086 |
test52_indexOfSeparator |
1426 | 1087 |
|j s| |
1420 | 1088 |
|
1089 |
self assert:('' indexOfSeparator) == 0. |
|
1090 |
1 to:20 do:[:n | |
|
1447 | 1091 |
s := (String new:n withAll:$a). |
1092 |
1 to:20 do:[:start | |
|
1093 |
self assert:(s indexOfSeparatorStartingAt:start) == 0. |
|
1094 |
]. |
|
1095 |
]. |
|
1420 | 1096 |
1 to:20 do:[:n | |
1447 | 1097 |
s := (String new:n withAll:$a),' '. |
1098 |
1 to:n do:[:start | |
|
1099 |
self assert:(s indexOfSeparatorStartingAt:start) == (n+1). |
|
1100 |
]. |
|
1101 |
]. |
|
1102 |
||
1103 |
{ |
|
1104 |
Character space . |
|
1105 |
Character tab . |
|
1106 |
Character return . |
|
1107 |
Character lf . |
|
1420 | 1108 |
} do:[:sep | |
1447 | 1109 |
1 to:20 do:[:na | |
1110 |
1 to:20 do:[:nb | |
|
1111 |
s := (String new:na withAll:$a),sep,(String new:na withAll:$a). |
|
1112 |
1 to:na do:[:start | |
|
1113 |
self assert:(s indexOfSeparatorStartingAt:start) == (na+1). |
|
1114 |
] |
|
1115 |
] |
|
1116 |
]. |
|
1420 | 1117 |
]. |
1447 | 1118 |
|
1119 |
{ |
|
1120 |
Character esc . |
|
1121 |
Character null . |
|
1122 |
$a . |
|
1420 | 1123 |
} do:[:nonSep | |
1447 | 1124 |
1 to:20 do:[:na | |
1125 |
1 to:20 do:[:nb | |
|
1126 |
s := (String new:na withAll:$a),nonSep,(String new:na withAll:$a). |
|
1127 |
1 to:20 do:[:start | |
|
1128 |
self assert:(s indexOfSeparatorStartingAt:start) == 0. |
|
1129 |
] |
|
1130 |
] |
|
1131 |
]. |
|
1420 | 1132 |
]. |
1133 |
||
1426 | 1134 |
s := String new:1000 withAll:$a. |
1135 |
self assert:(s indexOfSeparatorStartingAt:1) == 0. |
|
1136 |
400 to: 417 do:[:i | |
|
1447 | 1137 |
s := String new:1000 withAll:$a. |
1138 |
s at:i put:(Character space). |
|
1139 |
self assert:(s indexOfSeparatorStartingAt:1) == i. |
|
1426 | 1140 |
|
1447 | 1141 |
s := String new:1000 withAll:$a. |
1142 |
s at:i put:(Character return). |
|
1143 |
self assert:(s indexOfSeparatorStartingAt:1) == i. |
|
1144 |
]. |
|
1426 | 1145 |
|
1146 |
"/ 12345678901 |
|
1147 |
j := 'hello world' indexOfSeparatorStartingAt:1. |
|
1148 |
self assert:(j == 6). |
|
1149 |
j := 'hello world ' indexOfSeparatorStartingAt:2. |
|
1150 |
self assert:(j == 6). |
|
1151 |
j := 'hello world ' indexOfSeparatorStartingAt:3. |
|
1447 | 1152 |
self assert:(j == 6). |
1426 | 1153 |
j := 'hello world ' indexOfSeparatorStartingAt:4. |
1447 | 1154 |
self assert:(j == 6). |
1426 | 1155 |
j := 'hello world ' indexOfSeparatorStartingAt:5. |
1156 |
self assert:(j == 6). |
|
1157 |
j := 'hello world ' indexOfSeparatorStartingAt:6. |
|
1158 |
self assert:(j == 6). |
|
1159 |
j := 'hello world ' indexOfSeparatorStartingAt:7. |
|
1160 |
self assert:(j == 12). |
|
1161 |
j := 'hello world ' indexOfSeparatorStartingAt:8. |
|
1162 |
self assert:(j == 12). |
|
1163 |
j := 'hello world ' indexOfSeparatorStartingAt:9. |
|
1447 | 1164 |
self assert:(j == 12). |
1426 | 1165 |
j := 'hello world ' indexOfSeparatorStartingAt:10. |
1447 | 1166 |
self assert:(j == 12). |
1426 | 1167 |
j := 'hello world ' indexOfSeparatorStartingAt:11. |
1168 |
self assert:(j == 12). |
|
1169 |
j := 'hello world ' indexOfSeparatorStartingAt:12. |
|
1170 |
self assert:(j == 12). |
|
1171 |
j := 'hello world' indexOfSeparatorStartingAt:12. |
|
1447 | 1172 |
self assert:(j == 0). |
1426 | 1173 |
j := 'hello world ' indexOfSeparatorStartingAt:13. |
1174 |
self assert:(j == 0). |
|
1175 |
j := 'hello world ' indexOfSeparatorStartingAt:10000. |
|
1447 | 1176 |
self assert:(j == 0). |
1177 |
||
1420 | 1178 |
" |
1179 |
self new test52_indexOfSeparator |
|
1180 |
" |
|
1181 |
! |
|
1182 |
||
1183 |
test54_occurrencesOf |
|
1184 |
|s| |
|
1185 |
||
1186 |
self assert:('' occurrencesOf:$a) == 0. |
|
1187 |
1 to:20 do:[:n | |
|
1447 | 1188 |
s := (String new:n withAll:$a). |
1189 |
self assert:(s occurrencesOf:$a) == n. |
|
1190 |
]. |
|
1420 | 1191 |
1 to:20 do:[:na | |
1447 | 1192 |
1 to:20 do:[:nb | |
1193 |
s := (String new:na withAll:$a),(String new:nb withAll:$b). |
|
1194 |
self assert:(s occurrencesOf:$a) == na. |
|
1195 |
]. |
|
1196 |
]. |
|
1420 | 1197 |
1 to:40 do:[:n | |
1447 | 1198 |
s := String new:n withAll:$a. |
1199 |
1 to:n by:2 do:[:n | |
|
1200 |
s at:n put:$b. |
|
1201 |
]. |
|
1202 |
self assert:(s occurrencesOf:$a) == (n // 2). |
|
1203 |
]. |
|
1204 |
||
1420 | 1205 |
s := String new:1000 withAll:$a. |
1206 |
self assert:(s occurrencesOf:$a) == 1000. |
|
1207 |
1 to:1000 do:[:i | |
|
1447 | 1208 |
s at:i put:$b. |
1209 |
self assert:(s occurrencesOf:$a) == (1000-i). |
|
1210 |
self assert:(s occurrencesOf:$b) == i. |
|
1420 | 1211 |
]. |
1447 | 1212 |
|
1420 | 1213 |
" |
1214 |
self new test54_occurrencesOf |
|
1215 |
" |
|
1216 |
! |
|
1217 |
||
2211 | 1218 |
test60a_hash |
751
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1219 |
" |
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1220 |
As of 2013-01-09 for strings of size 7 String & Unicode16String hash |
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1221 |
returned different values. This test checks this |
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1222 |
" |
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1223 |
|
753
81af28f807cf
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
752
diff
changeset
|
1224 |
| tester | |
751
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1225 |
|
753
81af28f807cf
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
752
diff
changeset
|
1226 |
tester := [:s| |
2211 | 1227 |
|sHash u16Hash u32Hash| |
1385 | 1228 |
|
2211 | 1229 |
sHash := s hash. |
1230 |
u16Hash := s asUnicode16String hash. |
|
1231 |
u32Hash := s asUnicode32String hash. |
|
1385 | 1232 |
|
2211 | 1233 |
self assert: sHash == u16Hash |
1234 |
description: ('String and Unicode16String hashes differ on "%1" (%2)' |
|
1235 |
bindWith:s with:s class name). |
|
1236 |
self assert: sHash == u32Hash |
|
1237 |
description: ('String and Unicode32String hashes differ on "%1" (%2)' |
|
1238 |
bindWith:s with:s class name) |
|
751
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1239 |
]. |
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1240 |
|
753
81af28f807cf
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
752
diff
changeset
|
1241 |
tester value:'a'. |
2211 | 1242 |
tester value:'123456789012345678'. |
1243 |
tester value:'12345678901234567'. |
|
1244 |
tester value:'1234567890123456'. |
|
1245 |
tester value:'123456789012345'. |
|
1385 | 1246 |
tester value:'12345678901234'. |
1247 |
tester value:'1234567890123'. |
|
1248 |
tester value:'123456789012'. |
|
1249 |
tester value:'12345678901'. |
|
1250 |
tester value:'1234567890'. |
|
1251 |
tester value:'123456789'. |
|
753
81af28f807cf
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
752
diff
changeset
|
1252 |
tester value:'12345678'. |
81af28f807cf
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
752
diff
changeset
|
1253 |
tester value:'1234567'. |
81af28f807cf
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
752
diff
changeset
|
1254 |
tester value:'123456'. |
1385 | 1255 |
tester value:'12345'. |
1256 |
tester value:'1234'. |
|
1257 |
tester value:'123'. |
|
1258 |
tester value:'12'. |
|
753
81af28f807cf
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
752
diff
changeset
|
1259 |
tester value:'boolean'. |
751
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1260 |
|
1417 | 1261 |
"/ strings with 0-elements |
1262 |
tester value:('' copyWith:Character null). |
|
1263 |
tester value:('1' copyWith:Character null). |
|
1264 |
tester value:('12' copyWith:Character null). |
|
1265 |
tester value:('123' copyWith:Character null). |
|
1266 |
tester value:('1234' copyWith:Character null). |
|
1267 |
tester value:('12345' copyWith:Character null). |
|
1268 |
tester value:('123456' copyWith:Character null). |
|
1269 |
tester value:('1234567' copyWith:Character null). |
|
1270 |
tester value:('12345678' copyWith:Character null). |
|
1271 |
tester value:('123456789' copyWith:Character null). |
|
2211 | 1272 |
tester value:('1234567890' copyWith:Character null). |
1273 |
tester value:('12345678901' copyWith:Character null). |
|
1274 |
tester value:('123456789012' copyWith:Character null). |
|
1275 |
tester value:('1234567890123' copyWith:Character null). |
|
1276 |
tester value:('12345678901234' copyWith:Character null). |
|
1277 |
tester value:('123456789012345' copyWith:Character null). |
|
1278 |
tester value:('1234567890123456' copyWith:Character null). |
|
1279 |
tester value:('12345678901234567' copyWith:Character null). |
|
1419 | 1280 |
|
1281 |
tester value:('' copyWith:Character null),'123'. |
|
1282 |
tester value:('1' copyWith:Character null),'123'. |
|
1283 |
tester value:('12' copyWith:Character null),'123'. |
|
1284 |
tester value:('123' copyWith:Character null),'123'. |
|
1285 |
tester value:('1234' copyWith:Character null),'123'. |
|
1286 |
tester value:('12345' copyWith:Character null),'123'. |
|
1287 |
tester value:('123456' copyWith:Character null),'123'. |
|
1288 |
tester value:('1234567' copyWith:Character null),'123'. |
|
1289 |
tester value:('12345678' copyWith:Character null),'123'. |
|
1290 |
tester value:('123456789' copyWith:Character null),'123'. |
|
2211 | 1291 |
tester value:('1234567890' copyWith:Character null),'123'. |
1292 |
tester value:('12345678901' copyWith:Character null),'123'. |
|
1293 |
tester value:('123456789012' copyWith:Character null),'123'. |
|
1294 |
tester value:('1234567890123' copyWith:Character null),'123'. |
|
1295 |
tester value:('12345678901234' copyWith:Character null),'123'. |
|
1296 |
tester value:('123456789012345' copyWith:Character null),'123'. |
|
1297 |
tester value:('1234567890123456' copyWith:Character null),'123'. |
|
1298 |
||
1299 |
"Created: / 02-04-2019 / 10:55:23 / Claus Gittinger" |
|
1300 |
! |
|
1301 |
||
1302 |
test60b_hash |
|
1303 |
| tester | |
|
1304 |
||
2212 | 1305 |
"/ self skip:'takes long'. |
2211 | 1306 |
|
1307 |
tester := [:s| |
|
1308 |
|sHash u16Hash u32Hash| |
|
1309 |
||
1310 |
sHash := s hash. |
|
1311 |
u16Hash := s asUnicode16String hash. |
|
1312 |
u32Hash := s asUnicode32String hash. |
|
1313 |
||
1314 |
self assert: sHash == u16Hash |
|
1315 |
description: ('String and Unicode16String hashes differ on "%1" (%2)' |
|
1316 |
bindWith:s with:s class name). |
|
1317 |
self assert: sHash == u32Hash |
|
1318 |
description: ('String and Unicode32String hashes differ on "%1" (%2)' |
|
1319 |
bindWith:s with:s class name) |
|
1320 |
]. |
|
1447 | 1321 |
|
1419 | 1322 |
"/ String allInstancesDo:[:each| tester value:each]. |
753
81af28f807cf
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
752
diff
changeset
|
1323 |
Symbol allInstancesDo:[:each| tester value:each]. |
751
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1324 |
|
2211 | 1325 |
"Created: / 02-04-2019 / 10:55:26 / Claus Gittinger" |
962
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1326 |
! |
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1327 |
|
1426 | 1328 |
test65_concatenation |
1329 |
|strA strB| |
|
1330 |
||
1447 | 1331 |
0 to:32 do:[:szA | |
2207 | 1332 |
0 to:32 do:[:szB | |
1333 |
|szAB| |
|
1426 | 1334 |
|
2207 | 1335 |
strA := String new:szA withAll:$a. |
1336 |
strB := String new:szB withAll:$b. |
|
1337 |
szAB := szA + szB. |
|
1338 |
self assert:(szA = strA size). |
|
1339 |
self assert:(szB = strB size). |
|
1340 |
"/ why repeat ??? - to check GC??? |
|
1341 |
1 "10000" timesRepeat:[ |
|
1342 |
|strAB| |
|
1426 | 1343 |
|
2207 | 1344 |
strAB := strA , strB. |
1345 |
self assert:(szAB == strAB size). |
|
1346 |
] |
|
1347 |
] |
|
1426 | 1348 |
]. |
1349 |
||
1350 |
strA := strB := ''. |
|
1351 |
self assert: ((strA , strB) = ''). |
|
1352 |
self assert: ((strA , strA) = ''). |
|
1353 |
strA := 'a'. |
|
1447 | 1354 |
self assert: ((strA , strA) = 'aa'). |
1426 | 1355 |
self assert: ((strA , strB) = 'a'). |
1356 |
strA := ''. |
|
1357 |
strB := 'b'. |
|
1447 | 1358 |
self assert: ((strA , strB) = 'b'). |
1426 | 1359 |
strA := 'b'. |
1360 |
strB := 'a'. |
|
1447 | 1361 |
self assert: ((strB , strA) = 'ab'). |
2207 | 1362 |
|
1363 |
"/ concatenating other things |
|
1364 |
self assert:('hello',123) = 'hello123'. |
|
1365 |
self assert:('hello' asUnicode16String,123) = 'hello123' asUnicode16String. |
|
1366 |
self assert:('hello' asUnicode32String,123) = 'hello123' asUnicode32String. |
|
1367 |
||
1368 |
"/ concatenating other things |
|
1369 |
self assert:('hello',,123) = c'hello\n123'. |
|
1370 |
self assert:('hello' asUnicode16String,,123) = c'hello\n123' asUnicode16String. |
|
1371 |
self assert:('hello' asUnicode32String,,123) = c'hello\n123' asUnicode32String. |
|
1372 |
||
1426 | 1373 |
" |
1374 |
self new test65_concatenation |
|
1375 |
" |
|
2207 | 1376 |
|
1377 |
"Modified: / 02-04-2019 / 10:41:24 / Claus Gittinger" |
|
1426 | 1378 |
! |
1379 |
||
1380 |
test66_replace |
|
1381 |
|strA| |
|
1382 |
||
1383 |
1 to:64 do:[:szA | |
|
1447 | 1384 |
strA := String new:szA withAll:$a. |
1385 |
1 to:szA do:[:idx | |
|
1386 |
strA at:idx put:$*. |
|
1426 | 1387 |
|
1447 | 1388 |
strA replaceAll:$* with:$#. |
1426 | 1389 |
|
1447 | 1390 |
self assert:(strA at:idx) = $#. |
1391 |
self assert:(strA occurrencesOf:$#) = idx. |
|
1392 |
self assert:(strA count:[:ch | ch = $#]) = idx. |
|
1393 |
self assert:(strA occurrencesOf:$*) = 0. |
|
1394 |
self assert:(strA count:[:ch | ch = $*]) = 0. |
|
1395 |
self assert:(strA includes:$#). |
|
1396 |
self assert:(strA includes:$*) not. |
|
1397 |
] |
|
1426 | 1398 |
] |
1399 |
||
1400 |
" |
|
1401 |
self new test66_replace |
|
1402 |
" |
|
1403 |
! |
|
1404 |
||
1405 |
test67_concatenationAnd |
|
1406 |
|strA strB strC| |
|
1407 |
||
1447 | 1408 |
0 to:32 do:[:szA | |
2210 | 1409 |
0 to:32 do:[:szB | |
1410 |
0 to:32 do:[:szC | |
|
1411 |
|szABC| |
|
1412 |
strA := String new:szA withAll:$a. |
|
1413 |
strB := String new:szB withAll:$b. |
|
1414 |
strC := String new:szC withAll:$c. |
|
1426 | 1415 |
|
2210 | 1416 |
szABC := szA + szB + szC. |
1417 |
self assert:(szA = strA size). |
|
1418 |
self assert:(szB = strB size). |
|
1419 |
self assert:(szC = strC size). |
|
1426 | 1420 |
|
2210 | 1421 |
"/ why repeat? to test GC??? |
1422 |
1 "300" timesRepeat:[ |
|
1423 |
|strABC| |
|
1426 | 1424 |
|
2210 | 1425 |
strABC := strA concatenate:strB and:strC. |
1426 |
||
1427 |
self assert:(szABC == strABC size). |
|
1428 |
] |
|
1429 |
] |
|
1430 |
] |
|
1426 | 1431 |
]. |
1432 |
strA := strB := strC := ''. |
|
1433 |
self assert: ((strA concatenate:strB and:strC) = ''). |
|
1434 |
strA := 'a'. |
|
1435 |
self assert: ((strA concatenate:strB and:strC) = 'a'). |
|
1436 |
strA := ''. |
|
1437 |
strB := 'b'. |
|
1447 | 1438 |
self assert: ((strA concatenate:strB and:strC) = 'b'). |
1426 | 1439 |
strB := ''. |
1440 |
strC := 'c'. |
|
1447 | 1441 |
self assert: ((strA concatenate:strB and:strC) = 'c'). |
1426 | 1442 |
strA := 'c'. |
1443 |
strB := 'b'. |
|
1444 |
strC := 'a'. |
|
1447 | 1445 |
self assert: ((strC concatenate:strB and:strA) = 'abc'). |
1426 | 1446 |
" |
1447 |
self new test67_concatenationAnd |
|
1448 |
" |
|
2210 | 1449 |
|
1450 |
"Modified: / 02-04-2019 / 10:51:31 / Claus Gittinger" |
|
1426 | 1451 |
! |
1452 |
||
1453 |
test68_concatenationAndAnd |
|
1454 |
|strA strB strC strD| |
|
1455 |
||
1447 | 1456 |
0 to:32 do:[:szA | |
2210 | 1457 |
strA := String new:szA withAll:$a. |
1458 |
self assert:(szA = strA size). |
|
1459 |
0 to:32 do:[:szB | |
|
1460 |
strB := String new:szB withAll:$b. |
|
1461 |
self assert:(szB = strB size). |
|
1462 |
0 to:32 do:[:szC | |
|
1463 |
strC := String new:szC withAll:$c. |
|
1464 |
self assert:(szC = strC size). |
|
1465 |
0 to:32 do:[:szD | |
|
1466 |
|szABCD| |
|
1467 |
strD := String new:szD withAll:$d. |
|
1468 |
||
1469 |
szABCD := szA + szB + szC + szD. |
|
1426 | 1470 |
|
2210 | 1471 |
self assert:(szD = strD size). |
1426 | 1472 |
|
2210 | 1473 |
"/ why repeat??? |
1474 |
1 "5" timesRepeat:[ |
|
1475 |
|strABCD| |
|
1426 | 1476 |
|
2210 | 1477 |
strABCD := strA concatenate:strB and:strC and:strD. |
1426 | 1478 |
|
2210 | 1479 |
self assert:(szABCD == strABCD size). |
1480 |
] |
|
1481 |
] |
|
1482 |
] |
|
1483 |
] |
|
1426 | 1484 |
]. |
1485 |
||
1486 |
strA := strB := strC := strD := ''. |
|
1487 |
self assert: ((strA concatenate:strB and:strC and:strD) = ''). |
|
1488 |
strA := 'a'. |
|
1489 |
self assert: ((strA concatenate:strB and:strC and:strD) = 'a'). |
|
1490 |
strA := ''. |
|
1491 |
strB := 'b'. |
|
1447 | 1492 |
self assert: ((strA concatenate:strB and:strC and:strD) = 'b'). |
1426 | 1493 |
strB := ''. |
1494 |
strC := 'c'. |
|
1447 | 1495 |
self assert: ((strA concatenate:strB and:strC and:strD) = 'c'). |
1426 | 1496 |
strC := ''. |
1497 |
strD := 'd'. |
|
1447 | 1498 |
self assert: ((strA concatenate:strB and:strC and:strD) = 'd'). |
1426 | 1499 |
strA := 'd'. |
1500 |
strB := 'c'. |
|
1501 |
strC := 'b'. |
|
1447 | 1502 |
strD := 'a'. |
1503 |
self assert: ((strD concatenate:strC and:strB and:strA) = 'abcd'). |
|
1426 | 1504 |
" |
1505 |
self new test68_concatenationAndAnd |
|
1506 |
" |
|
2210 | 1507 |
|
1508 |
"Modified: / 02-04-2019 / 10:51:50 / Claus Gittinger" |
|
1426 | 1509 |
! |
1510 |
||
1991 | 1511 |
test69_split |
1512 |
self assert:(('a,b,c,d' splitByAny:',;') sameContentsAs: #('a' 'b' 'c' 'd')). |
|
1513 |
self assert:(('a;b;c;d' splitByAny:',;') sameContentsAs: #('a' 'b' 'c' 'd')). |
|
1514 |
self assert:(('a;b,c;d' splitByAny:',;') sameContentsAs: #('a' 'b' 'c' 'd')). |
|
1515 |
||
1516 |
self assert:(($, split:'a,b,c,d') sameContentsAs: #('a' 'b' 'c' 'd')). |
|
1517 |
self assert:((',' split:'a,b,c,d') sameContentsAs: #('a' 'b' 'c' 'd')). |
|
1518 |
self assert:(('//' split:'a//b//c//d') sameContentsAs: #('a' 'b' 'c' 'd')). |
|
1519 |
self assert:(('a//b//c//d' splitOn:'//') sameContentsAs: #('a' 'b' 'c' 'd')). |
|
1520 |
||
1521 |
"/ self assert:(([:ch | ch isLetter] split:'a2b3c4') sameContentsAs: #('1' '2' '3' '4')). |
|
1522 |
"/ self assert:(([:char | char isDigit] split: '1a2b3c4') sameContentsAs: #('a' 'b' 'c')). |
|
1523 |
||
1524 |
" |
|
1525 |
self new test69_split |
|
1526 |
" |
|
1527 |
||
1528 |
"Created: / 20-07-2018 / 23:54:15 / Claus Gittinger" |
|
1529 |
! |
|
1530 |
||
962
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1531 |
test70_storeString |
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1532 |
|
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1533 |
self assert: 'AAA' storeString = '''AAA'''. |
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1534 |
self assert: 'A''A''A' storeString = '''A''''A''''A'''. |
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1535 |
|
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1536 |
self assert: 'AAA' asImmutableString storeString = '''AAA'''. |
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1537 |
self assert: 'A''A''A' asImmutableString storeString = '''A''''A''''A'''. |
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1538 |
|
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1539 |
"Created: / 14-07-2013 / 19:17:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1103
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1540 |
! |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1541 |
|
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1542 |
test80_copyReplaceAll |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1543 |
|
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1544 |
| orig copy | |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1545 |
|
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1546 |
orig := 'AAA' copy. "/ In case literals are immutable... |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1547 |
self assert: orig = 'AAA'. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1548 |
|
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1549 |
copy := orig copyReplaceAll: $A with: $X. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1550 |
self assert: copy = 'XXX'. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1551 |
self assert: orig = 'AAA'. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1552 |
|
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1553 |
orig := 'AAA' asImmutableString. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1554 |
self assert: orig = 'AAA'. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1555 |
|
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1556 |
copy := orig copyReplaceAll: $A with: $X. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1557 |
self assert: copy = 'XXX'. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1558 |
self assert: orig = 'AAA'. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1559 |
|
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1560 |
"Created: / 06-03-2014 / 15:10:19 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1214
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1561 |
! |
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1562 |
|
1240
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1563 |
test81_filling |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1564 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1565 |
| str | |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1566 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1567 |
str := 'AAA' copy. "/ In case literals are immutable... |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1568 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1569 |
str atAllPut:$B. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1570 |
self assert: str = 'BBB'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1571 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1572 |
str from:1 to:0 put:$C. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1573 |
self assert: str = 'BBB'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1574 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1575 |
str from:1 to:1 put:$D. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1576 |
self assert: str = 'DBB'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1577 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1578 |
str from:1 to:2 put:$E. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1579 |
self assert: str = 'EEB'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1580 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1581 |
str from:1 to:3 put:$F. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1582 |
self assert: str = 'FFF'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1583 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1584 |
str from:1 to:0 put:$G. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1585 |
self assert: str = 'FFF'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1586 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1587 |
str from:-1 to:-2 put:$G. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1588 |
self assert: str = 'FFF'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1589 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1590 |
self should:[ |
1421 | 1591 |
str from:-1 to:-1 put:$x |
1240
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1592 |
] raise:SubscriptOutOfBoundsError. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1593 |
self assert: str = 'FFF'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1594 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1595 |
self should:[ |
1421 | 1596 |
str from:-1 to:1 put:$x |
1240
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1597 |
] raise:SubscriptOutOfBoundsError. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1598 |
self assert: str = 'FFF'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1599 |
! |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1600 |
|
2211 | 1601 |
test82a_expanding |
2077 | 1602 |
|
1603 |
| rslt | |
|
1604 |
||
1605 |
rslt := 'A%1B%2C' expandPlaceholdersWith:#(10 20 30). |
|
1606 |
self assert:(rslt = 'A10B20C'). |
|
1607 |
||
1608 |
rslt := 'A%1B%2C%' expandPlaceholdersWith:#(10 20 30). |
|
1609 |
self assert:(rslt = 'A10B20C%'). |
|
1610 |
||
1611 |
rslt := 'A%%1B%2C%' expandPlaceholdersWith:#(10 20 30). |
|
1612 |
self assert:(rslt = 'A%1B20C%'). |
|
1613 |
||
1614 |
||
1615 |
rslt := 'A%aB%bC' expandPlaceholdersWith:(Dictionary withKeys:#(a b c) |
|
1616 |
andValues:#(10 20 30)). |
|
1617 |
self assert:(rslt = 'A10B20C'). |
|
1618 |
||
1619 |
"/ not expanded, if not found |
|
1620 |
rslt := 'A%aB%bC' expandPlaceholdersWith:(Dictionary withKeys:#(aa bb cc) |
|
1621 |
andValues:#(10 20 30)). |
|
1622 |
self assert:(rslt = 'A%aB%bC'). |
|
1623 |
||
1624 |
rslt := 'A%aaB%bbC' expandPlaceholdersWith:(Dictionary withKeys:#(aa bb cc) |
|
1625 |
andValues:#(10 20 30)). |
|
1626 |
self assert:(rslt = 'A%aaB%bbC'). |
|
1627 |
||
1628 |
rslt := 'A%(aa)B%(bb)C' expandPlaceholdersWith:(Dictionary withKeys:#(aa bb cc) |
|
1629 |
andValues:#(10 20 30)). |
|
1630 |
self assert:(rslt = 'A10B20C'). |
|
1631 |
||
1632 |
"/ allowing non-parenthized |
|
1633 |
rslt := String streamContents:[:s | |
|
1634 |
'A%aa,B%bb,C' |
|
1635 |
expandPlaceholders:$% |
|
1636 |
with:(Dictionary withKeys:#(aa bb cc) andValues:#(10 20 30)) |
|
1637 |
ignoreNumericEscapes:false |
|
1638 |
requireParentheses:false |
|
1639 |
on:s. |
|
1640 |
]. |
|
1641 |
self assert:(rslt = 'A10,B20,C'). |
|
1642 |
||
2211 | 1643 |
"Created: / 02-04-2019 / 11:00:08 / Claus Gittinger" |
1644 |
! |
|
1645 |
||
1646 |
test82b_expanding |
|
1647 |
| rslt | |
|
1648 |
||
1649 |
rslt := 'hello' copyExpanding:(Dictionary |
|
1650 |
withKeys:{$h . $e . $o} |
|
1651 |
andValues:{'HH' . 'EE' . $O }). |
|
1652 |
self assert:(rslt = 'HHEEllO'). |
|
1653 |
||
1654 |
rslt := 'he%2llo%1' % { 123 . 456 }. |
|
1655 |
self assert:(rslt = 'he456llo123'). |
|
1656 |
||
1657 |
"Created: / 02-04-2019 / 11:00:43 / Claus Gittinger" |
|
2077 | 1658 |
! |
1659 |
||
2112 | 1660 |
test83_padding |
1661 |
| rslt | |
|
1662 |
||
1663 |
rslt := 'foo' paddedTo:10. |
|
1664 |
self assert:(rslt = 'foo '). |
|
1665 |
||
1666 |
rslt := 'foo' paddedTo:3. |
|
1667 |
self assert:(rslt = 'foo'). |
|
1668 |
rslt := 'foo' paddedTo:4. |
|
1669 |
self assert:(rslt = 'foo '). |
|
1670 |
rslt := 'foo' paddedTo:2. |
|
1671 |
self assert:(rslt = 'foo'). |
|
1672 |
||
1673 |
rslt := '' paddedTo:2. |
|
1674 |
self assert:(rslt = ' '). |
|
1675 |
||
1676 |
rslt := 'foo' paddedTo:10 with:$-. |
|
1677 |
self assert:(rslt = 'foo-------'). |
|
1678 |
||
1679 |
rslt := 'foo' paddedTo:3 with:$-. |
|
1680 |
self assert:(rslt = 'foo'). |
|
1681 |
rslt := 'foo' paddedTo:4 with:$-. |
|
1682 |
self assert:(rslt = 'foo-'). |
|
1683 |
rslt := 'foo' paddedTo:2 with:$-. |
|
1684 |
self assert:(rslt = 'foo'). |
|
1685 |
||
1686 |
rslt := '' paddedTo:2 with:$-. |
|
1687 |
self assert:(rslt = '--'). |
|
1688 |
||
1689 |
rslt := 'foo' leftPaddedTo:10. |
|
1690 |
self assert:(rslt = ' foo'). |
|
1691 |
||
1692 |
rslt := 'foo' leftPaddedTo:3. |
|
1693 |
self assert:(rslt = 'foo'). |
|
1694 |
rslt := 'foo' leftPaddedTo:4. |
|
1695 |
self assert:(rslt = ' foo'). |
|
1696 |
rslt := 'foo' leftPaddedTo:2. |
|
1697 |
self assert:(rslt = 'foo'). |
|
1698 |
||
1699 |
rslt := '' leftPaddedTo:2. |
|
1700 |
self assert:(rslt = ' '). |
|
1701 |
||
1702 |
rslt := 'foo' leftPaddedTo:10 with:$-. |
|
1703 |
self assert:(rslt = '-------foo'). |
|
1704 |
||
1705 |
rslt := 'foo' leftPaddedTo:3 with:$-. |
|
1706 |
self assert:(rslt = 'foo'). |
|
1707 |
rslt := 'foo' leftPaddedTo:4 with:$-. |
|
1708 |
self assert:(rslt = '-foo'). |
|
1709 |
rslt := 'foo' leftPaddedTo:2 with:$-. |
|
1710 |
self assert:(rslt = 'foo'). |
|
1711 |
||
1712 |
rslt := '' leftPaddedTo:2 with:$-. |
|
1713 |
self assert:(rslt = '--'). |
|
1714 |
||
1715 |
"Created: / 21-03-2019 / 12:58:33 / Claus Gittinger" |
|
1716 |
! |
|
1717 |
||
2211 | 1718 |
test84_withCRs |
1719 |
| rslt | |
|
1720 |
||
1721 |
rslt := 'foo\bar' addLineDelimiters. |
|
1722 |
self assert:(rslt = ('foo',Character cr,'bar')). |
|
1723 |
||
1724 |
"Created: / 02-04-2019 / 10:57:44 / Claus Gittinger" |
|
1725 |
! |
|
1726 |
||
1214
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1727 |
test90_hash |
2208 | 1728 |
"all string-representations must hash equal" |
1729 |
||
1214
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1730 |
| string8 string16 string32 | |
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1731 |
|
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1732 |
string8 := 'sun/nio/cs/UTF_8.class'. |
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1733 |
string16 := string8 asUnicode16String. |
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1734 |
string32 := string8 asUnicode16String. |
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1735 |
|
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1736 |
self assert: string8 hash == string16 hash. |
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1737 |
self assert: string8 hash == string32 hash. |
2208 | 1738 |
self assert: string8 hash == string8 asSymbol hash. |
1214
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1739 |
|
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1740 |
"Created: / 09-10-2014 / 12:41:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2208 | 1741 |
"Modified: / 02-04-2019 / 10:42:35 / Claus Gittinger" |
283 | 1742 |
! ! |
1743 |
||
1744 |
!StringTests class methodsFor:'documentation'! |
|
1745 |
||
1746 |
version |
|
1747 |
^ '$Header$' |
|
570 | 1748 |
! |
1749 |
||
1750 |
version_CVS |
|
1751 |
^ '$Header$' |
|
283 | 1752 |
! ! |
752
ef9236c7271c
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
751
diff
changeset
|
1753 |