author | Claus Gittinger <cg@exept.de> |
Mon, 12 Aug 2019 11:53:18 +0200 | |
changeset 2378 | 789f2fc52c57 |
parent 2377 | e730910ab2a5 |
child 2388 | 6ac280a6d988 |
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 |
|
2365 | 152 |
bench_stringSearch |
153 |
" |
|
154 |
self new bench_stringSearch |
|
155 |
" |
|
156 |
||
157 |
|haystack toBeFoundAtEnd| |
|
158 |
||
159 |
toBeFoundAtEnd := '0123456789012345678901234567890123456789'. |
|
160 |
haystack := String new:50000. |
|
161 |
haystack := String new:1000. |
|
162 |
haystack replaceFrom:(haystack size-toBeFoundAtEnd size) with:toBeFoundAtEnd. |
|
163 |
||
164 |
#( |
|
165 |
$0 |
|
166 |
'0' |
|
167 |
'01' |
|
168 |
'012' |
|
169 |
'0123' |
|
170 |
'01234' |
|
171 |
'012345' |
|
172 |
'0123456' |
|
173 |
'01234567' |
|
174 |
'012345678' |
|
175 |
'0123456789' |
|
176 |
'01234567890123456789' |
|
177 |
'0123456789012345678901234567890123456789' |
|
178 |
'01234567890123456789012345678901234567890123456789' |
|
179 |
'0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789' |
|
180 |
) do:[:needle | |
|
181 |
|micros i| |
|
182 |
||
183 |
needle isCharacter ifTrue:[ |
|
184 |
micros := Time microsecondsToRun:[ |
|
185 |
1000 timesRepeat:[ |
|
186 |
haystack indexOf:needle startingAt:1 |
|
187 |
]. |
|
188 |
]. |
|
189 |
i := haystack indexOf:needle startingAt:1 |
|
190 |
] ifFalse:[ |
|
191 |
micros := Time microsecondsToRun:[ |
|
192 |
1000 timesRepeat:[ |
|
193 |
haystack indexOfSubCollection:needle startingAt:1 ifAbsent:0 caseSensitive:true |
|
194 |
||
195 |
]. |
|
196 |
]. |
|
197 |
i := haystack indexOfSubCollection:needle startingAt:1 ifAbsent:(haystack size) caseSensitive:true. |
|
198 |
]. |
|
199 |
||
200 |
Transcript showCR:'size %1: t=%2 (%3 chars/second)' |
|
201 |
with:(needle isCharacter ifTrue:[1] ifFalse:[needle size]) |
|
202 |
with:(TimeDuration microseconds:micros) |
|
203 |
with:(UnitConverter |
|
204 |
unitStringFor:((i*1000000.0) / micros ) |
|
205 |
scale:1000 rounded:true |
|
206 |
unitStrings:#('' 'k' 'M' 'G' 'T' 'P' 'E' )). |
|
207 |
]. |
|
208 |
! |
|
209 |
||
288 | 210 |
test01_access |
211 |
0 to:33 do:[:l | |
|
1447 | 212 |
|str| |
288 | 213 |
|
1447 | 214 |
str := String new:l. |
215 |
str atAllPut:(Character space). |
|
216 |
self assert:( str isBlank ). |
|
217 |
self assert:((str size == 0) or: [(str first) == Character space.]). |
|
288 | 218 |
|
1447 | 219 |
1 to:l do:[:pos | |
220 |
str at:pos put:$a. |
|
221 |
self assert:( str isBlank not ). |
|
222 |
self assert:((str at:pos) == $a). |
|
223 |
str at:pos put:(Character space). |
|
224 |
]. |
|
288 | 225 |
]. |
226 |
self runAccessTestsOnInstancesOf:String |
|
227 |
||
228 |
" |
|
229 |
self new test01_access |
|
230 |
" |
|
231 |
! |
|
232 |
||
233 |
test02_subclassAccess |
|
234 |
|myStringClass s1| |
|
235 |
||
236 |
Class withoutUpdatingChangesDo:[ |
|
1421 | 237 |
myStringClass := String |
238 |
subclass:#'MyString' |
|
239 |
instanceVariableNames:'foo' |
|
240 |
classVariableNames:'' |
|
241 |
poolDictionaries:nil. |
|
242 |
myStringClass compile:'foo ^foo'. |
|
243 |
myStringClass compile:'foo:arg foo := arg'. |
|
288 | 244 |
]. |
245 |
||
246 |
s1 := (myStringClass new:5) replaceFrom:1 with:'hello'. |
|
247 |
self assert:(s1 foo isNil). |
|
248 |
self assert:(s1 size == 5). |
|
874
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
249 |
s1 foo:16r11413344. "/ ensure there is a $A inside (hex 41) |
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
250 |
self assert:(s1 foo == 16r11413344). |
288 | 251 |
self assert:(s1 = 'hello'). |
874
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
252 |
self assert:(s1 deepCopy foo == 16r11413344). |
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
253 |
|
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
254 |
self assert:((s1 indexOf:$A) == 0). "/ should not find the A |
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
255 |
self assert:((s1 identityIndexOf:$A) == 0). "/ should not find the A |
7936c9ee23d5
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
256 |
self assert:((s1 findFirst:[:ch | ch == $A]) == 0). "/ should not find the A |
288 | 257 |
|
258 |
self runAccessTestsOnInstancesOf:myStringClass. |
|
285 | 259 |
|
284 | 260 |
" |
261 |
self new test02_subclassAccess |
|
262 |
" |
|
263 |
! |
|
264 |
||
2209 | 265 |
test03a_unicode16 |
1693 | 266 |
|u s u2| |
267 |
||
268 |
u := 'hello' asUnicode16String. |
|
269 |
self assert:(u class == Unicode16String). |
|
270 |
self assert:(u size == 5). |
|
271 |
self assert:((u at:1) == $h). |
|
272 |
self assert:((u at:2) == $e). |
|
273 |
self assert:((u at:3) == $l). |
|
274 |
self assert:((u at:4) == $l). |
|
275 |
self assert:((u at:5) == $o). |
|
276 |
||
277 |
s := u asSingleByteString. |
|
278 |
self assert:(s class == String). |
|
279 |
self assert:(s size == 5). |
|
280 |
self assert:((s at:1) == $h). |
|
281 |
self assert:((s at:2) == $e). |
|
282 |
self assert:((s at:3) == $l). |
|
283 |
self assert:((s at:4) == $l). |
|
284 |
self assert:((s at:5) == $o). |
|
285 |
||
286 |
s := u asSingleByteStringIfPossible. |
|
287 |
self assert:(s class == String). |
|
288 |
self assert:(s size == 5). |
|
289 |
self assert:((s at:1) == $h). |
|
290 |
self assert:((s at:2) == $e). |
|
291 |
self assert:((s at:3) == $l). |
|
292 |
self assert:((s at:4) == $l). |
|
293 |
self assert:((s at:5) == $o). |
|
294 |
||
295 |
u2 := 'hello' asUnicode16String. |
|
296 |
u2 at:1 put:(Character codePoint:16r20AC). "/ euro character |
|
297 |
self assert:(u2 size == 5). |
|
298 |
self assert:((u2 at:1) = (Character codePoint:16r20AC)). |
|
299 |
self assert:((u2 at:2) == $e). |
|
300 |
self assert:((u2 at:3) == $l). |
|
301 |
self assert:((u2 at:4) == $l). |
|
302 |
self assert:((u2 at:5) == $o). |
|
303 |
||
304 |
s := u2 asSingleByteStringIfPossible. |
|
305 |
self assert:(s class == Unicode16String). |
|
306 |
self assert:(u2 == s). |
|
307 |
||
308 |
u := Unicode16String fromString:'hello'. |
|
309 |
self assert:(u class == Unicode16String). |
|
310 |
self assert:(u size == 5). |
|
311 |
self assert:((u at:1) == $h). |
|
312 |
self assert:((u at:2) == $e). |
|
313 |
self assert:((u at:3) == $l). |
|
314 |
self assert:((u at:4) == $l). |
|
315 |
self assert:((u at:5) == $o). |
|
316 |
||
317 |
u replaceFrom:1 to:5 with:'abcde' startingAt:1. |
|
318 |
self assert:(u class == Unicode16String). |
|
319 |
self assert:(u size == 5). |
|
320 |
self assert:((u at:1) == $a). |
|
321 |
self assert:((u at:2) == $b). |
|
322 |
self assert:((u at:3) == $c). |
|
323 |
self assert:((u at:4) == $d). |
|
324 |
self assert:((u at:5) == $e). |
|
325 |
||
326 |
" |
|
2209 | 327 |
self new test03a_unicode16 |
1693 | 328 |
" |
329 |
||
2209 | 330 |
"Created: / 02-04-2019 / 10:43:49 / Claus Gittinger" |
331 |
! |
|
332 |
||
333 |
test03b_unicode32 |
|
334 |
|u s u2| |
|
335 |
||
336 |
u := 'hello' asUnicode32String. |
|
337 |
self assert:(u class == Unicode32String). |
|
338 |
self assert:(u size == 5). |
|
339 |
self assert:((u at:1) == $h). |
|
340 |
self assert:((u at:2) == $e). |
|
341 |
self assert:((u at:3) == $l). |
|
342 |
self assert:((u at:4) == $l). |
|
343 |
self assert:((u at:5) == $o). |
|
344 |
||
345 |
s := u asSingleByteString. |
|
346 |
self assert:(s class == String). |
|
347 |
self assert:(s size == 5). |
|
348 |
self assert:((s at:1) == $h). |
|
349 |
self assert:((s at:2) == $e). |
|
350 |
self assert:((s at:3) == $l). |
|
351 |
self assert:((s at:4) == $l). |
|
352 |
self assert:((s at:5) == $o). |
|
353 |
||
354 |
s := u asSingleByteStringIfPossible. |
|
355 |
self assert:(s class == String). |
|
356 |
self assert:(s size == 5). |
|
357 |
self assert:((s at:1) == $h). |
|
358 |
self assert:((s at:2) == $e). |
|
359 |
self assert:((s at:3) == $l). |
|
360 |
self assert:((s at:4) == $l). |
|
361 |
self assert:((s at:5) == $o). |
|
362 |
||
363 |
u2 := 'hello' asUnicode32String. |
|
364 |
u2 at:1 put:(Character codePoint:16r20AC). "/ euro character |
|
365 |
self assert:(u2 size == 5). |
|
366 |
self assert:((u2 at:1) = (Character codePoint:16r20AC)). |
|
367 |
self assert:((u2 at:2) == $e). |
|
368 |
self assert:((u2 at:3) == $l). |
|
369 |
self assert:((u2 at:4) == $l). |
|
370 |
self assert:((u2 at:5) == $o). |
|
371 |
||
372 |
s := u2 asSingleByteStringIfPossible. |
|
373 |
self assert:(s class == Unicode32String). |
|
374 |
self assert:(u2 == s). |
|
375 |
||
376 |
u := Unicode32String fromString:'hello'. |
|
377 |
self assert:(u class == Unicode32String). |
|
378 |
self assert:(u size == 5). |
|
379 |
self assert:((u at:1) == $h). |
|
380 |
self assert:((u at:2) == $e). |
|
381 |
self assert:((u at:3) == $l). |
|
382 |
self assert:((u at:4) == $l). |
|
383 |
self assert:((u at:5) == $o). |
|
384 |
||
385 |
u replaceFrom:1 to:5 with:'abcde' startingAt:1. |
|
386 |
self assert:(u class == Unicode32String). |
|
387 |
self assert:(u size == 5). |
|
388 |
self assert:((u at:1) == $a). |
|
389 |
self assert:((u at:2) == $b). |
|
390 |
self assert:((u at:3) == $c). |
|
391 |
self assert:((u at:4) == $d). |
|
392 |
self assert:((u at:5) == $e). |
|
393 |
||
394 |
" |
|
395 |
self new test03b_unicode32 |
|
396 |
" |
|
397 |
||
398 |
"Created: / 02-04-2019 / 10:44:34 / Claus Gittinger" |
|
399 |
! |
|
400 |
||
401 |
test03c_unicodeStrings |
|
402 |
|u32 u16 u8| |
|
403 |
||
404 |
u32 := 'hello' asUnicode32String. |
|
405 |
u16 := 'hello' asUnicode16String. |
|
406 |
u8 := 'hello' asString. |
|
407 |
self assert:(u32 = u16). |
|
408 |
self assert:(u16 = u32). |
|
409 |
self assert:(u32 = u8). |
|
410 |
self assert:(u8 = u32). |
|
411 |
self assert:(u16 = u8). |
|
412 |
self assert:(u8 = u16). |
|
413 |
||
414 |
self assert:(u32 asDenseUnicodeString = u8). |
|
415 |
self assert:(u32 asDenseUnicodeString class == String). |
|
416 |
self assert:(u16 asDenseUnicodeString = u8). |
|
417 |
self assert:(u16 asDenseUnicodeString class == String). |
|
418 |
self assert:(u8 asDenseUnicodeString == u8). |
|
419 |
||
420 |
" |
|
421 |
self new test03c_unicodeStrings |
|
422 |
" |
|
423 |
||
424 |
"Created: / 02-04-2019 / 10:46:10 / Claus Gittinger" |
|
1693 | 425 |
! |
426 |
||
284 | 427 |
test10_Contains8BitCharacters |
288 | 428 |
0 to:65 do:[:l | |
1421 | 429 |
|str| |
283 | 430 |
|
1421 | 431 |
str := String new:l. |
432 |
str atAllPut:(Character value:16r7F). |
|
433 |
self assert:( str contains8BitCharacters not ). |
|
283 | 434 |
|
1421 | 435 |
1 to:l do:[:pos | |
436 |
str at:pos put:(Character value:16r80). |
|
437 |
self assert:( str contains8BitCharacters ). |
|
438 |
str at:pos put:(Character value:16r7F). |
|
439 |
]. |
|
283 | 440 |
]. |
441 |
||
442 |
" |
|
284 | 443 |
self new test10_Contains8BitCharacters |
283 | 444 |
" |
288 | 445 |
! |
446 |
||
1426 | 447 |
test11_IsEmpty |
448 |
|nul n| |
|
449 |
nul := 0 asCharacter. |
|
450 |
n := 1. |
|
451 |
self assert:('' isEmpty). |
|
452 |
self assert:(' ' isEmpty not). |
|
453 |
self assert:(nul asCharacter asString isEmpty not). |
|
454 |
self assert:(('' , nul) isEmpty not). |
|
455 |
self assert:((String new:0) isEmpty). |
|
456 |
self assert:((String new:17 withAll:nul) isEmpty not). |
|
457 |
||
1447 | 458 |
29 timesRepeat:[ |
459 |
|s| |
|
1426 | 460 |
|
1447 | 461 |
s := String new:(n + 17). |
462 |
self assert:(s isEmpty not). |
|
463 |
n := n * 2. |
|
1426 | 464 |
]. |
465 |
self assert:((String new:17 withAll:nul) isEmpty not). |
|
466 |
self assert:((String new:0 withAll:nul) isEmpty). |
|
467 |
" |
|
1429 | 468 |
self new test11_IsEmpty |
469 |
" |
|
1426 | 470 |
! |
471 |
||
472 |
test12_Comparison |
|
473 |
0 to: 255 do: [ :i | |
|
1447 | 474 |
|s t| |
1426 | 475 |
|
1447 | 476 |
1 to: 9 do: [ :j | |
477 |
s := String new:j withAll:(i asCharacter). |
|
478 |
t := s copy. |
|
1426 | 479 |
|
1447 | 480 |
self assert:(s notNil). |
481 |
self assert:(s = s). |
|
482 |
self assert:(s ~= s) not. |
|
483 |
self assert:(s < s) not. |
|
484 |
self assert:(s > s) not. |
|
485 |
self assert:(s = (s,s)) not. |
|
1426 | 486 |
|
1447 | 487 |
self assert:(t notNil). |
488 |
self assert:(s = t). |
|
489 |
self assert:(s ~= t) not. |
|
490 |
self assert:(s < t) not. |
|
491 |
self assert:(s > t) not. |
|
1426 | 492 |
|
1447 | 493 |
self assert:((s = nil) == ((s ~= nil) not)). |
494 |
self assert:((s = '') == ((s ~= '') not)). |
|
495 |
]. |
|
1426 | 496 |
|
1447 | 497 |
s := i asCharacter asString. |
498 |
0 to: 255 do: [ :j | |
|
499 |
t := j asCharacter asString. |
|
500 |
self assert:(t notNil). |
|
1426 | 501 |
|
1447 | 502 |
self assert:((s = t) == ((s ~= t) not)). |
503 |
] |
|
1426 | 504 |
]. |
505 |
||
506 |
" |
|
507 |
self new test12_Comparison |
|
508 |
" |
|
509 |
! |
|
510 |
||
1990 | 511 |
test13_startsWithEndsWithSameAs |
512 |
self assert:('hello' startsWith:''). |
|
513 |
self assert:('hello' startsWith:'h'). |
|
514 |
self assert:('hello' startsWith:'he'). |
|
515 |
self assert:('hello' startsWith:'hel'). |
|
516 |
self assert:('hello' startsWith:'hell'). |
|
517 |
self assert:('hello' startsWith:'hello'). |
|
518 |
self assert:('hello' startsWith:'hello world') not. |
|
519 |
"/ int size |
|
520 |
self assert:('1234' startsWith:'123'). |
|
521 |
self assert:('1234' startsWith:'1234'). |
|
522 |
self assert:('1234' startsWith:'12345') not. |
|
523 |
self assert:('12345678' startsWith:'123'). |
|
524 |
self assert:('12345678' startsWith:'1234'). |
|
525 |
self assert:('12345678' startsWith:'12345'). |
|
526 |
self assert:('12345678' startsWith:'123456'). |
|
527 |
self assert:('12345678' startsWith:'1234567'). |
|
528 |
self assert:('12345678' startsWith:'12345678'). |
|
529 |
self assert:('12345678' startsWith:'123456789') not. |
|
530 |
||
531 |
self assert:('1234' startsWith:'x23') not. |
|
532 |
self assert:('1234' startsWith:'x234') not. |
|
533 |
self assert:('1234' startsWith:'1x34') not. |
|
534 |
self assert:('1234' startsWith:'12x4') not. |
|
535 |
self assert:('1234' startsWith:'123x') not. |
|
536 |
self assert:('1234' startsWith:'12345') not. |
|
537 |
self assert:('12345678' startsWith:'x234') not. |
|
538 |
self assert:('12345678' startsWith:'1x34') not. |
|
539 |
self assert:('12345678' startsWith:'12x4') not. |
|
540 |
self assert:('12345678' startsWith:'123x') not. |
|
541 |
||
542 |
self assert:('hello' endsWith:''). |
|
543 |
self assert:('hello' endsWith:'o'). |
|
544 |
self assert:('hello' endsWith:'lo'). |
|
545 |
self assert:('hello' endsWith:'llo'). |
|
546 |
self assert:('hello' endsWith:'ello'). |
|
547 |
self assert:('hello' endsWith:'hello'). |
|
548 |
self assert:('hello' endsWith:'hello world') not. |
|
549 |
"/ int size |
|
550 |
self assert:('1234' endsWith:'234'). |
|
551 |
self assert:('1234' endsWith:'1234'). |
|
552 |
self assert:('1234' endsWith:'1235') not. |
|
553 |
self assert:('1234' endsWith:'12345') not. |
|
554 |
self assert:('12345678' endsWith:'678'). |
|
555 |
self assert:('12345678' endsWith:'5678'). |
|
556 |
self assert:('12345678' endsWith:'45678'). |
|
557 |
self assert:('12345678' endsWith:'345678'). |
|
558 |
self assert:('12345678' endsWith:'2345678'). |
|
559 |
self assert:('12345678' endsWith:'12345678'). |
|
560 |
self assert:('12345678' endsWith:'123456789') not. |
|
561 |
self assert:('12345678' endsWith:'012345678') not. |
|
562 |
||
563 |
self assert:('1234' endsWith:'x233') not. |
|
564 |
self assert:('1234' endsWith:'1x34') not. |
|
565 |
self assert:('1234' endsWith:'12x4') not. |
|
566 |
self assert:('1234' endsWith:'123x') not. |
|
567 |
self assert:('12345678' endsWith:'x2345678') not. |
|
568 |
self assert:('12345678' endsWith:'1x345678') not. |
|
569 |
self assert:('12345678' endsWith:'12x45678') not. |
|
570 |
self assert:('12345678' endsWith:'123x5678') not. |
|
571 |
self assert:('12345678' endsWith:'1234x678') not. |
|
572 |
self assert:('12345678' endsWith:'12345x78') not. |
|
573 |
self assert:('12345678' endsWith:'123456x8') not. |
|
574 |
self assert:('12345678' endsWith:'1234567x') not. |
|
575 |
||
576 |
self assert:('' sameAs:''). |
|
577 |
self assert:('' sameAs:'a') not. |
|
578 |
self assert:('a' sameAs:'') not. |
|
579 |
self assert:('a' sameAs:'a'). |
|
580 |
self assert:('a' sameAs:'A'). |
|
581 |
self assert:('A' sameAs:'A'). |
|
582 |
self assert:('A' sameAs:'a'). |
|
583 |
||
584 |
self assert:('a' sameAs:'1') not. |
|
585 |
self assert:('A' sameAs:'1') not. |
|
586 |
||
587 |
1 to:20 do:[:len | |
|
588 |
|s1 s2| |
|
589 |
||
590 |
s1 := ($a to:($a + len - 1)) asString. |
|
591 |
s2 := s1 copy. |
|
592 |
1 to:len do:[:idx | |
|
593 |
s2 at:idx put:(s2 at:idx) asUppercase. |
|
594 |
self assert:(s1 sameAs:s2). |
|
595 |
]. |
|
596 |
]. |
|
597 |
||
598 |
self assert:('Ä' sameAs:'ä'). |
|
599 |
self assert:('Ä' sameAs:'ä'). |
|
600 |
self assert:('ß' sameAs:'ÿ') not. |
|
601 |
self assert:('Ÿ' sameAs:'ÿ'). "/ single byte char ws. wide char |
|
602 |
self assert:('Ÿ' sameAs:'Ÿ'). "/ single byte char ws. wide char |
|
603 |
self assert:('ÿ' sameAs:'ÿ'). "/ single byte char ws. wide char |
|
604 |
||
605 |
" |
|
606 |
self new test13_startsWithEndsWithSameAs |
|
607 |
" |
|
608 |
||
609 |
"Created: / 19-07-2018 / 11:05:32 / Claus Gittinger" |
|
610 |
! |
|
611 |
||
1426 | 612 |
test15_CompareWithCollating |
613 |
| nul | |
|
614 |
||
615 |
nul := 0 asCharacter asString. |
|
616 |
self assert:('' compareWith:'' collating:true) == 0. |
|
617 |
self assert:('' compareWith:'' collating:false) == 0. |
|
1447 | 618 |
self assert:(nul compareWith:(255 asCharacter asString) collating:false) == -1. |
1426 | 619 |
self assert:((255 asCharacter asString) compareWith:nul collating:false) == 1. |
1433 | 620 |
"/ This will fail and is a WONTFIX |
621 |
"/ self assert:((('' compareWith:nul collating:false) == 0) == ('' = nul)). |
|
1426 | 622 |
|
623 |
0 to: 255 do: [ :i | |
|
1447 | 624 |
|s| |
1426 | 625 |
|
1447 | 626 |
s := i asCharacter asString. |
627 |
self assert:(s notNil). |
|
1426 | 628 |
|
1447 | 629 |
"/ This will fail and is a WONTFIX |
630 |
"/ self assert:('' compareWith:s collating:false) ~= 0. |
|
631 |
self assert:('' compareWith:s collating:false) == ((s compareWith:'' collating:false) negated). |
|
1426 | 632 |
|
1447 | 633 |
0 to: 255 do: [ :j | |
634 |
| t | |
|
635 |
t := j asCharacter asString. |
|
636 |
self assert:(t notNil). |
|
1426 | 637 |
|
1447 | 638 |
self assert:(((s compareWith:t collating:false) == -1) == (s < t)). |
639 |
self assert:(((s compareWith:t collating:false) == 0) == (s = t)). |
|
640 |
self assert:(((s compareWith:t collating:false) == 1) == (s > t)). |
|
641 |
self assert:(((s compareWith:t collating:true) == -1) == (s < t)). |
|
642 |
self assert:(((s compareWith:t collating:true) == 0) == (s = t)). |
|
643 |
self assert:(((s compareWith:t collating:true) == 1) == (s > t)). |
|
644 |
] |
|
1426 | 645 |
]. |
646 |
||
647 |
0 to: 9 do: [ :i | |
|
1447 | 648 |
0 to: 255 do: [ :j | |
649 |
|s t| |
|
650 |
s := String new:i withAll:(j asCharacter). |
|
651 |
t := s copy. |
|
1426 | 652 |
|
1447 | 653 |
self assert: (s compareWith:s collating:false) == 0. |
654 |
self assert: (s compareWith:s collating:true) == 0. |
|
655 |
self assert: (s compareWith:t collating:false) == 0. |
|
656 |
self assert: (s compareWith:t collating:true) == 0 |
|
657 |
] |
|
1426 | 658 |
]. |
659 |
||
660 |
" |
|
661 |
self new test15_CompareWithCollating |
|
662 |
" |
|
663 |
! |
|
664 |
||
288 | 665 |
test20_literalsAreReadonly |
605
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
666 |
|myClass s1 l2 s2 parserFlags compiler| |
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
667 |
|
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
668 |
parserFlags := Compiler new parserFlags copy. |
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
669 |
parserFlags stringsAreImmutable:true. |
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
670 |
parserFlags arraysAreImmutable:true. |
288 | 671 |
|
672 |
Class withoutUpdatingChangesDo:[ |
|
1421 | 673 |
myClass := Object |
674 |
subclass:#'MyClass' |
|
675 |
instanceVariableNames:'' |
|
676 |
classVariableNames:'' |
|
677 |
poolDictionaries:nil. |
|
605
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
678 |
|
1421 | 679 |
compiler := myClass compilerClass new. |
680 |
compiler parserFlags:parserFlags. |
|
681 |
compiler compile:'lit1 ^''hello''' forClass:myClass install:true. |
|
605
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
682 |
|
1421 | 683 |
compiler := myClass compilerClass new. |
684 |
compiler parserFlags:parserFlags. |
|
685 |
compiler compile:'lit2 ^#(''foo'' ''bar'' ''baz'')' forClass:myClass install:true. |
|
288 | 686 |
]. |
687 |
||
688 |
s1 := myClass new perform:#lit1. |
|
689 |
self assert:(s1 isString). |
|
690 |
self assert:(s1 class == ImmutableString). |
|
691 |
self should:[ s1 at:1 put:$H ] raise:Error. |
|
692 |
||
693 |
l2 := myClass new perform:#lit2. |
|
694 |
self assert:(l2 isArray). |
|
695 |
self assert:(l2 class == ImmutableArray). |
|
696 |
self should:[ l2 at:1 put:$H ] raise:Error. |
|
697 |
s2 := l2 at:1. |
|
698 |
self assert:(s2 isString). |
|
699 |
self assert:(s2 class == ImmutableString). |
|
700 |
self should:[ s2 at:1 put:$H ] raise:Error. |
|
701 |
||
702 |
" |
|
703 |
self new test20_literalsAreReadonly |
|
704 |
" |
|
605
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
705 |
|
6f0411c4d46f
changed: #test20_literalsAreReadonly
Claus Gittinger <cg@exept.de>
parents:
571
diff
changeset
|
706 |
"Modified: / 02-08-2011 / 19:30:53 / cg" |
352 | 707 |
! |
708 |
||
1418 | 709 |
test30_indexOfSubCollection |
352 | 710 |
|i| |
711 |
"/ 12345678901 |
|
712 |
i := 'hello world' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:true. |
|
713 |
self assert:(i == 7). |
|
714 |
i := 'hello wOrLd' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:true. |
|
715 |
self assert:(i == 0). |
|
716 |
i := 'hello wOrLd' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:false. |
|
717 |
self assert:(i == 7). |
|
718 |
i := 'hello wOrLd' indexOfSubCollection:'ll' startingAt:1 ifAbsent:0 caseSensitive:false. |
|
719 |
self assert:(i == 3). |
|
720 |
||
721 |
i := 'hello wOrLd yellow' indexOfSubCollection:'ll' startingAt:1 ifAbsent:0 caseSensitive:false. |
|
722 |
self assert:(i == 3). |
|
723 |
i := 'hello wOrLd yellow' indexOfSubCollection:'ll' startingAt:3 ifAbsent:0 caseSensitive:false. |
|
724 |
self assert:(i == 3). |
|
725 |
i := 'hello wOrLd yellow' indexOfSubCollection:'ll' startingAt:4 ifAbsent:0 caseSensitive:false. |
|
726 |
self assert:(i == 15). |
|
727 |
||
353 | 728 |
i := 'hello wOrLd yellow' indexOfSubCollection:'low' startingAt:1 ifAbsent:0 caseSensitive:false. |
729 |
self assert:(i == 16). |
|
730 |
i := 'hello wOrLd yellow' indexOfSubCollection:'low' startingAt:17 ifAbsent:0 caseSensitive:false. |
|
731 |
self assert:(i == 0). |
|
732 |
i := 'hello wOrLd yellow' indexOfSubCollection:'low' startingAt:18 ifAbsent:0 caseSensitive:false. |
|
733 |
self assert:(i == 0). |
|
734 |
||
2241 | 735 |
i := 'world' indexOfString:'world'. |
736 |
self assert:(i == 1). |
|
737 |
i := 'world' indexOfString:'world' startingAt:1. |
|
738 |
self assert:(i == 1). |
|
739 |
i := 'world' indexOfString:'world' startingAt:6. |
|
740 |
self assert:(i == 0). |
|
741 |
||
742 |
i := 'hello world' indexOfString:'world'. |
|
743 |
self assert:(i == 7). |
|
744 |
i := 'hello world' indexOfString:'world' startingAt:1. |
|
745 |
self assert:(i == 7). |
|
746 |
i := 'hello world' indexOfString:'world' startingAt:4. |
|
747 |
self assert:(i == 7). |
|
748 |
i := 'hello world' indexOfString:'world' startingAt:7. |
|
749 |
self assert:(i == 7). |
|
750 |
i := 'hello world' indexOfString:'world' startingAt:8. |
|
751 |
self assert:(i == 0). |
|
752 |
||
753 |
i := 'hello wOrLd' indexOfString:'world' startingAt:1. |
|
754 |
self assert:(i == 0). |
|
755 |
||
352 | 756 |
" |
1418 | 757 |
self new test30_indexOfSubCollection |
352 | 758 |
" |
2241 | 759 |
|
760 |
"Modified: / 25-05-2019 / 09:01:43 / Claus Gittinger" |
|
761 |
! |
|
762 |
||
2364 | 763 |
test30b_indexOfSubCollection |
764 |
|i| |
|
765 |
||
766 |
"/ 12345678901 |
|
767 |
i := 'hello world' indexOfSubCollection:'w' startingAt:1 ifAbsent:0 caseSensitive:true. |
|
768 |
self assert:(i == 7). |
|
769 |
i := 'hello world' indexOfSubCollection:'w' startingAt:6 ifAbsent:0 caseSensitive:true. |
|
770 |
self assert:(i == 7). |
|
771 |
i := 'hello world' indexOfSubCollection:'w' startingAt:7 ifAbsent:0 caseSensitive:true. |
|
772 |
self assert:(i == 7). |
|
773 |
i := 'hello world' indexOfSubCollection:'w' startingAt:8 ifAbsent:0 caseSensitive:true. |
|
774 |
self assert:(i == 0). |
|
775 |
i := 'hello world' indexOfSubCollection:'x' startingAt:1 ifAbsent:0 caseSensitive:true. |
|
776 |
self assert:(i == 0). |
|
777 |
||
778 |
"/ 12345678901 |
|
779 |
i := 'hello world' indexOfSubCollection:'wo' startingAt:1 ifAbsent:0 caseSensitive:true. |
|
780 |
self assert:(i == 7). |
|
781 |
i := 'hello world' indexOfSubCollection:'wo' startingAt:6 ifAbsent:0 caseSensitive:true. |
|
782 |
self assert:(i == 7). |
|
783 |
i := 'hello world' indexOfSubCollection:'wo' startingAt:7 ifAbsent:0 caseSensitive:true. |
|
784 |
self assert:(i == 7). |
|
785 |
i := 'hello world' indexOfSubCollection:'wo' startingAt:8 ifAbsent:0 caseSensitive:true. |
|
786 |
self assert:(i == 0). |
|
787 |
i := 'hello world' indexOfSubCollection:'xx' startingAt:1 ifAbsent:0 caseSensitive:true. |
|
788 |
self assert:(i == 0). |
|
789 |
i := 'hello world' indexOfSubCollection:'wO' startingAt:1 ifAbsent:0 caseSensitive:true. |
|
790 |
self assert:(i == 0). |
|
791 |
i := 'hello world' indexOfSubCollection:'wO' startingAt:6 ifAbsent:0 caseSensitive:true. |
|
792 |
self assert:(i == 0). |
|
793 |
i := 'hello world' indexOfSubCollection:'wO' startingAt:7 ifAbsent:0 caseSensitive:true. |
|
794 |
self assert:(i == 0). |
|
795 |
i := 'hello world' indexOfSubCollection:'wO' startingAt:8 ifAbsent:0 caseSensitive:true. |
|
796 |
self assert:(i == 0). |
|
797 |
||
798 |
"/ 12345678901 |
|
799 |
i := 'hello world' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:true. |
|
800 |
self assert:(i == 7). |
|
801 |
i := 'hello wOrLd' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:true. |
|
802 |
self assert:(i == 0). |
|
803 |
i := 'hello wOrLd' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:false. |
|
804 |
self assert:(i == 7). |
|
805 |
i := 'hello wOrLd' indexOfSubCollection:'ll' startingAt:1 ifAbsent:0 caseSensitive:false. |
|
806 |
self assert:(i == 3). |
|
807 |
||
808 |
i := 'hello wOrLd yellow' indexOfSubCollection:'ll' startingAt:1 ifAbsent:0 caseSensitive:false. |
|
809 |
self assert:(i == 3). |
|
810 |
i := 'hello wOrLd yellow' indexOfSubCollection:'ll' startingAt:3 ifAbsent:0 caseSensitive:false. |
|
811 |
self assert:(i == 3). |
|
812 |
i := 'hello wOrLd yellow' indexOfSubCollection:'ll' startingAt:4 ifAbsent:0 caseSensitive:false. |
|
813 |
self assert:(i == 15). |
|
814 |
||
815 |
i := 'hello wOrLd yellow' indexOfSubCollection:'low' startingAt:1 ifAbsent:0 caseSensitive:false. |
|
816 |
self assert:(i == 16). |
|
817 |
i := 'hello wOrLd yellow' indexOfSubCollection:'low' startingAt:17 ifAbsent:0 caseSensitive:false. |
|
818 |
self assert:(i == 0). |
|
819 |
i := 'hello wOrLd yellow' indexOfSubCollection:'low' startingAt:18 ifAbsent:0 caseSensitive:false. |
|
820 |
self assert:(i == 0). |
|
821 |
||
822 |
i := 'world' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:true. |
|
823 |
self assert:(i == 1). |
|
824 |
i := 'world' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:false. |
|
825 |
self assert:(i == 1). |
|
826 |
i := 'world' indexOfSubCollection:'world' startingAt:2 ifAbsent:0 caseSensitive:true. |
|
827 |
self assert:(i == 0). |
|
828 |
i := 'world' indexOfSubCollection:'world' startingAt:2 ifAbsent:0 caseSensitive:false. |
|
829 |
self assert:(i == 0). |
|
830 |
i := 'world' indexOfSubCollection:'world' startingAt:6 ifAbsent:0 caseSensitive:true. |
|
831 |
self assert:(i == 0). |
|
832 |
i := 'world' indexOfSubCollection:'world' startingAt:6 ifAbsent:0 caseSensitive:false. |
|
833 |
self assert:(i == 0). |
|
834 |
||
835 |
i := 'hello world' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:false. |
|
836 |
self assert:(i == 7). |
|
837 |
i := 'hello world' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:true. |
|
838 |
self assert:(i == 7). |
|
839 |
||
840 |
i := 'hello world' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:false. |
|
841 |
self assert:(i == 7). |
|
842 |
i := 'hello world' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:true. |
|
843 |
self assert:(i == 7). |
|
844 |
||
845 |
i := 'hello world' indexOfSubCollection:'world' startingAt:4 ifAbsent:0 caseSensitive:false. |
|
846 |
self assert:(i == 7). |
|
847 |
i := 'hello world' indexOfSubCollection:'world' startingAt:4 ifAbsent:0 caseSensitive:true. |
|
848 |
self assert:(i == 7). |
|
849 |
||
850 |
i := 'hello world' indexOfSubCollection:'world' startingAt:7 ifAbsent:0 caseSensitive:false. |
|
851 |
self assert:(i == 7). |
|
852 |
i := 'hello world' indexOfSubCollection:'world' startingAt:7 ifAbsent:0 caseSensitive:true. |
|
853 |
self assert:(i == 7). |
|
854 |
||
855 |
i := 'hello world' indexOfSubCollection:'world' startingAt:8 ifAbsent:0 caseSensitive:false. |
|
856 |
self assert:(i == 0). |
|
857 |
i := 'hello world' indexOfSubCollection:'world' startingAt:8 ifAbsent:0 caseSensitive:true. |
|
858 |
self assert:(i == 0). |
|
859 |
||
860 |
i := 'hello wOrLd' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:true. |
|
861 |
self assert:(i == 0). |
|
862 |
i := 'hello wOrLd' indexOfSubCollection:'world' startingAt:1 ifAbsent:0 caseSensitive:false. |
|
863 |
self assert:(i == 7). |
|
864 |
||
865 |
" |
|
866 |
self new test30b_indexOfSubCollection |
|
867 |
" |
|
868 |
||
869 |
"Modified: / 25-05-2019 / 09:01:43 / Claus Gittinger" |
|
870 |
! |
|
871 |
||
2241 | 872 |
test31_occurrencesOfString |
873 |
|n| |
|
874 |
"/ 12345678901 |
|
875 |
n := 'hello world' occurrencesOfString:'world'. |
|
876 |
self assert:(n == 1). |
|
877 |
||
878 |
n := 'hello wOrLd world' occurrencesOfString:'world'. |
|
879 |
self assert:(n == 1). |
|
880 |
||
2242 | 881 |
n := 'hello wOrLd world' occurrencesOfString:'world' caseSensitive:false. |
882 |
self assert:(n == 2). |
|
883 |
||
2241 | 884 |
n := 'hello world hello world' occurrencesOfString:'world'. |
885 |
self assert:(n == 2). |
|
886 |
||
887 |
n := '' occurrencesOfString:'aa'. |
|
888 |
self assert:(n == 0). |
|
889 |
||
890 |
n := 'a' occurrencesOfString:'aa'. |
|
891 |
self assert:(n == 0). |
|
892 |
||
893 |
n := 'aa' occurrencesOfString:'aa'. |
|
894 |
self assert:(n == 1). |
|
895 |
||
896 |
n := ' aa ' occurrencesOfString:'aa'. |
|
897 |
self assert:(n == 1). |
|
898 |
||
899 |
n := ' aa a' occurrencesOfString:'aa'. |
|
900 |
self assert:(n == 1). |
|
901 |
||
902 |
n := ' aaaa' occurrencesOfString:'aa'. |
|
903 |
self assert:(n == 2). |
|
904 |
||
905 |
n := ' aa aa ' occurrencesOfString:'aa'. |
|
906 |
self assert:(n == 2). |
|
907 |
||
908 |
n := ' aa bb ab ba aa ab' occurrencesOfString:'aa'. |
|
909 |
self assert:(n == 2). |
|
910 |
||
911 |
n := ' aa bb cc aa bb cc aa bb ' occurrencesOfString:'aa'. |
|
912 |
self assert:(n == 3). |
|
913 |
||
2242 | 914 |
n := ' aa bb cc aA bb cc Aa bb ' occurrencesOfString:'aa'. |
915 |
self assert:(n == 1). |
|
916 |
n := ' aa bb cc aA bb cc Aa bb ' occurrencesOfString:'aa' caseSensitive:false. |
|
917 |
self assert:(n == 3). |
|
918 |
||
2241 | 919 |
" |
920 |
self new test31_occurrencesOfString |
|
921 |
" |
|
922 |
||
923 |
"Created: / 25-05-2019 / 09:03:11 / Claus Gittinger" |
|
570 | 924 |
! |
925 |
||
926 |
test40_indexOfAny |
|
1426 | 927 |
|s i collection| |
570 | 928 |
|
929 |
s := 'Some Sample Generators (74035660-d1f6-11df-9ab3-00ff7b08316c)'. |
|
930 |
1 to:s size do:[:start | |
|
1447 | 931 |
i := s indexOfAny:'-' startingAt:start. |
932 |
self assert:(i == 0 or:[ i >= start]). |
|
933 |
(i ~~ 0) ifTrue:[ |
|
934 |
self assert:(s at:i) == $- |
|
935 |
]. |
|
1308 | 936 |
]. |
1447 | 937 |
"/ 123456789012 |
1308 | 938 |
s := 'bla bla 1234'. |
939 |
1 to:s size do:[:start | |
|
1447 | 940 |
i := s indexOfAny:'1234' startingAt:start. |
941 |
self assert:(i == 0 or:[ i >= start]). |
|
942 |
(i == 9) ifTrue:[ self assert:((s at:i) == $1) ]. |
|
943 |
(i == 10) ifTrue:[ self assert:((s at:i) == $2) ]. |
|
944 |
(i == 11) ifTrue:[ self assert:((s at:i) == $3) ]. |
|
945 |
(i == 12) ifTrue:[ self assert:((s at:i) == $4) ]. |
|
570 | 946 |
]. |
947 |
||
1426 | 948 |
collection := #($o, $l, $o). |
949 |
"/ 12345678901 |
|
950 |
i := 'hello world' indexOfAny:collection startingAt:1. |
|
951 |
self assert:(i == 3). |
|
952 |
i := 'hello world' indexOfAny:collection startingAt:2. |
|
953 |
self assert:(i == 3). |
|
954 |
i := 'hello world' indexOfAny:collection startingAt:3. |
|
1447 | 955 |
self assert:(i == 3). |
1426 | 956 |
i := 'hello world' indexOfAny:collection startingAt:4. |
1447 | 957 |
self assert:(i == 4). |
1426 | 958 |
i := 'hello world' indexOfAny:collection startingAt:5. |
1447 | 959 |
self assert:(i == 5). |
1426 | 960 |
i := 'hello world' indexOfAny:collection startingAt:6. |
1447 | 961 |
self assert:(i == 8). |
1426 | 962 |
i := 'hello world' indexOfAny:collection startingAt:7. |
963 |
self assert:(i == 8). |
|
964 |
i := 'hello world' indexOfAny:collection startingAt:8. |
|
1447 | 965 |
self assert:(i == 8). |
1426 | 966 |
i := 'hello world' indexOfAny:collection startingAt:9. |
1447 | 967 |
self assert:(i == 10). |
1426 | 968 |
i := 'hello world' indexOfAny:collection startingAt:10. |
1447 | 969 |
self assert:(i == 10). |
1426 | 970 |
i := 'hello world' indexOfAny:collection startingAt:11. |
971 |
self assert:(i == 0). |
|
972 |
i := 'hello world' indexOfAny:collection startingAt:12. |
|
973 |
self assert:(i == 0). |
|
974 |
i := 'hello world' indexOfAny:collection startingAt:10000. |
|
975 |
self assert:(i == 0). |
|
570 | 976 |
" |
977 |
self new test40_indexOfAny |
|
978 |
" |
|
979 |
||
980 |
"Created: / 29-10-2010 / 14:58:21 / cg" |
|
571 | 981 |
! |
982 |
||
1308 | 983 |
test41_contains |
984 |
|s| |
|
985 |
||
986 |
s := 'abcdefg'. |
|
987 |
self assert:(s contains:[:ch | ch == $a]). |
|
988 |
self assert:(s contains:[:ch | ch == $A]) not. |
|
989 |
self assert:(s contains:[:ch | ch == $1]) not. |
|
1426 | 990 |
self assert:(s contains:[:ch | ch == (0 asCharacter)]) not. |
1308 | 991 |
" |
992 |
self new test41_contains |
|
993 |
" |
|
994 |
! |
|
995 |
||
2211 | 996 |
test42a_includesAny |
1420 | 997 |
|s| |
998 |
||
999 |
1 to:20 do:[:na | |
|
2211 | 1000 |
s := (String new:na withAll:$a),'bla bla 1234'. |
1001 |
self assert:( s includesAny:'12'). |
|
1002 |
self assert:( s includesAny:'21'). |
|
1003 |
self assert:( s includesAny:'15'). |
|
1004 |
self assert:( s includesAny:'51'). |
|
1005 |
self assert:( s includesAny:'45'). |
|
1006 |
self assert:( s includesAny:'54'). |
|
1007 |
self assert:( s includesAny:'56') not. |
|
1420 | 1008 |
]. |
1447 | 1009 |
|
1420 | 1010 |
" |
2211 | 1011 |
self new test42a_includesAny |
1012 |
" |
|
1013 |
||
1014 |
"Created: / 02-04-2019 / 11:03:13 / Claus Gittinger" |
|
1015 |
! |
|
1016 |
||
1017 |
test42b_includesMatchCharacters |
|
1018 |
self assert:('hello' includesMatchCharacters not). |
|
1019 |
self assert:('he*llo' includesMatchCharacters). |
|
1020 |
self assert:('h[eE]llo' includesMatchCharacters). |
|
1021 |
self assert:('h#llo' includesMatchCharacters). |
|
1022 |
||
1023 |
" |
|
1024 |
self new test42b_includesMatchCharacters |
|
1420 | 1025 |
" |
2211 | 1026 |
|
1027 |
"Created: / 02-04-2019 / 11:03:46 / Claus Gittinger" |
|
1028 |
! |
|
1029 |
||
1030 |
test42c_includesSeparator |
|
1031 |
self assert:('hello' includesSeparator not). |
|
1032 |
self assert:('he llo' includesSeparator). |
|
1033 |
self assert:(' hello' includesSeparator). |
|
1034 |
self assert:('hello ' includesSeparator). |
|
1035 |
self assert:(' he llo ' includesSeparator). |
|
1036 |
self assert:(c'h\nllo' includesSeparator). |
|
1037 |
self assert:(c'h\tllo' includesSeparator). |
|
1038 |
||
1039 |
" |
|
1040 |
self new test42c_includesSeparator |
|
1041 |
" |
|
1042 |
||
1043 |
"Created: / 02-04-2019 / 11:05:39 / Claus Gittinger" |
|
1421 | 1044 |
! |
1420 | 1045 |
|
1421 | 1046 |
test43_occurrencesOf |
1418 | 1047 |
|s| |
1048 |
||
1049 |
"/ 12345678901 |
|
1050 |
self assert:( 'hello world' occurrencesOf:$0 ) == 0. |
|
1447 | 1051 |
self assert:( 'hello world' occurrencesOf:$l ) == 3. |
1052 |
self assert:( 'hello world' occurrencesOf:$d ) == 1. |
|
1418 | 1053 |
|
1054 |
"/ how about 0-bytes in between |
|
1055 |
self assert:( #[0 0 1 0 0] asString occurrencesOf:(Character value:1) ) == 1. |
|
1056 |
self assert:( #[0 0 1 0 0] asString occurrencesOf:(Character value:0) ) == 4. |
|
1057 |
||
1058 |
1 to:10 do:[:nA | |
|
1447 | 1059 |
1 to:10 do:[:nB | |
1060 |
s := (String new:nA withAll:$a),(String new:nB withAll:$b). |
|
1061 |
self assert:(s occurrencesOf:$a) == nA. |
|
1062 |
self assert:(s occurrencesOf:$b) == nB. |
|
1063 |
] |
|
1064 |
]. |
|
1418 | 1065 |
|
1066 |
s := String new:1024. |
|
1067 |
s atAllPut:$a. |
|
1068 |
s at:512 put:(Character space). |
|
1069 |
self assert:(s occurrencesOf:(Character space)) == 1. |
|
1070 |
self assert:(s occurrencesOf:$a) == 1023. |
|
1071 |
||
1072 |
s := String new:1024. |
|
1073 |
s atAllPut:$a. |
|
1074 |
1 to:1024 by:2 do:[:i | s at:i put:$b]. |
|
1075 |
self assert:(s occurrencesOf:$a) == 512. |
|
1076 |
self assert:(s occurrencesOf:$b) == 512. |
|
1421 | 1077 |
|
1418 | 1078 |
" |
1421 | 1079 |
self new test43_occurrencesOf |
1418 | 1080 |
" |
1081 |
! |
|
1082 |
||
571 | 1083 |
test50_indexOf |
1084 |
|s i| |
|
1085 |
||
1086 |
s := 'Some Sample Generators (74035660-d1f6-11df-9ab3-00ff7b08316c)'. |
|
1087 |
1 to:s size do:[:start | |
|
2211 | 1088 |
i := s indexOf:$- startingAt:start. |
1089 |
self assert:(i == 0 or:[ i >= start]). |
|
571 | 1090 |
]. |
1418 | 1091 |
"/ 12345678901 |
1092 |
self assert:( 'hello world' indexOf:$0 startingAt:1 ) == 0. |
|
1447 | 1093 |
self assert:( 'hello world' indexOf:$l startingAt:1 ) == 3. |
1094 |
self assert:( 'hello world' indexOf:$l startingAt:5 ) == 10. |
|
1095 |
self assert:( 'hello world' indexOf:$d startingAt:5 ) == 11. |
|
1418 | 1096 |
|
1426 | 1097 |
"/ 12345678901 |
1098 |
self assert:(('hello world' indexOf:$o startingAt:1) == 5). |
|
1099 |
self assert:(('hello world' indexOf:$o startingAt:2) == 5). |
|
1100 |
self assert:(('hello world' indexOf:$o startingAt:3) == 5). |
|
1101 |
self assert:(('hello world' indexOf:$o startingAt:4) == 5). |
|
1102 |
self assert:(('hello world' indexOf:$o startingAt:5) == 5). |
|
1103 |
self assert:(('hello world' indexOf:$o startingAt:6) == 8). |
|
1104 |
self assert:(('hello world' indexOf:$o startingAt:7) == 8). |
|
1105 |
self assert:(('hello world' indexOf:$o startingAt:8) == 8). |
|
1106 |
self assert:(('hello world' indexOf:$o startingAt:9) == 0). |
|
1107 |
self assert:(('hello world' indexOf:$o startingAt:10) == 0). |
|
1108 |
self assert:(('hello world' indexOf:$o startingAt:11) == 0). |
|
1109 |
self assert:(('hello world' indexOf:$o startingAt:12) == 0). |
|
1110 |
self assert:(('hello world' indexOf:$o startingAt:10000) == 0). |
|
1111 |
||
1418 | 1112 |
"/ how about 0-bytes in between |
1113 |
self assert:( #[0 0 1 0 0] asString indexOf:(Character value:1) startingAt:1 ) == 3. |
|
1114 |
self assert:( #[0 0 1 0 0] asString indexOf:(Character value:0) startingAt:3 ) == 4. |
|
1115 |
self assert:( #[0 0 1 1 0] asString indexOf:(Character value:0) startingAt:3 ) == 5. |
|
1116 |
self assert:( #[0 1 0 1 0] asString indexOf:(Character value:1) startingAt:3 ) == 4. |
|
1117 |
||
1118 |
s := '12345678901234b'. |
|
1119 |
self assert:(s indexOf:$x) == 0. |
|
1120 |
self assert:(s indexOf:$1) == 1. |
|
1121 |
self assert:(s indexOf:$2) == 2. |
|
1122 |
self assert:(s indexOf:$3) == 3. |
|
1123 |
self assert:(s indexOf:$4) == 4. |
|
1124 |
self assert:(s indexOf:$5) == 5. |
|
1125 |
self assert:(s indexOf:$0) == 10. |
|
1126 |
self assert:(s indexOf:$b) == 15. |
|
1127 |
||
1128 |
s := ''. |
|
1129 |
self assert:(s indexOf:$1) == 0. |
|
1130 |
s := '1'. |
|
1131 |
self assert:(s indexOf:$1) == 1. |
|
1132 |
self assert:(s indexOf:$2) == 0. |
|
1133 |
s := '12'. |
|
1134 |
self assert:(s indexOf:$1) == 1. |
|
1135 |
self assert:(s indexOf:$2) == 2. |
|
1136 |
self assert:(s indexOf:$3) == 0. |
|
1137 |
s := '123'. |
|
1138 |
self assert:(s indexOf:$1) == 1. |
|
1139 |
self assert:(s indexOf:$2) == 2. |
|
1140 |
self assert:(s indexOf:$3) == 3. |
|
1141 |
self assert:(s indexOf:$4) == 0. |
|
1142 |
s := '1234'. |
|
1143 |
self assert:(s indexOf:$1) == 1. |
|
1144 |
self assert:(s indexOf:$2) == 2. |
|
1145 |
self assert:(s indexOf:$3) == 3. |
|
1146 |
self assert:(s indexOf:$4) == 4. |
|
1147 |
self assert:(s indexOf:$5) == 0. |
|
1148 |
s := '12345'. |
|
1149 |
self assert:(s indexOf:$1) == 1. |
|
1150 |
self assert:(s indexOf:$2) == 2. |
|
1151 |
self assert:(s indexOf:$3) == 3. |
|
1152 |
self assert:(s indexOf:$4) == 4. |
|
1153 |
self assert:(s indexOf:$5) == 5. |
|
1154 |
self assert:(s indexOf:$6) == 0. |
|
1155 |
s := '123456'. |
|
1156 |
self assert:(s indexOf:$1) == 1. |
|
1157 |
self assert:(s indexOf:$2) == 2. |
|
1158 |
self assert:(s indexOf:$3) == 3. |
|
1159 |
self assert:(s indexOf:$4) == 4. |
|
1160 |
self assert:(s indexOf:$5) == 5. |
|
1161 |
self assert:(s indexOf:$6) == 6. |
|
1162 |
self assert:(s indexOf:$7) == 0. |
|
1163 |
s := '1234567'. |
|
1164 |
self assert:(s indexOf:$1) == 1. |
|
1165 |
self assert:(s indexOf:$2) == 2. |
|
1166 |
self assert:(s indexOf:$3) == 3. |
|
1167 |
self assert:(s indexOf:$4) == 4. |
|
1168 |
self assert:(s indexOf:$5) == 5. |
|
1169 |
self assert:(s indexOf:$6) == 6. |
|
1170 |
self assert:(s indexOf:$7) == 7. |
|
1171 |
self assert:(s indexOf:$8) == 0. |
|
1172 |
s := '12345678'. |
|
1173 |
self assert:(s indexOf:$1) == 1. |
|
1174 |
self assert:(s indexOf:$2) == 2. |
|
1175 |
self assert:(s indexOf:$3) == 3. |
|
1176 |
self assert:(s indexOf:$4) == 4. |
|
1177 |
self assert:(s indexOf:$5) == 5. |
|
1178 |
self assert:(s indexOf:$6) == 6. |
|
1179 |
self assert:(s indexOf:$7) == 7. |
|
1180 |
self assert:(s indexOf:$8) == 8. |
|
1181 |
self assert:(s indexOf:$9) == 0. |
|
1182 |
s := '123456789'. |
|
1183 |
self assert:(s indexOf:$1) == 1. |
|
1184 |
self assert:(s indexOf:$2) == 2. |
|
1185 |
self assert:(s indexOf:$3) == 3. |
|
1186 |
self assert:(s indexOf:$4) == 4. |
|
1187 |
self assert:(s indexOf:$5) == 5. |
|
1188 |
self assert:(s indexOf:$6) == 6. |
|
1189 |
self assert:(s indexOf:$7) == 7. |
|
1190 |
self assert:(s indexOf:$8) == 8. |
|
1191 |
self assert:(s indexOf:$9) == 9. |
|
1192 |
||
1193 |
self assert:(s indexOf:$0) == 0. |
|
1194 |
self assert:(s indexOf:$b) == 0. |
|
1195 |
||
1196 |
s := String new:1024. |
|
1197 |
s atAllPut:$a. |
|
1198 |
s at:512 put:(Character space). |
|
1199 |
self assert:(s indexOf:(Character space)) == 512. |
|
1200 |
self assert:(s indexOf:(Character space) startingAt:1) == 512. |
|
1201 |
self assert:(s indexOf:(Character space) startingAt:2) == 512. |
|
1202 |
self assert:(s indexOf:(Character space) startingAt:3) == 512. |
|
1203 |
self assert:(s indexOf:(Character space) startingAt:4) == 512. |
|
1204 |
self assert:(s indexOf:(Character space) startingAt:5) == 512. |
|
1205 |
self assert:(s indexOf:(Character space) startingAt:6) == 512. |
|
1206 |
self assert:(s indexOf:(Character space) startingAt:7) == 512. |
|
1207 |
self assert:(s indexOf:(Character space) startingAt:8) == 512. |
|
1208 |
self assert:(s indexOf:(Character space) startingAt:9) == 512. |
|
1209 |
self assert:(s indexOf:(Character space) startingAt:511) == 512. |
|
1210 |
self assert:(s indexOf:(Character space) startingAt:512) == 512. |
|
1211 |
self assert:(s indexOf:(Character space) startingAt:513) == 0. |
|
571 | 1212 |
|
2211 | 1213 |
self assert:(s indexOfSeparator) == 512. |
1214 |
self assert:(s indexOfSeparatorStartingAt:1) == 512. |
|
1215 |
self assert:(s indexOfSeparatorStartingAt:2) == 512. |
|
1216 |
self assert:(s indexOfSeparatorStartingAt:3) == 512. |
|
1217 |
self assert:(s indexOfSeparatorStartingAt:4) == 512. |
|
1218 |
self assert:(s indexOfSeparatorStartingAt:5) == 512. |
|
1219 |
self assert:(s indexOfSeparatorStartingAt:6) == 512. |
|
1220 |
self assert:(s indexOfSeparatorStartingAt:7) == 512. |
|
1221 |
self assert:(s indexOfSeparatorStartingAt:8) == 512. |
|
1222 |
self assert:(s indexOfSeparatorStartingAt:9) == 512. |
|
1223 |
self assert:(s indexOfSeparatorStartingAt:511) == 512. |
|
1224 |
self assert:(s indexOfSeparatorStartingAt:512) == 512. |
|
1225 |
self assert:(s indexOfSeparatorStartingAt:513) == 0. |
|
1226 |
||
571 | 1227 |
" |
1228 |
self new test50_indexOf |
|
1229 |
" |
|
1230 |
||
1231 |
"Created: / 29-10-2010 / 14:58:21 / cg" |
|
2211 | 1232 |
"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
|
1233 |
! |
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1234 |
|
1373 | 1235 |
test51_substrings |
1236 |
self assert:('aaa/bbb/ccc' subStrings:'/') asArray = #('aaa' 'bbb' 'ccc'). |
|
1237 |
self assert:(('aaa/bbb/ccc' subStrings:'/') asStringWith:'/') = 'aaa/bbb/ccc'. |
|
1238 |
||
2083 | 1239 |
self assert:('aaa/bbb' withoutSuffix:'bbb') = 'aaa/'. |
1240 |
self assert:('aaa/bbb' withoutPrefix:'aaa') = '/bbb'. |
|
1241 |
||
1385 | 1242 |
"/ self assert:('/aaa/bbb/ccc' subStrings:'/') asArray = #('' 'aaa' 'bbb' 'ccc'). |
1243 |
"/ self assert:(('/aaa/bbb/ccc' subStrings:'/') asStringWith:'/') = '/aaa/bbb/ccc'. |
|
1244 |
"/ |
|
1245 |
"/ self assert:('aaa/bbb/ccc/' subStrings:'/') asArray = #('aaa' 'bbb' 'ccc' '' ). |
|
1246 |
"/ self assert:(('aaa/bbb/ccc/' subStrings:'/') asStringWith:'/') = '/aaa/bbb/ccc/'. |
|
1247 |
"/ |
|
1248 |
"/ self assert:('/aaa/bbb/ccc/' subStrings:'/') asArray = #('' 'aaa' 'bbb' 'ccc' ''). |
|
1249 |
"/ self assert:(('/aaa/bbb/ccc/' subStrings:'/') asStringWith:'/') = '/aaa/bbb/ccc'' '. |
|
1250 |
"/ |
|
1251 |
"/ self assert:('//aaa/bbb/ccc' subStrings:'/') asArray = #('' '' 'aaa' 'bbb' 'ccc'). |
|
1252 |
"/ self assert:(('//aaa/bbb/ccc' subStrings:'/') asStringWith:'/') = '//aaa/bbb/ccc'. |
|
1373 | 1253 |
|
1254 |
" |
|
1255 |
self new test51_substrings |
|
1256 |
" |
|
2083 | 1257 |
|
1258 |
"Modified: / 11-02-2019 / 23:57:03 / Claus Gittinger" |
|
1373 | 1259 |
! |
1260 |
||
1420 | 1261 |
test52_indexOfSeparator |
1426 | 1262 |
|j s| |
1420 | 1263 |
|
1264 |
self assert:('' indexOfSeparator) == 0. |
|
1265 |
1 to:20 do:[:n | |
|
1447 | 1266 |
s := (String new:n withAll:$a). |
1267 |
1 to:20 do:[:start | |
|
1268 |
self assert:(s indexOfSeparatorStartingAt:start) == 0. |
|
1269 |
]. |
|
1270 |
]. |
|
1420 | 1271 |
1 to:20 do:[:n | |
1447 | 1272 |
s := (String new:n withAll:$a),' '. |
1273 |
1 to:n do:[:start | |
|
1274 |
self assert:(s indexOfSeparatorStartingAt:start) == (n+1). |
|
1275 |
]. |
|
1276 |
]. |
|
1277 |
||
1278 |
{ |
|
1279 |
Character space . |
|
1280 |
Character tab . |
|
1281 |
Character return . |
|
1282 |
Character lf . |
|
1420 | 1283 |
} do:[:sep | |
1447 | 1284 |
1 to:20 do:[:na | |
1285 |
1 to:20 do:[:nb | |
|
1286 |
s := (String new:na withAll:$a),sep,(String new:na withAll:$a). |
|
1287 |
1 to:na do:[:start | |
|
1288 |
self assert:(s indexOfSeparatorStartingAt:start) == (na+1). |
|
1289 |
] |
|
1290 |
] |
|
1291 |
]. |
|
1420 | 1292 |
]. |
1447 | 1293 |
|
1294 |
{ |
|
1295 |
Character esc . |
|
1296 |
Character null . |
|
1297 |
$a . |
|
1420 | 1298 |
} do:[:nonSep | |
1447 | 1299 |
1 to:20 do:[:na | |
1300 |
1 to:20 do:[:nb | |
|
1301 |
s := (String new:na withAll:$a),nonSep,(String new:na withAll:$a). |
|
1302 |
1 to:20 do:[:start | |
|
1303 |
self assert:(s indexOfSeparatorStartingAt:start) == 0. |
|
1304 |
] |
|
1305 |
] |
|
1306 |
]. |
|
1420 | 1307 |
]. |
1308 |
||
1426 | 1309 |
s := String new:1000 withAll:$a. |
1310 |
self assert:(s indexOfSeparatorStartingAt:1) == 0. |
|
1311 |
400 to: 417 do:[:i | |
|
1447 | 1312 |
s := String new:1000 withAll:$a. |
1313 |
s at:i put:(Character space). |
|
1314 |
self assert:(s indexOfSeparatorStartingAt:1) == i. |
|
1426 | 1315 |
|
1447 | 1316 |
s := String new:1000 withAll:$a. |
1317 |
s at:i put:(Character return). |
|
1318 |
self assert:(s indexOfSeparatorStartingAt:1) == i. |
|
1319 |
]. |
|
1426 | 1320 |
|
1321 |
"/ 12345678901 |
|
1322 |
j := 'hello world' indexOfSeparatorStartingAt:1. |
|
1323 |
self assert:(j == 6). |
|
1324 |
j := 'hello world ' indexOfSeparatorStartingAt:2. |
|
1325 |
self assert:(j == 6). |
|
1326 |
j := 'hello world ' indexOfSeparatorStartingAt:3. |
|
1447 | 1327 |
self assert:(j == 6). |
1426 | 1328 |
j := 'hello world ' indexOfSeparatorStartingAt:4. |
1447 | 1329 |
self assert:(j == 6). |
1426 | 1330 |
j := 'hello world ' indexOfSeparatorStartingAt:5. |
1331 |
self assert:(j == 6). |
|
1332 |
j := 'hello world ' indexOfSeparatorStartingAt:6. |
|
1333 |
self assert:(j == 6). |
|
1334 |
j := 'hello world ' indexOfSeparatorStartingAt:7. |
|
1335 |
self assert:(j == 12). |
|
1336 |
j := 'hello world ' indexOfSeparatorStartingAt:8. |
|
1337 |
self assert:(j == 12). |
|
1338 |
j := 'hello world ' indexOfSeparatorStartingAt:9. |
|
1447 | 1339 |
self assert:(j == 12). |
1426 | 1340 |
j := 'hello world ' indexOfSeparatorStartingAt:10. |
1447 | 1341 |
self assert:(j == 12). |
1426 | 1342 |
j := 'hello world ' indexOfSeparatorStartingAt:11. |
1343 |
self assert:(j == 12). |
|
1344 |
j := 'hello world ' indexOfSeparatorStartingAt:12. |
|
1345 |
self assert:(j == 12). |
|
1346 |
j := 'hello world' indexOfSeparatorStartingAt:12. |
|
1447 | 1347 |
self assert:(j == 0). |
1426 | 1348 |
j := 'hello world ' indexOfSeparatorStartingAt:13. |
1349 |
self assert:(j == 0). |
|
1350 |
j := 'hello world ' indexOfSeparatorStartingAt:10000. |
|
1447 | 1351 |
self assert:(j == 0). |
1352 |
||
1420 | 1353 |
" |
1354 |
self new test52_indexOfSeparator |
|
1355 |
" |
|
1356 |
! |
|
1357 |
||
1358 |
test54_occurrencesOf |
|
1359 |
|s| |
|
1360 |
||
1361 |
self assert:('' occurrencesOf:$a) == 0. |
|
1362 |
1 to:20 do:[:n | |
|
1447 | 1363 |
s := (String new:n withAll:$a). |
1364 |
self assert:(s occurrencesOf:$a) == n. |
|
1365 |
]. |
|
1420 | 1366 |
1 to:20 do:[:na | |
1447 | 1367 |
1 to:20 do:[:nb | |
1368 |
s := (String new:na withAll:$a),(String new:nb withAll:$b). |
|
1369 |
self assert:(s occurrencesOf:$a) == na. |
|
1370 |
]. |
|
1371 |
]. |
|
1420 | 1372 |
1 to:40 do:[:n | |
1447 | 1373 |
s := String new:n withAll:$a. |
1374 |
1 to:n by:2 do:[:n | |
|
1375 |
s at:n put:$b. |
|
1376 |
]. |
|
1377 |
self assert:(s occurrencesOf:$a) == (n // 2). |
|
1378 |
]. |
|
1379 |
||
1420 | 1380 |
s := String new:1000 withAll:$a. |
1381 |
self assert:(s occurrencesOf:$a) == 1000. |
|
1382 |
1 to:1000 do:[:i | |
|
1447 | 1383 |
s at:i put:$b. |
1384 |
self assert:(s occurrencesOf:$a) == (1000-i). |
|
1385 |
self assert:(s occurrencesOf:$b) == i. |
|
1420 | 1386 |
]. |
1447 | 1387 |
|
1420 | 1388 |
" |
1389 |
self new test54_occurrencesOf |
|
1390 |
" |
|
1391 |
! |
|
1392 |
||
2211 | 1393 |
test60a_hash |
751
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1394 |
" |
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1395 |
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
|
1396 |
returned different values. This test checks this |
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1397 |
" |
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1398 |
|
753
81af28f807cf
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
752
diff
changeset
|
1399 |
| tester | |
751
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1400 |
|
753
81af28f807cf
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
752
diff
changeset
|
1401 |
tester := [:s| |
2211 | 1402 |
|sHash u16Hash u32Hash| |
1385 | 1403 |
|
2211 | 1404 |
sHash := s hash. |
1405 |
u16Hash := s asUnicode16String hash. |
|
1406 |
u32Hash := s asUnicode32String hash. |
|
1385 | 1407 |
|
2211 | 1408 |
self assert: sHash == u16Hash |
1409 |
description: ('String and Unicode16String hashes differ on "%1" (%2)' |
|
1410 |
bindWith:s with:s class name). |
|
1411 |
self assert: sHash == u32Hash |
|
1412 |
description: ('String and Unicode32String hashes differ on "%1" (%2)' |
|
1413 |
bindWith:s with:s class name) |
|
751
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1414 |
]. |
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1415 |
|
753
81af28f807cf
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
752
diff
changeset
|
1416 |
tester value:'a'. |
2211 | 1417 |
tester value:'123456789012345678'. |
1418 |
tester value:'12345678901234567'. |
|
1419 |
tester value:'1234567890123456'. |
|
1420 |
tester value:'123456789012345'. |
|
1385 | 1421 |
tester value:'12345678901234'. |
1422 |
tester value:'1234567890123'. |
|
1423 |
tester value:'123456789012'. |
|
1424 |
tester value:'12345678901'. |
|
1425 |
tester value:'1234567890'. |
|
1426 |
tester value:'123456789'. |
|
753
81af28f807cf
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
752
diff
changeset
|
1427 |
tester value:'12345678'. |
81af28f807cf
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
752
diff
changeset
|
1428 |
tester value:'1234567'. |
81af28f807cf
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
752
diff
changeset
|
1429 |
tester value:'123456'. |
1385 | 1430 |
tester value:'12345'. |
1431 |
tester value:'1234'. |
|
1432 |
tester value:'123'. |
|
1433 |
tester value:'12'. |
|
753
81af28f807cf
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
752
diff
changeset
|
1434 |
tester value:'boolean'. |
751
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1435 |
|
1417 | 1436 |
"/ strings with 0-elements |
1437 |
tester value:('' copyWith:Character null). |
|
1438 |
tester value:('1' copyWith:Character null). |
|
1439 |
tester value:('12' copyWith:Character null). |
|
1440 |
tester value:('123' copyWith:Character null). |
|
1441 |
tester value:('1234' copyWith:Character null). |
|
1442 |
tester value:('12345' copyWith:Character null). |
|
1443 |
tester value:('123456' copyWith:Character null). |
|
1444 |
tester value:('1234567' copyWith:Character null). |
|
1445 |
tester value:('12345678' copyWith:Character null). |
|
1446 |
tester value:('123456789' copyWith:Character null). |
|
2211 | 1447 |
tester value:('1234567890' copyWith:Character null). |
1448 |
tester value:('12345678901' copyWith:Character null). |
|
1449 |
tester value:('123456789012' copyWith:Character null). |
|
1450 |
tester value:('1234567890123' copyWith:Character null). |
|
1451 |
tester value:('12345678901234' copyWith:Character null). |
|
1452 |
tester value:('123456789012345' copyWith:Character null). |
|
1453 |
tester value:('1234567890123456' copyWith:Character null). |
|
1454 |
tester value:('12345678901234567' copyWith:Character null). |
|
1419 | 1455 |
|
1456 |
tester value:('' copyWith:Character null),'123'. |
|
1457 |
tester value:('1' copyWith:Character null),'123'. |
|
1458 |
tester value:('12' copyWith:Character null),'123'. |
|
1459 |
tester value:('123' copyWith:Character null),'123'. |
|
1460 |
tester value:('1234' copyWith:Character null),'123'. |
|
1461 |
tester value:('12345' copyWith:Character null),'123'. |
|
1462 |
tester value:('123456' copyWith:Character null),'123'. |
|
1463 |
tester value:('1234567' copyWith:Character null),'123'. |
|
1464 |
tester value:('12345678' copyWith:Character null),'123'. |
|
1465 |
tester value:('123456789' copyWith:Character null),'123'. |
|
2211 | 1466 |
tester value:('1234567890' copyWith:Character null),'123'. |
1467 |
tester value:('12345678901' copyWith:Character null),'123'. |
|
1468 |
tester value:('123456789012' copyWith:Character null),'123'. |
|
1469 |
tester value:('1234567890123' copyWith:Character null),'123'. |
|
1470 |
tester value:('12345678901234' copyWith:Character null),'123'. |
|
1471 |
tester value:('123456789012345' copyWith:Character null),'123'. |
|
1472 |
tester value:('1234567890123456' copyWith:Character null),'123'. |
|
1473 |
||
1474 |
"Created: / 02-04-2019 / 10:55:23 / Claus Gittinger" |
|
1475 |
! |
|
1476 |
||
1477 |
test60b_hash |
|
2377 | 1478 |
"verifies that symbols hash the same as string, u16string and u32string" |
1479 |
||
2211 | 1480 |
| tester | |
1481 |
||
2212 | 1482 |
"/ self skip:'takes long'. |
2211 | 1483 |
|
1484 |
tester := [:s| |
|
2377 | 1485 |
|sHash u8Hash u16Hash u32Hash| |
2211 | 1486 |
|
1487 |
sHash := s hash. |
|
2377 | 1488 |
u8Hash := s asString hash. |
2211 | 1489 |
u16Hash := s asUnicode16String hash. |
1490 |
u32Hash := s asUnicode32String hash. |
|
1491 |
||
2377 | 1492 |
self assert: sHash == u8Hash |
1493 |
description: ('Symbol and String hashes differ on "%1" (%2)' |
|
1494 |
bindWith:s with:s class name). |
|
2211 | 1495 |
self assert: sHash == u16Hash |
2377 | 1496 |
description: ('Symbol and Unicode16String hashes differ on "%1" (%2)' |
2211 | 1497 |
bindWith:s with:s class name). |
1498 |
self assert: sHash == u32Hash |
|
2377 | 1499 |
description: ('Symbol and Unicode32String hashes differ on "%1" (%2)' |
2211 | 1500 |
bindWith:s with:s class name) |
1501 |
]. |
|
1447 | 1502 |
|
1419 | 1503 |
"/ String allInstancesDo:[:each| tester value:each]. |
753
81af28f807cf
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
752
diff
changeset
|
1504 |
Symbol allInstancesDo:[:each| tester value:each]. |
751
8c9ff6c5efe2
Added string hashing tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
702
diff
changeset
|
1505 |
|
2211 | 1506 |
"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
|
1507 |
! |
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1508 |
|
2364 | 1509 |
test61_hash |
1510 |
"all string-representations must hash equal" |
|
1511 |
||
1512 |
| string8 string16 string32 | |
|
1513 |
||
1514 |
string8 := 'sun/nio/cs/UTF_8.class'. |
|
1515 |
string16 := string8 asUnicode16String. |
|
1516 |
string32 := string8 asUnicode16String. |
|
1517 |
||
1518 |
self assert: string8 hash == string16 hash. |
|
1519 |
self assert: string8 hash == string32 hash. |
|
1520 |
self assert: string8 hash == string8 asSymbol hash. |
|
1521 |
||
1522 |
"Created: / 09-10-2014 / 12:41:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1523 |
"Modified: / 02-04-2019 / 10:42:35 / Claus Gittinger" |
|
1524 |
! |
|
1525 |
||
1426 | 1526 |
test65_concatenation |
1527 |
|strA strB| |
|
1528 |
||
1447 | 1529 |
0 to:32 do:[:szA | |
2207 | 1530 |
0 to:32 do:[:szB | |
1531 |
|szAB| |
|
1426 | 1532 |
|
2207 | 1533 |
strA := String new:szA withAll:$a. |
1534 |
strB := String new:szB withAll:$b. |
|
1535 |
szAB := szA + szB. |
|
1536 |
self assert:(szA = strA size). |
|
1537 |
self assert:(szB = strB size). |
|
1538 |
"/ why repeat ??? - to check GC??? |
|
1539 |
1 "10000" timesRepeat:[ |
|
1540 |
|strAB| |
|
1426 | 1541 |
|
2207 | 1542 |
strAB := strA , strB. |
1543 |
self assert:(szAB == strAB size). |
|
1544 |
] |
|
1545 |
] |
|
1426 | 1546 |
]. |
1547 |
||
1548 |
strA := strB := ''. |
|
1549 |
self assert: ((strA , strB) = ''). |
|
1550 |
self assert: ((strA , strA) = ''). |
|
1551 |
strA := 'a'. |
|
1447 | 1552 |
self assert: ((strA , strA) = 'aa'). |
1426 | 1553 |
self assert: ((strA , strB) = 'a'). |
1554 |
strA := ''. |
|
1555 |
strB := 'b'. |
|
1447 | 1556 |
self assert: ((strA , strB) = 'b'). |
1426 | 1557 |
strA := 'b'. |
1558 |
strB := 'a'. |
|
1447 | 1559 |
self assert: ((strB , strA) = 'ab'). |
2207 | 1560 |
|
1561 |
"/ concatenating other things |
|
1562 |
self assert:('hello',123) = 'hello123'. |
|
1563 |
self assert:('hello' asUnicode16String,123) = 'hello123' asUnicode16String. |
|
1564 |
self assert:('hello' asUnicode32String,123) = 'hello123' asUnicode32String. |
|
1565 |
||
1566 |
"/ concatenating other things |
|
1567 |
self assert:('hello',,123) = c'hello\n123'. |
|
1568 |
self assert:('hello' asUnicode16String,,123) = c'hello\n123' asUnicode16String. |
|
1569 |
self assert:('hello' asUnicode32String,,123) = c'hello\n123' asUnicode32String. |
|
1570 |
||
1426 | 1571 |
" |
1572 |
self new test65_concatenation |
|
1573 |
" |
|
2207 | 1574 |
|
1575 |
"Modified: / 02-04-2019 / 10:41:24 / Claus Gittinger" |
|
1426 | 1576 |
! |
1577 |
||
1578 |
test66_replace |
|
1579 |
|strA| |
|
1580 |
||
1581 |
1 to:64 do:[:szA | |
|
1447 | 1582 |
strA := String new:szA withAll:$a. |
1583 |
1 to:szA do:[:idx | |
|
1584 |
strA at:idx put:$*. |
|
1426 | 1585 |
|
1447 | 1586 |
strA replaceAll:$* with:$#. |
1426 | 1587 |
|
1447 | 1588 |
self assert:(strA at:idx) = $#. |
1589 |
self assert:(strA occurrencesOf:$#) = idx. |
|
1590 |
self assert:(strA count:[:ch | ch = $#]) = idx. |
|
1591 |
self assert:(strA occurrencesOf:$*) = 0. |
|
1592 |
self assert:(strA count:[:ch | ch = $*]) = 0. |
|
1593 |
self assert:(strA includes:$#). |
|
1594 |
self assert:(strA includes:$*) not. |
|
1595 |
] |
|
1426 | 1596 |
] |
1597 |
||
1598 |
" |
|
1599 |
self new test66_replace |
|
1600 |
" |
|
1601 |
! |
|
1602 |
||
1603 |
test67_concatenationAnd |
|
1604 |
|strA strB strC| |
|
1605 |
||
1447 | 1606 |
0 to:32 do:[:szA | |
2210 | 1607 |
0 to:32 do:[:szB | |
1608 |
0 to:32 do:[:szC | |
|
1609 |
|szABC| |
|
1610 |
strA := String new:szA withAll:$a. |
|
1611 |
strB := String new:szB withAll:$b. |
|
1612 |
strC := String new:szC withAll:$c. |
|
1426 | 1613 |
|
2210 | 1614 |
szABC := szA + szB + szC. |
1615 |
self assert:(szA = strA size). |
|
1616 |
self assert:(szB = strB size). |
|
1617 |
self assert:(szC = strC size). |
|
1426 | 1618 |
|
2210 | 1619 |
"/ why repeat? to test GC??? |
1620 |
1 "300" timesRepeat:[ |
|
1621 |
|strABC| |
|
1426 | 1622 |
|
2210 | 1623 |
strABC := strA concatenate:strB and:strC. |
1624 |
||
1625 |
self assert:(szABC == strABC size). |
|
1626 |
] |
|
1627 |
] |
|
1628 |
] |
|
1426 | 1629 |
]. |
1630 |
strA := strB := strC := ''. |
|
1631 |
self assert: ((strA concatenate:strB and:strC) = ''). |
|
1632 |
strA := 'a'. |
|
1633 |
self assert: ((strA concatenate:strB and:strC) = 'a'). |
|
1634 |
strA := ''. |
|
1635 |
strB := 'b'. |
|
1447 | 1636 |
self assert: ((strA concatenate:strB and:strC) = 'b'). |
1426 | 1637 |
strB := ''. |
1638 |
strC := 'c'. |
|
1447 | 1639 |
self assert: ((strA concatenate:strB and:strC) = 'c'). |
1426 | 1640 |
strA := 'c'. |
1641 |
strB := 'b'. |
|
1642 |
strC := 'a'. |
|
1447 | 1643 |
self assert: ((strC concatenate:strB and:strA) = 'abc'). |
1426 | 1644 |
" |
1645 |
self new test67_concatenationAnd |
|
1646 |
" |
|
2210 | 1647 |
|
1648 |
"Modified: / 02-04-2019 / 10:51:31 / Claus Gittinger" |
|
1426 | 1649 |
! |
1650 |
||
1651 |
test68_concatenationAndAnd |
|
1652 |
|strA strB strC strD| |
|
1653 |
||
1447 | 1654 |
0 to:32 do:[:szA | |
2210 | 1655 |
strA := String new:szA withAll:$a. |
1656 |
self assert:(szA = strA size). |
|
1657 |
0 to:32 do:[:szB | |
|
1658 |
strB := String new:szB withAll:$b. |
|
1659 |
self assert:(szB = strB size). |
|
1660 |
0 to:32 do:[:szC | |
|
1661 |
strC := String new:szC withAll:$c. |
|
1662 |
self assert:(szC = strC size). |
|
1663 |
0 to:32 do:[:szD | |
|
1664 |
|szABCD| |
|
1665 |
strD := String new:szD withAll:$d. |
|
1666 |
||
1667 |
szABCD := szA + szB + szC + szD. |
|
1426 | 1668 |
|
2210 | 1669 |
self assert:(szD = strD size). |
1426 | 1670 |
|
2210 | 1671 |
"/ why repeat??? |
1672 |
1 "5" timesRepeat:[ |
|
1673 |
|strABCD| |
|
1426 | 1674 |
|
2210 | 1675 |
strABCD := strA concatenate:strB and:strC and:strD. |
1426 | 1676 |
|
2210 | 1677 |
self assert:(szABCD == strABCD size). |
1678 |
] |
|
1679 |
] |
|
1680 |
] |
|
1681 |
] |
|
1426 | 1682 |
]. |
1683 |
||
1684 |
strA := strB := strC := strD := ''. |
|
1685 |
self assert: ((strA concatenate:strB and:strC and:strD) = ''). |
|
1686 |
strA := 'a'. |
|
1687 |
self assert: ((strA concatenate:strB and:strC and:strD) = 'a'). |
|
1688 |
strA := ''. |
|
1689 |
strB := 'b'. |
|
1447 | 1690 |
self assert: ((strA concatenate:strB and:strC and:strD) = 'b'). |
1426 | 1691 |
strB := ''. |
1692 |
strC := 'c'. |
|
1447 | 1693 |
self assert: ((strA concatenate:strB and:strC and:strD) = 'c'). |
1426 | 1694 |
strC := ''. |
1695 |
strD := 'd'. |
|
1447 | 1696 |
self assert: ((strA concatenate:strB and:strC and:strD) = 'd'). |
1426 | 1697 |
strA := 'd'. |
1698 |
strB := 'c'. |
|
1699 |
strC := 'b'. |
|
1447 | 1700 |
strD := 'a'. |
1701 |
self assert: ((strD concatenate:strC and:strB and:strA) = 'abcd'). |
|
1426 | 1702 |
" |
1703 |
self new test68_concatenationAndAnd |
|
1704 |
" |
|
2210 | 1705 |
|
1706 |
"Modified: / 02-04-2019 / 10:51:50 / Claus Gittinger" |
|
1426 | 1707 |
! |
1708 |
||
1991 | 1709 |
test69_split |
1710 |
self assert:(('a,b,c,d' splitByAny:',;') sameContentsAs: #('a' 'b' 'c' 'd')). |
|
1711 |
self assert:(('a;b;c;d' splitByAny:',;') sameContentsAs: #('a' 'b' 'c' 'd')). |
|
1712 |
self assert:(('a;b,c;d' splitByAny:',;') sameContentsAs: #('a' 'b' 'c' 'd')). |
|
1713 |
||
1714 |
self assert:(($, split:'a,b,c,d') sameContentsAs: #('a' 'b' 'c' 'd')). |
|
1715 |
self assert:((',' split:'a,b,c,d') sameContentsAs: #('a' 'b' 'c' 'd')). |
|
1716 |
self assert:(('//' split:'a//b//c//d') sameContentsAs: #('a' 'b' 'c' 'd')). |
|
1717 |
self assert:(('a//b//c//d' splitOn:'//') sameContentsAs: #('a' 'b' 'c' 'd')). |
|
1718 |
||
1719 |
"/ self assert:(([:ch | ch isLetter] split:'a2b3c4') sameContentsAs: #('1' '2' '3' '4')). |
|
1720 |
"/ self assert:(([:char | char isDigit] split: '1a2b3c4') sameContentsAs: #('a' 'b' 'c')). |
|
1721 |
||
1722 |
" |
|
1723 |
self new test69_split |
|
1724 |
" |
|
1725 |
||
1726 |
"Created: / 20-07-2018 / 23:54:15 / Claus Gittinger" |
|
1727 |
! |
|
1728 |
||
962
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1729 |
test70_storeString |
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1730 |
|
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1731 |
self assert: 'AAA' storeString = '''AAA'''. |
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1732 |
self assert: 'A''A''A' storeString = '''A''''A''''A'''. |
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1733 |
|
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1734 |
self assert: 'AAA' asImmutableString storeString = '''AAA'''. |
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1735 |
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
|
1736 |
|
2fca937dc59b
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
874
diff
changeset
|
1737 |
"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
|
1738 |
! |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1739 |
|
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1740 |
test80_copyReplaceAll |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1741 |
|
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1742 |
| orig copy | |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1743 |
|
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1744 |
orig := 'AAA' copy. "/ In case literals are immutable... |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1745 |
self assert: orig = 'AAA'. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1746 |
|
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1747 |
copy := orig copyReplaceAll: $A with: $X. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1748 |
self assert: copy = 'XXX'. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1749 |
self assert: orig = 'AAA'. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1750 |
|
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1751 |
orig := 'AAA' asImmutableString. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1752 |
self assert: orig = 'AAA'. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1753 |
|
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1754 |
copy := orig copyReplaceAll: $A with: $X. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1755 |
self assert: copy = 'XXX'. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1756 |
self assert: orig = 'AAA'. |
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1757 |
|
373c0f5e539d
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1060
diff
changeset
|
1758 |
"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
|
1759 |
! |
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
1760 |
|
1240
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1761 |
test81_filling |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1762 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1763 |
| str | |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1764 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1765 |
str := 'AAA' copy. "/ In case literals are immutable... |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1766 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1767 |
str atAllPut:$B. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1768 |
self assert: str = 'BBB'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1769 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1770 |
str from:1 to:0 put:$C. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1771 |
self assert: str = 'BBB'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1772 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1773 |
str from:1 to:1 put:$D. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1774 |
self assert: str = 'DBB'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1775 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1776 |
str from:1 to:2 put:$E. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1777 |
self assert: str = 'EEB'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1778 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1779 |
str from:1 to:3 put:$F. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1780 |
self assert: str = 'FFF'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1781 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1782 |
str from:1 to:0 put:$G. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1783 |
self assert: str = 'FFF'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1784 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1785 |
str from:-1 to:-2 put:$G. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1786 |
self assert: str = 'FFF'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1787 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1788 |
self should:[ |
1421 | 1789 |
str from:-1 to:-1 put:$x |
1240
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1790 |
] raise:SubscriptOutOfBoundsError. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1791 |
self assert: str = 'FFF'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1792 |
|
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1793 |
self should:[ |
1421 | 1794 |
str from:-1 to:1 put:$x |
1240
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1795 |
] raise:SubscriptOutOfBoundsError. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1796 |
self assert: str = 'FFF'. |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1797 |
! |
4b187f56458b
class: RegressionTests::StringTests
Claus Gittinger <cg@exept.de>
parents:
1214
diff
changeset
|
1798 |
|
2211 | 1799 |
test82a_expanding |
2077 | 1800 |
|
1801 |
| rslt | |
|
1802 |
||
1803 |
rslt := 'A%1B%2C' expandPlaceholdersWith:#(10 20 30). |
|
1804 |
self assert:(rslt = 'A10B20C'). |
|
1805 |
||
1806 |
rslt := 'A%1B%2C%' expandPlaceholdersWith:#(10 20 30). |
|
1807 |
self assert:(rslt = 'A10B20C%'). |
|
1808 |
||
1809 |
rslt := 'A%%1B%2C%' expandPlaceholdersWith:#(10 20 30). |
|
1810 |
self assert:(rslt = 'A%1B20C%'). |
|
1811 |
||
1812 |
||
1813 |
rslt := 'A%aB%bC' expandPlaceholdersWith:(Dictionary withKeys:#(a b c) |
|
1814 |
andValues:#(10 20 30)). |
|
1815 |
self assert:(rslt = 'A10B20C'). |
|
1816 |
||
1817 |
"/ not expanded, if not found |
|
1818 |
rslt := 'A%aB%bC' expandPlaceholdersWith:(Dictionary withKeys:#(aa bb cc) |
|
1819 |
andValues:#(10 20 30)). |
|
1820 |
self assert:(rslt = 'A%aB%bC'). |
|
1821 |
||
1822 |
rslt := 'A%aaB%bbC' expandPlaceholdersWith:(Dictionary withKeys:#(aa bb cc) |
|
1823 |
andValues:#(10 20 30)). |
|
1824 |
self assert:(rslt = 'A%aaB%bbC'). |
|
1825 |
||
1826 |
rslt := 'A%(aa)B%(bb)C' expandPlaceholdersWith:(Dictionary withKeys:#(aa bb cc) |
|
1827 |
andValues:#(10 20 30)). |
|
1828 |
self assert:(rslt = 'A10B20C'). |
|
1829 |
||
1830 |
"/ allowing non-parenthized |
|
1831 |
rslt := String streamContents:[:s | |
|
1832 |
'A%aa,B%bb,C' |
|
1833 |
expandPlaceholders:$% |
|
1834 |
with:(Dictionary withKeys:#(aa bb cc) andValues:#(10 20 30)) |
|
1835 |
ignoreNumericEscapes:false |
|
1836 |
requireParentheses:false |
|
1837 |
on:s. |
|
1838 |
]. |
|
1839 |
self assert:(rslt = 'A10,B20,C'). |
|
1840 |
||
2211 | 1841 |
"Created: / 02-04-2019 / 11:00:08 / Claus Gittinger" |
1842 |
! |
|
1843 |
||
1844 |
test82b_expanding |
|
1845 |
| rslt | |
|
1846 |
||
1847 |
rslt := 'hello' copyExpanding:(Dictionary |
|
1848 |
withKeys:{$h . $e . $o} |
|
1849 |
andValues:{'HH' . 'EE' . $O }). |
|
1850 |
self assert:(rslt = 'HHEEllO'). |
|
1851 |
||
1852 |
rslt := 'he%2llo%1' % { 123 . 456 }. |
|
1853 |
self assert:(rslt = 'he456llo123'). |
|
1854 |
||
1855 |
"Created: / 02-04-2019 / 11:00:43 / Claus Gittinger" |
|
2077 | 1856 |
! |
1857 |
||
2327 | 1858 |
test82c_expanding |
1859 |
| rslt | |
|
1860 |
||
1861 |
rslt := '%1-%2-%3' |
|
1862 |
expandPlaceholders:$$ |
|
1863 |
with:{10 . 20 . 30} |
|
1864 |
ignoreNumericEscapes:false |
|
1865 |
ignoreNonNumericEscapes:false |
|
1866 |
ignoreSpecialEscapes:false |
|
1867 |
requireParentheses:false. |
|
1868 |
self assert:(rslt = '%1-%2-%3'). |
|
1869 |
||
2328 | 1870 |
rslt := '$$rev' |
1871 |
expandPlaceholders:$$ |
|
1872 |
with:{10 . 20 . 30} |
|
1873 |
ignoreNumericEscapes:false |
|
1874 |
ignoreNonNumericEscapes:false |
|
1875 |
ignoreSpecialEscapes:false |
|
1876 |
requireParentheses:false. |
|
1877 |
self assert:(rslt = '$rev'). |
|
1878 |
||
1879 |
rslt := '$$rev' |
|
1880 |
expandPlaceholders:$$ |
|
1881 |
with:(Dictionary withKeysAndValues:{ 'rev' . '1234'}) |
|
1882 |
ignoreNumericEscapes:false |
|
1883 |
ignoreNonNumericEscapes:false |
|
1884 |
ignoreSpecialEscapes:false |
|
1885 |
requireParentheses:false. |
|
1886 |
self assert:(rslt = '$rev'). |
|
1887 |
||
1888 |
rslt := '$rev' |
|
1889 |
expandPlaceholders:$$ |
|
1890 |
with:{10 . 20 . 30} |
|
1891 |
ignoreNumericEscapes:false |
|
1892 |
ignoreNonNumericEscapes:false |
|
1893 |
ignoreSpecialEscapes:false |
|
1894 |
requireParentheses:false. |
|
1895 |
self assert:(rslt = '$rev'). |
|
1896 |
||
1897 |
rslt := '$rev' |
|
1898 |
expandPlaceholders:$$ |
|
1899 |
with:(Dictionary withKeysAndValues:{ 'rev' . '1234'}) |
|
1900 |
ignoreNumericEscapes:false |
|
1901 |
ignoreNonNumericEscapes:false |
|
1902 |
ignoreSpecialEscapes:false |
|
1903 |
requireParentheses:false. |
|
1904 |
self assert:(rslt = '1234'). |
|
1905 |
||
2327 | 1906 |
rslt := '%1-%2-%3' |
1907 |
expandPlaceholders:$% |
|
1908 |
with:{10 . 20 . 30} |
|
1909 |
ignoreNumericEscapes:false |
|
1910 |
ignoreNonNumericEscapes:false |
|
1911 |
ignoreSpecialEscapes:false |
|
1912 |
requireParentheses:false. |
|
1913 |
self assert:(rslt = '10-20-30'). |
|
1914 |
||
1915 |
rslt := '%1-%2-%3' |
|
1916 |
expandPlaceholders:$% |
|
1917 |
with:{10 . 20 . 30} |
|
1918 |
ignoreNumericEscapes:true |
|
1919 |
ignoreNonNumericEscapes:false |
|
1920 |
ignoreSpecialEscapes:false |
|
1921 |
requireParentheses:false. |
|
1922 |
self assert:(rslt = '%1-%2-%3'). |
|
1923 |
||
1924 |
rslt := '%1%<cr>%2%<cr>%3' |
|
1925 |
expandPlaceholders:$% |
|
1926 |
with:{10 . 20 . 30} |
|
1927 |
ignoreNumericEscapes:true |
|
1928 |
ignoreNonNumericEscapes:false |
|
1929 |
ignoreSpecialEscapes:false |
|
1930 |
requireParentheses:false. |
|
1931 |
self assert:(rslt = c'%1\n%2\n%3'). |
|
1932 |
||
1933 |
rslt := '%1%<cr>%2%<cr>%3' |
|
1934 |
expandPlaceholders:$% |
|
1935 |
with:{10 . 20 . 30} |
|
1936 |
ignoreNumericEscapes:false |
|
1937 |
ignoreNonNumericEscapes:false |
|
1938 |
ignoreSpecialEscapes:false |
|
1939 |
requireParentheses:false. |
|
1940 |
self assert:(rslt = c'10\n20\n30'). |
|
1941 |
||
1942 |
rslt := '%1%<cr>%2%<cr>%3' |
|
1943 |
expandPlaceholders:$% |
|
1944 |
with:{10 . 20 . 30} |
|
1945 |
ignoreNumericEscapes:false |
|
1946 |
ignoreNonNumericEscapes:false |
|
1947 |
ignoreSpecialEscapes:true |
|
1948 |
requireParentheses:false. |
|
1949 |
self assert:(rslt = '10%<cr>20%<cr>30'). |
|
1950 |
||
1951 |
rslt := '%1 %(a) %(1) %(b)' |
|
1952 |
expandPlaceholders:$% |
|
1953 |
with:(Dictionary withKeysAndValues:{ 'a' . 'AAA' . 'b' . 'BBB' }) |
|
1954 |
ignoreNumericEscapes:false |
|
1955 |
ignoreNonNumericEscapes:true |
|
1956 |
ignoreSpecialEscapes:false |
|
1957 |
requireParentheses:false. |
|
1958 |
self assert:(rslt = ' %(a) %(b)'). |
|
1959 |
||
1960 |
rslt := '%1 %(a) %(1) %(b)' |
|
1961 |
expandPlaceholders:$% |
|
1962 |
with:(Dictionary withKeysAndValues:{ 'a' . 'AAA' . 'b' . 'BBB' }) |
|
1963 |
ignoreNumericEscapes:true |
|
1964 |
ignoreNonNumericEscapes:false |
|
1965 |
ignoreSpecialEscapes:false |
|
1966 |
requireParentheses:false. |
|
1967 |
self assert:(rslt = '%1 AAA %(1) BBB'). |
|
1968 |
||
1969 |
rslt := '%1 %a %(1) %b' |
|
1970 |
expandPlaceholders:$% |
|
1971 |
with:(Dictionary withKeysAndValues:{ 'a' . 'AAA' . 'b' . 'BBB' }) |
|
1972 |
ignoreNumericEscapes:true |
|
1973 |
ignoreNonNumericEscapes:false |
|
1974 |
ignoreSpecialEscapes:false |
|
1975 |
requireParentheses:false. |
|
1976 |
self assert:(rslt = '%1 AAA %(1) BBB'). |
|
1977 |
||
1978 |
||
1979 |
rslt := '%1 %aa %(1) %bb' |
|
1980 |
expandPlaceholders:$% |
|
1981 |
with:(Dictionary withKeysAndValues:{ 'a' . 'AAA' . 'b' . 'BBB' }) |
|
1982 |
ignoreNumericEscapes:true |
|
1983 |
ignoreNonNumericEscapes:false |
|
1984 |
ignoreSpecialEscapes:false |
|
1985 |
requireParentheses:true. |
|
1986 |
self assert:(rslt = '%1 AAAa %(1) BBBb'). |
|
1987 |
! |
|
1988 |
||
2377 | 1989 |
test82d_expanding |
1990 |
"what happens with missing keys:" |
|
1991 |
||
1992 |
| rslt | |
|
1993 |
||
1994 |
rslt := '%1-%2-%3' |
|
1995 |
expandPlaceholders:$% |
|
1996 |
with:{10 . 20 } |
|
1997 |
ignoreNumericEscapes:false |
|
1998 |
ignoreNonNumericEscapes:false |
|
1999 |
ignoreSpecialEscapes:false |
|
2000 |
requireParentheses:false. |
|
2001 |
self assert:(rslt = '10-20-'). |
|
2002 |
||
2003 |
"/ stupid backward compatibiliy!! |
|
2004 |
rslt := '%a-%b-%c' |
|
2005 |
expandPlaceholders:$% |
|
2006 |
with:(Dictionary withKeys:#('a' 'b') andValues:#(10 20 )) |
|
2007 |
ignoreNumericEscapes:false |
|
2008 |
ignoreNonNumericEscapes:false |
|
2009 |
ignoreSpecialEscapes:false |
|
2010 |
requireParentheses:false. |
|
2011 |
self assert:(rslt = '10-20-%c'). |
|
2012 |
||
2013 |
rslt := '%(a)-%(b)-%(c)' |
|
2014 |
expandPlaceholders:$% |
|
2015 |
with:(Dictionary withKeys:#('a' 'b') andValues:#(10 20 )) |
|
2016 |
ignoreNumericEscapes:false |
|
2017 |
ignoreNonNumericEscapes:false |
|
2018 |
ignoreSpecialEscapes:false |
|
2019 |
requireParentheses:false. |
|
2020 |
self assert:(rslt = '10-20-'). |
|
2378 | 2021 |
|
2022 |
rslt := '%(a)-%(b)-%(c)' |
|
2023 |
expandPlaceholders:$% |
|
2024 |
with:(Dictionary withKeys:#('a' 'b') andValues:#(10 20 )) |
|
2025 |
ignoreNumericEscapes:false |
|
2026 |
ignoreNonNumericEscapes:false |
|
2027 |
ignoreSpecialEscapes:false |
|
2028 |
requireParentheses:false |
|
2029 |
ifKeyAbsent:[:str :var | str]. |
|
2030 |
self assert:(rslt = '10-20-%(c)'). |
|
2031 |
||
2032 |
rslt := '%(a)-%(b)-%(abc)' |
|
2033 |
expandPlaceholders:$% |
|
2034 |
with:(Dictionary withKeys:#('a' 'b') andValues:#(10 20 )) |
|
2035 |
ignoreNumericEscapes:false |
|
2036 |
ignoreNonNumericEscapes:false |
|
2037 |
ignoreSpecialEscapes:false |
|
2038 |
requireParentheses:false |
|
2039 |
ifKeyAbsent:[:str :var | str]. |
|
2040 |
self assert:(rslt = '10-20-%(abc)'). |
|
2377 | 2041 |
! |
2042 |
||
2043 |
test82e_expandingSpecialSequences |
|
2044 |
| rslt | |
|
2045 |
||
2046 |
rslt := 'abc%<tab>def' |
|
2047 |
expandPlaceholders:$% |
|
2048 |
with:nil |
|
2049 |
ignoreNumericEscapes:false |
|
2050 |
ignoreNonNumericEscapes:false |
|
2051 |
ignoreSpecialEscapes:false |
|
2052 |
requireParentheses:false. |
|
2053 |
self assert:(rslt = ('abc',Character tab,'def')). |
|
2054 |
||
2055 |
rslt := 'abc%<crlf>def' |
|
2056 |
expandPlaceholders:$% |
|
2057 |
with:nil |
|
2058 |
ignoreNumericEscapes:false |
|
2059 |
ignoreNonNumericEscapes:false |
|
2060 |
ignoreSpecialEscapes:false |
|
2061 |
requireParentheses:false. |
|
2062 |
self assert:(rslt = ('abc',String crlf,'def')). |
|
2063 |
||
2064 |
rslt := 'abc%<crlf>def' with:nil. |
|
2065 |
self assert:(rslt = ('abc',String crlf,'def')). |
|
2066 |
! |
|
2067 |
||
2112 | 2068 |
test83_padding |
2069 |
| rslt | |
|
2070 |
||
2071 |
rslt := 'foo' paddedTo:10. |
|
2072 |
self assert:(rslt = 'foo '). |
|
2073 |
||
2074 |
rslt := 'foo' paddedTo:3. |
|
2075 |
self assert:(rslt = 'foo'). |
|
2076 |
rslt := 'foo' paddedTo:4. |
|
2077 |
self assert:(rslt = 'foo '). |
|
2078 |
rslt := 'foo' paddedTo:2. |
|
2079 |
self assert:(rslt = 'foo'). |
|
2080 |
||
2081 |
rslt := '' paddedTo:2. |
|
2082 |
self assert:(rslt = ' '). |
|
2083 |
||
2084 |
rslt := 'foo' paddedTo:10 with:$-. |
|
2085 |
self assert:(rslt = 'foo-------'). |
|
2086 |
||
2087 |
rslt := 'foo' paddedTo:3 with:$-. |
|
2088 |
self assert:(rslt = 'foo'). |
|
2089 |
rslt := 'foo' paddedTo:4 with:$-. |
|
2090 |
self assert:(rslt = 'foo-'). |
|
2091 |
rslt := 'foo' paddedTo:2 with:$-. |
|
2092 |
self assert:(rslt = 'foo'). |
|
2093 |
||
2094 |
rslt := '' paddedTo:2 with:$-. |
|
2095 |
self assert:(rslt = '--'). |
|
2096 |
||
2097 |
rslt := 'foo' leftPaddedTo:10. |
|
2098 |
self assert:(rslt = ' foo'). |
|
2099 |
||
2100 |
rslt := 'foo' leftPaddedTo:3. |
|
2101 |
self assert:(rslt = 'foo'). |
|
2102 |
rslt := 'foo' leftPaddedTo:4. |
|
2103 |
self assert:(rslt = ' foo'). |
|
2104 |
rslt := 'foo' leftPaddedTo:2. |
|
2105 |
self assert:(rslt = 'foo'). |
|
2106 |
||
2107 |
rslt := '' leftPaddedTo:2. |
|
2108 |
self assert:(rslt = ' '). |
|
2109 |
||
2110 |
rslt := 'foo' leftPaddedTo:10 with:$-. |
|
2111 |
self assert:(rslt = '-------foo'). |
|
2112 |
||
2113 |
rslt := 'foo' leftPaddedTo:3 with:$-. |
|
2114 |
self assert:(rslt = 'foo'). |
|
2115 |
rslt := 'foo' leftPaddedTo:4 with:$-. |
|
2116 |
self assert:(rslt = '-foo'). |
|
2117 |
rslt := 'foo' leftPaddedTo:2 with:$-. |
|
2118 |
self assert:(rslt = 'foo'). |
|
2119 |
||
2120 |
rslt := '' leftPaddedTo:2 with:$-. |
|
2121 |
self assert:(rslt = '--'). |
|
2122 |
||
2123 |
"Created: / 21-03-2019 / 12:58:33 / Claus Gittinger" |
|
2124 |
! |
|
2125 |
||
2211 | 2126 |
test84_withCRs |
2127 |
| rslt | |
|
2128 |
||
2129 |
rslt := 'foo\bar' addLineDelimiters. |
|
2130 |
self assert:(rslt = ('foo',Character cr,'bar')). |
|
2131 |
||
2132 |
"Created: / 02-04-2019 / 10:57:44 / Claus Gittinger" |
|
2133 |
! |
|
2134 |
||
2364 | 2135 |
test90_enumeratingLines |
2208 | 2136 |
|
2364 | 2137 |
| | |
2138 |
||
2139 |
#( |
|
2140 |
c'' |
|
2141 |
c'abc' |
|
2142 |
c'\n' |
|
2143 |
c'abc\n' |
|
2144 |
c'\n\n' |
|
2145 |
c'abc\n\n' |
|
2146 |
c'\n\nabc' |
|
2147 |
c'\nabc\n' |
|
2148 |
c'abc\nabc\nabc' |
|
2149 |
c'abc\nabc\nabc\n' |
|
2150 |
c'abc\nabc\nabc\n\n' |
|
2151 |
c'a\nb\nc\n\n' |
|
2152 |
c'a\n\n\nb\nc\n\n\n\nd' |
|
2153 |
) do:[:eachTestString | |
|
2154 |
|testString sColl calledWith1 calledWith2 count1 count2 countReturned| |
|
2155 |
||
2156 |
#( yourself asUnicode16String asUnicode32String ) do:[:conv | |
|
2157 |
testString := eachTestString perform:conv. |
|
2158 |
||
2159 |
"/ try asStringCollection as reference |
|
2160 |
sColl := testString asStringCollection. |
|
2161 |
count1 := 0. |
|
2162 |
calledWith1 := OrderedCollection new. |
|
2163 |
sColl do:[:each | |
|
2164 |
count1 := count1 + 1. |
|
2165 |
calledWith1 add:each. |
|
2166 |
]. |
|
2167 |
||
2168 |
"/ check asCollectionOfLinesDo: |
|
2169 |
count2 := 0. |
|
2170 |
calledWith2 := OrderedCollection new. |
|
2171 |
countReturned := testString asCollectionOfLinesDo:[:each | |
|
2172 |
count2 := count2 + 1. |
|
2173 |
calledWith2 add:each. |
|
2174 |
]. |
|
2175 |
self assert:(count1 == count2). |
|
2176 |
self assert:(count2 == countReturned). |
|
2177 |
self assert:(calledWith1 = calledWith2). |
|
2178 |
]. |
|
2179 |
]. |
|
2180 |
! |
|
1214
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
2181 |
|
2364 | 2182 |
test91_enumeratingWords |
2183 |
||
2184 |
| | |
|
2185 |
||
2186 |
#( |
|
2187 |
0 c'' |
|
2188 |
1 c'abc' |
|
2189 |
0 c'\n' |
|
2190 |
1 c'abc\n' |
|
2191 |
0 c'\n\n' |
|
2192 |
1 c'abc\n\n' |
|
2193 |
1 c'\n\nabc' |
|
2194 |
1 c'\nabc\n' |
|
2195 |
3 c'abc\nabc\nabc' |
|
2196 |
3 c'abc\nabc\nabc\n' |
|
2197 |
3 c'abc\nabc\nabc\n\n' |
|
2198 |
3 c'a\nb\nc\n\n' |
|
2199 |
4 c'a\n\n\nb\nc\n\n\n\nd' |
|
2200 |
) pairWiseDo:[:expectedCount :eachTestString | |
|
2201 |
|testString sColl calledWith1 calledWith2 count1 count2 countReturned| |
|
1214
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
2202 |
|
2364 | 2203 |
#( yourself asUnicode16String asUnicode32String ) do:[:conv | |
2204 |
testString := eachTestString perform:conv. |
|
2205 |
||
2206 |
"/ try asStringCollection as reference |
|
2207 |
sColl := testString asCollectionOfWords. |
|
2208 |
count1 := 0. |
|
2209 |
calledWith1 := OrderedCollection new. |
|
2210 |
sColl do:[:each | |
|
2211 |
count1 := count1 + 1. |
|
2212 |
calledWith1 add:each. |
|
2213 |
]. |
|
1214
11cb005634cb
class: RegressionTests::StringTests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1103
diff
changeset
|
2214 |
|
2364 | 2215 |
"/ check asCollectionOfWordsDo: |
2216 |
count2 := 0. |
|
2217 |
calledWith2 := OrderedCollection new. |
|
2218 |
countReturned := testString asCollectionOfWordsDo:[:each | |
|
2219 |
count2 := count2 + 1. |
|
2220 |
calledWith2 add:each. |
|
2221 |
]. |
|
2222 |
self assert:(count1 == expectedCount). |
|
2223 |
self assert:(count1 == count2). |
|
2224 |
self assert:(count2 == countReturned). |
|
2225 |
self assert:(calledWith1 = calledWith2). |
|
2226 |
]. |
|
2227 |
]. |
|
283 | 2228 |
! ! |
2229 |
||
2230 |
!StringTests class methodsFor:'documentation'! |
|
2231 |
||
2232 |
version |
|
2233 |
^ '$Header$' |
|
570 | 2234 |
! |
2235 |
||
2236 |
version_CVS |
|
2237 |
^ '$Header$' |
|
283 | 2238 |
! ! |
752
ef9236c7271c
class: RegressionTests::StringTests
Stefan Vogel <sv@exept.de>
parents:
751
diff
changeset
|
2239 |