author | Claus Gittinger <cg@exept.de> |
Tue, 26 Mar 2019 18:29:38 +0100 | |
changeset 2182 | abba80b6780f |
parent 2112 | 3e51f70c1b03 |
child 2207 | 33fec8c61cb8 |
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 |
||
1693 | 207 |
test03_unicode16 |
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 |
" |
|
269 |
self new test03_unicode16 |
|
270 |
" |
|
271 |
||
272 |
"Created: / 30-08-2017 / 23:51:07 / cg" |
|
273 |
! |
|
274 |
||
284 | 275 |
test10_Contains8BitCharacters |
288 | 276 |
0 to:65 do:[:l | |
1421 | 277 |
|str| |
283 | 278 |
|
1421 | 279 |
str := String new:l. |
280 |
str atAllPut:(Character value:16r7F). |
|
281 |
self assert:( str contains8BitCharacters not ). |
|
283 | 282 |
|
1421 | 283 |
1 to:l do:[:pos | |
284 |
str at:pos put:(Character value:16r80). |
|
285 |
self assert:( str contains8BitCharacters ). |
|
286 |
str at:pos put:(Character value:16r7F). |
|
287 |
]. |
|
283 | 288 |
]. |
289 |
||
290 |
" |
|
284 | 291 |
self new test10_Contains8BitCharacters |
283 | 292 |
" |
288 | 293 |
! |
294 |
||
1426 | 295 |
test11_IsEmpty |
296 |
|nul n| |
|
297 |
nul := 0 asCharacter. |
|
298 |
n := 1. |
|
299 |
self assert:('' isEmpty). |
|
300 |
self assert:(' ' isEmpty not). |
|
301 |
self assert:(nul asCharacter asString isEmpty not). |
|
302 |
self assert:(('' , nul) isEmpty not). |
|
303 |
self assert:((String new:0) isEmpty). |
|
304 |
self assert:((String new:17 withAll:nul) isEmpty not). |
|
305 |
||
1447 | 306 |
29 timesRepeat:[ |
307 |
|s| |
|
1426 | 308 |
|
1447 | 309 |
s := String new:(n + 17). |
310 |
self assert:(s isEmpty not). |
|
311 |
n := n * 2. |
|
1426 | 312 |
]. |
313 |
self assert:((String new:17 withAll:nul) isEmpty not). |
|
314 |
self assert:((String new:0 withAll:nul) isEmpty). |
|
315 |
" |
|
1429 | 316 |
self new test11_IsEmpty |
317 |
" |
|
1426 | 318 |
! |
319 |
||
320 |
test12_Comparison |
|
321 |
0 to: 255 do: [ :i | |
|
1447 | 322 |
|s t| |
1426 | 323 |
|
1447 | 324 |
1 to: 9 do: [ :j | |
325 |
s := String new:j withAll:(i asCharacter). |
|
326 |
t := s copy. |
|
1426 | 327 |
|
1447 | 328 |
self assert:(s notNil). |
329 |
self assert:(s = s). |
|
330 |
self assert:(s ~= s) not. |
|
331 |
self assert:(s < s) not. |
|
332 |
self assert:(s > s) not. |
|
333 |
self assert:(s = (s,s)) not. |
|
1426 | 334 |
|
1447 | 335 |
self assert:(t notNil). |
336 |
self assert:(s = t). |
|
337 |
self assert:(s ~= t) not. |
|
338 |
self assert:(s < t) not. |
|
339 |
self assert:(s > t) not. |
|
1426 | 340 |
|
1447 | 341 |
self assert:((s = nil) == ((s ~= nil) not)). |
342 |
self assert:((s = '') == ((s ~= '') not)). |
|
343 |
]. |
|
1426 | 344 |
|
1447 | 345 |
s := i asCharacter asString. |
346 |
0 to: 255 do: [ :j | |
|
347 |
t := j asCharacter asString. |
|
348 |
self assert:(t notNil). |
|
1426 | 349 |
|
1447 | 350 |
self assert:((s = t) == ((s ~= t) not)). |
351 |
] |
|
1426 | 352 |
]. |
353 |
||
354 |
" |
|
355 |
self new test12_Comparison |
|
356 |
" |
|
357 |
! |
|
358 |
||
1990 | 359 |
test13_startsWithEndsWithSameAs |
360 |
self assert:('hello' startsWith:''). |
|
361 |
self assert:('hello' startsWith:'h'). |
|
362 |
self assert:('hello' startsWith:'he'). |
|
363 |
self assert:('hello' startsWith:'hel'). |
|
364 |
self assert:('hello' startsWith:'hell'). |
|
365 |
self assert:('hello' startsWith:'hello'). |
|
366 |
self assert:('hello' startsWith:'hello world') not. |
|
367 |
"/ int size |
|
368 |
self assert:('1234' startsWith:'123'). |
|
369 |
self assert:('1234' startsWith:'1234'). |
|
370 |
self assert:('1234' startsWith:'12345') not. |
|
371 |
self assert:('12345678' startsWith:'123'). |
|
372 |
self assert:('12345678' startsWith:'1234'). |
|
373 |
self assert:('12345678' startsWith:'12345'). |
|
374 |
self assert:('12345678' startsWith:'123456'). |
|
375 |
self assert:('12345678' startsWith:'1234567'). |
|
376 |
self assert:('12345678' startsWith:'12345678'). |
|
377 |
self assert:('12345678' startsWith:'123456789') not. |
|
378 |
||
379 |
self assert:('1234' startsWith:'x23') not. |
|
380 |
self assert:('1234' startsWith:'x234') not. |
|
381 |
self assert:('1234' startsWith:'1x34') not. |
|
382 |
self assert:('1234' startsWith:'12x4') not. |
|
383 |
self assert:('1234' startsWith:'123x') not. |
|
384 |
self assert:('1234' startsWith:'12345') not. |
|
385 |
self assert:('12345678' startsWith:'x234') not. |
|
386 |
self assert:('12345678' startsWith:'1x34') not. |
|
387 |
self assert:('12345678' startsWith:'12x4') not. |
|
388 |
self assert:('12345678' startsWith:'123x') not. |
|
389 |
||
390 |
self assert:('hello' endsWith:''). |
|
391 |
self assert:('hello' endsWith:'o'). |
|
392 |
self assert:('hello' endsWith:'lo'). |
|
393 |
self assert:('hello' endsWith:'llo'). |
|
394 |
self assert:('hello' endsWith:'ello'). |
|
395 |
self assert:('hello' endsWith:'hello'). |
|
396 |
self assert:('hello' endsWith:'hello world') not. |
|
397 |
"/ int size |
|
398 |
self assert:('1234' endsWith:'234'). |
|
399 |
self assert:('1234' endsWith:'1234'). |
|
400 |
self assert:('1234' endsWith:'1235') not. |
|
401 |
self assert:('1234' endsWith:'12345') not. |
|
402 |
self assert:('12345678' endsWith:'678'). |
|
403 |
self assert:('12345678' endsWith:'5678'). |
|
404 |
self assert:('12345678' endsWith:'45678'). |
|
405 |
self assert:('12345678' endsWith:'345678'). |
|
406 |
self assert:('12345678' endsWith:'2345678'). |
|
407 |
self assert:('12345678' endsWith:'12345678'). |
|
408 |
self assert:('12345678' endsWith:'123456789') not. |
|
409 |
self assert:('12345678' endsWith:'012345678') not. |
|
410 |
||
411 |
self assert:('1234' endsWith:'x233') not. |
|
412 |
self assert:('1234' endsWith:'1x34') not. |
|
413 |
self assert:('1234' endsWith:'12x4') not. |
|
414 |
self assert:('1234' endsWith:'123x') not. |
|
415 |
self assert:('12345678' endsWith:'x2345678') not. |
|
416 |
self assert:('12345678' endsWith:'1x345678') not. |
|
417 |
self assert:('12345678' endsWith:'12x45678') not. |
|
418 |
self assert:('12345678' endsWith:'123x5678') not. |
|
419 |
self assert:('12345678' endsWith:'1234x678') not. |
|
420 |
self assert:('12345678' endsWith:'12345x78') not. |
|
421 |
self assert:('12345678' endsWith:'123456x8') not. |
|
422 |
self assert:('12345678' endsWith:'1234567x') not. |
|
423 |
||
424 |
self assert:('' sameAs:''). |
|
425 |
self assert:('' sameAs:'a') not. |
|
426 |
self assert:('a' sameAs:'') not. |
|
427 |
self assert:('a' sameAs:'a'). |
|
428 |
self assert:('a' sameAs:'A'). |
|
429 |
self assert:('A' sameAs:'A'). |
|
430 |
self assert:('A' sameAs:'a'). |
|
431 |
||
432 |
self assert:('a' sameAs:'1') not. |
|
433 |
self assert:('A' sameAs:'1') not. |
|
434 |
||
435 |
1 to:20 do:[:len | |
|
436 |
|s1 s2| |
|
437 |
||
438 |
s1 := ($a to:($a + len - 1)) asString. |
|
439 |
s2 := s1 copy. |
|
440 |
1 to:len do:[:idx | |
|
441 |
s2 at:idx put:(s2 at:idx) asUppercase. |
|
442 |
self assert:(s1 sameAs:s2). |
|
443 |
]. |
|
444 |
]. |
|
445 |
||
446 |
self assert:('Ä' sameAs:'ä'). |
|
447 |
self assert:('Ä' sameAs:'ä'). |
|
448 |
self assert:('ß' sameAs:'ÿ') not. |
|
449 |
self assert:('Ÿ' sameAs:'ÿ'). "/ single byte char ws. wide char |
|
450 |
self assert:('Ÿ' sameAs:'Ÿ'). "/ single byte char ws. wide char |
|
451 |
self assert:('ÿ' sameAs:'ÿ'). "/ single byte char ws. wide char |
|
452 |
||
453 |
" |
|
454 |
self new test13_startsWithEndsWithSameAs |
|
455 |
" |
|
456 |
||
457 |
"Created: / 19-07-2018 / 11:05:32 / Claus Gittinger" |
|
458 |
! |
|
459 |
||
1426 | 460 |
test15_CompareWithCollating |
461 |
| nul | |
|
462 |
||
463 |
nul := 0 asCharacter asString. |
|
464 |
self assert:('' compareWith:'' collating:true) == 0. |
|
465 |
self assert:('' compareWith:'' collating:false) == 0. |
|
1447 | 466 |
self assert:(nul compareWith:(255 asCharacter asString) collating:false) == -1. |
1426 | 467 |
self assert:((255 asCharacter asString) compareWith:nul collating:false) == 1. |
1433 | 468 |
"/ This will fail and is a WONTFIX |
469 |
"/ self assert:((('' compareWith:nul collating:false) == 0) == ('' = nul)). |
|
1426 | 470 |
|
471 |
0 to: 255 do: [ :i | |
|
1447 | 472 |
|s| |
1426 | 473 |
|
1447 | 474 |
s := i asCharacter asString. |
475 |
self assert:(s notNil). |
|
1426 | 476 |
|
1447 | 477 |
"/ This will fail and is a WONTFIX |
478 |
"/ self assert:('' compareWith:s collating:false) ~= 0. |
|
479 |
self assert:('' compareWith:s collating:false) == ((s compareWith:'' collating:false) negated). |
|
1426 | 480 |
|
1447 | 481 |
0 to: 255 do: [ :j | |
482 |
| t | |
|
483 |
t := j asCharacter asString. |
|
484 |
self assert:(t notNil). |
|
1426 | 485 |
|
1447 | 486 |
self assert:(((s compareWith:t collating:false) == -1) == (s < t)). |
487 |
self assert:(((s compareWith:t collating:false) == 0) == (s = t)). |
|
488 |
self assert:(((s compareWith:t collating:false) == 1) == (s > t)). |
|
489 |
self assert:(((s compareWith:t collating:true) == -1) == (s < t)). |
|
490 |
self assert:(((s compareWith:t collating:true) == 0) == (s = t)). |
|
491 |
self assert:(((s compareWith:t collating:true) == 1) == (s > t)). |
|
492 |
] |
|
1426 | 493 |
]. |
494 |
||
495 |
0 to: 9 do: [ :i | |
|
1447 | 496 |
0 to: 255 do: [ :j | |
497 |
|s t| |
|
498 |
s := String new:i withAll:(j asCharacter). |
|
499 |
t := s copy. |
|
1426 | 500 |
|
1447 | 501 |
self assert: (s compareWith:s collating:false) == 0. |
502 |
self assert: (s compareWith:s collating:true) == 0. |
|
503 |
self assert: (s compareWith:t collating:false) == 0. |
|
504 |
self assert: (s compareWith:t collating:true) == 0 |
|
505 |
] |
|
1426 | 506 |
]. |
507 |
||
508 |
" |
|
509 |
self new test15_CompareWithCollating |
|
510 |
" |
|
511 |
! |
|
512 |
||
288 | 513 |
test20_literalsAreReadonly |
605
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
514 |
|myClass s1 l2 s2 parserFlags compiler| |
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
515 |
|
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
516 |
parserFlags := Compiler new parserFlags copy. |
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
517 |
parserFlags stringsAreImmutable:true. |
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
518 |
parserFlags arraysAreImmutable:true. |
288 | 519 |
|
520 |
Class withoutUpdatingChangesDo:[ |
|
1421 | 521 |
myClass := Object |
522 |
subclass:#'MyClass' |
|
523 |
instanceVariableNames:'' |
|
524 |
classVariableNames:'' |
|
525 |
poolDictionaries:nil. |
|
605
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
526 |
|
1421 | 527 |
compiler := myClass compilerClass new. |
528 |
compiler parserFlags:parserFlags. |
|
529 |
compiler compile:'lit1 ^''hello''' forClass:myClass install:true. |
|
605
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
530 |
|
1421 | 531 |
compiler := myClass compilerClass new. |
532 |
compiler parserFlags:parserFlags. |
|
533 |
compiler compile:'lit2 ^#(''foo'' ''bar'' ''baz'')' forClass:myClass install:true. |
|
288 | 534 |
]. |
535 |
||
536 |
s1 := myClass new perform:#lit1. |
|
537 |
self assert:(s1 isString). |
|
538 |
self assert:(s1 class == ImmutableString). |
|
539 |
self should:[ s1 at:1 put:$H ] raise:Error. |
|
540 |
||
541 |
l2 := myClass new perform:#lit2. |
|
542 |
self assert:(l2 isArray). |
|
543 |
self assert:(l2 class == ImmutableArray). |
|
544 |
self should:[ l2 at:1 put:$H ] raise:Error. |
|
545 |
s2 := l2 at:1. |
|
546 |
self assert:(s2 isString). |
|
547 |
self assert:(s2 class == ImmutableString). |
|
548 |
self should:[ s2 at:1 put:$H ] raise:Error. |
|
549 |
||
550 |
" |
|
551 |
self new test20_literalsAreReadonly |
|
552 |
" |
|
605
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
553 |
|
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
554 |
"Modified: / 02-08-2011 / 19:30:53 / cg" |
352 | 555 |
! |
556 |
||
1418 | 557 |
test30_indexOfSubCollection |
352 | 558 |
|i| |
559 |
"/ 12345678901 |
|
560 |
i := 'hello world' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:true. |
|
561 |
self assert:(i == 7). |
|
562 |
i := 'hello wOrLd' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:true. |
|
563 |
self assert:(i == 0). |
|
564 |
i := 'hello wOrLd' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:false. |
|
565 |
self assert:(i == 7). |
|
566 |
i := 'hello wOrLd' indexOfSubCollection:'ll' startingAt:1 ifAbsent:0 caseSensitive:false. |
|
567 |
self assert:(i == 3). |
|
568 |
||
569 |
i := 'hello wOrLd yellow' indexOfSubCollection:'ll' startingAt:1 ifAbsent:0 caseSensitive:false. |
|
570 |
self assert:(i == 3). |
|
571 |
i := 'hello wOrLd yellow' indexOfSubCollection:'ll' startingAt:3 ifAbsent:0 caseSensitive:false. |
|
572 |
self assert:(i == 3). |
|
573 |
i := 'hello wOrLd yellow' indexOfSubCollection:'ll' startingAt:4 ifAbsent:0 caseSensitive:false. |
|
574 |
self assert:(i == 15). |
|
575 |
||
353 | 576 |
i := 'hello wOrLd yellow' indexOfSubCollection:'low' startingAt:1 ifAbsent:0 caseSensitive:false. |
577 |
self assert:(i == 16). |
|
578 |
i := 'hello wOrLd yellow' indexOfSubCollection:'low' startingAt:17 ifAbsent:0 caseSensitive:false. |
|
579 |
self assert:(i == 0). |
|
580 |
i := 'hello wOrLd yellow' indexOfSubCollection:'low' startingAt:18 ifAbsent:0 caseSensitive:false. |
|
581 |
self assert:(i == 0). |
|
582 |
||
352 | 583 |
" |
1418 | 584 |
self new test30_indexOfSubCollection |
352 | 585 |
" |
570 | 586 |
! |
587 |
||
588 |
test40_indexOfAny |
|
1426 | 589 |
|s i collection| |
570 | 590 |
|
591 |
s := 'Some Sample Generators (74035660-d1f6-11df-9ab3-00ff7b08316c)'. |
|
592 |
1 to:s size do:[:start | |
|
1447 | 593 |
i := s indexOfAny:'-' startingAt:start. |
594 |
self assert:(i == 0 or:[ i >= start]). |
|
595 |
(i ~~ 0) ifTrue:[ |
|
596 |
self assert:(s at:i) == $- |
|
597 |
]. |
|
1308 | 598 |
]. |
1447 | 599 |
"/ 123456789012 |
1308 | 600 |
s := 'bla bla 1234'. |
601 |
1 to:s size do:[:start | |
|
1447 | 602 |
i := s indexOfAny:'1234' startingAt:start. |
603 |
self assert:(i == 0 or:[ i >= start]). |
|
604 |
(i == 9) ifTrue:[ self assert:((s at:i) == $1) ]. |
|
605 |
(i == 10) ifTrue:[ self assert:((s at:i) == $2) ]. |
|
606 |
(i == 11) ifTrue:[ self assert:((s at:i) == $3) ]. |
|
607 |
(i == 12) ifTrue:[ self assert:((s at:i) == $4) ]. |
|
570 | 608 |
]. |
609 |
||
1426 | 610 |
collection := #($o, $l, $o). |
611 |
"/ 12345678901 |
|
612 |
i := 'hello world' indexOfAny:collection startingAt:1. |
|
613 |
self assert:(i == 3). |
|
614 |
i := 'hello world' indexOfAny:collection startingAt:2. |
|
615 |
self assert:(i == 3). |
|
616 |
i := 'hello world' indexOfAny:collection startingAt:3. |
|
1447 | 617 |
self assert:(i == 3). |
1426 | 618 |
i := 'hello world' indexOfAny:collection startingAt:4. |
1447 | 619 |
self assert:(i == 4). |
1426 | 620 |
i := 'hello world' indexOfAny:collection startingAt:5. |
1447 | 621 |
self assert:(i == 5). |
1426 | 622 |
i := 'hello world' indexOfAny:collection startingAt:6. |
1447 | 623 |
self assert:(i == 8). |
1426 | 624 |
i := 'hello world' indexOfAny:collection startingAt:7. |
625 |
self assert:(i == 8). |
|
626 |
i := 'hello world' indexOfAny:collection startingAt:8. |
|
1447 | 627 |
self assert:(i == 8). |
1426 | 628 |
i := 'hello world' indexOfAny:collection startingAt:9. |
1447 | 629 |
self assert:(i == 10). |
1426 | 630 |
i := 'hello world' indexOfAny:collection startingAt:10. |
1447 | 631 |
self assert:(i == 10). |
1426 | 632 |
i := 'hello world' indexOfAny:collection startingAt:11. |
633 |
self assert:(i == 0). |
|
634 |
i := 'hello world' indexOfAny:collection startingAt:12. |
|
635 |
self assert:(i == 0). |
|
636 |
i := 'hello world' indexOfAny:collection startingAt:10000. |
|
637 |
self assert:(i == 0). |
|
570 | 638 |
" |
639 |
self new test40_indexOfAny |
|
640 |
" |
|
641 |
||
642 |
"Created: / 29-10-2010 / 14:58:21 / cg" |
|
571 | 643 |
! |
644 |
||
1308 | 645 |
test41_contains |
646 |
|s| |
|
647 |
||
648 |
s := 'abcdefg'. |
|
649 |
self assert:(s contains:[:ch | ch == $a]). |
|
650 |
self assert:(s contains:[:ch | ch == $A]) not. |
|
651 |
self assert:(s contains:[:ch | ch == $1]) not. |
|
1426 | 652 |
self assert:(s contains:[:ch | ch == (0 asCharacter)]) not. |
1308 | 653 |
" |
654 |
self new test41_contains |
|
655 |
" |
|
656 |
! |
|
657 |
||
1420 | 658 |
test42_includesAny |
659 |
|s| |
|
660 |
||
661 |
1 to:20 do:[:na | |
|
1447 | 662 |
s := (String new:na withAll:$a),'bla bla 1234'. |
663 |
self assert:( s includesAny:'12'). |
|
664 |
self assert:( s includesAny:'21'). |
|
665 |
self assert:( s includesAny:'15'). |
|
666 |
self assert:( s includesAny:'51'). |
|
667 |
self assert:( s includesAny:'45'). |
|
668 |
self assert:( s includesAny:'54'). |
|
669 |
self assert:( s includesAny:'56') not. |
|
1420 | 670 |
]. |
1447 | 671 |
|
1420 | 672 |
" |
673 |
self new test42_includesAny |
|
674 |
" |
|
1421 | 675 |
! |
1420 | 676 |
|
1421 | 677 |
test43_occurrencesOf |
1418 | 678 |
|s| |
679 |
||
680 |
"/ 12345678901 |
|
681 |
self assert:( 'hello world' occurrencesOf:$0 ) == 0. |
|
1447 | 682 |
self assert:( 'hello world' occurrencesOf:$l ) == 3. |
683 |
self assert:( 'hello world' occurrencesOf:$d ) == 1. |
|
1418 | 684 |
|
685 |
"/ how about 0-bytes in between |
|
686 |
self assert:( #[0 0 1 0 0] asString occurrencesOf:(Character value:1) ) == 1. |
|
687 |
self assert:( #[0 0 1 0 0] asString occurrencesOf:(Character value:0) ) == 4. |
|
688 |
||
689 |
1 to:10 do:[:nA | |
|
1447 | 690 |
1 to:10 do:[:nB | |
691 |
s := (String new:nA withAll:$a),(String new:nB withAll:$b). |
|
692 |
self assert:(s occurrencesOf:$a) == nA. |
|
693 |
self assert:(s occurrencesOf:$b) == nB. |
|
694 |
] |
|
695 |
]. |
|
1418 | 696 |
|
697 |
s := String new:1024. |
|
698 |
s atAllPut:$a. |
|
699 |
s at:512 put:(Character space). |
|
700 |
self assert:(s occurrencesOf:(Character space)) == 1. |
|
701 |
self assert:(s occurrencesOf:$a) == 1023. |
|
702 |
||
703 |
s := String new:1024. |
|
704 |
s atAllPut:$a. |
|
705 |
1 to:1024 by:2 do:[:i | s at:i put:$b]. |
|
706 |
self assert:(s occurrencesOf:$a) == 512. |
|
707 |
self assert:(s occurrencesOf:$b) == 512. |
|
1421 | 708 |
|
1418 | 709 |
" |
1421 | 710 |
self new test43_occurrencesOf |
1418 | 711 |
" |
712 |
! |
|
713 |
||
571 | 714 |
test50_indexOf |
715 |
|s i| |
|
716 |
||
717 |
s := 'Some Sample Generators (74035660-d1f6-11df-9ab3-00ff7b08316c)'. |
|
718 |
1 to:s size do:[:start | |
|
1447 | 719 |
i := s indexOf:$- startingAt:start. |
720 |
self assert:(i == 0 or:[ i >= start]). |
|
571 | 721 |
]. |
1418 | 722 |
"/ 12345678901 |
723 |
self assert:( 'hello world' indexOf:$0 startingAt:1 ) == 0. |
|
1447 | 724 |
self assert:( 'hello world' indexOf:$l startingAt:1 ) == 3. |
725 |
self assert:( 'hello world' indexOf:$l startingAt:5 ) == 10. |
|
726 |
self assert:( 'hello world' indexOf:$d startingAt:5 ) == 11. |
|
1418 | 727 |
|
1426 | 728 |
"/ 12345678901 |
729 |
self assert:(('hello world' indexOf:$o startingAt:1) == 5). |
|
730 |
self assert:(('hello world' indexOf:$o startingAt:2) == 5). |
|
731 |
self assert:(('hello world' indexOf:$o startingAt:3) == 5). |
|
732 |
self assert:(('hello world' indexOf:$o startingAt:4) == 5). |
|
733 |
self assert:(('hello world' indexOf:$o startingAt:5) == 5). |
|
734 |
self assert:(('hello world' indexOf:$o startingAt:6) == 8). |
|
735 |
self assert:(('hello world' indexOf:$o startingAt:7) == 8). |
|
736 |
self assert:(('hello world' indexOf:$o startingAt:8) == 8). |
|
737 |
self assert:(('hello world' indexOf:$o startingAt:9) == 0). |
|
738 |
self assert:(('hello world' indexOf:$o startingAt:10) == 0). |
|
739 |
self assert:(('hello world' indexOf:$o startingAt:11) == 0). |
|
740 |
self assert:(('hello world' indexOf:$o startingAt:12) == 0). |
|
741 |
self assert:(('hello world' indexOf:$o startingAt:10000) == 0). |
|
742 |
||
1418 | 743 |
"/ how about 0-bytes in between |
744 |
self assert:( #[0 0 1 0 0] asString indexOf:(Character value:1) startingAt:1 ) == 3. |
|
745 |
self assert:( #[0 0 1 0 0] asString indexOf:(Character value:0) startingAt:3 ) == 4. |
|
746 |
self assert:( #[0 0 1 1 0] asString indexOf:(Character value:0) startingAt:3 ) == 5. |
|
747 |
self assert:( #[0 1 0 1 0] asString indexOf:(Character value:1) startingAt:3 ) == 4. |
|
748 |
||
749 |
s := '12345678901234b'. |
|
750 |
self assert:(s indexOf:$x) == 0. |
|
751 |
self assert:(s indexOf:$1) == 1. |
|
752 |
self assert:(s indexOf:$2) == 2. |
|
753 |
self assert:(s indexOf:$3) == 3. |
|
754 |
self assert:(s indexOf:$4) == 4. |
|
755 |
self assert:(s indexOf:$5) == 5. |
|
756 |
self assert:(s indexOf:$0) == 10. |
|
757 |
self assert:(s indexOf:$b) == 15. |
|
758 |
||
759 |
s := ''. |
|
760 |
self assert:(s indexOf:$1) == 0. |
|
761 |
s := '1'. |
|
762 |
self assert:(s indexOf:$1) == 1. |
|
763 |
self assert:(s indexOf:$2) == 0. |
|
764 |
s := '12'. |
|
765 |
self assert:(s indexOf:$1) == 1. |
|
766 |
self assert:(s indexOf:$2) == 2. |
|
767 |
self assert:(s indexOf:$3) == 0. |
|
768 |
s := '123'. |
|
769 |
self assert:(s indexOf:$1) == 1. |
|
770 |
self assert:(s indexOf:$2) == 2. |
|
771 |
self assert:(s indexOf:$3) == 3. |
|
772 |
self assert:(s indexOf:$4) == 0. |
|
773 |
s := '1234'. |
|
774 |
self assert:(s indexOf:$1) == 1. |
|
775 |
self assert:(s indexOf:$2) == 2. |
|
776 |
self assert:(s indexOf:$3) == 3. |
|
777 |
self assert:(s indexOf:$4) == 4. |
|
778 |
self assert:(s indexOf:$5) == 0. |
|
779 |
s := '12345'. |
|
780 |
self assert:(s indexOf:$1) == 1. |
|
781 |
self assert:(s indexOf:$2) == 2. |
|
782 |
self assert:(s indexOf:$3) == 3. |
|
783 |
self assert:(s indexOf:$4) == 4. |
|
784 |
self assert:(s indexOf:$5) == 5. |
|
785 |
self assert:(s indexOf:$6) == 0. |
|
786 |
s := '123456'. |
|
787 |
self assert:(s indexOf:$1) == 1. |
|
788 |
self assert:(s indexOf:$2) == 2. |
|
789 |
self assert:(s indexOf:$3) == 3. |
|
790 |
self assert:(s indexOf:$4) == 4. |
|
791 |
self assert:(s indexOf:$5) == 5. |
|
792 |
self assert:(s indexOf:$6) == 6. |
|
793 |
self assert:(s indexOf:$7) == 0. |
|
794 |
s := '1234567'. |
|
795 |
self assert:(s indexOf:$1) == 1. |
|
796 |
self assert:(s indexOf:$2) == 2. |
|
797 |
self assert:(s indexOf:$3) == 3. |
|
798 |
self assert:(s indexOf:$4) == 4. |
|
799 |
self assert:(s indexOf:$5) == 5. |
|
800 |
self assert:(s indexOf:$6) == 6. |
|
801 |
self assert:(s indexOf:$7) == 7. |
|
802 |
self assert:(s indexOf:$8) == 0. |
|
803 |
s := '12345678'. |
|
804 |
self assert:(s indexOf:$1) == 1. |
|
805 |
self assert:(s indexOf:$2) == 2. |
|
806 |
self assert:(s indexOf:$3) == 3. |
|
807 |
self assert:(s indexOf:$4) == 4. |
|
808 |
self assert:(s indexOf:$5) == 5. |
|
809 |
self assert:(s indexOf:$6) == 6. |
|
810 |
self assert:(s indexOf:$7) == 7. |
|
811 |
self assert:(s indexOf:$8) == 8. |
|
812 |
self assert:(s indexOf:$9) == 0. |
|
813 |
s := '123456789'. |
|
814 |
self assert:(s indexOf:$1) == 1. |
|
815 |
self assert:(s indexOf:$2) == 2. |
|
816 |
self assert:(s indexOf:$3) == 3. |
|
817 |
self assert:(s indexOf:$4) == 4. |
|
818 |
self assert:(s indexOf:$5) == 5. |
|
819 |
self assert:(s indexOf:$6) == 6. |
|
820 |
self assert:(s indexOf:$7) == 7. |
|
821 |
self assert:(s indexOf:$8) == 8. |
|
822 |
self assert:(s indexOf:$9) == 9. |
|
823 |
||
824 |
self assert:(s indexOf:$0) == 0. |
|
825 |
self assert:(s indexOf:$b) == 0. |
|
826 |
||
827 |
s := String new:1024. |
|
828 |
s atAllPut:$a. |
|
829 |
s at:512 put:(Character space). |
|
830 |
self assert:(s indexOf:(Character space)) == 512. |
|
831 |
self assert:(s indexOf:(Character space) startingAt:1) == 512. |
|
832 |
self assert:(s indexOf:(Character space) startingAt:2) == 512. |
|
833 |
self assert:(s indexOf:(Character space) startingAt:3) == 512. |
|
834 |
self assert:(s indexOf:(Character space) startingAt:4) == 512. |
|
835 |
self assert:(s indexOf:(Character space) startingAt:5) == 512. |
|
836 |
self assert:(s indexOf:(Character space) startingAt:6) == 512. |
|
837 |
self assert:(s indexOf:(Character space) startingAt:7) == 512. |
|
838 |
self assert:(s indexOf:(Character space) startingAt:8) == 512. |
|
839 |
self assert:(s indexOf:(Character space) startingAt:9) == 512. |
|
840 |
self assert:(s indexOf:(Character space) startingAt:511) == 512. |
|
841 |
self assert:(s indexOf:(Character space) startingAt:512) == 512. |
|
842 |
self assert:(s indexOf:(Character space) startingAt:513) == 0. |
|
571 | 843 |
|
844 |
" |
|
845 |
self new test50_indexOf |
|
846 |
" |
|
847 |
||
848 |
"Created: / 29-10-2010 / 14:58:21 / cg" |
|
751
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
849 |
! |
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
850 |
|
1373 | 851 |
test51_substrings |
852 |
self assert:('aaa/bbb/ccc' subStrings:'/') asArray = #('aaa' 'bbb' 'ccc'). |
|
853 |
self assert:(('aaa/bbb/ccc' subStrings:'/') asStringWith:'/') = 'aaa/bbb/ccc'. |
|
854 |
||
2083 | 855 |
self assert:('aaa/bbb' withoutSuffix:'bbb') = 'aaa/'. |
856 |
self assert:('aaa/bbb' withoutPrefix:'aaa') = '/bbb'. |
|
857 |
||
1385 | 858 |
"/ self assert:('/aaa/bbb/ccc' subStrings:'/') asArray = #('' 'aaa' 'bbb' 'ccc'). |
859 |
"/ self assert:(('/aaa/bbb/ccc' subStrings:'/') asStringWith:'/') = '/aaa/bbb/ccc'. |
|
860 |
"/ |
|
861 |
"/ self assert:('aaa/bbb/ccc/' subStrings:'/') asArray = #('aaa' 'bbb' 'ccc' '' ). |
|
862 |
"/ self assert:(('aaa/bbb/ccc/' subStrings:'/') asStringWith:'/') = '/aaa/bbb/ccc/'. |
|
863 |
"/ |
|
864 |
"/ self assert:('/aaa/bbb/ccc/' subStrings:'/') asArray = #('' 'aaa' 'bbb' 'ccc' ''). |
|
865 |
"/ self assert:(('/aaa/bbb/ccc/' subStrings:'/') asStringWith:'/') = '/aaa/bbb/ccc'' '. |
|
866 |
"/ |
|
867 |
"/ self assert:('//aaa/bbb/ccc' subStrings:'/') asArray = #('' '' 'aaa' 'bbb' 'ccc'). |
|
868 |
"/ self assert:(('//aaa/bbb/ccc' subStrings:'/') asStringWith:'/') = '//aaa/bbb/ccc'. |
|
1373 | 869 |
|
870 |
" |
|
871 |
self new test51_substrings |
|
872 |
" |
|
2083 | 873 |
|
874 |
"Modified: / 11-02-2019 / 23:57:03 / Claus Gittinger" |
|
1373 | 875 |
! |
876 |
||
1420 | 877 |
test52_indexOfSeparator |
1426 | 878 |
|j s| |
1420 | 879 |
|
880 |
self assert:('' indexOfSeparator) == 0. |
|
881 |
1 to:20 do:[:n | |
|
1447 | 882 |
s := (String new:n withAll:$a). |
883 |
1 to:20 do:[:start | |
|
884 |
self assert:(s indexOfSeparatorStartingAt:start) == 0. |
|
885 |
]. |
|
886 |
]. |
|
1420 | 887 |
1 to:20 do:[:n | |
1447 | 888 |
s := (String new:n withAll:$a),' '. |
889 |
1 to:n do:[:start | |
|
890 |
self assert:(s indexOfSeparatorStartingAt:start) == (n+1). |
|
891 |
]. |
|
892 |
]. |
|
893 |
||
894 |
{ |
|
895 |
Character space . |
|
896 |
Character tab . |
|
897 |
Character return . |
|
898 |
Character lf . |
|
1420 | 899 |
} do:[:sep | |
1447 | 900 |
1 to:20 do:[:na | |
901 |
1 to:20 do:[:nb | |
|
902 |
s := (String new:na withAll:$a),sep,(String new:na withAll:$a). |
|
903 |
1 to:na do:[:start | |
|
904 |
self assert:(s indexOfSeparatorStartingAt:start) == (na+1). |
|
905 |
] |
|
906 |
] |
|
907 |
]. |
|
1420 | 908 |
]. |
1447 | 909 |
|
910 |
{ |
|
911 |
Character esc . |
|
912 |
Character null . |
|
913 |
$a . |
|
1420 | 914 |
} do:[:nonSep | |
1447 | 915 |
1 to:20 do:[:na | |
916 |
1 to:20 do:[:nb | |
|
917 |
s := (String new:na withAll:$a),nonSep,(String new:na withAll:$a). |
|
918 |
1 to:20 do:[:start | |
|
919 |
self assert:(s indexOfSeparatorStartingAt:start) == 0. |
|
920 |
] |
|
921 |
] |
|
922 |
]. |
|
1420 | 923 |
]. |
924 |
||
1426 | 925 |
s := String new:1000 withAll:$a. |
926 |
self assert:(s indexOfSeparatorStartingAt:1) == 0. |
|
927 |
400 to: 417 do:[:i | |
|
1447 | 928 |
s := String new:1000 withAll:$a. |
929 |
s at:i put:(Character space). |
|
930 |
self assert:(s indexOfSeparatorStartingAt:1) == i. |
|
1426 | 931 |
|
1447 | 932 |
s := String new:1000 withAll:$a. |
933 |
s at:i put:(Character return). |
|
934 |
self assert:(s indexOfSeparatorStartingAt:1) == i. |
|
935 |
]. |
|
1426 | 936 |
|
937 |
"/ 12345678901 |
|
938 |
j := 'hello world' indexOfSeparatorStartingAt:1. |
|
939 |
self assert:(j == 6). |
|
940 |
j := 'hello world ' indexOfSeparatorStartingAt:2. |
|
941 |
self assert:(j == 6). |
|
942 |
j := 'hello world ' indexOfSeparatorStartingAt:3. |
|
1447 | 943 |
self assert:(j == 6). |
1426 | 944 |
j := 'hello world ' indexOfSeparatorStartingAt:4. |
1447 | 945 |
self assert:(j == 6). |
1426 | 946 |
j := 'hello world ' indexOfSeparatorStartingAt:5. |
947 |
self assert:(j == 6). |
|
948 |
j := 'hello world ' indexOfSeparatorStartingAt:6. |
|
949 |
self assert:(j == 6). |
|
950 |
j := 'hello world ' indexOfSeparatorStartingAt:7. |
|
951 |
self assert:(j == 12). |
|
952 |
j := 'hello world ' indexOfSeparatorStartingAt:8. |
|
953 |
self assert:(j == 12). |
|
954 |
j := 'hello world ' indexOfSeparatorStartingAt:9. |
|
1447 | 955 |
self assert:(j == 12). |
1426 | 956 |
j := 'hello world ' indexOfSeparatorStartingAt:10. |
1447 | 957 |
self assert:(j == 12). |
1426 | 958 |
j := 'hello world ' indexOfSeparatorStartingAt:11. |
959 |
self assert:(j == 12). |
|
960 |
j := 'hello world ' indexOfSeparatorStartingAt:12. |
|
961 |
self assert:(j == 12). |
|
962 |
j := 'hello world' indexOfSeparatorStartingAt:12. |
|
1447 | 963 |
self assert:(j == 0). |
1426 | 964 |
j := 'hello world ' indexOfSeparatorStartingAt:13. |
965 |
self assert:(j == 0). |
|
966 |
j := 'hello world ' indexOfSeparatorStartingAt:10000. |
|
1447 | 967 |
self assert:(j == 0). |
968 |
||
1420 | 969 |
" |
970 |
self new test52_indexOfSeparator |
|
971 |
" |
|
972 |
! |
|
973 |
||
974 |
test54_occurrencesOf |
|
975 |
|s| |
|
976 |
||
977 |
self assert:('' occurrencesOf:$a) == 0. |
|
978 |
1 to:20 do:[:n | |
|
1447 | 979 |
s := (String new:n withAll:$a). |
980 |
self assert:(s occurrencesOf:$a) == n. |
|
981 |
]. |
|
1420 | 982 |
1 to:20 do:[:na | |
1447 | 983 |
1 to:20 do:[:nb | |
984 |
s := (String new:na withAll:$a),(String new:nb withAll:$b). |
|
985 |
self assert:(s occurrencesOf:$a) == na. |
|
986 |
]. |
|
987 |
]. |
|
1420 | 988 |
1 to:40 do:[:n | |
1447 | 989 |
s := String new:n withAll:$a. |
990 |
1 to:n by:2 do:[:n | |
|
991 |
s at:n put:$b. |
|
992 |
]. |
|
993 |
self assert:(s occurrencesOf:$a) == (n // 2). |
|
994 |
]. |
|
995 |
||
1420 | 996 |
s := String new:1000 withAll:$a. |
997 |
self assert:(s occurrencesOf:$a) == 1000. |
|
998 |
1 to:1000 do:[:i | |
|
1447 | 999 |
s at:i put:$b. |
1000 |
self assert:(s occurrencesOf:$a) == (1000-i). |
|
1001 |
self assert:(s occurrencesOf:$b) == i. |
|
1420 | 1002 |
]. |
1447 | 1003 |
|
1420 | 1004 |
" |
1005 |
self new test54_occurrencesOf |
|
1006 |
" |
|
1007 |
! |
|
1008 |
||
751
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1009 |
test60_hash |
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1010 |
" |
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1011 |
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
|
1012 |
returned different values. This test checks this |
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1013 |
" |
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1014 |
|
753
81af28f807cf
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
752
diff
changeset
|
1015 |
| tester | |
751
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1016 |
|
753
81af28f807cf
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
752
diff
changeset
|
1017 |
tester := [:s| |
1447 | 1018 |
|sHash u16Hash u32Hash| |
1385 | 1019 |
|
1447 | 1020 |
sHash := s hash. |
1021 |
u16Hash := s asUnicode16String hash. |
|
1022 |
u32Hash := s asUnicode32String hash. |
|
1385 | 1023 |
|
1447 | 1024 |
self assert: sHash == u16Hash |
1025 |
description: ('String and Unicode16String hashes differ on "%1" (%2)' |
|
1026 |
bindWith:s with:s class name). |
|
1027 |
self assert: sHash == u32Hash |
|
1028 |
description: ('String and Unicode32String hashes differ on "%1" (%2)' |
|
1029 |
bindWith:s with:s class name) |
|
751
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1030 |
]. |
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1031 |
|
753
81af28f807cf
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
752
diff
changeset
|
1032 |
tester value:'a'. |
1385 | 1033 |
tester value:'12345678901234'. |
1034 |
tester value:'1234567890123'. |
|
1035 |
tester value:'123456789012'. |
|
1036 |
tester value:'12345678901'. |
|
1037 |
tester value:'1234567890'. |
|
1038 |
tester value:'123456789'. |
|
753
81af28f807cf
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
752
diff
changeset
|
1039 |
tester value:'12345678'. |
81af28f807cf
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
752
diff
changeset
|
1040 |
tester value:'1234567'. |
81af28f807cf
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
752
diff
changeset
|
1041 |
tester value:'123456'. |
1385 | 1042 |
tester value:'12345'. |
1043 |
tester value:'1234'. |
|
1044 |
tester value:'123'. |
|
1045 |
tester value:'12'. |
|
753
81af28f807cf
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
752
diff
changeset
|
1046 |
tester value:'boolean'. |
751
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1047 |
|
1417 | 1048 |
"/ strings with 0-elements |
1049 |
tester value:('' copyWith:Character null). |
|
1050 |
tester value:('1' copyWith:Character null). |
|
1051 |
tester value:('12' copyWith:Character null). |
|
1052 |
tester value:('123' copyWith:Character null). |
|
1053 |
tester value:('1234' copyWith:Character null). |
|
1054 |
tester value:('12345' copyWith:Character null). |
|
1055 |
tester value:('123456' copyWith:Character null). |
|
1056 |
tester value:('1234567' copyWith:Character null). |
|
1057 |
tester value:('12345678' copyWith:Character null). |
|
1058 |
tester value:('123456789' copyWith:Character null). |
|
1419 | 1059 |
|
1060 |
tester value:('' copyWith:Character null),'123'. |
|
1061 |
tester value:('1' copyWith:Character null),'123'. |
|
1062 |
tester value:('12' copyWith:Character null),'123'. |
|
1063 |
tester value:('123' copyWith:Character null),'123'. |
|
1064 |
tester value:('1234' copyWith:Character null),'123'. |
|
1065 |
tester value:('12345' copyWith:Character null),'123'. |
|
1066 |
tester value:('123456' copyWith:Character null),'123'. |
|
1067 |
tester value:('1234567' copyWith:Character null),'123'. |
|
1068 |
tester value:('12345678' copyWith:Character null),'123'. |
|
1069 |
tester value:('123456789' copyWith:Character null),'123'. |
|
1447 | 1070 |
|
1419 | 1071 |
"/ String allInstancesDo:[:each| tester value:each]. |
753
81af28f807cf
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
752
diff
changeset
|
1072 |
Symbol allInstancesDo:[:each| tester value:each]. |
751
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1073 |
|
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1074 |
"Created: / 09-01-2013 / 10:58:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
962
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1075 |
! |
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1076 |
|
1426 | 1077 |
test65_concatenation |
1078 |
|strA strB| |
|
1079 |
||
1447 | 1080 |
0 to:32 do:[:szA | |
1081 |
0 to:32 do:[:szB | |
|
1082 |
|szAB| |
|
1426 | 1083 |
|
1447 | 1084 |
strA := String new:szA withAll:$a. |
1085 |
strB := String new:szB withAll:$b. |
|
1086 |
szAB := szA + szB. |
|
1087 |
self assert:(szA = strA size). |
|
1088 |
self assert:(szB = strB size). |
|
1089 |
10000 timesRepeat:[ |
|
1090 |
|strAB| |
|
1426 | 1091 |
|
1447 | 1092 |
strAB := strA , strB. |
1426 | 1093 |
|
1447 | 1094 |
self assert:(szAB == strAB size). |
1095 |
] |
|
1096 |
] |
|
1426 | 1097 |
]. |
1098 |
||
1099 |
strA := strB := ''. |
|
1100 |
self assert: ((strA , strB) = ''). |
|
1101 |
self assert: ((strA , strA) = ''). |
|
1102 |
strA := 'a'. |
|
1447 | 1103 |
self assert: ((strA , strA) = 'aa'). |
1426 | 1104 |
self assert: ((strA , strB) = 'a'). |
1105 |
strA := ''. |
|
1106 |
strB := 'b'. |
|
1447 | 1107 |
self assert: ((strA , strB) = 'b'). |
1426 | 1108 |
strA := 'b'. |
1109 |
strB := 'a'. |
|
1447 | 1110 |
self assert: ((strB , strA) = 'ab'). |
1426 | 1111 |
" |
1112 |
self new test65_concatenation |
|
1113 |
" |
|
1114 |
! |
|
1115 |
||
1116 |
test66_replace |
|
1117 |
|strA| |
|
1118 |
||
1119 |
1 to:64 do:[:szA | |
|
1447 | 1120 |
strA := String new:szA withAll:$a. |
1121 |
1 to:szA do:[:idx | |
|
1122 |
strA at:idx put:$*. |
|
1426 | 1123 |
|
1447 | 1124 |
strA replaceAll:$* with:$#. |
1426 | 1125 |
|
1447 | 1126 |
self assert:(strA at:idx) = $#. |
1127 |
self assert:(strA occurrencesOf:$#) = idx. |
|
1128 |
self assert:(strA count:[:ch | ch = $#]) = idx. |
|
1129 |
self assert:(strA occurrencesOf:$*) = 0. |
|
1130 |
self assert:(strA count:[:ch | ch = $*]) = 0. |
|
1131 |
self assert:(strA includes:$#). |
|
1132 |
self assert:(strA includes:$*) not. |
|
1133 |
] |
|
1426 | 1134 |
] |
1135 |
||
1136 |
" |
|
1137 |
self new test66_replace |
|
1138 |
" |
|
1139 |
! |
|
1140 |
||
1141 |
test67_concatenationAnd |
|
1142 |
|strA strB strC| |
|
1143 |
||
1447 | 1144 |
0 to:32 do:[:szA | |
1145 |
0 to:32 do:[:szB | |
|
1146 |
0 to:32 do:[:szC | |
|
1147 |
|szABC| |
|
1148 |
strA := String new:szA withAll:$a. |
|
1149 |
strB := String new:szB withAll:$b. |
|
1150 |
strC := String new:szC withAll:$c. |
|
1426 | 1151 |
|
1447 | 1152 |
szABC := szA + szB + szC. |
1153 |
self assert:(szA = strA size). |
|
1154 |
self assert:(szB = strB size). |
|
1155 |
self assert:(szC = strC size). |
|
1426 | 1156 |
|
1447 | 1157 |
300 timesRepeat:[ |
1158 |
|strABC| |
|
1426 | 1159 |
|
1447 | 1160 |
strABC := strA concatenate:strB and:strC. |
1426 | 1161 |
|
1447 | 1162 |
self assert:(szABC == strABC size). |
1163 |
] |
|
1164 |
] |
|
1165 |
] |
|
1426 | 1166 |
]. |
1167 |
strA := strB := strC := ''. |
|
1168 |
self assert: ((strA concatenate:strB and:strC) = ''). |
|
1169 |
strA := 'a'. |
|
1170 |
self assert: ((strA concatenate:strB and:strC) = 'a'). |
|
1171 |
strA := ''. |
|
1172 |
strB := 'b'. |
|
1447 | 1173 |
self assert: ((strA concatenate:strB and:strC) = 'b'). |
1426 | 1174 |
strB := ''. |
1175 |
strC := 'c'. |
|
1447 | 1176 |
self assert: ((strA concatenate:strB and:strC) = 'c'). |
1426 | 1177 |
strA := 'c'. |
1178 |
strB := 'b'. |
|
1179 |
strC := 'a'. |
|
1447 | 1180 |
self assert: ((strC concatenate:strB and:strA) = 'abc'). |
1426 | 1181 |
" |
1182 |
self new test67_concatenationAnd |
|
1183 |
" |
|
1184 |
! |
|
1185 |
||
1186 |
test68_concatenationAndAnd |
|
1187 |
|strA strB strC strD| |
|
1188 |
||
1447 | 1189 |
0 to:32 do:[:szA | |
1190 |
strA := String new:szA withAll:$a. |
|
1191 |
self assert:(szA = strA size). |
|
1192 |
0 to:32 do:[:szB | |
|
1193 |
strB := String new:szB withAll:$b. |
|
1194 |
self assert:(szB = strB size). |
|
1195 |
0 to:32 do:[:szC | |
|
1196 |
strC := String new:szC withAll:$c. |
|
1197 |
self assert:(szC = strC size). |
|
1198 |
0 to:32 do:[:szD | |
|
1199 |
|szABCD| |
|
1200 |
strD := String new:szD withAll:$d. |
|
1426 | 1201 |
|
1447 | 1202 |
szABCD := szA + szB + szC + szD. |
1426 | 1203 |
|
1447 | 1204 |
self assert:(szD = strD size). |
1426 | 1205 |
|
1447 | 1206 |
5 timesRepeat:[ |
1207 |
|strABCD| |
|
1426 | 1208 |
|
1447 | 1209 |
strABCD := strA concatenate:strB and:strC and:strD. |
1426 | 1210 |
|
1447 | 1211 |
self assert:(szABCD == strABCD size). |
1212 |
] |
|
1213 |
] |
|
1214 |
] |
|
1215 |
] |
|
1426 | 1216 |
]. |
1217 |
||
1218 |
strA := strB := strC := strD := ''. |
|
1219 |
self assert: ((strA concatenate:strB and:strC and:strD) = ''). |
|
1220 |
strA := 'a'. |
|
1221 |
self assert: ((strA concatenate:strB and:strC and:strD) = 'a'). |
|
1222 |
strA := ''. |
|
1223 |
strB := 'b'. |
|
1447 | 1224 |
self assert: ((strA concatenate:strB and:strC and:strD) = 'b'). |
1426 | 1225 |
strB := ''. |
1226 |
strC := 'c'. |
|
1447 | 1227 |
self assert: ((strA concatenate:strB and:strC and:strD) = 'c'). |
1426 | 1228 |
strC := ''. |
1229 |
strD := 'd'. |
|
1447 | 1230 |
self assert: ((strA concatenate:strB and:strC and:strD) = 'd'). |
1426 | 1231 |
strA := 'd'. |
1232 |
strB := 'c'. |
|
1233 |
strC := 'b'. |
|
1447 | 1234 |
strD := 'a'. |
1235 |
self assert: ((strD concatenate:strC and:strB and:strA) = 'abcd'). |
|
1426 | 1236 |
" |
1237 |
self new test68_concatenationAndAnd |
|
1238 |
" |
|
1239 |
! |
|
1240 |
||
1991 | 1241 |
test69_split |
1242 |
self assert:(('a,b,c,d' splitByAny:',;') sameContentsAs: #('a' 'b' 'c' 'd')). |
|
1243 |
self assert:(('a;b;c;d' splitByAny:',;') sameContentsAs: #('a' 'b' 'c' 'd')). |
|
1244 |
self assert:(('a;b,c;d' splitByAny:',;') sameContentsAs: #('a' 'b' 'c' 'd')). |
|
1245 |
||
1246 |
self assert:(($, split:'a,b,c,d') sameContentsAs: #('a' 'b' 'c' 'd')). |
|
1247 |
self assert:((',' split:'a,b,c,d') sameContentsAs: #('a' 'b' 'c' 'd')). |
|
1248 |
self assert:(('//' split:'a//b//c//d') sameContentsAs: #('a' 'b' 'c' 'd')). |
|
1249 |
self assert:(('a//b//c//d' splitOn:'//') sameContentsAs: #('a' 'b' 'c' 'd')). |
|
1250 |
||
1251 |
"/ self assert:(([:ch | ch isLetter] split:'a2b3c4') sameContentsAs: #('1' '2' '3' '4')). |
|
1252 |
"/ self assert:(([:char | char isDigit] split: '1a2b3c4') sameContentsAs: #('a' 'b' 'c')). |
|
1253 |
||
1254 |
" |
|
1255 |
self new test69_split |
|
1256 |
" |
|
1257 |
||
1258 |
"Created: / 20-07-2018 / 23:54:15 / Claus Gittinger" |
|
1259 |
! |
|
1260 |
||
962
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1261 |
test70_storeString |
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1262 |
|
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1263 |
self assert: 'AAA' storeString = '''AAA'''. |
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1264 |
self assert: 'A''A''A' storeString = '''A''''A''''A'''. |
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1265 |
|
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1266 |
self assert: 'AAA' asImmutableString storeString = '''AAA'''. |
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1267 |
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
|
1268 |
|
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1269 |
"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
|
1270 |
! |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1271 |
|
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1272 |
test80_copyReplaceAll |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1273 |
|
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1274 |
| orig copy | |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1275 |
|
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1276 |
orig := 'AAA' copy. "/ In case literals are immutable... |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1277 |
self assert: orig = 'AAA'. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1278 |
|
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1279 |
copy := orig copyReplaceAll: $A with: $X. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1280 |
self assert: copy = 'XXX'. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1281 |
self assert: orig = 'AAA'. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1282 |
|
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1283 |
orig := 'AAA' asImmutableString. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1284 |
self assert: orig = 'AAA'. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1285 |
|
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1286 |
copy := orig copyReplaceAll: $A with: $X. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1287 |
self assert: copy = 'XXX'. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1288 |
self assert: orig = 'AAA'. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1289 |
|
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1290 |
"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
|
1291 |
! |
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1292 |
|
1240
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1293 |
test81_filling |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1294 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1295 |
| str | |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1296 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1297 |
str := 'AAA' copy. "/ In case literals are immutable... |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1298 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1299 |
str atAllPut:$B. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1300 |
self assert: str = 'BBB'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1301 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1302 |
str from:1 to:0 put:$C. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1303 |
self assert: str = 'BBB'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1304 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1305 |
str from:1 to:1 put:$D. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1306 |
self assert: str = 'DBB'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1307 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1308 |
str from:1 to:2 put:$E. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1309 |
self assert: str = 'EEB'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1310 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1311 |
str from:1 to:3 put:$F. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1312 |
self assert: str = 'FFF'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1313 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1314 |
str from:1 to:0 put:$G. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1315 |
self assert: str = 'FFF'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1316 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1317 |
str from:-1 to:-2 put:$G. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1318 |
self assert: str = 'FFF'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1319 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1320 |
self should:[ |
1421 | 1321 |
str from:-1 to:-1 put:$x |
1240
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1322 |
] raise:SubscriptOutOfBoundsError. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1323 |
self assert: str = 'FFF'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1324 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1325 |
self should:[ |
1421 | 1326 |
str from:-1 to:1 put:$x |
1240
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1327 |
] raise:SubscriptOutOfBoundsError. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1328 |
self assert: str = 'FFF'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1329 |
! |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1330 |
|
2077 | 1331 |
test82_expanding |
1332 |
||
1333 |
| rslt | |
|
1334 |
||
1335 |
rslt := 'A%1B%2C' expandPlaceholdersWith:#(10 20 30). |
|
1336 |
self assert:(rslt = 'A10B20C'). |
|
1337 |
||
1338 |
rslt := 'A%1B%2C%' expandPlaceholdersWith:#(10 20 30). |
|
1339 |
self assert:(rslt = 'A10B20C%'). |
|
1340 |
||
1341 |
rslt := 'A%%1B%2C%' expandPlaceholdersWith:#(10 20 30). |
|
1342 |
self assert:(rslt = 'A%1B20C%'). |
|
1343 |
||
1344 |
||
1345 |
rslt := 'A%aB%bC' expandPlaceholdersWith:(Dictionary withKeys:#(a b c) |
|
1346 |
andValues:#(10 20 30)). |
|
1347 |
self assert:(rslt = 'A10B20C'). |
|
1348 |
||
1349 |
"/ not expanded, if not found |
|
1350 |
rslt := 'A%aB%bC' expandPlaceholdersWith:(Dictionary withKeys:#(aa bb cc) |
|
1351 |
andValues:#(10 20 30)). |
|
1352 |
self assert:(rslt = 'A%aB%bC'). |
|
1353 |
||
1354 |
rslt := 'A%aaB%bbC' expandPlaceholdersWith:(Dictionary withKeys:#(aa bb cc) |
|
1355 |
andValues:#(10 20 30)). |
|
1356 |
self assert:(rslt = 'A%aaB%bbC'). |
|
1357 |
||
1358 |
rslt := 'A%(aa)B%(bb)C' expandPlaceholdersWith:(Dictionary withKeys:#(aa bb cc) |
|
1359 |
andValues:#(10 20 30)). |
|
1360 |
self assert:(rslt = 'A10B20C'). |
|
1361 |
||
1362 |
"/ allowing non-parenthized |
|
1363 |
rslt := String streamContents:[:s | |
|
1364 |
'A%aa,B%bb,C' |
|
1365 |
expandPlaceholders:$% |
|
1366 |
with:(Dictionary withKeys:#(aa bb cc) andValues:#(10 20 30)) |
|
1367 |
ignoreNumericEscapes:false |
|
1368 |
requireParentheses:false |
|
1369 |
on:s. |
|
1370 |
]. |
|
1371 |
self assert:(rslt = 'A10,B20,C'). |
|
1372 |
||
1373 |
"Created: / 14-01-2019 / 18:35:40 / Claus Gittinger" |
|
1374 |
! |
|
1375 |
||
2112 | 1376 |
test83_padding |
1377 |
| rslt | |
|
1378 |
||
1379 |
rslt := 'foo' paddedTo:10. |
|
1380 |
self assert:(rslt = 'foo '). |
|
1381 |
||
1382 |
rslt := 'foo' paddedTo:3. |
|
1383 |
self assert:(rslt = 'foo'). |
|
1384 |
rslt := 'foo' paddedTo:4. |
|
1385 |
self assert:(rslt = 'foo '). |
|
1386 |
rslt := 'foo' paddedTo:2. |
|
1387 |
self assert:(rslt = 'foo'). |
|
1388 |
||
1389 |
rslt := '' paddedTo:2. |
|
1390 |
self assert:(rslt = ' '). |
|
1391 |
||
1392 |
rslt := 'foo' paddedTo:10 with:$-. |
|
1393 |
self assert:(rslt = 'foo-------'). |
|
1394 |
||
1395 |
rslt := 'foo' paddedTo:3 with:$-. |
|
1396 |
self assert:(rslt = 'foo'). |
|
1397 |
rslt := 'foo' paddedTo:4 with:$-. |
|
1398 |
self assert:(rslt = 'foo-'). |
|
1399 |
rslt := 'foo' paddedTo:2 with:$-. |
|
1400 |
self assert:(rslt = 'foo'). |
|
1401 |
||
1402 |
rslt := '' paddedTo:2 with:$-. |
|
1403 |
self assert:(rslt = '--'). |
|
1404 |
||
1405 |
rslt := 'foo' leftPaddedTo:10. |
|
1406 |
self assert:(rslt = ' foo'). |
|
1407 |
||
1408 |
rslt := 'foo' leftPaddedTo:3. |
|
1409 |
self assert:(rslt = 'foo'). |
|
1410 |
rslt := 'foo' leftPaddedTo:4. |
|
1411 |
self assert:(rslt = ' foo'). |
|
1412 |
rslt := 'foo' leftPaddedTo:2. |
|
1413 |
self assert:(rslt = 'foo'). |
|
1414 |
||
1415 |
rslt := '' leftPaddedTo:2. |
|
1416 |
self assert:(rslt = ' '). |
|
1417 |
||
1418 |
rslt := 'foo' leftPaddedTo:10 with:$-. |
|
1419 |
self assert:(rslt = '-------foo'). |
|
1420 |
||
1421 |
rslt := 'foo' leftPaddedTo:3 with:$-. |
|
1422 |
self assert:(rslt = 'foo'). |
|
1423 |
rslt := 'foo' leftPaddedTo:4 with:$-. |
|
1424 |
self assert:(rslt = '-foo'). |
|
1425 |
rslt := 'foo' leftPaddedTo:2 with:$-. |
|
1426 |
self assert:(rslt = 'foo'). |
|
1427 |
||
1428 |
rslt := '' leftPaddedTo:2 with:$-. |
|
1429 |
self assert:(rslt = '--'). |
|
1430 |
||
1431 |
"Created: / 21-03-2019 / 12:58:33 / Claus Gittinger" |
|
1432 |
! |
|
1433 |
||
1214
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1434 |
test90_hash |
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1435 |
| string8 string16 string32 | |
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1436 |
|
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1437 |
string8 := 'sun/nio/cs/UTF_8.class'. |
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1438 |
string16 := string8 asUnicode16String. |
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1439 |
string32 := string8 asUnicode16String. |
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1440 |
|
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1441 |
self assert: string8 hash == string16 hash. |
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1442 |
self assert: string8 hash == string32 hash. |
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1443 |
|
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1444 |
"Created: / 09-10-2014 / 12:41:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
283 | 1445 |
! ! |
1446 |
||
1447 |
!StringTests class methodsFor:'documentation'! |
|
1448 |
||
1449 |
version |
|
1450 |
^ '$Header$' |
|
570 | 1451 |
! |
1452 |
||
1453 |
version_CVS |
|
1454 |
^ '$Header$' |
|
283 | 1455 |
! ! |
752
ef9236c7271c
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
751
diff
changeset
|
1456 |