2265
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
1867
|
3 |
"{ Package: 'stx:goodies/regression' }"
|
1865
|
4 |
|
1866
|
5 |
"{ NameSpace: RegressionTests }"
|
1865
|
6 |
|
|
7 |
TestCase subclass:#RxTests
|
|
8 |
instanceVariableNames:''
|
|
9 |
classVariableNames:''
|
|
10 |
poolDictionaries:''
|
2042
|
11 |
category:'tests-Regression-Collections-Utilities'
|
1865
|
12 |
!
|
|
13 |
|
|
14 |
!RxTests class methodsFor:'documentation'!
|
|
15 |
|
|
16 |
documentation
|
|
17 |
"
|
2042
|
18 |
regex tests.
|
1865
|
19 |
"
|
|
20 |
! !
|
|
21 |
|
|
22 |
!RxTests methodsFor:'profiling'!
|
|
23 |
|
|
24 |
bigHonkingStream
|
2265
|
25 |
^ '~/Downloads/smalltalk/Pharo6.1-64.app/Contents/MacOS/PharoV60.sources' asFilename readStream "36Mb"
|
|
26 |
"/ ^'/home/vassili/VisualWorks/image/visualnc.sou' asFilename readStream "7 Megs"
|
|
27 |
|
|
28 |
"Modified: / 04-06-2019 / 10:52:51 / Claus Gittinger"
|
1865
|
29 |
!
|
|
30 |
|
|
31 |
frequentMatchProfile
|
1868
|
32 |
"
|
|
33 |
TimeProfiler profile: [self frequentMatchProfile]
|
|
34 |
Time millisecondsToRun: [self frequentMatchProfile]
|
|
35 |
"
|
|
36 |
|
|
37 |
| stream matcher count |
|
|
38 |
stream := self bigHonkingStream.
|
|
39 |
count := 0.
|
|
40 |
matcher := '\<\w+' asRegex.
|
|
41 |
[
|
|
42 |
[matcher searchStream: stream] whileTrue: [count := count + 1].
|
|
43 |
]
|
|
44 |
valueNowOrOnUnwindDo: [stream close].
|
|
45 |
^count
|
1865
|
46 |
!
|
|
47 |
|
|
48 |
rareMatchProfile
|
2265
|
49 |
" o:Regex::RxMatcher
|
|
50 |
TimeProfiler profile: [self new rareMatchProfile]
|
|
51 |
Time millisecondsToRun: [self new rareMatchProfile] -> 22760
|
|
52 |
"
|
|
53 |
|
|
54 |
| stream matcher count |
|
|
55 |
stream := self bigHonkingStream.
|
|
56 |
count := 0.
|
|
57 |
matcher := 'foo' asRegex.
|
|
58 |
[
|
|
59 |
[matcher searchStream: stream] whileTrue: [count := count + 1].
|
|
60 |
]
|
|
61 |
valueNowOrOnUnwindDo: [stream close].
|
|
62 |
^count
|
|
63 |
|
|
64 |
"Modified (comment): / 04-06-2019 / 10:54:16 / Claus Gittinger"
|
1865
|
65 |
!
|
|
66 |
|
|
67 |
singleCharPrefixMatchProfile
|
|
68 |
"
|
|
69 |
TimeProfiler profile: [self singleCharPrefixMatchProfile]
|
|
70 |
Time millisecondsToRun: [self singleCharPrefixMatchProfile]
|
|
71 |
"
|
|
72 |
|
|
73 |
| stream matcher count |
|
|
74 |
stream := self bigHonkingStream.
|
|
75 |
count := 0.
|
|
76 |
matcher := 'm(e|a)th' asRegex.
|
|
77 |
[
|
|
78 |
[matcher searchStream: stream] whileTrue: [count := count + 1].
|
|
79 |
]
|
|
80 |
valueNowOrOnUnwindDo: [stream close].
|
|
81 |
^count
|
|
82 |
! !
|
|
83 |
|
|
84 |
!RxTests methodsFor:'test suite - new'!
|
|
85 |
|
|
86 |
test001
|
|
87 |
"patt. input match-expected matched-expression
|
|
88 |
abc abc y & abc
|
|
89 |
abc xbc n - -
|
|
90 |
abc axc n - -
|
|
91 |
abc abx n - -
|
|
92 |
abc xabcy y & abc
|
|
93 |
abc ababc y & abc
|
|
94 |
"
|
1868
|
95 |
|
1865
|
96 |
|matcher|
|
|
97 |
|
1868
|
98 |
self
|
|
99 |
should:[ (matcher := self compileRegex:'abc' into:Regex::RxMatcher) ~= nil ].
|
1865
|
100 |
self should:[ (matcher search:'abc') = true ].
|
|
101 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
102 |
self should:[ (matcher search:'xbc') = false ].
|
|
103 |
self should:[ (matcher search:'axc') = false ].
|
|
104 |
self should:[ (matcher search:'abx') = false ].
|
|
105 |
self should:[ (matcher search:'xabcy') = true ].
|
|
106 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
107 |
self should:[ (matcher search:'ababc') = true ].
|
|
108 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
109 |
|
|
110 |
"
|
|
111 |
self new test01
|
|
112 |
"
|
|
113 |
!
|
|
114 |
|
|
115 |
test002
|
|
116 |
"patt. input match-expected matched-expression
|
|
117 |
ab*c abc y & abc
|
|
118 |
"
|
1868
|
119 |
|
1865
|
120 |
|matcher|
|
|
121 |
|
1868
|
122 |
self
|
|
123 |
should:[ (matcher := self compileRegex:'ab*c' into:Regex::RxMatcher) ~= nil ].
|
1865
|
124 |
self should:[ (matcher search:'abc') = true ].
|
|
125 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
126 |
|
|
127 |
"
|
|
128 |
self new test02
|
|
129 |
"
|
|
130 |
!
|
|
131 |
|
|
132 |
test003
|
|
133 |
"patt. input match-expected matched-expression
|
|
134 |
ab*bc abc y & abc
|
|
135 |
ab*bc abbc y & abbc
|
|
136 |
ab*bc abbbbc y & abbbbc
|
|
137 |
"
|
1868
|
138 |
|
1865
|
139 |
|matcher|
|
|
140 |
|
1868
|
141 |
self
|
|
142 |
should:[ (matcher := self compileRegex:'ab*bc' into:Regex::RxMatcher) ~= nil ].
|
1865
|
143 |
self should:[ (matcher search:'abc') = true ].
|
|
144 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
145 |
self should:[ (matcher search:'abbc') = true ].
|
|
146 |
self should:[ (matcher subexpression:1) = 'abbc' ].
|
|
147 |
self should:[ (matcher search:'abbbbc') = true ].
|
|
148 |
self should:[ (matcher subexpression:1) = 'abbbbc' ].
|
|
149 |
|
|
150 |
"
|
|
151 |
self new test02
|
|
152 |
"
|
|
153 |
!
|
|
154 |
|
|
155 |
test004
|
|
156 |
"patt. input match-expected matched-expression
|
|
157 |
ab+bc abbc y & abbc
|
|
158 |
ab+bc abc n - -
|
|
159 |
ab+bc abq n - -
|
|
160 |
ab+bc abbbbc y & abbbbc
|
|
161 |
"
|
1868
|
162 |
|
1865
|
163 |
|matcher|
|
|
164 |
|
1868
|
165 |
self
|
|
166 |
should:[ (matcher := self compileRegex:'ab+bc' into:Regex::RxMatcher) ~= nil ].
|
1865
|
167 |
self should:[ (matcher search:'abbc') = true ].
|
|
168 |
self should:[ (matcher subexpression:1) = 'abbc' ].
|
|
169 |
self should:[ (matcher search:'abc') = false ].
|
|
170 |
self should:[ (matcher search:'abq') = false ].
|
|
171 |
self should:[ (matcher search:'abbbbc') = true ].
|
|
172 |
self should:[ (matcher subexpression:1) = 'abbbbc' ].
|
|
173 |
|
|
174 |
"
|
|
175 |
self new test04
|
|
176 |
"
|
|
177 |
!
|
|
178 |
|
|
179 |
test005
|
|
180 |
"patt. input match-expected matched-expression
|
|
181 |
ab?bc abbc y & abbc
|
|
182 |
ab?bc abc y & abc
|
|
183 |
ab?bc abbbbc n - -
|
|
184 |
"
|
1868
|
185 |
|
1865
|
186 |
|matcher|
|
|
187 |
|
1868
|
188 |
self
|
|
189 |
should:[ (matcher := self compileRegex:'ab?bc' into:Regex::RxMatcher) ~= nil ].
|
1865
|
190 |
self should:[ (matcher search:'abbc') = true ].
|
|
191 |
self should:[ (matcher subexpression:1) = 'abbc' ].
|
|
192 |
self should:[ (matcher search:'abc') = true ].
|
|
193 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
194 |
self should:[ (matcher search:'abbbbc') = false ].
|
|
195 |
|
|
196 |
"
|
|
197 |
self new test05
|
|
198 |
"
|
|
199 |
!
|
|
200 |
|
|
201 |
test005b
|
|
202 |
"patt. input match-expected matched-expression
|
|
203 |
ab?c abc y & abc
|
|
204 |
"
|
1868
|
205 |
|
1865
|
206 |
|matcher|
|
|
207 |
|
1868
|
208 |
self
|
|
209 |
should:[ (matcher := self compileRegex:'ab?c' into:Regex::RxMatcher) ~= nil ].
|
1865
|
210 |
self should:[ (matcher search:'abc') = true ].
|
|
211 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
212 |
|
|
213 |
"
|
|
214 |
self new test05b
|
|
215 |
"
|
|
216 |
!
|
|
217 |
|
|
218 |
test006
|
|
219 |
"patt. input match-expected matched-expression
|
|
220 |
^abc$ abc y & abc
|
|
221 |
^abc$ abcc n - -
|
|
222 |
^abc$ aabc n - -
|
|
223 |
"
|
1868
|
224 |
|
1865
|
225 |
|matcher|
|
|
226 |
|
1868
|
227 |
self
|
|
228 |
should:[ (matcher := self compileRegex:'^abc$' into:Regex::RxMatcher) ~= nil ].
|
1865
|
229 |
self should:[ (matcher search:'abc') = true ].
|
|
230 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
231 |
self should:[ (matcher search:'abcc') = false ].
|
|
232 |
self should:[ (matcher search:'aabc') = false ].
|
|
233 |
|
|
234 |
"
|
|
235 |
self new test06
|
|
236 |
"
|
|
237 |
!
|
|
238 |
|
|
239 |
test007
|
|
240 |
"patt. input match-expected matched-expression
|
|
241 |
^abc abcc y & abc
|
|
242 |
"
|
1868
|
243 |
|
1865
|
244 |
|matcher|
|
|
245 |
|
1868
|
246 |
self
|
|
247 |
should:[ (matcher := self compileRegex:'^abc' into:Regex::RxMatcher) ~= nil ].
|
1865
|
248 |
self should:[ (matcher search:'abcc') = true ].
|
|
249 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
250 |
|
|
251 |
"
|
|
252 |
self new test07
|
|
253 |
"
|
|
254 |
!
|
|
255 |
|
|
256 |
test008
|
|
257 |
"patt. input match-expected matched-expression
|
|
258 |
abc$ aabc y & abc
|
|
259 |
"
|
1868
|
260 |
|
1865
|
261 |
|matcher|
|
|
262 |
|
1868
|
263 |
self
|
|
264 |
should:[ (matcher := self compileRegex:'abc$' into:Regex::RxMatcher) ~= nil ].
|
1865
|
265 |
self should:[ (matcher search:'aabc') = true ].
|
|
266 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
267 |
|
|
268 |
"
|
|
269 |
self new test08
|
|
270 |
"
|
|
271 |
!
|
|
272 |
|
|
273 |
test009
|
|
274 |
"patt. input match-expected matched-expression
|
1868
|
275 |
^ abc y &
|
1865
|
276 |
"
|
1868
|
277 |
|
1865
|
278 |
|matcher|
|
|
279 |
|
1868
|
280 |
self should:[ (matcher := self compileRegex:'^' into:Regex::RxMatcher) ~= nil ].
|
1865
|
281 |
self should:[ (matcher search:'abc') = true ].
|
|
282 |
|
|
283 |
"
|
|
284 |
self new test09
|
|
285 |
"
|
|
286 |
!
|
|
287 |
|
|
288 |
test010
|
|
289 |
"patt. input match-expected matched-expression
|
1868
|
290 |
$ abc y &
|
1865
|
291 |
"
|
1868
|
292 |
|
1865
|
293 |
|matcher|
|
|
294 |
|
1868
|
295 |
self should:[ (matcher := self compileRegex:'$' into:Regex::RxMatcher) ~= nil ].
|
1865
|
296 |
self should:[ (matcher search:'abc') = true ].
|
|
297 |
|
|
298 |
"
|
|
299 |
self new test10
|
|
300 |
"
|
|
301 |
!
|
|
302 |
|
|
303 |
test011
|
|
304 |
|matcher|
|
|
305 |
|
1868
|
306 |
self
|
|
307 |
should:[ (matcher := self compileRegex:'a.c' into:Regex::RxMatcher) ~= nil ].
|
1865
|
308 |
self should:[ (matcher search:'abc') = true ].
|
|
309 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
310 |
self should:[ (matcher search:'axc') = true ].
|
|
311 |
self should:[ (matcher subexpression:1) = 'axc' ].
|
|
312 |
!
|
|
313 |
|
|
314 |
test012
|
|
315 |
|matcher|
|
|
316 |
|
1868
|
317 |
self
|
|
318 |
should:[ (matcher := self compileRegex:'a.*c' into:Regex::RxMatcher) ~= nil ].
|
1865
|
319 |
self should:[ (matcher search:'axyzc') = true ].
|
|
320 |
self should:[ (matcher subexpression:1) = 'axyzc' ].
|
|
321 |
self should:[ (matcher search:'axy zc') = true ].
|
|
322 |
self should:[ (matcher subexpression:1) = 'axy zc' ].
|
1868
|
323 |
self
|
|
324 |
should:[
|
|
325 |
(matcher search:'axy
|
|
326 |
zc')
|
|
327 |
= false
|
|
328 |
].
|
1865
|
329 |
self should:[ (matcher search:'axyzd') = false ].
|
|
330 |
!
|
|
331 |
|
|
332 |
test013
|
|
333 |
|matcher|
|
|
334 |
|
1868
|
335 |
self
|
|
336 |
should:[ (matcher := self compileRegex:'.a.*' into:Regex::RxMatcher) ~= nil ].
|
1865
|
337 |
self should:[ (matcher search:'1234abc') = true ].
|
|
338 |
self should:[ (matcher subexpression:1) = '4abc' ].
|
|
339 |
self should:[ (matcher search:'abcd') = false ].
|
|
340 |
!
|
|
341 |
|
|
342 |
test014
|
|
343 |
|matcher|
|
|
344 |
|
1868
|
345 |
self
|
|
346 |
should:[ (matcher := self compileRegex:'a\w+c' into:Regex::RxMatcher) ~= nil ].
|
1865
|
347 |
self should:[ (matcher search:' abbbbc ') = true ].
|
|
348 |
self should:[ (matcher subexpression:1) = 'abbbbc' ].
|
|
349 |
self should:[ (matcher search:'abb bc') = false ].
|
|
350 |
!
|
|
351 |
|
|
352 |
test015
|
|
353 |
|matcher|
|
|
354 |
|
1868
|
355 |
self
|
|
356 |
should:[ (matcher := self compileRegex:'\w+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
357 |
self should:[ (matcher search:' foobar quux') = true ].
|
|
358 |
self should:[ (matcher subexpression:1) = 'foobar' ].
|
|
359 |
self should:[ (matcher search:' ~!!@#$%^&*()-+=\|/?.>,<') = false ].
|
|
360 |
!
|
|
361 |
|
|
362 |
test016
|
|
363 |
|matcher|
|
|
364 |
|
1868
|
365 |
self
|
|
366 |
should:[ (matcher := self compileRegex:'a\W+c' into:Regex::RxMatcher) ~= nil ].
|
1865
|
367 |
self should:[ (matcher search:'a c') = true ].
|
|
368 |
self should:[ (matcher subexpression:1) = 'a c' ].
|
|
369 |
self should:[ (matcher search:'a bc') = false ].
|
|
370 |
!
|
|
371 |
|
|
372 |
test017
|
|
373 |
|matcher|
|
|
374 |
|
1868
|
375 |
self
|
|
376 |
should:[ (matcher := self compileRegex:'\W+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
377 |
self should:[ (matcher search:'foo!!@#$bar') = true ].
|
|
378 |
self should:[ (matcher subexpression:1) = '!!@#$' ].
|
|
379 |
self should:[ (matcher search:'foobar') = false ].
|
|
380 |
!
|
|
381 |
|
|
382 |
test018
|
|
383 |
|matcher|
|
|
384 |
|
1868
|
385 |
self
|
|
386 |
should:[ (matcher := self compileRegex:'a\s*c' into:Regex::RxMatcher) ~= nil ].
|
1865
|
387 |
self should:[ (matcher search:'a c') = true ].
|
|
388 |
self should:[ (matcher subexpression:1) = 'a c' ].
|
|
389 |
self should:[ (matcher search:'a bc') = false ].
|
|
390 |
!
|
|
391 |
|
|
392 |
test019
|
|
393 |
|matcher|
|
|
394 |
|
1868
|
395 |
self
|
|
396 |
should:[ (matcher := self compileRegex:'\s+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
397 |
self should:[ (matcher search:'abc3457 sd') = true ].
|
|
398 |
self should:[ (matcher subexpression:1) = ' ' ].
|
|
399 |
self should:[ (matcher search:'1234$^*^&asdfb') = false ].
|
|
400 |
!
|
|
401 |
|
|
402 |
test020
|
|
403 |
|matcher|
|
|
404 |
|
1868
|
405 |
self
|
|
406 |
should:[ (matcher := self compileRegex:'a\S*c' into:Regex::RxMatcher) ~= nil ].
|
1865
|
407 |
self should:[ (matcher search:'aqwertyc') = true ].
|
|
408 |
self should:[ (matcher subexpression:1) = 'aqwertyc' ].
|
|
409 |
self should:[ (matcher search:'ab c') = false ].
|
|
410 |
!
|
|
411 |
|
|
412 |
test021
|
|
413 |
|matcher|
|
|
414 |
|
1868
|
415 |
self
|
|
416 |
should:[ (matcher := self compileRegex:'\S+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
417 |
self should:[ (matcher search:' asdf ') = true ].
|
|
418 |
self should:[ (matcher subexpression:1) = 'asdf' ].
|
1868
|
419 |
self
|
|
420 |
should:[ (matcher search:'
|
|
421 |
') = false ].
|
1865
|
422 |
!
|
|
423 |
|
|
424 |
test022
|
|
425 |
|matcher|
|
|
426 |
|
1868
|
427 |
self
|
|
428 |
should:[ (matcher := self compileRegex:'a\d+c' into:Regex::RxMatcher) ~= nil ].
|
1865
|
429 |
self should:[ (matcher search:'a0123456789c') = true ].
|
|
430 |
self should:[ (matcher subexpression:1) = 'a0123456789c' ].
|
|
431 |
self should:[ (matcher search:'a12b34c') = false ].
|
|
432 |
!
|
|
433 |
|
|
434 |
test023
|
|
435 |
|matcher|
|
|
436 |
|
1868
|
437 |
self
|
|
438 |
should:[ (matcher := self compileRegex:'\d+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
439 |
self should:[ (matcher search:'foo@#$%123ASD #$$%^&') = true ].
|
|
440 |
self should:[ (matcher subexpression:1) = '123' ].
|
|
441 |
self should:[ (matcher search:'foo!!@#$asdfl;') = false ].
|
|
442 |
!
|
|
443 |
|
|
444 |
test024
|
|
445 |
|matcher|
|
|
446 |
|
1868
|
447 |
self
|
|
448 |
should:[ (matcher := self compileRegex:'a\D+c' into:Regex::RxMatcher) ~= nil ].
|
1865
|
449 |
self should:[ (matcher search:'aqwertyc') = true ].
|
|
450 |
self should:[ (matcher subexpression:1) = 'aqwertyc' ].
|
|
451 |
self should:[ (matcher search:'aqw6ertc') = false ].
|
|
452 |
!
|
|
453 |
|
|
454 |
test025
|
|
455 |
|matcher|
|
|
456 |
|
1868
|
457 |
self
|
|
458 |
should:[ (matcher := self compileRegex:'\D+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
459 |
self should:[ (matcher search:'1234 abc 456') = true ].
|
|
460 |
self should:[ (matcher subexpression:1) = ' abc ' ].
|
|
461 |
self should:[ (matcher search:'1234567890') = false ].
|
|
462 |
!
|
|
463 |
|
|
464 |
test026
|
|
465 |
|matcher|
|
|
466 |
|
1868
|
467 |
self
|
|
468 |
should:[ (matcher := self compileRegex:'(f|o)+\b' into:Regex::RxMatcher) ~= nil ].
|
1865
|
469 |
self should:[ (matcher search:'foo') = true ].
|
|
470 |
self should:[ (matcher subexpression:1) = 'foo' ].
|
|
471 |
self should:[ (matcher search:' foo ') = true ].
|
|
472 |
self should:[ (matcher subexpression:1) = 'foo' ].
|
|
473 |
!
|
|
474 |
|
|
475 |
test027
|
|
476 |
|matcher|
|
|
477 |
|
1868
|
478 |
self
|
|
479 |
should:[ (matcher := self compileRegex:'\ba\w+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
480 |
self should:[ (matcher search:'land ancient') = true ].
|
|
481 |
self should:[ (matcher subexpression:1) = 'ancient' ].
|
|
482 |
self should:[ (matcher search:'antique vase') = true ].
|
|
483 |
self should:[ (matcher subexpression:1) = 'antique' ].
|
|
484 |
self should:[ (matcher search:'goofy foobar') = false ].
|
|
485 |
!
|
|
486 |
|
|
487 |
test028
|
|
488 |
|matcher|
|
|
489 |
|
1868
|
490 |
self
|
|
491 |
should:[ (matcher := self compileRegex:'(f|o)+\B' into:Regex::RxMatcher) ~= nil ].
|
1865
|
492 |
self should:[ (matcher search:'quuxfoobar') = true ].
|
|
493 |
self should:[ (matcher subexpression:1) = 'foo' ].
|
|
494 |
self should:[ (matcher search:'quuxfoo ') = true ].
|
|
495 |
self should:[ (matcher subexpression:1) = 'fo' ].
|
|
496 |
!
|
|
497 |
|
|
498 |
test029
|
|
499 |
|matcher|
|
|
500 |
|
1868
|
501 |
self
|
|
502 |
should:[ (matcher := self compileRegex:'\Ba\w+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
503 |
self should:[ (matcher search:'land ancient') = true ].
|
|
504 |
self should:[ (matcher subexpression:1) = 'and' ].
|
|
505 |
self should:[ (matcher search:'antique vase') = true ].
|
|
506 |
self should:[ (matcher subexpression:1) = 'ase' ].
|
|
507 |
self should:[ (matcher search:'smalltalk shall overcome') = true ].
|
|
508 |
self should:[ (matcher subexpression:1) = 'alltalk' ].
|
|
509 |
self should:[ (matcher search:'foonix is better') = false ].
|
|
510 |
!
|
|
511 |
|
|
512 |
test030
|
|
513 |
|matcher|
|
|
514 |
|
1868
|
515 |
self
|
|
516 |
should:[ (matcher := self compileRegex:'fooa\>.*' into:Regex::RxMatcher) ~= nil ].
|
1865
|
517 |
self should:[ (matcher search:'fooa ') = true ].
|
|
518 |
self should:[ (matcher search:'fooa123') = false ].
|
|
519 |
self should:[ (matcher search:'fooa bar') = true ].
|
|
520 |
self should:[ (matcher search:'fooa') = true ].
|
|
521 |
self should:[ (matcher search:'fooargh') = false ].
|
|
522 |
!
|
|
523 |
|
|
524 |
test031
|
|
525 |
|matcher|
|
|
526 |
|
1868
|
527 |
self
|
|
528 |
should:[ (matcher := self compileRegex:'\>.+abc' into:Regex::RxMatcher) ~= nil ].
|
1865
|
529 |
self should:[ (matcher search:' abcde fg') = false ].
|
|
530 |
self should:[ (matcher search:'foo abcde') = true ].
|
|
531 |
self should:[ (matcher subexpression:1) = ' abc' ].
|
|
532 |
self should:[ (matcher search:'abcde') = false ].
|
|
533 |
!
|
|
534 |
|
|
535 |
test032
|
|
536 |
|matcher|
|
|
537 |
|
1868
|
538 |
self
|
|
539 |
should:[ (matcher := self compileRegex:'\<foo.*' into:Regex::RxMatcher) ~= nil ].
|
1865
|
540 |
self should:[ (matcher search:'foo') = true ].
|
|
541 |
self should:[ (matcher search:'foobar') = true ].
|
|
542 |
self should:[ (matcher search:'qfoobarq foonix') = true ].
|
|
543 |
self should:[ (matcher subexpression:1) = 'foonix' ].
|
|
544 |
self should:[ (matcher search:' foo') = true ].
|
|
545 |
self should:[ (matcher search:' 12foo') = false ].
|
|
546 |
self should:[ (matcher search:'barfoo') = false ].
|
|
547 |
!
|
|
548 |
|
|
549 |
test033
|
|
550 |
|matcher|
|
|
551 |
|
1868
|
552 |
self
|
|
553 |
should:[ (matcher := self compileRegex:'.+\<foo' into:Regex::RxMatcher) ~= nil ].
|
1865
|
554 |
self should:[ (matcher search:'foo') = false ].
|
|
555 |
self should:[ (matcher search:'ab foo') = true ].
|
|
556 |
self should:[ (matcher subexpression:1) = 'ab foo' ].
|
|
557 |
self should:[ (matcher search:'abfoo') = false ].
|
|
558 |
!
|
|
559 |
|
|
560 |
test034
|
|
561 |
|matcher|
|
|
562 |
|
1868
|
563 |
self
|
|
564 |
should:[ (matcher := self compileRegex:'a[bc]d' into:Regex::RxMatcher) ~= nil ].
|
1865
|
565 |
self should:[ (matcher search:'abc') = false ].
|
|
566 |
self should:[ (matcher search:'abd') = true ].
|
|
567 |
self should:[ (matcher subexpression:1) = 'abd' ].
|
|
568 |
!
|
|
569 |
|
|
570 |
test035
|
|
571 |
|matcher|
|
|
572 |
|
1868
|
573 |
self
|
|
574 |
should:[ (matcher := self compileRegex:'a[b-d]e' into:Regex::RxMatcher) ~= nil ].
|
1865
|
575 |
self should:[ (matcher search:'abd') = false ].
|
|
576 |
self should:[ (matcher search:'ace') = true ].
|
|
577 |
self should:[ (matcher subexpression:1) = 'ace' ].
|
|
578 |
!
|
|
579 |
|
|
580 |
test036
|
|
581 |
|matcher|
|
|
582 |
|
1868
|
583 |
self
|
|
584 |
should:[ (matcher := self compileRegex:'a[b-d]' into:Regex::RxMatcher) ~= nil ].
|
1865
|
585 |
self should:[ (matcher search:'aac') = true ].
|
|
586 |
self should:[ (matcher subexpression:1) = 'ac' ].
|
|
587 |
!
|
|
588 |
|
|
589 |
test037
|
|
590 |
|matcher|
|
|
591 |
|
1868
|
592 |
self
|
|
593 |
should:[ (matcher := self compileRegex:'a[-b]' into:Regex::RxMatcher) ~= nil ].
|
1865
|
594 |
self should:[ (matcher search:'a-') = true ].
|
|
595 |
self should:[ (matcher subexpression:1) = 'a-' ].
|
|
596 |
!
|
|
597 |
|
|
598 |
test038
|
|
599 |
|matcher|
|
|
600 |
|
1868
|
601 |
self
|
|
602 |
should:[ (matcher := self compileRegex:'a[b-]' into:Regex::RxMatcher) ~= nil ].
|
1865
|
603 |
self should:[ (matcher search:'a-') = true ].
|
|
604 |
self should:[ (matcher subexpression:1) = 'a-' ].
|
|
605 |
!
|
|
606 |
|
|
607 |
test039
|
|
608 |
|matcher|
|
|
609 |
|
1868
|
610 |
self
|
|
611 |
should:[ (matcher := self compileRegex:'a[a-b-c]' into:Regex::RxMatcher) = nil ].
|
1865
|
612 |
!
|
|
613 |
|
|
614 |
test040
|
|
615 |
|matcher|
|
|
616 |
|
1868
|
617 |
self
|
|
618 |
should:[ (matcher := self compileRegex:'[k]' into:Regex::RxMatcher) ~= nil ].
|
1865
|
619 |
self should:[ (matcher search:'ab') = false ].
|
|
620 |
!
|
|
621 |
|
|
622 |
test041
|
|
623 |
|matcher|
|
|
624 |
|
1868
|
625 |
self
|
|
626 |
should:[ (matcher := self compileRegex:'a[b-a]' into:Regex::RxMatcher) = nil ].
|
1865
|
627 |
!
|
|
628 |
|
|
629 |
test042
|
|
630 |
|matcher|
|
|
631 |
|
1868
|
632 |
self
|
|
633 |
should:[ (matcher := self compileRegex:'a[]b' into:Regex::RxMatcher) = nil ].
|
1865
|
634 |
!
|
|
635 |
|
|
636 |
test043
|
|
637 |
|matcher|
|
|
638 |
|
1868
|
639 |
self should:[ (matcher := self compileRegex:'a[' into:Regex::RxMatcher) = nil ].
|
1865
|
640 |
!
|
|
641 |
|
|
642 |
test044
|
|
643 |
|matcher|
|
|
644 |
|
1868
|
645 |
self should:[ (matcher := self compileRegex:'a]' into:Regex::RxMatcher) ~= nil ].
|
1865
|
646 |
self should:[ (matcher search:'a]') = true ].
|
|
647 |
self should:[ (matcher subexpression:1) = 'a]' ].
|
|
648 |
!
|
|
649 |
|
|
650 |
test045
|
|
651 |
|matcher|
|
|
652 |
|
1868
|
653 |
self
|
|
654 |
should:[ (matcher := self compileRegex:'a[]]b' into:Regex::RxMatcher) ~= nil ].
|
1865
|
655 |
self should:[ (matcher search:'a]b') = true ].
|
|
656 |
self should:[ (matcher subexpression:1) = 'a]b' ].
|
|
657 |
!
|
|
658 |
|
|
659 |
test046
|
|
660 |
|matcher|
|
|
661 |
|
1868
|
662 |
self
|
|
663 |
should:[ (matcher := self compileRegex:'a[^bc]d' into:Regex::RxMatcher) ~= nil ].
|
1865
|
664 |
self should:[ (matcher search:'aed') = true ].
|
|
665 |
self should:[ (matcher subexpression:1) = 'aed' ].
|
|
666 |
self should:[ (matcher search:'abd') = false ].
|
|
667 |
!
|
|
668 |
|
|
669 |
test047
|
|
670 |
|matcher|
|
|
671 |
|
1868
|
672 |
self
|
|
673 |
should:[ (matcher := self compileRegex:'a[^-b]c' into:Regex::RxMatcher) ~= nil ].
|
1865
|
674 |
self should:[ (matcher search:'adc') = true ].
|
|
675 |
self should:[ (matcher subexpression:1) = 'adc' ].
|
|
676 |
self should:[ (matcher search:'a-c') = false ].
|
|
677 |
!
|
|
678 |
|
|
679 |
test048
|
|
680 |
|matcher|
|
|
681 |
|
1868
|
682 |
self
|
|
683 |
should:[ (matcher := self compileRegex:'a[^]b]c' into:Regex::RxMatcher) ~= nil ].
|
1865
|
684 |
self should:[ (matcher search:'a]c') = false ].
|
|
685 |
self should:[ (matcher search:'adc') = true ].
|
|
686 |
self should:[ (matcher subexpression:1) = 'adc' ].
|
|
687 |
!
|
|
688 |
|
|
689 |
test049
|
|
690 |
|matcher|
|
|
691 |
|
1868
|
692 |
self
|
|
693 |
should:[ (matcher := self compileRegex:'[\de]+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
694 |
self should:[ (matcher search:'01234') = true ].
|
|
695 |
self should:[ (matcher subexpression:1) = '01234' ].
|
|
696 |
self should:[ (matcher search:'0123e456') = true ].
|
|
697 |
self should:[ (matcher subexpression:1) = '0123e456' ].
|
|
698 |
self should:[ (matcher search:'0123e45g78') = true ].
|
|
699 |
self should:[ (matcher subexpression:1) = '0123e45' ].
|
|
700 |
!
|
|
701 |
|
|
702 |
test050
|
|
703 |
|matcher|
|
|
704 |
|
1868
|
705 |
self
|
|
706 |
should:[ (matcher := self compileRegex:'[e\d]+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
707 |
self should:[ (matcher search:'01234') = true ].
|
|
708 |
self should:[ (matcher subexpression:1) = '01234' ].
|
|
709 |
self should:[ (matcher search:'0123e456') = true ].
|
|
710 |
self should:[ (matcher subexpression:1) = '0123e456' ].
|
|
711 |
self should:[ (matcher search:'0123e45g78') = true ].
|
|
712 |
self should:[ (matcher subexpression:1) = '0123e45' ].
|
|
713 |
!
|
|
714 |
|
|
715 |
test051
|
|
716 |
|matcher|
|
|
717 |
|
1868
|
718 |
self
|
|
719 |
should:[ (matcher := self compileRegex:'[\D]+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
720 |
self should:[ (matcher search:'123abc45def78') = true ].
|
|
721 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
722 |
!
|
|
723 |
|
|
724 |
test052
|
|
725 |
|matcher|
|
|
726 |
|
1868
|
727 |
self
|
|
728 |
should:[ (matcher := self compileRegex:'[[:digit:]e]+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
729 |
self should:[ (matcher search:'01234') = true ].
|
|
730 |
self should:[ (matcher subexpression:1) = '01234' ].
|
|
731 |
self should:[ (matcher search:'0123e456') = true ].
|
|
732 |
self should:[ (matcher subexpression:1) = '0123e456' ].
|
|
733 |
self should:[ (matcher search:'0123e45g78') = true ].
|
|
734 |
self should:[ (matcher subexpression:1) = '0123e45' ].
|
|
735 |
!
|
|
736 |
|
|
737 |
test053
|
|
738 |
|matcher|
|
|
739 |
|
1868
|
740 |
self
|
|
741 |
should:[ (matcher := self compileRegex:'[\s]+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
742 |
self should:[ (matcher search:'2 spaces') = true ].
|
|
743 |
self should:[ (matcher subexpression:1) = ' ' ].
|
|
744 |
!
|
|
745 |
|
|
746 |
test054
|
|
747 |
|matcher|
|
|
748 |
|
1868
|
749 |
self
|
|
750 |
should:[ (matcher := self compileRegex:'[\S]+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
751 |
self should:[ (matcher search:' word12!!@#$ ') = true ].
|
|
752 |
self should:[ (matcher subexpression:1) = 'word12!!@#$' ].
|
|
753 |
!
|
|
754 |
|
|
755 |
test055
|
|
756 |
|matcher|
|
|
757 |
|
1868
|
758 |
self
|
|
759 |
should:[ (matcher := self compileRegex:'[\w]+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
760 |
self should:[ (matcher search:' foo123bar 45') = true ].
|
|
761 |
self should:[ (matcher subexpression:1) = 'foo123bar' ].
|
|
762 |
!
|
|
763 |
|
|
764 |
test056
|
|
765 |
|matcher|
|
|
766 |
|
1868
|
767 |
self
|
|
768 |
should:[ (matcher := self compileRegex:'[\W]+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
769 |
self should:[ (matcher search:'fii234!!@#$34f') = true ].
|
|
770 |
self should:[ (matcher subexpression:1) = '!!@#$' ].
|
|
771 |
!
|
|
772 |
|
|
773 |
test057
|
|
774 |
|matcher|
|
|
775 |
|
1868
|
776 |
self
|
|
777 |
should:[ (matcher := self compileRegex:'[^[:alnum:]]+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
778 |
self should:[ (matcher search:'fii234!!@#$34f') = true ].
|
|
779 |
self should:[ (matcher subexpression:1) = '!!@#$' ].
|
|
780 |
!
|
|
781 |
|
|
782 |
test058
|
|
783 |
|matcher|
|
|
784 |
|
1868
|
785 |
self
|
|
786 |
should:[
|
|
787 |
(matcher := self compileRegex:'[%&[:alnum:]]+' into:Regex::RxMatcher) ~= nil
|
|
788 |
].
|
1865
|
789 |
self should:[ (matcher search:'foo%3') = true ].
|
|
790 |
self should:[ (matcher subexpression:1) = 'foo%3' ].
|
|
791 |
self should:[ (matcher search:'foo34&rt4$57a') = true ].
|
|
792 |
self should:[ (matcher subexpression:1) = 'foo34&rt4' ].
|
|
793 |
self should:[ (matcher search:'!!@#$') = false ].
|
|
794 |
!
|
|
795 |
|
|
796 |
test059
|
|
797 |
|matcher|
|
|
798 |
|
1868
|
799 |
self
|
|
800 |
should:[ (matcher := self compileRegex:'[[:alpha:]]+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
801 |
self should:[ (matcher search:' 123foo3 ') = true ].
|
|
802 |
self should:[ (matcher subexpression:1) = 'foo' ].
|
|
803 |
self should:[ (matcher search:'123foo') = true ].
|
|
804 |
self should:[ (matcher subexpression:1) = 'foo' ].
|
|
805 |
self should:[ (matcher search:'foo1b') = true ].
|
|
806 |
self should:[ (matcher subexpression:1) = 'foo' ].
|
|
807 |
!
|
|
808 |
|
|
809 |
test060
|
|
810 |
|matcher|
|
|
811 |
|
1868
|
812 |
self
|
|
813 |
should:[ (matcher := self compileRegex:'[[:cntrl:]]+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
814 |
self should:[ (matcher search:' a 1234asdf') = false ].
|
|
815 |
!
|
|
816 |
|
|
817 |
test061
|
|
818 |
|matcher|
|
|
819 |
|
1868
|
820 |
self
|
|
821 |
should:[ (matcher := self compileRegex:'[[:lower:]]+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
822 |
self should:[ (matcher search:'UPPERlower1234') = true ].
|
|
823 |
self should:[ (matcher subexpression:1) = 'lower' ].
|
|
824 |
self should:[ (matcher search:'lowerUPPER') = true ].
|
|
825 |
self should:[ (matcher subexpression:1) = 'lower' ].
|
|
826 |
!
|
|
827 |
|
|
828 |
test062
|
|
829 |
|matcher|
|
|
830 |
|
1868
|
831 |
self
|
|
832 |
should:[ (matcher := self compileRegex:'[[:upper:]]+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
833 |
self should:[ (matcher search:'UPPERlower1234') = true ].
|
|
834 |
self should:[ (matcher subexpression:1) = 'UPPER' ].
|
|
835 |
self should:[ (matcher search:'lowerUPPER ') = true ].
|
|
836 |
self should:[ (matcher subexpression:1) = 'UPPER' ].
|
|
837 |
!
|
|
838 |
|
|
839 |
test063
|
|
840 |
|matcher|
|
|
841 |
|
1868
|
842 |
self
|
|
843 |
should:[ (matcher := self compileRegex:'[[:space:]]+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
844 |
self should:[ (matcher search:'2 spaces') = true ].
|
|
845 |
self should:[ (matcher subexpression:1) = ' ' ].
|
|
846 |
!
|
|
847 |
|
|
848 |
test064
|
|
849 |
|matcher|
|
|
850 |
|
1868
|
851 |
self
|
|
852 |
should:[ (matcher := self compileRegex:'[^[:space:]]+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
853 |
self should:[ (matcher search:' word12!!@#$ ') = true ].
|
|
854 |
self should:[ (matcher subexpression:1) = 'word12!!@#$' ].
|
|
855 |
!
|
|
856 |
|
|
857 |
test065
|
|
858 |
|matcher|
|
|
859 |
|
1868
|
860 |
self
|
|
861 |
should:[ (matcher := self compileRegex:'[[:graph:]]+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
862 |
self should:[ (matcher search:'abc') = true ].
|
|
863 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
864 |
!
|
|
865 |
|
|
866 |
test066
|
|
867 |
|matcher|
|
|
868 |
|
1868
|
869 |
self
|
|
870 |
should:[ (matcher := self compileRegex:'[[:print:]]+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
871 |
self should:[ (matcher search:'abc') = true ].
|
|
872 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
873 |
!
|
|
874 |
|
|
875 |
test067
|
|
876 |
|matcher|
|
|
877 |
|
1868
|
878 |
self
|
|
879 |
should:[ (matcher := self compileRegex:'[^[:punct:]]+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
880 |
self should:[ (matcher search:'!!hello,world!!') = true ].
|
|
881 |
self should:[ (matcher subexpression:1) = 'hello' ].
|
|
882 |
!
|
|
883 |
|
|
884 |
test068
|
|
885 |
|matcher|
|
|
886 |
|
1868
|
887 |
self
|
|
888 |
should:[ (matcher := self compileRegex:'[[:xdigit:]]+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
889 |
self should:[ (matcher search:' x10FCD ') = true ].
|
|
890 |
self should:[ (matcher subexpression:1) = '10FCD' ].
|
|
891 |
self should:[ (matcher search:' hgfedcba0123456789ABCDEFGH ') = true ].
|
|
892 |
self should:[ (matcher subexpression:1) = 'fedcba0123456789ABCDEF' ].
|
|
893 |
!
|
|
894 |
|
|
895 |
test069
|
|
896 |
|matcher|
|
|
897 |
|
1868
|
898 |
self
|
|
899 |
should:[ (matcher := self compileRegex:'ab|cd' into:Regex::RxMatcher) ~= nil ].
|
1865
|
900 |
self should:[ (matcher search:'abc') = true ].
|
|
901 |
self should:[ (matcher subexpression:1) = 'ab' ].
|
|
902 |
self should:[ (matcher search:'abcd') = true ].
|
|
903 |
self should:[ (matcher subexpression:1) = 'ab' ].
|
|
904 |
!
|
|
905 |
|
|
906 |
test070
|
|
907 |
|matcher|
|
|
908 |
|
1868
|
909 |
self
|
|
910 |
should:[ (matcher := self compileRegex:'()ef' into:Regex::RxMatcher) ~= nil ].
|
1865
|
911 |
self should:[ (matcher search:'def') = true ].
|
|
912 |
self should:[ (matcher subexpression:1) = 'ef' ].
|
|
913 |
self should:[ (matcher subexpression:2) = '' ].
|
|
914 |
!
|
|
915 |
|
|
916 |
test071
|
|
917 |
|matcher|
|
|
918 |
|
1868
|
919 |
self should:[ (matcher := self compileRegex:'()*' into:Regex::RxMatcher) = nil ].
|
1865
|
920 |
!
|
|
921 |
|
|
922 |
test072
|
|
923 |
|matcher|
|
|
924 |
|
1868
|
925 |
self should:[ (matcher := self compileRegex:'*a' into:Regex::RxMatcher) = nil ].
|
1865
|
926 |
!
|
|
927 |
|
|
928 |
test073
|
|
929 |
|matcher|
|
|
930 |
|
1868
|
931 |
self should:[ (matcher := self compileRegex:'^*' into:Regex::RxMatcher) = nil ].
|
1865
|
932 |
!
|
|
933 |
|
|
934 |
test074
|
|
935 |
|matcher|
|
|
936 |
|
1868
|
937 |
self should:[ (matcher := self compileRegex:'$*' into:Regex::RxMatcher) = nil ].
|
1865
|
938 |
!
|
|
939 |
|
|
940 |
test075
|
|
941 |
|matcher|
|
|
942 |
|
1868
|
943 |
self
|
|
944 |
should:[ (matcher := self compileRegex:'(*)b' into:Regex::RxMatcher) = nil ].
|
1865
|
945 |
!
|
|
946 |
|
|
947 |
test076
|
|
948 |
|matcher|
|
|
949 |
|
1868
|
950 |
self should:[ (matcher := self compileRegex:'$b' into:Regex::RxMatcher) ~= nil ].
|
1865
|
951 |
self should:[ (matcher search:'b') = false ].
|
|
952 |
!
|
|
953 |
|
|
954 |
test077
|
|
955 |
|matcher|
|
|
956 |
|
1868
|
957 |
self should:[ (matcher := self compileRegex:'a\' into:Regex::RxMatcher) = nil ].
|
1865
|
958 |
!
|
|
959 |
|
|
960 |
test078
|
|
961 |
|matcher|
|
|
962 |
|
1868
|
963 |
self
|
|
964 |
should:[ (matcher := self compileRegex:'a\(b' into:Regex::RxMatcher) ~= nil ].
|
1865
|
965 |
self should:[ (matcher search:'a(b') = true ].
|
|
966 |
self should:[ (matcher subexpression:1) = 'a(b' ].
|
|
967 |
!
|
|
968 |
|
|
969 |
test079
|
|
970 |
|matcher|
|
|
971 |
|
1868
|
972 |
self
|
|
973 |
should:[ (matcher := self compileRegex:'a\(*b' into:Regex::RxMatcher) ~= nil ].
|
1865
|
974 |
self should:[ (matcher search:'ab') = true ].
|
|
975 |
self should:[ (matcher subexpression:1) = 'ab' ].
|
|
976 |
self should:[ (matcher search:'a((b') = true ].
|
|
977 |
self should:[ (matcher subexpression:1) = 'a((b' ].
|
|
978 |
!
|
|
979 |
|
|
980 |
test080
|
|
981 |
|matcher|
|
|
982 |
|
1868
|
983 |
self
|
|
984 |
should:[ (matcher := self compileRegex:'a\\b' into:Regex::RxMatcher) ~= nil ].
|
1865
|
985 |
self should:[ (matcher search:'a\b') = true ].
|
|
986 |
self should:[ (matcher subexpression:1) = 'a\b' ].
|
|
987 |
!
|
|
988 |
|
|
989 |
test081
|
|
990 |
|matcher|
|
|
991 |
|
1868
|
992 |
self
|
|
993 |
should:[ (matcher := self compileRegex:'abc)' into:Regex::RxMatcher) = nil ].
|
1865
|
994 |
!
|
|
995 |
|
|
996 |
test082
|
|
997 |
|matcher|
|
|
998 |
|
1868
|
999 |
self
|
|
1000 |
should:[ (matcher := self compileRegex:'(abc' into:Regex::RxMatcher) = nil ].
|
1865
|
1001 |
!
|
|
1002 |
|
|
1003 |
test083
|
|
1004 |
|matcher|
|
|
1005 |
|
1868
|
1006 |
self
|
|
1007 |
should:[ (matcher := self compileRegex:'((a))' into:Regex::RxMatcher) ~= nil ].
|
1865
|
1008 |
self should:[ (matcher search:'abc') = true ].
|
|
1009 |
self should:[ (matcher subexpression:1) = 'a' ].
|
|
1010 |
self should:[ (matcher subexpression:2) = 'a' ].
|
|
1011 |
self should:[ (matcher subexpression:3) = 'a' ].
|
|
1012 |
!
|
|
1013 |
|
|
1014 |
test084
|
|
1015 |
|matcher|
|
|
1016 |
|
1868
|
1017 |
self
|
|
1018 |
should:[ (matcher := self compileRegex:'(a)b(c)' into:Regex::RxMatcher) ~= nil ].
|
1865
|
1019 |
self should:[ (matcher search:'abc') = true ].
|
|
1020 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
1021 |
self should:[ (matcher subexpression:2) = 'a' ].
|
|
1022 |
self should:[ (matcher subexpression:3) = 'c' ].
|
|
1023 |
!
|
|
1024 |
|
|
1025 |
test085
|
|
1026 |
|matcher|
|
|
1027 |
|
1868
|
1028 |
self
|
|
1029 |
should:[ (matcher := self compileRegex:'a+b+c' into:Regex::RxMatcher) ~= nil ].
|
1865
|
1030 |
self should:[ (matcher search:'aabbabc') = true ].
|
|
1031 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
1032 |
!
|
|
1033 |
|
|
1034 |
test086
|
|
1035 |
|matcher|
|
|
1036 |
|
1868
|
1037 |
self should:[ (matcher := self compileRegex:'a**' into:Regex::RxMatcher) = nil ].
|
1865
|
1038 |
!
|
|
1039 |
|
|
1040 |
test087
|
|
1041 |
|matcher|
|
|
1042 |
|
1868
|
1043 |
self should:[ (matcher := self compileRegex:'a*?' into:Regex::RxMatcher) = nil ].
|
1865
|
1044 |
!
|
|
1045 |
|
|
1046 |
test088
|
|
1047 |
|matcher|
|
|
1048 |
|
1868
|
1049 |
self
|
|
1050 |
should:[ (matcher := self compileRegex:'(a*)*' into:Regex::RxMatcher) = nil ].
|
1865
|
1051 |
!
|
|
1052 |
|
|
1053 |
test089
|
|
1054 |
|matcher|
|
|
1055 |
|
1868
|
1056 |
self
|
|
1057 |
should:[ (matcher := self compileRegex:'(a*)+' into:Regex::RxMatcher) = nil ].
|
1865
|
1058 |
!
|
|
1059 |
|
|
1060 |
test090
|
|
1061 |
|matcher|
|
|
1062 |
|
1868
|
1063 |
self
|
|
1064 |
should:[ (matcher := self compileRegex:'(a|)*' into:Regex::RxMatcher) = nil ].
|
1865
|
1065 |
!
|
|
1066 |
|
|
1067 |
test091
|
|
1068 |
|matcher|
|
|
1069 |
|
1868
|
1070 |
self
|
|
1071 |
should:[ (matcher := self compileRegex:'(a*|b)*' into:Regex::RxMatcher) = nil ].
|
1865
|
1072 |
!
|
|
1073 |
|
|
1074 |
test092
|
|
1075 |
|matcher|
|
|
1076 |
|
1868
|
1077 |
self
|
|
1078 |
should:[ (matcher := self compileRegex:'(a+|b)*' into:Regex::RxMatcher) ~= nil ].
|
1865
|
1079 |
self should:[ (matcher search:'ab') = true ].
|
|
1080 |
self should:[ (matcher subexpression:1) = 'ab' ].
|
|
1081 |
self should:[ (matcher subexpression:2) = 'b' ].
|
|
1082 |
!
|
|
1083 |
|
|
1084 |
test093
|
|
1085 |
|matcher|
|
|
1086 |
|
1868
|
1087 |
self
|
|
1088 |
should:[ (matcher := self compileRegex:'(a+|b)+' into:Regex::RxMatcher) ~= nil ].
|
1865
|
1089 |
self should:[ (matcher search:'ab') = true ].
|
|
1090 |
self should:[ (matcher subexpression:1) = 'ab' ].
|
|
1091 |
self should:[ (matcher subexpression:2) = 'b' ].
|
|
1092 |
!
|
|
1093 |
|
|
1094 |
test094
|
|
1095 |
|matcher|
|
|
1096 |
|
1868
|
1097 |
self
|
|
1098 |
should:[ (matcher := self compileRegex:'(a+|b)?' into:Regex::RxMatcher) ~= nil ].
|
1865
|
1099 |
self should:[ (matcher search:'ab') = true ].
|
|
1100 |
self should:[ (matcher subexpression:1) = 'a' ].
|
|
1101 |
self should:[ (matcher subexpression:2) = 'a' ].
|
|
1102 |
!
|
|
1103 |
|
|
1104 |
test095
|
|
1105 |
|matcher|
|
|
1106 |
|
1868
|
1107 |
self
|
|
1108 |
should:[ (matcher := self compileRegex:'[^ab]*' into:Regex::RxMatcher) ~= nil ].
|
1865
|
1109 |
self should:[ (matcher search:'cde') = true ].
|
|
1110 |
self should:[ (matcher subexpression:1) = 'cde' ].
|
|
1111 |
!
|
|
1112 |
|
|
1113 |
test096
|
|
1114 |
|matcher|
|
|
1115 |
|
1868
|
1116 |
self
|
|
1117 |
should:[ (matcher := self compileRegex:'(^)*' into:Regex::RxMatcher) = nil ].
|
1865
|
1118 |
!
|
|
1119 |
|
|
1120 |
test097
|
|
1121 |
|matcher|
|
|
1122 |
|
1868
|
1123 |
self
|
|
1124 |
should:[ (matcher := self compileRegex:'(ab|)*' into:Regex::RxMatcher) = nil ].
|
1865
|
1125 |
!
|
|
1126 |
|
|
1127 |
test098
|
|
1128 |
|matcher|
|
|
1129 |
|
1868
|
1130 |
self should:[ (matcher := self compileRegex:')(' into:Regex::RxMatcher) = nil ].
|
1865
|
1131 |
!
|
|
1132 |
|
|
1133 |
test099
|
|
1134 |
|matcher|
|
|
1135 |
|
1868
|
1136 |
self should:[ (matcher := self compileRegex:'' into:Regex::RxMatcher) ~= nil ].
|
1865
|
1137 |
self should:[ (matcher search:'abc') = true ].
|
|
1138 |
self should:[ (matcher subexpression:1) = '' ].
|
|
1139 |
!
|
|
1140 |
|
|
1141 |
test100
|
|
1142 |
| matcher |
|
|
1143 |
|
1868
|
1144 |
self should: [ (matcher := self compileRegex: 'abc' into:Regex::RxMatcher) ~= nil ].
|
1865
|
1145 |
self should: [ (matcher search: '') = false ].
|
|
1146 |
|
|
1147 |
"
|
|
1148 |
self new test100
|
|
1149 |
"
|
|
1150 |
!
|
|
1151 |
|
|
1152 |
test101
|
|
1153 |
| matcher |
|
|
1154 |
|
1868
|
1155 |
self should: [ (matcher := self compileRegex: 'a*' into:Regex::RxMatcher) ~= nil ].
|
1865
|
1156 |
self should: [ (matcher search: '') = true ].
|
|
1157 |
|
|
1158 |
"
|
|
1159 |
self new test101
|
|
1160 |
"
|
|
1161 |
!
|
|
1162 |
|
|
1163 |
test102
|
|
1164 |
| matcher |
|
|
1165 |
|
1868
|
1166 |
self should: [ (matcher := self compileRegex: 'abcd' into:Regex::RxMatcher) ~= nil ].
|
1865
|
1167 |
self should: [ (matcher search: 'abcd') = true ].
|
|
1168 |
self should: [ (matcher subexpression: 1) = 'abcd' ].
|
|
1169 |
|
|
1170 |
"
|
|
1171 |
self new test102
|
|
1172 |
"
|
|
1173 |
!
|
|
1174 |
|
|
1175 |
test103
|
|
1176 |
| matcher |
|
|
1177 |
|
1868
|
1178 |
self should: [ (matcher := self compileRegex: 'a(bc)d' into:Regex::RxMatcher) ~= nil ].
|
1865
|
1179 |
self should: [ (matcher search: 'abcd') = true ].
|
|
1180 |
self should: [ (matcher subexpression: 1) = 'abcd' ].
|
|
1181 |
self should: [ (matcher subexpression: 2) = 'bc' ].
|
|
1182 |
|
|
1183 |
"
|
|
1184 |
self new test103
|
|
1185 |
"
|
|
1186 |
!
|
|
1187 |
|
|
1188 |
test104
|
1868
|
1189 |
| matcher |
|
|
1190 |
|
|
1191 |
|
|
1192 |
self should: [ (matcher := self compileRegex: '([abc])*d' into:Regex::RxMatcher) ~= nil ].
|
|
1193 |
self should: [ (matcher search: 'abbbcd') = true ].
|
|
1194 |
self should: [ (matcher subexpression: 1) = 'abbbcd' ].
|
|
1195 |
self should: [ (matcher subexpression: 2) = 'c' ].
|
1865
|
1196 |
!
|
|
1197 |
|
|
1198 |
test105
|
1868
|
1199 |
| matcher |
|
|
1200 |
|
|
1201 |
|
|
1202 |
self should: [ (matcher := self compileRegex: '([abc])*bcd' into:Regex::RxMatcher) ~= nil ].
|
|
1203 |
self should: [ (matcher search: 'abcd') = true ].
|
|
1204 |
self should: [ (matcher subexpression: 1) = 'abcd' ].
|
|
1205 |
self should: [ (matcher subexpression: 2) = 'a' ].
|
1865
|
1206 |
!
|
|
1207 |
|
|
1208 |
test106
|
1868
|
1209 |
| matcher |
|
|
1210 |
|
|
1211 |
|
|
1212 |
self should: [ (matcher := self compileRegex: 'a|b|c|d|e' into:Regex::RxMatcher) ~= nil ].
|
|
1213 |
self should: [ (matcher search: 'e') = true ].
|
|
1214 |
self should: [ (matcher subexpression: 1) = 'e' ].
|
1865
|
1215 |
!
|
|
1216 |
|
|
1217 |
test107
|
1868
|
1218 |
| matcher |
|
|
1219 |
|
|
1220 |
|
|
1221 |
self should: [ (matcher := self compileRegex: '(a|b|c|d|e)f' into:Regex::RxMatcher) ~= nil ].
|
|
1222 |
self should: [ (matcher search: 'ef') = true ].
|
|
1223 |
self should: [ (matcher subexpression: 1) = 'ef' ].
|
|
1224 |
self should: [ (matcher subexpression: 2) = 'e' ].
|
1865
|
1225 |
!
|
|
1226 |
|
|
1227 |
test108
|
1868
|
1228 |
| matcher |
|
|
1229 |
|
|
1230 |
|
|
1231 |
self should: [ (matcher := self compileRegex: 'abcd*efg' into:Regex::RxMatcher) ~= nil ].
|
|
1232 |
self should: [ (matcher search: 'abcdefg') = true ].
|
|
1233 |
self should: [ (matcher subexpression: 1) = 'abcdefg' ].
|
1865
|
1234 |
!
|
|
1235 |
|
|
1236 |
test109
|
1868
|
1237 |
| matcher |
|
|
1238 |
|
|
1239 |
|
|
1240 |
self should: [ (matcher := self compileRegex: 'ab*' into:Regex::RxMatcher) ~= nil ].
|
|
1241 |
self should: [ (matcher search: 'xabyabbbz') = true ].
|
|
1242 |
self should: [ (matcher subexpression: 1) = 'ab' ].
|
|
1243 |
self should: [ (matcher search: 'xayabbbz') = true ].
|
|
1244 |
self should: [ (matcher subexpression: 1) = 'a' ].
|
1865
|
1245 |
!
|
|
1246 |
|
|
1247 |
test110
|
1868
|
1248 |
| matcher |
|
|
1249 |
|
|
1250 |
|
|
1251 |
self should: [ (matcher := self compileRegex: '(ab|cd)e' into:Regex::RxMatcher) ~= nil ].
|
|
1252 |
self should: [ (matcher search: 'abcde') = true ].
|
|
1253 |
self should: [ (matcher subexpression: 1) = 'cde' ].
|
|
1254 |
self should: [ (matcher subexpression: 2) = 'cd' ].
|
1865
|
1255 |
!
|
|
1256 |
|
|
1257 |
test111
|
1868
|
1258 |
| matcher |
|
|
1259 |
|
|
1260 |
|
|
1261 |
self should: [ (matcher := self compileRegex: '[abhgefdc]ij' into:Regex::RxMatcher) ~= nil ].
|
|
1262 |
self should: [ (matcher search: 'hij') = true ].
|
|
1263 |
self should: [ (matcher subexpression: 1) = 'hij' ].
|
1865
|
1264 |
!
|
|
1265 |
|
|
1266 |
test112
|
1868
|
1267 |
| matcher |
|
|
1268 |
|
|
1269 |
|
|
1270 |
self should: [ (matcher := self compileRegex: '^(ab|cd)e' into:Regex::RxMatcher) ~= nil ].
|
|
1271 |
self should: [ (matcher search: 'abcde') = false ].
|
1865
|
1272 |
!
|
|
1273 |
|
|
1274 |
test113
|
1868
|
1275 |
| matcher |
|
|
1276 |
|
|
1277 |
|
|
1278 |
self should: [ (matcher := self compileRegex: '(abc|)def' into:Regex::RxMatcher) ~= nil ].
|
|
1279 |
self should: [ (matcher search: 'abcdef') = true ].
|
1865
|
1280 |
!
|
|
1281 |
|
|
1282 |
test114
|
1868
|
1283 |
| matcher |
|
|
1284 |
|
|
1285 |
|
|
1286 |
self should: [ (matcher := self compileRegex: '(a|b)c*d' into:Regex::RxMatcher) ~= nil ].
|
|
1287 |
self should: [ (matcher search: 'abcd') = true ].
|
|
1288 |
self should: [ (matcher subexpression: 1) = 'bcd' ].
|
|
1289 |
self should: [ (matcher subexpression: 2) = 'b' ].
|
1865
|
1290 |
!
|
|
1291 |
|
|
1292 |
test115
|
1868
|
1293 |
| matcher |
|
|
1294 |
|
|
1295 |
|
|
1296 |
self should: [ (matcher := self compileRegex: '(ab|ab*)bc' into:Regex::RxMatcher) ~= nil ].
|
|
1297 |
self should: [ (matcher search: 'abc') = true ].
|
|
1298 |
self should: [ (matcher subexpression: 1) = 'abc' ].
|
|
1299 |
self should: [ (matcher subexpression: 2) = 'a' ].
|
1865
|
1300 |
!
|
|
1301 |
|
|
1302 |
test116
|
1868
|
1303 |
| matcher |
|
|
1304 |
|
|
1305 |
|
|
1306 |
self should: [ (matcher := self compileRegex: 'a([bc]*)c*' into:Regex::RxMatcher) ~= nil ].
|
|
1307 |
self should: [ (matcher search: 'abc') = true ].
|
|
1308 |
self should: [ (matcher subexpression: 1) = 'abc' ].
|
|
1309 |
self should: [ (matcher subexpression: 2) = 'bc' ].
|
1865
|
1310 |
!
|
|
1311 |
|
|
1312 |
test117
|
1868
|
1313 |
| matcher |
|
|
1314 |
|
|
1315 |
|
|
1316 |
self should: [ (matcher := self compileRegex: 'a([bc]*)(c*d)' into:Regex::RxMatcher) ~= nil ].
|
|
1317 |
self should: [ (matcher search: 'abcd') = true ].
|
|
1318 |
self should: [ (matcher subexpression: 1) = 'abcd' ].
|
|
1319 |
self should: [ (matcher subexpression: 2) = 'bc' ].
|
|
1320 |
self should: [ (matcher subexpression: 3) = 'd' ].
|
1865
|
1321 |
!
|
|
1322 |
|
|
1323 |
test118
|
1868
|
1324 |
| matcher |
|
|
1325 |
|
|
1326 |
|
|
1327 |
self should: [ (matcher := self compileRegex: 'a([bc]+)(c*d)' into:Regex::RxMatcher) ~= nil ].
|
|
1328 |
self should: [ (matcher search: 'abcd') = true ].
|
|
1329 |
self should: [ (matcher subexpression: 1) = 'abcd' ].
|
|
1330 |
self should: [ (matcher subexpression: 2) = 'bc' ].
|
|
1331 |
self should: [ (matcher subexpression: 3) = 'd' ].
|
1865
|
1332 |
!
|
|
1333 |
|
|
1334 |
test119
|
1868
|
1335 |
| matcher |
|
|
1336 |
|
|
1337 |
|
|
1338 |
self should: [ (matcher := self compileRegex: 'a([bc]*)(c+d)' into:Regex::RxMatcher) ~= nil ].
|
|
1339 |
self should: [ (matcher search: 'abcd') = true ].
|
|
1340 |
self should: [ (matcher subexpression: 1) = 'abcd' ].
|
|
1341 |
self should: [ (matcher subexpression: 2) = 'b' ].
|
|
1342 |
self should: [ (matcher subexpression: 3) = 'cd' ].
|
1865
|
1343 |
!
|
|
1344 |
|
|
1345 |
test120
|
1868
|
1346 |
| matcher |
|
|
1347 |
|
|
1348 |
|
|
1349 |
self should: [ (matcher := self compileRegex: 'a[bcd]*dcdcde' into:Regex::RxMatcher) ~= nil ].
|
|
1350 |
self should: [ (matcher search: 'adcdcde') = true ].
|
|
1351 |
self should: [ (matcher subexpression: 1) = 'adcdcde' ].
|
1865
|
1352 |
!
|
|
1353 |
|
|
1354 |
test121
|
1868
|
1355 |
| matcher |
|
|
1356 |
|
|
1357 |
|
|
1358 |
self should: [ (matcher := self compileRegex: 'a[bcd]+dcdcde' into:Regex::RxMatcher) ~= nil ].
|
|
1359 |
self should: [ (matcher search: 'adcdcde') = false ].
|
1865
|
1360 |
!
|
|
1361 |
|
|
1362 |
test122
|
1868
|
1363 |
| matcher |
|
|
1364 |
|
|
1365 |
|
|
1366 |
self should: [ (matcher := self compileRegex: '(ab|a)b*c' into:Regex::RxMatcher) ~= nil ].
|
|
1367 |
self should: [ (matcher search: 'abc') = true ].
|
|
1368 |
self should: [ (matcher subexpression: 1) = 'abc' ].
|
1865
|
1369 |
!
|
|
1370 |
|
|
1371 |
test123
|
1868
|
1372 |
| matcher |
|
|
1373 |
|
|
1374 |
|
|
1375 |
self should: [ (matcher := self compileRegex: '((a)(b)c)(d)' into:Regex::RxMatcher) ~= nil ].
|
|
1376 |
self should: [ (matcher search: 'abcd') = true ].
|
|
1377 |
self should: [ (matcher subexpression: 1) = 'abcd' ].
|
|
1378 |
self should: [ (matcher subexpression: 3) = 'a' ].
|
|
1379 |
self should: [ (matcher subexpression: 4) = 'b' ].
|
|
1380 |
self should: [ (matcher subexpression: 5) = 'd' ].
|
1865
|
1381 |
!
|
|
1382 |
|
|
1383 |
test124
|
1868
|
1384 |
| matcher |
|
|
1385 |
|
|
1386 |
|
|
1387 |
self should: [ (matcher := self compileRegex: '[ -~]*' into:Regex::RxMatcher) ~= nil ].
|
|
1388 |
self should: [ (matcher search: 'abc') = true ].
|
|
1389 |
self should: [ (matcher subexpression: 1) = 'abc' ].
|
1865
|
1390 |
!
|
|
1391 |
|
|
1392 |
test125
|
1868
|
1393 |
| matcher |
|
|
1394 |
|
|
1395 |
|
|
1396 |
self should: [ (matcher := self compileRegex: '[ -~ -~]*' into:Regex::RxMatcher) ~= nil ].
|
|
1397 |
self should: [ (matcher search: 'abc') = true ].
|
|
1398 |
self should: [ (matcher subexpression: 1) = 'abc' ].
|
1865
|
1399 |
!
|
|
1400 |
|
|
1401 |
test126
|
1868
|
1402 |
| matcher |
|
|
1403 |
|
|
1404 |
|
|
1405 |
self should: [ (matcher := self compileRegex: '[ -~ -~ -~]*' into:Regex::RxMatcher) ~= nil ].
|
|
1406 |
self should: [ (matcher search: 'abc') = true ].
|
|
1407 |
self should: [ (matcher subexpression: 1) = 'abc' ].
|
1865
|
1408 |
!
|
|
1409 |
|
|
1410 |
test127
|
1868
|
1411 |
| matcher |
|
|
1412 |
|
|
1413 |
|
|
1414 |
self should: [ (matcher := self compileRegex: '[ -~ -~ -~ -~]*' into:Regex::RxMatcher) ~= nil ].
|
|
1415 |
self should: [ (matcher search: 'abc') = true ].
|
|
1416 |
self should: [ (matcher subexpression: 1) = 'abc' ].
|
1865
|
1417 |
!
|
|
1418 |
|
|
1419 |
test128
|
1868
|
1420 |
| matcher |
|
|
1421 |
|
|
1422 |
|
|
1423 |
self should: [ (matcher := self compileRegex: '[ -~ -~ -~ -~ -~]*' into:Regex::RxMatcher) ~= nil ].
|
|
1424 |
self should: [ (matcher search: 'abc') = true ].
|
|
1425 |
self should: [ (matcher subexpression: 1) = 'abc' ].
|
1865
|
1426 |
!
|
|
1427 |
|
|
1428 |
test129
|
1868
|
1429 |
| matcher |
|
|
1430 |
|
|
1431 |
|
|
1432 |
self should: [ (matcher := self compileRegex: '[ -~ -~ -~ -~ -~ -~]*' into:Regex::RxMatcher) ~= nil ].
|
|
1433 |
self should: [ (matcher search: 'abc') = true ].
|
|
1434 |
self should: [ (matcher subexpression: 1) = 'abc' ].
|
1865
|
1435 |
!
|
|
1436 |
|
|
1437 |
test130
|
1868
|
1438 |
| matcher |
|
|
1439 |
|
|
1440 |
|
|
1441 |
self should: [ (matcher := self compileRegex: '[ -~ -~ -~ -~ -~ -~ -~]*' into:Regex::RxMatcher) ~= nil ].
|
|
1442 |
self should: [ (matcher search: 'abc') = true ].
|
|
1443 |
self should: [ (matcher subexpression: 1) = 'abc' ].
|
1865
|
1444 |
!
|
|
1445 |
|
|
1446 |
test131
|
1868
|
1447 |
| matcher |
|
|
1448 |
|
|
1449 |
|
|
1450 |
self should: [ (matcher := self compileRegex: '[a-zA-Z_][a-zA-Z0-9_]*' into:Regex::RxMatcher) ~= nil ].
|
|
1451 |
self should: [ (matcher search: 'alpha') = true ].
|
|
1452 |
self should: [ (matcher subexpression: 1) = 'alpha' ].
|
1865
|
1453 |
!
|
|
1454 |
|
|
1455 |
test132
|
1868
|
1456 |
| matcher |
|
|
1457 |
|
|
1458 |
self should: [ (matcher := self compileRegex: '^a(bc+|b[eh])g|.h$' into:Regex::RxMatcher) ~= nil ].
|
|
1459 |
self should: [ (matcher search: 'abh') = true ].
|
|
1460 |
self should: [ (matcher subexpression: 1) = 'bh' ].
|
|
1461 |
self should: [ (matcher subexpression: 2) = '' ].
|
1865
|
1462 |
!
|
|
1463 |
|
|
1464 |
test133
|
1868
|
1465 |
| matcher |
|
|
1466 |
|
|
1467 |
self should: [ (matcher := self compileRegex: '(bc+d$|ef*g.|h?i(j|k))' into:Regex::RxMatcher) ~= nil ].
|
|
1468 |
self should: [ (matcher search: 'effgz') = true ].
|
|
1469 |
self should: [ (matcher subexpression: 1) = 'effgz' ].
|
|
1470 |
self should: [ (matcher subexpression: 2) = 'effgz' ].
|
|
1471 |
self should: [ (matcher subexpression: 3) = '' ].
|
|
1472 |
self should: [ (matcher search: 'ij') = true ].
|
|
1473 |
self should: [ (matcher subexpression: 1) = 'ij' ].
|
|
1474 |
self should: [ (matcher subexpression: 2) = 'ij' ].
|
|
1475 |
self should: [ (matcher subexpression: 3) = 'j' ].
|
|
1476 |
self should: [ (matcher search: 'effg') = false ].
|
|
1477 |
self should: [ (matcher search: 'bcdd') = false ].
|
|
1478 |
self should: [ (matcher search: 'reffgz') = true ].
|
|
1479 |
self should: [ (matcher subexpression: 1) = 'effgz' ].
|
|
1480 |
self should: [ (matcher subexpression: 2) = 'effgz' ].
|
|
1481 |
self should: [ (matcher subexpression: 3) = '' ].
|
1865
|
1482 |
!
|
|
1483 |
|
|
1484 |
test134
|
1868
|
1485 |
| matcher |
|
|
1486 |
|
|
1487 |
self should: [ (matcher := self compileRegex: '(((((((((a)))))))))' into:Regex::RxMatcher) ~= nil ].
|
|
1488 |
self should: [ (matcher search: 'a') = true ].
|
|
1489 |
self should: [ (matcher subexpression: 1) = 'a' ].
|
1865
|
1490 |
!
|
|
1491 |
|
|
1492 |
test135
|
1868
|
1493 |
| matcher |
|
|
1494 |
|
|
1495 |
self should: [ (matcher := self compileRegex: 'multiple words of text' into:Regex::RxMatcher) ~= nil ].
|
|
1496 |
self should: [ (matcher search: 'uh-uh') = false ].
|
|
1497 |
self should: [ (matcher search: 'multiple words of text, yeah') = true ].
|
|
1498 |
self should: [ (matcher subexpression: 1) = 'multiple words of text' ].
|
1865
|
1499 |
!
|
|
1500 |
|
|
1501 |
test136
|
1868
|
1502 |
| matcher |
|
|
1503 |
|
|
1504 |
self should: [ (matcher := self compileRegex: '(.*)c(.*)' into:Regex::RxMatcher) ~= nil ].
|
|
1505 |
self should: [ (matcher search: 'abcde') = true ].
|
|
1506 |
self should: [ (matcher subexpression: 1) = 'abcde' ].
|
|
1507 |
self should: [ (matcher subexpression: 2) = 'ab' ].
|
|
1508 |
self should: [ (matcher subexpression: 3) = 'de' ].
|
1865
|
1509 |
!
|
|
1510 |
|
|
1511 |
test137
|
1868
|
1512 |
| matcher |
|
|
1513 |
|
|
1514 |
self should: [ (matcher := self compileRegex: '\((.*), (.*)\)' into:Regex::RxMatcher) ~= nil ].
|
|
1515 |
self should: [ (matcher search: '(a, b)') = true ].
|
|
1516 |
self should: [ (matcher subexpression: 2) = 'a' ].
|
|
1517 |
self should: [ (matcher subexpression: 3) = 'b' ].
|
1865
|
1518 |
!
|
|
1519 |
|
|
1520 |
test199
|
|
1521 |
|matcher|
|
|
1522 |
|
1868
|
1523 |
self
|
|
1524 |
should:[ (matcher := self compileRegex:'a{}b' into:Regex::RxMatcher) = nil ].
|
1865
|
1525 |
!
|
|
1526 |
|
|
1527 |
test200
|
1868
|
1528 |
| matcher |
|
|
1529 |
|
|
1530 |
self should: [ (matcher := self compileRegex: '\d{2,5}' into:Regex::RxMatcher) ~= nil ].
|
|
1531 |
self should: [ (matcher search: '1') = false ].
|
|
1532 |
self should: [ (matcher search: '12') = true ].
|
|
1533 |
self should: [ (matcher search: '123') = true ].
|
|
1534 |
self should: [ (matcher search: '1234') = true ].
|
|
1535 |
self should: [ (matcher search: '12356') = true ].
|
|
1536 |
self should: [ (matcher search: '123456') = true ].
|
|
1537 |
self should: [ (matcher subexpression: 1) = '12345' ].
|
1865
|
1538 |
!
|
|
1539 |
|
|
1540 |
test201
|
1868
|
1541 |
| matcher |
|
|
1542 |
|
|
1543 |
self should: [ (matcher := self compileRegex: '[0-9]{2,5}' into:Regex::RxMatcher) ~= nil ].
|
|
1544 |
self should: [ (matcher search: '1') = false ].
|
|
1545 |
self should: [ (matcher search: '12') = true ].
|
|
1546 |
self should: [ (matcher search: '123') = true ].
|
|
1547 |
self should: [ (matcher search: '1234') = true ].
|
|
1548 |
self should: [ (matcher search: '12356') = true ].
|
|
1549 |
self should: [ (matcher search: '123456') = true ].
|
|
1550 |
self should: [ (matcher subexpression: 1) = '12345' ].
|
1865
|
1551 |
!
|
|
1552 |
|
|
1553 |
test202
|
1868
|
1554 |
| matcher |
|
|
1555 |
|
|
1556 |
self assert: ( (matcher := self compileRegex: '([0-9]{2,4}\s){2}' into:Regex::RxMatcher) ~= nil ).
|
|
1557 |
self deny: ( matcher matches: '1 1 ').
|
|
1558 |
self assert: ( matcher matches: '12 12 ' ).
|
|
1559 |
self assert: ( matcher matches: '12 123 ' ).
|
|
1560 |
self assert: ( matcher matches: '123 12 ' ).
|
|
1561 |
self assert: ( matcher matches: '123 123 ' ).
|
|
1562 |
self assert: ( matcher matches: '1234 12 ' ).
|
|
1563 |
self deny: ( matcher matches: '123456 12 ' ).
|
|
1564 |
self deny: ( matcher matches: '12356 12 ' ).
|
1865
|
1565 |
!
|
|
1566 |
|
|
1567 |
testProtocol
|
1869
|
1568 |
| matcher |
|
|
1569 |
|
|
1570 |
self should: [ (matcher := Regex::RxMatcher forString: '\w+') ~= nil ].
|
|
1571 |
self should: [ (matcher matchesIn: 'now is the time') asArray = #('now' 'is' 'the' 'time') ].
|
|
1572 |
self should: [ (matcher copy: 'now is the time ' translatingMatchesUsing: [:s | s reverse]) = 'won si eht emit ' ].
|
|
1573 |
|
|
1574 |
"See that the match context is preserved while copying stuff between matches:"
|
|
1575 |
|
|
1576 |
self should: [ ((Regex::RxMatcher forString: '\<\d\D+')
|
|
1577 |
copy: '9aaa1bbb 8ccc'
|
|
1578 |
replacingMatchesWith: 'foo') = 'foo1bbb foo' ].
|
1865
|
1579 |
!
|
|
1580 |
|
|
1581 |
testTermination001
|
|
1582 |
self assert:(('' allRegexMatches:'\S*') asArray = #('')).
|
|
1583 |
self assert:(('t' allRegexMatches:'\S*') asArray = #('t')).
|
|
1584 |
self assert:(('the' allRegexMatches:'\S*') asArray = #('the')).
|
|
1585 |
self assert:(('the time' allRegexMatches:'\S*') asArray = #('the' 'time')).
|
|
1586 |
|
|
1587 |
self assert:(('the time' allRegexMatches:'\S*') size >= 2).
|
|
1588 |
|
|
1589 |
"Created: / 04-05-2017 / 19:45:04 / mawalch"
|
|
1590 |
"Modified (format): / 07-06-2017 / 10:06:59 / mawalch"
|
|
1591 |
! !
|
|
1592 |
|
|
1593 |
!RxTests methodsFor:'test suite - old'!
|
|
1594 |
|
|
1595 |
compileRegex: regexSource into: matcherClass
|
1868
|
1596 |
"Compile the regex and answer the matcher, or answer nil if compilation fails."
|
|
1597 |
|
|
1598 |
| syntaxTree |
|
|
1599 |
syntaxTree := Regex::RxParser safelyParse: regexSource.
|
|
1600 |
syntaxTree == nil ifTrue: [^nil].
|
|
1601 |
^matcherClass for: syntaxTree
|
1865
|
1602 |
!
|
|
1603 |
|
|
1604 |
runProtocolTestsForMatcher: matcherClass
|
|
1605 |
|
|
1606 |
| matcher |
|
|
1607 |
Transcript show: 'Testing matcher protocol...'.
|
|
1608 |
matcher := matcherClass forString: '\w+'.
|
|
1609 |
(matcher matchesIn: 'now is the time') asArray = #('now' 'is' 'the' 'time')
|
|
1610 |
ifFalse: [self error: 'matchesIn: test failed'].
|
|
1611 |
(matcher copy: 'now is the time ' translatingMatchesUsing: [:s | s reverse])
|
|
1612 |
= 'won si eht emit '
|
|
1613 |
ifFalse: [self error: 'copy:translatingMatchesWith: test failed'].
|
|
1614 |
"See that the match context is preserved while copying stuff between matches:"
|
1868
|
1615 |
((matcherClass forString: '\<\d\D+')
|
1865
|
1616 |
copy: '9aaa1bbb 8ccc'
|
|
1617 |
replacingMatchesWith: 'foo') = 'foo1bbb foo'
|
|
1618 |
ifFalse: [self error: 'test failed'].
|
|
1619 |
Transcript show: 'OK'; cr
|
|
1620 |
!
|
|
1621 |
|
|
1622 |
runRegexTestsForMatcher: matcherClass
|
1868
|
1623 |
"Run the whole suite of tests for the given matcher class. May blow up
|
|
1624 |
if anything goes wrong with the matcher or parser. Since this is a
|
|
1625 |
developer's tool, who cares?"
|
|
1626 |
"self runRegexTestsForMatcher: Regex::RxMatcher"
|
|
1627 |
|
|
1628 |
| failures |
|
|
1629 |
failures := 0.
|
|
1630 |
Transcript cr.
|
|
1631 |
self xtestSuite do: [:clause |
|
|
1632 |
| rxSource matcher isOK |
|
|
1633 |
rxSource := clause first.
|
|
1634 |
Transcript show: 'Testing regex: '; show: rxSource printString; cr.
|
|
1635 |
matcher := self compileRegex: rxSource into: matcherClass.
|
|
1636 |
matcher == nil
|
|
1637 |
ifTrue:
|
|
1638 |
[(clause at: 2) isNil
|
|
1639 |
ifTrue:
|
|
1640 |
[Transcript tab; show: 'Compilation error as expected (ok)'; cr]
|
|
1641 |
ifFalse:
|
|
1642 |
[Transcript tab;
|
|
1643 |
show: 'Compilation error, UNEXPECTED -- FAILED'; cr.
|
|
1644 |
failures := failures + 1]]
|
|
1645 |
ifFalse:
|
|
1646 |
[(clause at: 2) == nil
|
|
1647 |
ifTrue:
|
|
1648 |
[Transcript tab;
|
|
1649 |
show: 'Compilation succeeded, should have failed -- FAILED!!';
|
|
1650 |
cr.
|
|
1651 |
failures := failures + 1]
|
|
1652 |
ifFalse:
|
|
1653 |
[2 to: clause size by: 3 do:
|
|
1654 |
[:i |
|
|
1655 |
isOK := self
|
|
1656 |
xtest: matcher
|
|
1657 |
with: (clause at: i)
|
|
1658 |
expect: (clause at: i + 1)
|
|
1659 |
withSubexpressions: (clause at: i + 2).
|
|
1660 |
isOK ifFalse: [failures := failures + 1].
|
|
1661 |
Transcript
|
|
1662 |
show: (isOK ifTrue: [' (ok).'] ifFalse: [' -- FAILED!!']);
|
|
1663 |
cr]]]].
|
|
1664 |
failures = 0
|
|
1665 |
ifTrue: [Transcript show: 'PASSED ALL TESTS.'; cr]
|
|
1666 |
ifFalse: [Transcript show: failures printString, ' TESTS FAILED!!'; cr]
|
1865
|
1667 |
!
|
|
1668 |
|
|
1669 |
runTestsForMatcher: matcherClass
|
|
1670 |
"Run the whole suite of tests for the given matcher class. May blow up
|
1868
|
1671 |
if something goes wrong with the matcher or the parser. Since this is a
|
1865
|
1672 |
developer's tool, who cares?"
|
1868
|
1673 |
"self runTestsForMatcher: Regex::RxMatcher"
|
1865
|
1674 |
|
|
1675 |
self
|
|
1676 |
runRegexTestsForMatcher: matcherClass;
|
|
1677 |
runProtocolTestsForMatcher: matcherClass
|
|
1678 |
!
|
|
1679 |
|
|
1680 |
testCadrMatching
|
|
1681 |
"self debug: #testCadrMatching"
|
|
1682 |
|
|
1683 |
"A bit more complex example is the following expression, matching the
|
|
1684 |
name of any of the Lisp-style `car', `cdr', `caar', `cadr',
|
|
1685 |
... functions:"
|
|
1686 |
|
|
1687 |
self assert: ( 'car' matchesRegex: 'c(a|d)+r').
|
|
1688 |
self assert: ( 'cdr' matchesRegex: 'c(a|d)+r').
|
|
1689 |
self assert: ( 'caar' matchesRegex: 'c(a|d)+r').
|
|
1690 |
self assert: ( 'cadr' matchesRegex: 'c(a|d)+r').
|
|
1691 |
self assert: ( 'caddar' matchesRegex: 'c(a|d)+r').
|
|
1692 |
!
|
|
1693 |
|
|
1694 |
testCharacterSet
|
|
1695 |
"self debug: #testCharacterSet"
|
1868
|
1696 |
|
1865
|
1697 |
"So far, we have used only characters as the 'smallest' components of
|
|
1698 |
regular expressions. There are other, more `interesting', components.
|
|
1699 |
A character set is a string of characters enclosed in square
|
|
1700 |
brackets. It matches any single character if it appears between the
|
|
1701 |
brackets. For example, `[01]' matches either `0' or `1':"
|
|
1702 |
|
1868
|
1703 |
self assert: ('0' matchesRegex: '[01]').
|
|
1704 |
self deny: ('3' matchesRegex: '[01]').
|
1865
|
1705 |
self deny: ('11' matchesRegex: '[01]'). "-- false: a set matches only one character"
|
|
1706 |
self deny: ('01' matchesRegex: '[01]').
|
|
1707 |
!
|
|
1708 |
|
|
1709 |
testCharacterSetBinaryNumber
|
|
1710 |
"self debug: #testCharacterSetBinaryNumber"
|
1868
|
1711 |
|
1865
|
1712 |
"Using plus operator, we can build the following binary number
|
|
1713 |
recognizer:"
|
1868
|
1714 |
self assert: ('10010100' matchesRegex: '[01]+').
|
|
1715 |
self deny: ('10001210' matchesRegex: '[01]+')
|
1865
|
1716 |
!
|
|
1717 |
|
|
1718 |
testCharacterSetInversion
|
|
1719 |
"self debug: #testCharacterSetInversion"
|
1868
|
1720 |
|
1865
|
1721 |
"If the first character after the opening bracket is `^', the set is
|
|
1722 |
inverted: it matches any single character *not* appearing between the
|
|
1723 |
brackets:"
|
1868
|
1724 |
|
|
1725 |
self deny: ('0' matchesRegex: '[^01]').
|
1865
|
1726 |
"0 appears in 01 so there is no match"
|
1868
|
1727 |
|
1865
|
1728 |
self assert: ('3' matchesRegex: '[^01]').
|
|
1729 |
"3 is not in 01 so it matches"
|
1868
|
1730 |
|
|
1731 |
|
|
1732 |
self deny: ('30' matchesRegex: '[^01]').
|
|
1733 |
self deny: ('33333333333333333333333330' matchesRegex: '[^01]').
|
1865
|
1734 |
"there is one zero so it does not match"
|
|
1735 |
!
|
|
1736 |
|
|
1737 |
testCharacterSetRange
|
|
1738 |
"self debug: #testCharacterSetRange"
|
1868
|
1739 |
|
1865
|
1740 |
"For convenience, a set may include ranges: pairs of characters
|
|
1741 |
separated with `-'. This is equivalent to listing all characters
|
1868
|
1742 |
between them: `[0-9]' is the same as `[0123456789]'. "
|
|
1743 |
|
|
1744 |
self assert: ('0' matchesRegex: '[0-9]').
|
|
1745 |
self assert: ('9' matchesRegex: '[0-9]').
|
1865
|
1746 |
self deny: ('a' matchesRegex: '[0-9]').
|
1868
|
1747 |
self deny: ('01' matchesRegex: '[0-9]').
|
|
1748 |
self assert: ('01442128629839374565' matchesRegex: '[0-9]+').
|
1865
|
1749 |
!
|
|
1750 |
|
|
1751 |
testMatchesInwW
|
|
1752 |
"self debug: #testMatchesInwW"
|
1868
|
1753 |
|
1865
|
1754 |
"1. Backslash escapes similar to those in Perl are allowed in patterns:
|
|
1755 |
\w any word constituent character (equivalent to [a-zA-Z0-9_])
|
|
1756 |
\W any character but a word constituent (equivalent to [^a-xA-Z0-9_]"
|
|
1757 |
|
|
1758 |
self assert: ('\w+' asRegex matchesIn: 'now is the time') asArray = #('now' 'is' 'the' 'time').
|
|
1759 |
self assert: ('\W+' asRegex matchesIn: 'now is the time') asArray = #(' ' ' ' ' ').
|
1868
|
1760 |
|
|
1761 |
|
1865
|
1762 |
"/ self halt.
|
|
1763 |
"why do we get that"
|
|
1764 |
self assert: ('\w' asRegex matchesIn: 'now') asArray = #('n' 'o' 'w').
|
|
1765 |
!
|
|
1766 |
|
|
1767 |
testOrOperator
|
|
1768 |
"self debug: #testOrOperator"
|
1868
|
1769 |
|
1865
|
1770 |
"The last operator is `|' meaning `or'. It is placed between two
|
|
1771 |
regular expressions, and the resulting expression matches if one of
|
|
1772 |
the expressions matches. It has the lowest possible precedence (lower
|
|
1773 |
than sequencing). For example, `ab*|ba*' means `a followed by any
|
|
1774 |
number of b's, or b followed by any number of a's':"
|
|
1775 |
|
1868
|
1776 |
self assert: ('abb' matchesRegex: 'ab*|ba*').
|
|
1777 |
self assert: ('baa' matchesRegex: 'ab*|ba*').
|
1865
|
1778 |
self deny: ('baab' matchesRegex: 'ab*|ba*').
|
1868
|
1779 |
|
1865
|
1780 |
|
|
1781 |
"It is possible to write an expression matching an empty string, for
|
|
1782 |
example: `a|'. However, it is an error to apply `*', `+', or `?' to
|
|
1783 |
such expression: `(a|)*' is an invalid expression."
|
|
1784 |
|
|
1785 |
self should: ['(a|)*' asRegex] raise: Error.
|
|
1786 |
!
|
|
1787 |
|
|
1788 |
testQuotingOperators
|
|
1789 |
"self debug: #testQuotingOperators"
|
1868
|
1790 |
|
1865
|
1791 |
"As we have seen, characters `*', `+', `?', `(', and `)' have special
|
|
1792 |
meaning in regular expressions. If one of them is to be used
|
|
1793 |
literally, it should be quoted: preceded with a backslash. (Thus,
|
|
1794 |
backslash is also special character, and needs to be quoted for a
|
|
1795 |
literal match--as well as any other special character described
|
|
1796 |
further)."
|
|
1797 |
|
|
1798 |
self deny: ('ab*' matchesRegex: 'ab*'). " -- false: star in the right string is special"
|
1868
|
1799 |
self assert: ('ab*' matchesRegex: 'ab\*').
|
|
1800 |
self assert: ('a\c' matchesRegex: 'a\\c').
|
1865
|
1801 |
!
|
|
1802 |
|
|
1803 |
testSimpleMatchesRegex
|
|
1804 |
"self debug: #testSimpleMatchesRegex"
|
1868
|
1805 |
|
1865
|
1806 |
"The simplest regular expression is a single character. It matches
|
|
1807 |
exactly that character. A sequence of characters matches a string with
|
|
1808 |
exactly the same sequence of characters:"
|
|
1809 |
|
|
1810 |
self assert: ('a' matchesRegex: 'a').
|
|
1811 |
self assert: ('foobar' matchesRegex: 'foobar') .
|
|
1812 |
self deny: ('blorple' matchesRegex: 'foobar')
|
|
1813 |
!
|
|
1814 |
|
|
1815 |
testSimpleMatchesRegexWithStar
|
|
1816 |
"self debug: #testSimpleMatchesRegexWithStar"
|
1868
|
1817 |
|
1865
|
1818 |
"The above paragraph in testSimpleMatchesRegex introduced a primitive regular expression (a
|
|
1819 |
character), and an operator (sequencing). Operators are applied to
|
|
1820 |
regular expressions to produce more complex regular expressions.
|
|
1821 |
Sequencing (placing expressions one after another) as an operator is,
|
|
1822 |
in a certain sense, `invisible'--yet it is arguably the most common.
|
|
1823 |
A more `visible' operator is Kleene closure, more often simply
|
|
1824 |
referred to as `a star'. A regular expression followed by an asterisk
|
|
1825 |
matches any number (including 0) of matches of the original
|
|
1826 |
expression. For example:"
|
|
1827 |
|
1868
|
1828 |
self assert: ('ab' matchesRegex: 'a*b').
|
|
1829 |
self assert: ('aaaaab' matchesRegex: 'a*b').
|
|
1830 |
self assert: ('b' matchesRegex: 'a*b').
|
|
1831 |
self deny: ('aac' matchesRegex: 'a*b').
|
1865
|
1832 |
!
|
|
1833 |
|
|
1834 |
testSpecialCharacterInSetRange
|
|
1835 |
"self debug: #testSpecialCharacterInSetRange"
|
1868
|
1836 |
|
1865
|
1837 |
"Special characters within a set are `^', `-', and `]' that closes the
|
|
1838 |
set. Below are the examples of how to literally use them in a set:
|
|
1839 |
[01^] -- put the caret anywhere except the beginning
|
|
1840 |
[01-] -- put the dash as the last character
|
1868
|
1841 |
[]01] -- put the closing bracket as the first character
|
1865
|
1842 |
[^]01] (thus, empty and universal sets cannot be specified)"
|
|
1843 |
|
|
1844 |
self assert: ('0' matchesRegex: '[01^]').
|
|
1845 |
self assert: ('1' matchesRegex: '[01^]').
|
|
1846 |
self assert: ('^' matchesRegex: '[01^]').
|
1868
|
1847 |
|
1865
|
1848 |
self deny: ('0' matchesRegex: '[^01]').
|
|
1849 |
self deny: ('1' matchesRegex: '[^01]').
|
1868
|
1850 |
|
1865
|
1851 |
"[^abc] means that everything except abc is matche"
|
|
1852 |
self assert: ('^' matchesRegex: '[^01]').
|
|
1853 |
!
|
|
1854 |
|
|
1855 |
testStarPlusQuestionMark
|
|
1856 |
"self debug: #testStarPlusQuestionMark"
|
1868
|
1857 |
|
1865
|
1858 |
"Two other operators similar to `*' are `+' and `?'. `+' (positive
|
|
1859 |
closure, or simply `plus') matches one or more occurrences of the
|
|
1860 |
original expression. `?' (`optional') matches zero or one, but never
|
|
1861 |
more, occurrences."
|
|
1862 |
|
1868
|
1863 |
self assert: ('ac' matchesRegex: 'ab*c').
|
1865
|
1864 |
self deny: ('ac' matchesRegex: 'ab+c'). "-- false: need at least one b"
|
1868
|
1865 |
self assert: ('abbc' matchesRegex: 'ab+c').
|
|
1866 |
self assert: ('abbbbbbc' matchesRegex: 'ab+c').
|
1865
|
1867 |
self deny: ('abbc' matchesRegex: 'ab?c') "-- false: too many b's"
|
|
1868 |
!
|
|
1869 |
|
|
1870 |
testStarPrecedence
|
|
1871 |
"self debug: #testStarPrecedence"
|
1868
|
1872 |
|
1865
|
1873 |
"A star's precedence is higher than that of sequencing. A star applies
|
|
1874 |
to the shortest possible subexpression that precedes it. For example,
|
|
1875 |
'ab*' means `a followed by zero or more occurrences of b', not `zero
|
|
1876 |
or more occurrences of ab':"
|
|
1877 |
|
1868
|
1878 |
self assert: ('abbb' matchesRegex: 'ab*').
|
|
1879 |
self deny: ('abab' matchesRegex: 'ab*').
|
|
1880 |
|
1865
|
1881 |
"To actually make a regex matching `zero or more occurrences of ab',
|
|
1882 |
`ab' is enclosed in parentheses:"
|
1868
|
1883 |
self assert: ('abab' matchesRegex: '(ab)*').
|
1865
|
1884 |
self deny: ('abcab' matchesRegex: '(ab)*')
|
|
1885 |
!
|
|
1886 |
|
|
1887 |
testTranslatingMatchesUsing
|
|
1888 |
"self debug: #testTranslatingMatchesUsing"
|
1868
|
1889 |
|
1865
|
1890 |
|
|
1891 |
self assert: ('\<t\w+' asRegexIgnoringCase
|
1868
|
1892 |
copy: 'now is the Time'
|
|
1893 |
translatingMatchesUsing: [:match | match asUppercase]) = 'now is THE TIME'.
|
1865
|
1894 |
|
|
1895 |
"the regular expression matches words beginning with either an uppercase or a lowercase T"
|
|
1896 |
!
|
|
1897 |
|
|
1898 |
xtest1
|
1868
|
1899 |
self runTestsForMatcher: Regex::RxMatcher
|
1865
|
1900 |
!
|
|
1901 |
|
|
1902 |
xtest: aMatcher with: testString expect: expected withSubexpressions: subexpr
|
|
1903 |
|
1868
|
1904 |
| got |
|
|
1905 |
Transcript tab;
|
|
1906 |
show: 'Matching: ';
|
|
1907 |
show: testString printString;
|
|
1908 |
show: ' expected: ';
|
|
1909 |
show: expected printString;
|
|
1910 |
show: ' got: '.
|
|
1911 |
got := aMatcher search: testString.
|
|
1912 |
Transcript show: got printString.
|
|
1913 |
got ~= expected
|
|
1914 |
ifTrue: [^false].
|
|
1915 |
(subexpr notNil and: [aMatcher supportsSubexpressions])
|
|
1916 |
ifFalse:
|
|
1917 |
[^true]
|
|
1918 |
ifTrue:
|
|
1919 |
[ | isOK |
|
|
1920 |
isOK := true.
|
|
1921 |
1 to: subexpr size by: 2 do: [: i |
|
|
1922 |
| sub subExpect subGot |
|
|
1923 |
sub := subexpr at: i.
|
|
1924 |
subExpect := subexpr at: i + 1.
|
|
1925 |
subGot := aMatcher subexpression: sub.
|
|
1926 |
Transcript cr; tab; tab;
|
|
1927 |
show: 'Subexpression: ', sub printString;
|
|
1928 |
show: ' expected: ';
|
|
1929 |
show: subExpect printString;
|
|
1930 |
show: ' got: ';
|
|
1931 |
show: subGot printString.
|
|
1932 |
subExpect ~= subGot
|
|
1933 |
ifTrue:
|
|
1934 |
[Transcript show: ' -- MISMATCH'.
|
|
1935 |
isOK := false]].
|
|
1936 |
^isOK]
|
1865
|
1937 |
!
|
|
1938 |
|
|
1939 |
xtestSuite
|
|
1940 |
"Answer an array of test clauses. Each clause is an array with a regex source
|
|
1941 |
string followed by sequence of 3-tuples. Each three-element
|
1868
|
1942 |
group is one test to try against the regex, and includes:
|
|
1943 |
1) test string;
|
|
1944 |
2) expected result;
|
|
1945 |
3) expected subexpression as an array of (index, substring), or nil.
|
1865
|
1946 |
The test suite is based on the one in Henry Spencer's regexp.c package."
|
|
1947 |
|
1868
|
1948 |
^#(
|
|
1949 |
('abc'
|
|
1950 |
'abc' true (1 'abc')
|
|
1951 |
'xbc' false nil
|
|
1952 |
'axc' false nil
|
|
1953 |
'abx' false nil
|
|
1954 |
'xabcy' true (1 'abc')
|
|
1955 |
'ababc' true (1 'abc'))
|
|
1956 |
('ab*c'
|
|
1957 |
'abc' true (1 'abc'))
|
|
1958 |
('ab*bc'
|
|
1959 |
'abc' true (1 'abc')
|
|
1960 |
'abbc' true (1 'abbc')
|
|
1961 |
'abbbbc' true (1 'abbbbc'))
|
|
1962 |
('ab+bc'
|
|
1963 |
'abbc' true (1 'abbc')
|
|
1964 |
'abc' false nil
|
|
1965 |
'abq' false nil
|
|
1966 |
'abbbbc' true (1 'abbbbc'))
|
|
1967 |
('ab?bc'
|
|
1968 |
'abbc' true (1 'abbc')
|
|
1969 |
'abc' true (1 'abc')
|
|
1970 |
'abbbbc' false nil
|
|
1971 |
'abc' true (1 'abc'))
|
|
1972 |
('ab?c' "added 08-Jan-2004 by cg "
|
|
1973 |
'abc' true (1 'abc'))
|
|
1974 |
('^abc$'
|
|
1975 |
'abc' true (1 'abc')
|
|
1976 |
'abcc' false nil
|
|
1977 |
'aabc' false nil)
|
|
1978 |
('^abc'
|
|
1979 |
'abcc' true (1 'abc'))
|
|
1980 |
('abc$'
|
|
1981 |
'aabc' true (1 'abc'))
|
|
1982 |
('^'
|
|
1983 |
'abc' true nil)
|
|
1984 |
('$'
|
|
1985 |
'abc' true nil)
|
|
1986 |
('a.c'
|
|
1987 |
'abc' true (1 'abc')
|
|
1988 |
'axc' true (1 'axc'))
|
|
1989 |
('a.*c'
|
|
1990 |
'axyzc' true (1 'axyzc')
|
|
1991 |
'axy zc' true (1 'axy zc') "testing that a dot matches a space"
|
|
1992 |
'axy
|
|
1993 |
zc' false nil "testing that a dot does not match a newline"
|
|
1994 |
'axyzd' false nil)
|
|
1995 |
('.a.*'
|
|
1996 |
'1234abc' true (1 '4abc')
|
|
1997 |
'abcd' false nil)
|
|
1998 |
('a\w+c'
|
|
1999 |
' abbbbc ' true (1 'abbbbc')
|
|
2000 |
'abb bc' false nil)
|
|
2001 |
('\w+'
|
|
2002 |
' foobar quux' true (1 'foobar')
|
|
2003 |
' ~!!@#$%^&*()-+=\|/?.>,<' false nil)
|
|
2004 |
('a\W+c'
|
|
2005 |
'a c' true (1 'a c')
|
|
2006 |
'a bc' false nil)
|
|
2007 |
('\W+'
|
|
2008 |
'foo!!@#$bar' true (1 '!!@#$')
|
|
2009 |
'foobar' false nil)
|
|
2010 |
('a\s*c'
|
|
2011 |
'a c' true (1 'a c')
|
|
2012 |
'a bc' false nil)
|
|
2013 |
('\s+'
|
|
2014 |
'abc3457 sd' true (1 ' ')
|
|
2015 |
'1234$^*^&asdfb' false nil)
|
|
2016 |
('a\S*c'
|
|
2017 |
'aqwertyc' true (1 'aqwertyc')
|
|
2018 |
'ab c' false nil)
|
|
2019 |
('\S+'
|
|
2020 |
' asdf ' true (1 'asdf')
|
|
2021 |
'
|
|
2022 |
' false nil)
|
|
2023 |
('a\d+c'
|
|
2024 |
'a0123456789c' true (1 'a0123456789c')
|
|
2025 |
'a12b34c' false nil)
|
|
2026 |
('\d+'
|
|
2027 |
'foo@#$%123ASD #$$%^&' true (1 '123')
|
|
2028 |
'foo!!@#$asdfl;' false nil)
|
|
2029 |
('a\D+c'
|
|
2030 |
'aqwertyc' true (1 'aqwertyc')
|
|
2031 |
'aqw6ertc' false nil)
|
|
2032 |
('\D+'
|
|
2033 |
'1234 abc 456' true (1 ' abc ')
|
|
2034 |
'1234567890' false nil)
|
|
2035 |
('(f|o)+\b'
|
|
2036 |
'foo' true (1 'foo')
|
|
2037 |
' foo ' true (1 'foo'))
|
|
2038 |
('\ba\w+' "a word beginning with an A"
|
|
2039 |
'land ancient' true (1 'ancient')
|
|
2040 |
'antique vase' true (1 'antique')
|
|
2041 |
'goofy foobar' false nil)
|
|
2042 |
('(f|o)+\B'
|
|
2043 |
'quuxfoobar' true (1 'foo')
|
|
2044 |
'quuxfoo ' true (1 'fo'))
|
|
2045 |
('\Ba\w+' "a word with an A in the middle, match at A and further"
|
|
2046 |
'land ancient' true (1 'and')
|
|
2047 |
'antique vase' true (1 'ase')
|
|
2048 |
'smalltalk shall overcome' true (1 'alltalk')
|
|
2049 |
'foonix is better' false nil)
|
|
2050 |
('fooa\>.*'
|
|
2051 |
'fooa ' true nil
|
|
2052 |
'fooa123' false nil
|
|
2053 |
'fooa bar' true nil
|
|
2054 |
'fooa' true nil
|
|
2055 |
'fooargh' false nil)
|
|
2056 |
('\>.+abc'
|
|
2057 |
' abcde fg' false nil
|
|
2058 |
'foo abcde' true (1 ' abc')
|
|
2059 |
'abcde' false nil)
|
|
2060 |
('\<foo.*'
|
|
2061 |
'foo' true nil
|
|
2062 |
'foobar' true nil
|
|
2063 |
'qfoobarq foonix' true (1 'foonix')
|
|
2064 |
' foo' true nil
|
|
2065 |
' 12foo' false nil
|
|
2066 |
'barfoo' false nil)
|
|
2067 |
('.+\<foo'
|
|
2068 |
'foo' false nil
|
|
2069 |
'ab foo' true (1 'ab foo')
|
|
2070 |
'abfoo' false nil)
|
|
2071 |
('a[bc]d'
|
|
2072 |
'abc' false nil
|
|
2073 |
'abd' true (1 'abd'))
|
|
2074 |
('a[b-d]e'
|
|
2075 |
'abd' false nil
|
|
2076 |
'ace' true (1 'ace'))
|
|
2077 |
('a[b-d]'
|
|
2078 |
'aac' true (1 'ac'))
|
|
2079 |
('a[-b]'
|
|
2080 |
'a-' true (1 'a-'))
|
|
2081 |
('a[b-]'
|
|
2082 |
'a-' true (1 'a-'))
|
|
2083 |
('a[a-b-c]' nil)
|
|
2084 |
('[k]'
|
|
2085 |
'ab' false nil)
|
|
2086 |
('a[b-a]' nil)
|
|
2087 |
('a[]b' nil)
|
|
2088 |
('a[' nil)
|
|
2089 |
('a]'
|
|
2090 |
'a]' true (1 'a]'))
|
|
2091 |
('a[]]b'
|
|
2092 |
'a]b' true (1 'a]b'))
|
|
2093 |
('a[^bc]d'
|
|
2094 |
'aed' true (1 'aed')
|
|
2095 |
'abd' false nil)
|
|
2096 |
('a[^-b]c'
|
|
2097 |
'adc' true (1 'adc')
|
|
2098 |
'a-c' false nil)
|
|
2099 |
('a[^]b]c'
|
|
2100 |
'a]c' false nil
|
|
2101 |
'adc' true (1 'adc'))
|
|
2102 |
('[\de]+'
|
|
2103 |
'01234' true (1 '01234')
|
|
2104 |
'0123e456' true (1 '0123e456')
|
|
2105 |
'0123e45g78' true (1 '0123e45'))
|
|
2106 |
('[e\d]+' "reversal of the above, should be the same"
|
|
2107 |
'01234' true (1 '01234')
|
|
2108 |
'0123e456' true (1 '0123e456')
|
|
2109 |
'0123e45g78' true (1 '0123e45'))
|
|
2110 |
('[\D]+'
|
|
2111 |
'123abc45def78' true (1 'abc'))
|
|
2112 |
('[[:digit:]e]+'
|
|
2113 |
'01234' true (1 '01234')
|
|
2114 |
'0123e456' true (1 '0123e456')
|
|
2115 |
'0123e45g78' true (1 '0123e45'))
|
|
2116 |
('[\s]+'
|
|
2117 |
'2 spaces' true (1 ' '))
|
|
2118 |
('[\S]+'
|
|
2119 |
' word12!!@#$ ' true (1 'word12!!@#$'))
|
|
2120 |
('[\w]+'
|
|
2121 |
' foo123bar 45' true (1 'foo123bar'))
|
|
2122 |
('[\W]+'
|
|
2123 |
'fii234!!@#$34f' true (1 '!!@#$'))
|
|
2124 |
('[^[:alnum:]]+'
|
|
2125 |
'fii234!!@#$34f' true (1 '!!@#$'))
|
|
2126 |
('[%&[:alnum:]]+'
|
|
2127 |
'foo%3' true (1 'foo%3')
|
|
2128 |
'foo34&rt4$57a' true (1 'foo34&rt4')
|
|
2129 |
'!!@#$' false nil)
|
|
2130 |
('[[:alpha:]]+'
|
|
2131 |
' 123foo3 ' true (1 'foo')
|
|
2132 |
'123foo' true (1 'foo')
|
|
2133 |
'foo1b' true (1 'foo'))
|
|
2134 |
('[[:blank:]]+'
|
|
2135 |
'2 blanks' true (1 ' '))
|
|
2136 |
('[^[:blank:]]+'
|
|
2137 |
' word12!!@#$ ' true (1 'word12!!@#$'))
|
|
2138 |
('[[:cntrl:]]+'
|
|
2139 |
' a 1234asdf' false nil)
|
|
2140 |
('[[:lower:]]+'
|
|
2141 |
'UPPERlower1234' true (1 'lower')
|
|
2142 |
'lowerUPPER' true (1 'lower'))
|
|
2143 |
('[[:upper:]]+'
|
|
2144 |
'UPPERlower1234' true (1 'UPPER')
|
|
2145 |
'lowerUPPER ' true (1 'UPPER'))
|
|
2146 |
('[[:space:]]+'
|
|
2147 |
'2 spaces' true (1 ' '))
|
|
2148 |
('[^[:space:]]+'
|
|
2149 |
' word12!!@#$ ' true (1 'word12!!@#$'))
|
|
2150 |
('[[:graph:]]+'
|
|
2151 |
'abc' true (1 'abc'))
|
|
2152 |
('[[:print:]]+'
|
|
2153 |
'abc' true (1 'abc'))
|
|
2154 |
('[^[:punct:]]+'
|
|
2155 |
'!!hello,world!!' true (1 'hello'))
|
|
2156 |
('[[:xdigit:]]+'
|
|
2157 |
' x10FCD ' true (1 '10FCD')
|
|
2158 |
' hgfedcba0123456789ABCDEFGH '
|
|
2159 |
true (1 'fedcba0123456789ABCDEF'))
|
|
2160 |
('ab|cd'
|
|
2161 |
'abc' true (1 'ab')
|
|
2162 |
'abcd' true (1 'ab'))
|
|
2163 |
('()ef'
|
|
2164 |
'def' true (1 'ef' 2 ''))
|
|
2165 |
('()*' nil)
|
|
2166 |
('*a' nil)
|
|
2167 |
('^*' nil)
|
|
2168 |
('$*' nil)
|
|
2169 |
('(*)b' nil)
|
|
2170 |
('$b' 'b' false nil)
|
|
2171 |
('a\' nil)
|
|
2172 |
('a\(b'
|
|
2173 |
'a(b' true (1 'a(b'))
|
|
2174 |
('a\(*b'
|
|
2175 |
'ab' true (1 'ab')
|
|
2176 |
'a((b' true (1 'a((b'))
|
|
2177 |
('a\\b'
|
|
2178 |
'a\b' true (1 'a\b'))
|
|
2179 |
('abc)' nil)
|
|
2180 |
('(abc' nil)
|
|
2181 |
('((a))'
|
|
2182 |
'abc' true (1 'a' 2 'a' 3 'a'))
|
|
2183 |
('(a)b(c)'
|
|
2184 |
'abc' true (1 'abc' 2 'a' 3 'c'))
|
|
2185 |
('a+b+c'
|
|
2186 |
'aabbabc' true (1 'abc'))
|
|
2187 |
('a**' nil)
|
|
2188 |
('a*?' nil)
|
|
2189 |
('(a*)*' nil)
|
|
2190 |
('(a*)+' nil)
|
|
2191 |
('(a|)*' nil)
|
|
2192 |
('(a*|b)*' nil)
|
|
2193 |
('(a+|b)*'
|
|
2194 |
'ab' true (1 'ab' 2 'b'))
|
|
2195 |
('(a+|b)+'
|
|
2196 |
'ab' true (1 'ab' 2 'b'))
|
|
2197 |
('(a+|b)?'
|
|
2198 |
'ab' true (1 'a' 2 'a'))
|
|
2199 |
('[^ab]*'
|
|
2200 |
'cde' true (1 'cde'))
|
|
2201 |
|
|
2202 |
('(^)*' nil)
|
|
2203 |
('(ab|)*' nil)
|
|
2204 |
(')(' nil)
|
|
2205 |
('' 'abc' true (1 ''))
|
|
2206 |
('abc' '' false nil)
|
|
2207 |
('a*'
|
|
2208 |
'' true '')
|
|
2209 |
('abcd'
|
|
2210 |
'abcd' true (1 'abcd'))
|
|
2211 |
('a(bc)d'
|
|
2212 |
'abcd' true (1 'abcd' 2 'bc'))
|
|
2213 |
('([abc])*d'
|
|
2214 |
'abbbcd' true (1 'abbbcd' 2 'c'))
|
|
2215 |
('([abc])*bcd'
|
|
2216 |
'abcd' true (1 'abcd' 2 'a'))
|
|
2217 |
('a|b|c|d|e' 'e' true (1 'e'))
|
|
2218 |
('(a|b|c|d|e)f' 'ef' true (1 'ef' 2 'e'))
|
|
2219 |
" ((a*|b))* - c - -"
|
|
2220 |
('abcd*efg' 'abcdefg' true (1 'abcdefg'))
|
|
2221 |
('ab*'
|
|
2222 |
'xabyabbbz' true (1 'ab')
|
|
2223 |
'xayabbbz' true (1 'a'))
|
|
2224 |
('(ab|cd)e' 'abcde' true (1 'cde' 2 'cd'))
|
|
2225 |
('[abhgefdc]ij' 'hij' true (1 'hij'))
|
|
2226 |
('^(ab|cd)e' 'abcde' false nil)
|
|
2227 |
('(abc|)def' 'abcdef' true nil)
|
|
2228 |
('(a|b)c*d' 'abcd' true (1 'bcd' 2 'b'))
|
|
2229 |
('(ab|ab*)bc' 'abc' true (1 'abc' 2 'a'))
|
|
2230 |
('a([bc]*)c*' 'abc' true (1 'abc' 2 'bc'))
|
|
2231 |
('a([bc]*)(c*d)' 'abcd' true (1 'abcd' 2 'bc' 3 'd'))
|
|
2232 |
('a([bc]+)(c*d)' 'abcd' true (1 'abcd' 2 'bc' 3 'd'))
|
|
2233 |
('a([bc]*)(c+d)' 'abcd' true (1 'abcd' 2 'b' 3 'cd'))
|
|
2234 |
('a[bcd]*dcdcde' 'adcdcde' true (1 'adcdcde'))
|
|
2235 |
('a[bcd]+dcdcde' 'adcdcde' false nil)
|
|
2236 |
('(ab|a)b*c' 'abc' true (1 'abc'))
|
|
2237 |
('((a)(b)c)(d)' 'abcd' true (1 'abcd' 3 'a' 4 'b' 5 'd'))
|
|
2238 |
('[ -~]*' 'abc' true (1 'abc'))
|
|
2239 |
('[ -~ -~]*' 'abc' true (1 'abc'))
|
|
2240 |
('[ -~ -~ -~]*' 'abc' true (1 'abc'))
|
|
2241 |
('[ -~ -~ -~ -~]*' 'abc' true (1 'abc'))
|
|
2242 |
('[ -~ -~ -~ -~ -~]*' 'abc' true (1 'abc'))
|
|
2243 |
('[ -~ -~ -~ -~ -~ -~]*' 'abc' true (1 'abc'))
|
|
2244 |
('[ -~ -~ -~ -~ -~ -~ -~]*' 'abc' true (1 'abc'))
|
|
2245 |
('[a-zA-Z_][a-zA-Z0-9_]*' 'alpha' true (1 'alpha'))
|
|
2246 |
('^a(bc+|b[eh])g|.h$' 'abh' true (1 'bh' 2 ''))
|
|
2247 |
('(bc+d$|ef*g.|h?i(j|k))'
|
|
2248 |
'effgz' true (1 'effgz' 2 'effgz' 3 '')
|
|
2249 |
'ij' true (1 'ij' 2 'ij' 3 'j')
|
|
2250 |
'effg' false nil
|
|
2251 |
'bcdd' false nil
|
|
2252 |
'reffgz' true (1 'effgz' 2 'effgz' 3 ''))
|
|
2253 |
('(((((((((a)))))))))' 'a' true (1 'a'))
|
|
2254 |
('multiple words of text'
|
|
2255 |
'uh-uh' false nil
|
|
2256 |
'multiple words of text, yeah' true (1 'multiple words of text'))
|
|
2257 |
('(.*)c(.*)' 'abcde' true (1 'abcde' 2 'ab' 3 'de'))
|
|
2258 |
('\((.*), (.*)\)' '(a, b)' true (2 'a' 3 'b'))
|
|
2259 |
|
|
2260 |
)
|
1865
|
2261 |
! !
|
|
2262 |
|
|
2263 |
!RxTests methodsFor:'test suite - string interface'!
|
|
2264 |
|
|
2265 |
testS001
|
|
2266 |
self assert:( 'abc' matchesRegex:'abc' ).
|
|
2267 |
self assert:( 'abc' matchesRegex:'ab.' ).
|
|
2268 |
self assert:( 'abc' matchesRegex:'ab.*' ).
|
|
2269 |
self assert:( 'abc' matchesRegex:'a.*' ).
|
|
2270 |
self assert:( 'abc' matchesRegex:'.*' ).
|
|
2271 |
self assert:( 'abc' matchesRegex:'[ab].*' ).
|
|
2272 |
self assert:( 'bca' matchesRegex:'[ab].*' ).
|
|
2273 |
self assert:( 'cab' matchesRegex:'[ab].*' ) not.
|
|
2274 |
|
|
2275 |
"
|
|
2276 |
self new testS001
|
|
2277 |
"
|
|
2278 |
!
|
|
2279 |
|
|
2280 |
testS002
|
|
2281 |
self assert:( 'abc' matchesRegexIgnoringCase:'abc' ).
|
|
2282 |
self assert:( 'ABC' matchesRegexIgnoringCase:'abc' ).
|
|
2283 |
self assert:( 'ABC' matchesRegex:'abc' ) not.
|
|
2284 |
self assert:( 'aBc' matchesRegexIgnoringCase:'abc' ).
|
|
2285 |
self assert:( 'aBc' matchesRegex:'abc' ) not.
|
|
2286 |
|
|
2287 |
self assert:( 'abc' matchesRegexIgnoringCase:'ab.' ).
|
|
2288 |
self assert:( 'ABC' matchesRegexIgnoringCase:'ab.' ).
|
|
2289 |
self assert:( 'ABC' matchesRegex:'ab.' ) not.
|
|
2290 |
self assert:( 'aBc' matchesRegexIgnoringCase:'ab.' ).
|
|
2291 |
self assert:( 'aBc' matchesRegex:'ab.' ) not.
|
|
2292 |
|
|
2293 |
self assert:( 'abc' matchesRegexIgnoringCase:'ab.*' ).
|
|
2294 |
self assert:( 'ABC' matchesRegexIgnoringCase:'ab.*' ).
|
|
2295 |
self assert:( 'ABC' matchesRegex:'ab.*' ) not.
|
|
2296 |
self assert:( 'aBc' matchesRegexIgnoringCase:'ab.*' ).
|
|
2297 |
self assert:( 'aBc' matchesRegex:'ab.*' ) not.
|
|
2298 |
|
|
2299 |
self assert:( 'abc' matchesRegexIgnoringCase:'a.*' ).
|
|
2300 |
self assert:( 'ABC' matchesRegexIgnoringCase:'a.*' ).
|
|
2301 |
self assert:( 'ABC' matchesRegex:'a.*' ) not.
|
|
2302 |
self assert:( 'aBc' matchesRegexIgnoringCase:'a.*' ).
|
|
2303 |
self assert:( 'aBc' matchesRegex:'a.*' ).
|
|
2304 |
|
|
2305 |
self assert:( 'abc' matchesRegexIgnoringCase:'.*' ).
|
|
2306 |
self assert:( 'ABC' matchesRegexIgnoringCase:'.*' ).
|
|
2307 |
self assert:( 'ABC' matchesRegex:'.*' ).
|
|
2308 |
self assert:( 'aBc' matchesRegexIgnoringCase:'.*' ).
|
|
2309 |
self assert:( 'aBc' matchesRegex:'.*' ).
|
|
2310 |
|
|
2311 |
self assert:( 'abc' matchesRegexIgnoringCase:'[ab].*' ).
|
|
2312 |
self assert:( 'ABC' matchesRegexIgnoringCase:'[ab].*' ).
|
|
2313 |
self assert:( 'ABC' matchesRegex:'[ab].*' ) not.
|
|
2314 |
self assert:( 'aBc' matchesRegexIgnoringCase:'[ab].*' ).
|
|
2315 |
self assert:( 'aBc' matchesRegex:'[ab].*' ).
|
|
2316 |
|
|
2317 |
self assert:( 'bca' matchesRegexIgnoringCase:'[ab].*' ).
|
|
2318 |
self assert:( 'BCA' matchesRegexIgnoringCase:'[ab].*' ).
|
|
2319 |
self assert:( 'BCA' matchesRegex:'[ab].*' ) not.
|
|
2320 |
self assert:( 'Bca' matchesRegexIgnoringCase:'[ab].*' ).
|
|
2321 |
self assert:( 'Bca' matchesRegex:'[ab].*' ) not.
|
|
2322 |
|
|
2323 |
self assert:( 'cab' matchesRegexIgnoringCase:'[ab].*' ) not.
|
|
2324 |
self assert:( 'CAB' matchesRegexIgnoringCase:'[ab].*' ) not.
|
|
2325 |
self assert:( 'CAB' matchesRegex:'[ab].*' ) not.
|
|
2326 |
self assert:( 'caB' matchesRegexIgnoringCase:'[ab].*' ) not.
|
|
2327 |
self assert:( 'caB' matchesRegex:'[ab].*' ) not.
|
|
2328 |
|
|
2329 |
"
|
|
2330 |
self new testS002
|
|
2331 |
"
|
|
2332 |
! !
|
|
2333 |
|
|
2334 |
!RxTests methodsFor:'test suite conversion'!
|
|
2335 |
|
|
2336 |
writeAllTests
|
1868
|
2337 |
"Build individual tests from the test suite."
|
|
2338 |
|
|
2339 |
| aTest matcherClass rxSource matcher isOK subexpr |
|
|
2340 |
|
|
2341 |
matcherClass := Regex::RxMatcher.
|
|
2342 |
|
|
2343 |
1 to: self xtestSuite size do: [ :n |
|
|
2344 |
aTest := self xtestSuite at: n.
|
|
2345 |
Transcript
|
|
2346 |
show: 'test', n printString; cr;
|
|
2347 |
tab; show: '| matcher |'; cr; cr;
|
|
2348 |
tab; show: 'self should: [ (matcher := Regex::RxParser compileRegex: ''', aTest first, ''' into:Regex::RxMatcher)'.
|
|
2349 |
(aTest at: 2) isNil
|
|
2350 |
ifTrue: [ Transcript show: ' = nil ].'; cr ]
|
|
2351 |
ifFalse: [
|
|
2352 |
Transcript show: ' ~= nil ].'; cr.
|
|
2353 |
2 to: aTest size by: 3 do:
|
|
2354 |
[:i |
|
|
2355 |
Transcript tab; show: 'self should: [ (matcher search: ', (aTest at: i) printString, ') = ',
|
|
2356 |
(aTest at: i+1) printString, ' ].'; cr.
|
|
2357 |
(aTest at: i+1) ~= nil ifTrue: [
|
|
2358 |
subexpr := aTest at: i+2.
|
|
2359 |
1 to: subexpr size by: 2 do: [ :j |
|
|
2360 |
Transcript tab; show: 'self should: [ (matcher subexpression: ',
|
|
2361 |
(subexpr at: j) printString, ') = ', (subexpr at: j+1) printString,
|
|
2362 |
' ].'; cr ]]]]]
|
1865
|
2363 |
! !
|
|
2364 |
|
|
2365 |
!RxTests class methodsFor:'documentation'!
|
|
2366 |
|
|
2367 |
version
|
|
2368 |
^ '$Header$'
|
|
2369 |
!
|
|
2370 |
|
|
2371 |
version_CVS
|
|
2372 |
^ '$Header$'
|
|
2373 |
! !
|
1869
|
2374 |
|