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