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