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