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 |
|
2342
|
22 |
!RxTests methodsFor:'helper'!
|
|
23 |
|
2409
|
24 |
compileRegex: aString
|
|
25 |
|
|
26 |
"Compile the regex and answer the matcher, or answer nil if compilation fails."
|
|
27 |
|
|
28 |
| syntaxTree |
|
|
29 |
|
|
30 |
syntaxTree := Regex::RxParser safelyParse: aString.
|
|
31 |
^ syntaxTree ifNotNil: [ self matcherClass for: syntaxTree ]
|
|
32 |
!
|
|
33 |
|
2342
|
34 |
compileRegex: regexSource into: matcherClass
|
|
35 |
"Compile the regex and answer the matcher, or answer nil if compilation fails."
|
|
36 |
|
|
37 |
| syntaxTree |
|
|
38 |
|
|
39 |
"/ ^ Regex::RxMatcher2 forString: regexSource.
|
|
40 |
|
2409
|
41 |
syntaxTree := Regex::RxParser "self matcherClass" safelyParse: regexSource.
|
2342
|
42 |
syntaxTree == nil ifTrue: [^nil].
|
|
43 |
^matcherClass for: syntaxTree
|
|
44 |
|
|
45 |
"Modified: / 31-07-2019 / 11:48:08 / Stefan Reise"
|
|
46 |
!
|
|
47 |
|
2409
|
48 |
matcherClass
|
|
49 |
^ Regex::RxMatcher
|
|
50 |
!
|
|
51 |
|
|
52 |
runMatcher: aMatcher with: aString expect: aBoolean withSubexpressions: anArray
|
|
53 |
| copy got sub subExpect subGot |
|
|
54 |
copy := aMatcher
|
|
55 |
copy: aString
|
|
56 |
translatingMatchesUsing: [ :each | each ].
|
|
57 |
self
|
|
58 |
assert: copy = aString
|
|
59 |
description: 'Copying: expected ' , aString printString , ', but got ' , copy printString.
|
|
60 |
got := aMatcher search: aString.
|
|
61 |
self
|
|
62 |
assert: got = aBoolean
|
|
63 |
description: 'Searching: expected ' , aBoolean printString , ', but got ' , got printString.
|
|
64 |
(anArray isNil or: [ aMatcher supportsSubexpressions not ])
|
|
65 |
ifTrue: [ ^ self ].
|
|
66 |
1 to: anArray size by: 2 do: [ :index |
|
|
67 |
sub := anArray at: index.
|
|
68 |
subExpect := anArray at: index + 1.
|
|
69 |
subGot := aMatcher subexpression: sub.
|
|
70 |
self
|
|
71 |
assert: subExpect = subGot
|
|
72 |
description: 'Subexpression ' , sub printString , ': expected ' , subExpect printString , ', but got ' , subGot storeString ]
|
|
73 |
!
|
|
74 |
|
2342
|
75 |
runProtocolTestsForMatcher: matcherClass
|
|
76 |
|
|
77 |
| matcher |
|
|
78 |
Transcript show: 'Testing matcher protocol...'.
|
|
79 |
matcher := matcherClass forString: '\w+'.
|
|
80 |
(matcher matchesIn: 'now is the time') asArray = #('now' 'is' 'the' 'time')
|
|
81 |
ifFalse: [self error: 'matchesIn: test failed'].
|
|
82 |
(matcher copy: 'now is the time ' translatingMatchesUsing: [:s | s reverse])
|
|
83 |
= 'won si eht emit '
|
|
84 |
ifFalse: [self error: 'copy:translatingMatchesWith: test failed'].
|
|
85 |
"See that the match context is preserved while copying stuff between matches:"
|
|
86 |
((matcherClass forString: '\<\d\D+')
|
|
87 |
copy: '9aaa1bbb 8ccc'
|
|
88 |
replacingMatchesWith: 'foo') = 'foo1bbb foo'
|
|
89 |
ifFalse: [self error: 'test failed'].
|
|
90 |
Transcript show: 'OK'; cr
|
|
91 |
!
|
|
92 |
|
2409
|
93 |
runRegex: anArray
|
|
94 |
|
|
95 |
"Run a clause anArray against a set of tests. Each clause is an array with a regex source string followed by sequence of 3-tuples. Each three-element group is one test to try against the regex, and includes: 1) test string; 2) expected result; 3) expected subexpression as an array of (index, substring), or nil."
|
|
96 |
|
|
97 |
| source matcher |
|
|
98 |
|
|
99 |
source := anArray first.
|
|
100 |
matcher := self compileRegex: source.
|
|
101 |
matcher
|
|
102 |
ifNil: [ ( anArray at: 2 )
|
|
103 |
ifNotNil: [ self signalFailure: 'Compilation failed, should have succeeded: ' , source printString ]
|
|
104 |
]
|
|
105 |
ifNotNil: [ ( anArray at: 2 )
|
|
106 |
ifNil: [ self signalFailure: 'Compilation succeeded, should have failed: ' , source printString ]
|
|
107 |
ifNotNil: [ 2 to: anArray size by: 3 do: [ :index |
|
|
108 |
self
|
|
109 |
runMatcher: matcher
|
|
110 |
with: ( anArray at: index )
|
|
111 |
expect: ( anArray at: index + 1 )
|
|
112 |
withSubexpressions: ( anArray at: index + 2 )
|
|
113 |
]
|
|
114 |
]
|
|
115 |
]
|
|
116 |
!
|
|
117 |
|
2342
|
118 |
runRegexTestsForMatcher: matcherClass
|
2409
|
119 |
"Run the whole suite of tests for the given matcher class. May blow up
|
|
120 |
if anything goes wrong with the matcher or parser. Since this is a
|
|
121 |
developer's tool, who cares?"
|
|
122 |
"self new runRegexTestsForMatcher: Regex::RxMatcher"
|
|
123 |
|
|
124 |
| failures |
|
|
125 |
failures := 0.
|
|
126 |
Transcript cr.
|
|
127 |
self xtestSuite do: [:clause |
|
|
128 |
| rxSource matcher isOK |
|
|
129 |
rxSource := clause first.
|
|
130 |
Transcript show: 'Testing regex: '; show: rxSource printString; cr.
|
|
131 |
matcher := self compileRegex: rxSource into: matcherClass.
|
|
132 |
matcher == nil
|
|
133 |
ifTrue:
|
|
134 |
[(clause at: 2) isNil
|
|
135 |
ifTrue:
|
|
136 |
[Transcript tab; show: 'Compilation error as expected (ok)'; cr]
|
|
137 |
ifFalse:
|
|
138 |
[Transcript tab;
|
|
139 |
show: 'Compilation error, UNEXPECTED -- FAILED'; cr.
|
|
140 |
failures := failures + 1]]
|
|
141 |
ifFalse:
|
|
142 |
[(clause at: 2) == nil
|
|
143 |
ifTrue:
|
|
144 |
[Transcript tab;
|
|
145 |
show: 'Compilation succeeded, should have failed -- FAILED!!';
|
|
146 |
cr.
|
|
147 |
failures := failures + 1]
|
|
148 |
ifFalse:
|
|
149 |
[2 to: clause size by: 3 do:
|
|
150 |
[:i |
|
|
151 |
isOK := self
|
|
152 |
xtest: matcher
|
|
153 |
with: (clause at: i)
|
|
154 |
expect: (clause at: i + 1)
|
|
155 |
withSubexpressions: (clause at: i + 2).
|
|
156 |
isOK ifFalse: [failures := failures + 1].
|
|
157 |
Transcript
|
|
158 |
show: (isOK ifTrue: [' (ok).'] ifFalse: [' -- FAILED!!']);
|
|
159 |
cr]]]].
|
|
160 |
failures = 0
|
|
161 |
ifTrue: [Transcript show: 'PASSED ALL TESTS.'; cr]
|
|
162 |
ifFalse: [Transcript show: failures printString, ' TESTS FAILED!!'; cr]
|
2342
|
163 |
!
|
|
164 |
|
|
165 |
runTestsForMatcher: matcherClass
|
2409
|
166 |
"Run the whole suite of tests for the given matcher class. May blow up
|
|
167 |
if something goes wrong with the matcher or the parser. Since this is a
|
|
168 |
developer's tool, who cares?"
|
|
169 |
"self new runTestsForMatcher: Regex::RxMatcher"
|
|
170 |
|
|
171 |
self
|
|
172 |
runRegexTestsForMatcher: matcherClass;
|
|
173 |
runProtocolTestsForMatcher: matcherClass
|
2342
|
174 |
! !
|
|
175 |
|
1865
|
176 |
!RxTests methodsFor:'profiling'!
|
|
177 |
|
|
178 |
bigHonkingStream
|
2409
|
179 |
^ '~/Documents/Pharo/images/Pharo 8.0 - 64bit (development version, latest)/Pharo8.0-32bit-3a0b722.sources' asFilename readStream "38Mb"
|
|
180 |
"/ ^ '~/Downloads/smalltalk/Pharo6.1-64.app/Contents/MacOS/PharoV60.sources' asFilename readStream "36Mb"
|
2265
|
181 |
"/ ^'/home/vassili/VisualWorks/image/visualnc.sou' asFilename readStream "7 Megs"
|
|
182 |
|
|
183 |
"Modified: / 04-06-2019 / 10:52:51 / Claus Gittinger"
|
1865
|
184 |
!
|
|
185 |
|
|
186 |
frequentMatchProfile
|
1868
|
187 |
"
|
|
188 |
TimeProfiler profile: [self frequentMatchProfile]
|
|
189 |
Time millisecondsToRun: [self frequentMatchProfile]
|
|
190 |
"
|
|
191 |
|
|
192 |
| stream matcher count |
|
|
193 |
stream := self bigHonkingStream.
|
|
194 |
count := 0.
|
|
195 |
matcher := '\<\w+' asRegex.
|
|
196 |
[
|
|
197 |
[matcher searchStream: stream] whileTrue: [count := count + 1].
|
|
198 |
]
|
|
199 |
valueNowOrOnUnwindDo: [stream close].
|
|
200 |
^count
|
1865
|
201 |
!
|
|
202 |
|
|
203 |
rareMatchProfile
|
2265
|
204 |
" o:Regex::RxMatcher
|
|
205 |
TimeProfiler profile: [self new rareMatchProfile]
|
|
206 |
Time millisecondsToRun: [self new rareMatchProfile] -> 22760
|
|
207 |
"
|
|
208 |
|
|
209 |
| stream matcher count |
|
|
210 |
stream := self bigHonkingStream.
|
|
211 |
count := 0.
|
|
212 |
matcher := 'foo' asRegex.
|
|
213 |
[
|
|
214 |
[matcher searchStream: stream] whileTrue: [count := count + 1].
|
|
215 |
]
|
|
216 |
valueNowOrOnUnwindDo: [stream close].
|
|
217 |
^count
|
|
218 |
|
|
219 |
"Modified (comment): / 04-06-2019 / 10:54:16 / Claus Gittinger"
|
1865
|
220 |
!
|
|
221 |
|
|
222 |
singleCharPrefixMatchProfile
|
|
223 |
"
|
|
224 |
TimeProfiler profile: [self singleCharPrefixMatchProfile]
|
|
225 |
Time millisecondsToRun: [self singleCharPrefixMatchProfile]
|
|
226 |
"
|
|
227 |
|
|
228 |
| stream matcher count |
|
|
229 |
stream := self bigHonkingStream.
|
|
230 |
count := 0.
|
|
231 |
matcher := 'm(e|a)th' asRegex.
|
|
232 |
[
|
|
233 |
[matcher searchStream: stream] whileTrue: [count := count + 1].
|
|
234 |
]
|
|
235 |
valueNowOrOnUnwindDo: [stream close].
|
|
236 |
^count
|
|
237 |
! !
|
|
238 |
|
2409
|
239 |
!RxTests methodsFor:'test suite - henry'!
|
|
240 |
|
|
241 |
testHenry001
|
|
242 |
self runRegex: #('abc'
|
|
243 |
'abc' true (1 'abc')
|
|
244 |
'xbc' false nil
|
|
245 |
'axc' false nil
|
|
246 |
'abx' false nil
|
|
247 |
'xabcy' true (1 'abc')
|
|
248 |
'ababc' true (1 'abc'))
|
|
249 |
!
|
|
250 |
|
|
251 |
testHenry002
|
|
252 |
self runRegex: #('ab*c'
|
|
253 |
'abc' true (1 'abc'))
|
|
254 |
!
|
|
255 |
|
|
256 |
testHenry003
|
|
257 |
self runRegex: #('ab*bc'
|
|
258 |
'abc' true (1 'abc')
|
|
259 |
'abbc' true (1 'abbc')
|
|
260 |
'abbbbc' true (1 'abbbbc'))
|
|
261 |
!
|
|
262 |
|
|
263 |
testHenry004
|
|
264 |
self runRegex: #('ab+bc'
|
|
265 |
'abbc' true (1 'abbc')
|
|
266 |
'abc' false nil
|
|
267 |
'abq' false nil
|
|
268 |
'abbbbc' true (1 'abbbbc'))
|
|
269 |
!
|
|
270 |
|
|
271 |
testHenry005
|
|
272 |
self runRegex: #('ab?bc'
|
|
273 |
'abbc' true (1 'abbc')
|
|
274 |
'abc' true (1 'abc')
|
|
275 |
'abbbbc' false nil
|
|
276 |
'abc' true (1 'abc'))
|
|
277 |
!
|
|
278 |
|
|
279 |
testHenry006
|
|
280 |
self runRegex: #('^abc$'
|
|
281 |
'abc' true (1 'abc')
|
|
282 |
'abcc' false nil
|
|
283 |
'aabc' false nil)
|
|
284 |
!
|
|
285 |
|
|
286 |
testHenry007
|
|
287 |
self runRegex: #('^abc'
|
|
288 |
'abcc' true (1 'abc'))
|
|
289 |
!
|
|
290 |
|
|
291 |
testHenry008
|
|
292 |
self runRegex: #('abc$'
|
|
293 |
'aabc' true (1 'abc'))
|
|
294 |
!
|
|
295 |
|
|
296 |
testHenry009
|
|
297 |
self runRegex: #('^'
|
|
298 |
'abc' true nil)
|
|
299 |
!
|
|
300 |
|
|
301 |
testHenry010
|
|
302 |
self runRegex: #('$'
|
|
303 |
'abc' true nil)
|
|
304 |
!
|
|
305 |
|
|
306 |
testHenry011
|
|
307 |
self runRegex: #('a.c'
|
|
308 |
'abc' true (1 'abc')
|
|
309 |
'axc' true (1 'axc'))
|
|
310 |
!
|
|
311 |
|
|
312 |
testHenry012
|
|
313 |
"Need to get creative to include the null character..."
|
|
314 |
self runRegex:
|
|
315 |
#('a.*c'
|
|
316 |
'axyzd' false nil
|
|
317 |
'axyzc' true (1 'axyzc')
|
|
318 |
'axy zc' true (1 'axy zc') "testing that a dot matches a space"
|
|
319 |
).
|
|
320 |
|
|
321 |
self runRegex:
|
|
322 |
{'a.*c' .
|
|
323 |
'axy',(String with: 0 asCharacter),'zc' . false . nil} "testing that a dot does not match a null"
|
|
324 |
!
|
|
325 |
|
|
326 |
testHenry014
|
|
327 |
self runRegex: #('a\w+c'
|
|
328 |
' abbbbc ' true (1 'abbbbc')
|
|
329 |
'abb bc' false nil)
|
|
330 |
!
|
|
331 |
|
|
332 |
testHenry015
|
|
333 |
self runRegex: #('\w+'
|
|
334 |
' foobar quux' true (1 'foobar')
|
|
335 |
' ~!!@#$%^&*()-+=\|/?.>,<' false nil)
|
|
336 |
!
|
|
337 |
|
|
338 |
testHenry016
|
|
339 |
self runRegex: #('a\W+c'
|
|
340 |
'a c' true (1 'a c')
|
|
341 |
'a bc' false nil)
|
|
342 |
!
|
|
343 |
|
|
344 |
testHenry017
|
|
345 |
self runRegex: #('\W+'
|
|
346 |
'foo!!@#$bar' true (1 '!!@#$')
|
|
347 |
'foobar' false nil)
|
|
348 |
!
|
|
349 |
|
|
350 |
testHenry018
|
|
351 |
self runRegex: #('a\s*c'
|
|
352 |
'a c' true (1 'a c')
|
|
353 |
'a bc' false nil)
|
|
354 |
!
|
|
355 |
|
|
356 |
testHenry019
|
|
357 |
self runRegex: #('\s+'
|
|
358 |
'abc3457 sd' true (1 ' ')
|
|
359 |
'1234$^*^&asdfb' false nil)
|
|
360 |
!
|
|
361 |
|
|
362 |
testHenry020
|
|
363 |
self runRegex: #('a\S*c'
|
|
364 |
'aqwertyc' true (1 'aqwertyc')
|
|
365 |
'ab c' false nil)
|
|
366 |
!
|
|
367 |
|
|
368 |
testHenry021
|
|
369 |
self runRegex: #('\S+'
|
|
370 |
' asdf ' true (1 'asdf')
|
|
371 |
'
|
|
372 |
' false nil)
|
|
373 |
!
|
|
374 |
|
|
375 |
testHenry022
|
|
376 |
self runRegex: #('a\d+c'
|
|
377 |
'a0123456789c' true (1 'a0123456789c')
|
|
378 |
'a12b34c' false nil)
|
|
379 |
!
|
|
380 |
|
|
381 |
testHenry023
|
|
382 |
self runRegex: #('\d+'
|
|
383 |
'foo@#$%123ASD #$$%^&' true (1 '123')
|
|
384 |
'foo!!@#$asdfl;' false nil)
|
|
385 |
!
|
|
386 |
|
|
387 |
testHenry024
|
|
388 |
self runRegex: #('a\D+c'
|
|
389 |
'aqwertyc' true (1 'aqwertyc')
|
|
390 |
'aqw6ertc' false nil)
|
|
391 |
!
|
|
392 |
|
|
393 |
testHenry025
|
|
394 |
self runRegex: #('\D+'
|
|
395 |
'1234 abc 456' true (1 ' abc ')
|
|
396 |
'1234567890' false nil)
|
|
397 |
!
|
|
398 |
|
|
399 |
testHenry026
|
|
400 |
self runRegex: #('(f|o)+\b'
|
|
401 |
'foo' true (1 'foo')
|
|
402 |
' foo ' true (1 'foo'))
|
|
403 |
!
|
|
404 |
|
|
405 |
testHenry027
|
|
406 |
self runRegex: #('\ba\w+' "a word beginning with an A"
|
|
407 |
'land ancient' true (1 'ancient')
|
|
408 |
'antique vase' true (1 'antique')
|
|
409 |
'goofy foobar' false nil)
|
|
410 |
!
|
|
411 |
|
|
412 |
testHenry028
|
|
413 |
self runRegex: #('(f|o)+\B'
|
|
414 |
'quuxfoobar' true (1 'foo')
|
|
415 |
'quuxfoo ' true (1 'fo'))
|
|
416 |
!
|
|
417 |
|
|
418 |
testHenry029
|
|
419 |
self runRegex: #('\Ba\w+' "a word with an A in the middle, match at A and further"
|
|
420 |
'land ancient' true (1 'and')
|
|
421 |
'antique vase' true (1 'ase')
|
|
422 |
'smalltalk shall overcome' true (1 'alltalk')
|
|
423 |
'foonix is better' false nil)
|
|
424 |
!
|
|
425 |
|
|
426 |
testHenry030
|
|
427 |
self runRegex: #('fooa\>.*'
|
|
428 |
'fooa ' true nil
|
|
429 |
'fooa123' false nil
|
|
430 |
'fooa bar' true nil
|
|
431 |
'fooa' true nil
|
|
432 |
'fooargh' false nil)
|
|
433 |
!
|
|
434 |
|
|
435 |
testHenry031
|
|
436 |
self runRegex: #('\>.+abc'
|
|
437 |
' abcde fg' false nil
|
|
438 |
'foo abcde' true (1 ' abc')
|
|
439 |
'abcde' false nil)
|
|
440 |
!
|
|
441 |
|
|
442 |
testHenry032
|
|
443 |
self runRegex: #('\<foo.*'
|
|
444 |
'foo' true nil
|
|
445 |
'foobar' true nil
|
|
446 |
'qfoobarq foonix' true (1 'foonix')
|
|
447 |
' foo' true nil
|
|
448 |
' 12foo' false nil
|
|
449 |
'barfoo' false nil)
|
|
450 |
!
|
|
451 |
|
|
452 |
testHenry033
|
|
453 |
self runRegex: #('.+\<foo'
|
|
454 |
'foo' false nil
|
|
455 |
'ab foo' true (1 'ab foo')
|
|
456 |
'abfoo' false nil)
|
|
457 |
!
|
|
458 |
|
|
459 |
testHenry034
|
|
460 |
self runRegex: #('a[bc]d'
|
|
461 |
'abc' false nil
|
|
462 |
'abd' true (1 'abd'))
|
|
463 |
!
|
|
464 |
|
|
465 |
testHenry035
|
|
466 |
self runRegex: #('a[b-d]e'
|
|
467 |
'abd' false nil
|
|
468 |
'ace' true (1 'ace'))
|
|
469 |
!
|
|
470 |
|
|
471 |
testHenry036
|
|
472 |
self runRegex: #('a[b-d]'
|
|
473 |
'aac' true (1 'ac'))
|
|
474 |
!
|
|
475 |
|
|
476 |
testHenry037
|
|
477 |
self runRegex: #('a[-b]'
|
|
478 |
'a-' true (1 'a-'))
|
|
479 |
!
|
|
480 |
|
|
481 |
testHenry038
|
|
482 |
self runRegex: #('a[b-]'
|
|
483 |
'a-' true (1 'a-'))
|
|
484 |
!
|
|
485 |
|
|
486 |
testHenry039
|
|
487 |
self runRegex: #('a[a-b-c]' nil)
|
|
488 |
!
|
|
489 |
|
|
490 |
testHenry040
|
|
491 |
self runRegex: #('[k]'
|
|
492 |
'ab' false nil)
|
|
493 |
!
|
|
494 |
|
|
495 |
testHenry041
|
|
496 |
self runRegex: #('a[b-a]' nil)
|
|
497 |
!
|
|
498 |
|
|
499 |
testHenry042
|
|
500 |
self runRegex: #('a[]b' nil)
|
|
501 |
!
|
|
502 |
|
|
503 |
testHenry043
|
|
504 |
self runRegex: #('a[' nil)
|
|
505 |
!
|
|
506 |
|
|
507 |
testHenry044
|
|
508 |
self runRegex: #('a]'
|
|
509 |
'a]' true (1 'a]'))
|
|
510 |
!
|
|
511 |
|
|
512 |
testHenry045
|
|
513 |
self runRegex: #('a[]]b'
|
|
514 |
'a]b' true (1 'a]b'))
|
|
515 |
!
|
|
516 |
|
|
517 |
testHenry046
|
|
518 |
self runRegex: #('a[^bc]d'
|
|
519 |
'aed' true (1 'aed')
|
|
520 |
'abd' false nil)
|
|
521 |
!
|
|
522 |
|
|
523 |
testHenry047
|
|
524 |
self runRegex: #('a[^-b]c'
|
|
525 |
'adc' true (1 'adc')
|
|
526 |
'a-c' false nil)
|
|
527 |
!
|
|
528 |
|
|
529 |
testHenry048
|
|
530 |
self runRegex: #('a[^]b]c'
|
|
531 |
'a]c' false nil
|
|
532 |
'adc' true (1 'adc'))
|
|
533 |
!
|
|
534 |
|
|
535 |
testHenry049
|
|
536 |
self runRegex: #('[\de]+'
|
|
537 |
'01234' true (1 '01234')
|
|
538 |
'0123e456' true (1 '0123e456')
|
|
539 |
'0123e45g78' true (1 '0123e45'))
|
|
540 |
!
|
|
541 |
|
|
542 |
testHenry050
|
|
543 |
self runRegex: #('[e\d]+' "reversal of the above, should be the same"
|
|
544 |
'01234' true (1 '01234')
|
|
545 |
'0123e456' true (1 '0123e456')
|
|
546 |
'0123e45g78' true (1 '0123e45'))
|
|
547 |
!
|
|
548 |
|
|
549 |
testHenry051
|
|
550 |
self runRegex: #('[\D]+'
|
|
551 |
'123abc45def78' true (1 'abc'))
|
|
552 |
!
|
|
553 |
|
|
554 |
testHenry052
|
|
555 |
self runRegex: #('[[:digit:]e]+'
|
|
556 |
'01234' true (1 '01234')
|
|
557 |
'0123e456' true (1 '0123e456')
|
|
558 |
'0123e45g78' true (1 '0123e45'))
|
|
559 |
!
|
|
560 |
|
|
561 |
testHenry053
|
|
562 |
self runRegex: #('[\s]+'
|
|
563 |
'2 spaces' true (1 ' '))
|
|
564 |
!
|
|
565 |
|
|
566 |
testHenry054
|
|
567 |
self runRegex: #('[\S]+'
|
|
568 |
' word12!!@#$ ' true (1 'word12!!@#$'))
|
|
569 |
!
|
|
570 |
|
|
571 |
testHenry055
|
|
572 |
self runRegex: #('[\w]+'
|
|
573 |
' foo123bar 45' true (1 'foo123bar'))
|
|
574 |
!
|
|
575 |
|
|
576 |
testHenry056
|
|
577 |
self runRegex: #('[\W]+'
|
|
578 |
'fii234!!@#$34f' true (1 '!!@#$'))
|
|
579 |
!
|
|
580 |
|
|
581 |
testHenry057
|
|
582 |
self runRegex: #('[^[:alnum:]]+'
|
|
583 |
'fii234!!@#$34f' true (1 '!!@#$'))
|
|
584 |
!
|
|
585 |
|
|
586 |
testHenry058
|
|
587 |
self runRegex: #('[%&[:alnum:]]+'
|
|
588 |
'foo%3' true (1 'foo%3')
|
|
589 |
'foo34&rt4$57a' true (1 'foo34&rt4')
|
|
590 |
'!!@#$' false nil)
|
|
591 |
!
|
|
592 |
|
|
593 |
testHenry060
|
|
594 |
self runRegex: #('[[:cntrl:]]+'
|
|
595 |
' a 1234asdf' false nil)
|
|
596 |
!
|
|
597 |
|
|
598 |
testHenry061
|
|
599 |
self runRegex: #('[[:lower:]]+'
|
|
600 |
'UPPERlower1234' true (1 'lower')
|
|
601 |
'lowerUPPER' true (1 'lower'))
|
|
602 |
!
|
|
603 |
|
|
604 |
testHenry062
|
|
605 |
self runRegex: #('[[:upper:]]+'
|
|
606 |
'UPPERlower1234' true (1 'UPPER')
|
|
607 |
'lowerUPPER ' true (1 'UPPER'))
|
|
608 |
!
|
|
609 |
|
|
610 |
testHenry063
|
|
611 |
self runRegex: #('[[:space:]]+'
|
|
612 |
'2 spaces' true (1 ' '))
|
|
613 |
!
|
|
614 |
|
|
615 |
testHenry064
|
|
616 |
self runRegex: #('[^[:space:]]+'
|
|
617 |
' word12!!@#$ ' true (1 'word12!!@#$'))
|
|
618 |
!
|
|
619 |
|
|
620 |
testHenry065
|
|
621 |
self runRegex: #('[[:graph:]]+'
|
|
622 |
'abc' true (1 'abc'))
|
|
623 |
!
|
|
624 |
|
|
625 |
testHenry066
|
|
626 |
self runRegex: #('[[:print:]]+'
|
|
627 |
'abc' true (1 'abc'))
|
|
628 |
!
|
|
629 |
|
|
630 |
testHenry067
|
|
631 |
self runRegex: #('[^[:punct:]]+'
|
|
632 |
'!!hello,world!!' true (1 'hello'))
|
|
633 |
!
|
|
634 |
|
|
635 |
testHenry068
|
|
636 |
self runRegex: #('[[:xdigit:]]+'
|
|
637 |
' x10FCD ' true (1 '10FCD')
|
|
638 |
' hgfedcba0123456789ABCDEFGH '
|
|
639 |
true (1 'fedcba0123456789ABCDEF'))
|
|
640 |
!
|
|
641 |
|
|
642 |
testHenry069
|
|
643 |
self runRegex: #('ab|cd'
|
|
644 |
'abc' true (1 'ab')
|
|
645 |
'abcd' true (1 'ab'))
|
|
646 |
!
|
|
647 |
|
|
648 |
testHenry070
|
|
649 |
self runRegex: #('()ef'
|
|
650 |
'def' true (1 'ef' 2 ''))
|
|
651 |
!
|
|
652 |
|
|
653 |
testHenry071
|
|
654 |
self runRegex: #('()*' nil)
|
|
655 |
!
|
|
656 |
|
|
657 |
testHenry072
|
|
658 |
self runRegex: #('*a' nil)
|
|
659 |
!
|
|
660 |
|
|
661 |
testHenry073
|
|
662 |
self runRegex: #('^*' nil)
|
|
663 |
!
|
|
664 |
|
|
665 |
testHenry074
|
|
666 |
self runRegex: #('$*' nil)
|
|
667 |
!
|
|
668 |
|
|
669 |
testHenry075
|
|
670 |
self runRegex: #('(*)b' nil)
|
|
671 |
!
|
|
672 |
|
|
673 |
testHenry076
|
|
674 |
self runRegex: #('$b' 'b' false nil)
|
|
675 |
!
|
|
676 |
|
|
677 |
testHenry077
|
|
678 |
self runRegex: #('a\' nil)
|
|
679 |
!
|
|
680 |
|
|
681 |
testHenry078
|
|
682 |
self runRegex: #('a\(b'
|
|
683 |
'a(b' true (1 'a(b'))
|
|
684 |
!
|
|
685 |
|
|
686 |
testHenry079
|
|
687 |
self runRegex: #('a\(*b'
|
|
688 |
'ab' true (1 'ab')
|
|
689 |
'a((b' true (1 'a((b'))
|
|
690 |
!
|
|
691 |
|
|
692 |
testHenry080
|
|
693 |
self runRegex: #('a\\b'
|
|
694 |
'a\b' true (1 'a\b'))
|
|
695 |
!
|
|
696 |
|
|
697 |
testHenry081
|
|
698 |
self runRegex: #('abc)' nil)
|
|
699 |
!
|
|
700 |
|
|
701 |
testHenry082
|
|
702 |
self runRegex: #('(abc' nil)
|
|
703 |
!
|
|
704 |
|
|
705 |
testHenry083
|
|
706 |
self runRegex: #('((a))'
|
|
707 |
'abc' true (1 'a' 2 'a' 3 'a'))
|
|
708 |
!
|
|
709 |
|
|
710 |
testHenry084
|
|
711 |
self runRegex: #('(a)b(c)'
|
|
712 |
'abc' true (1 'abc' 2 'a' 3 'c'))
|
|
713 |
!
|
|
714 |
|
|
715 |
testHenry085
|
|
716 |
self runRegex: #('a+b+c'
|
|
717 |
'aabbabc' true (1 'abc'))
|
|
718 |
!
|
|
719 |
|
|
720 |
testHenry086
|
|
721 |
self runRegex: #('a**' nil)
|
|
722 |
!
|
|
723 |
|
|
724 |
testHenry087
|
|
725 |
self runRegex: #('a*?' nil)
|
|
726 |
!
|
|
727 |
|
|
728 |
testHenry088
|
|
729 |
self runRegex: #('(a*)*' nil)
|
|
730 |
!
|
|
731 |
|
|
732 |
testHenry089
|
|
733 |
self runRegex: #('(a*)+' nil)
|
|
734 |
!
|
|
735 |
|
|
736 |
testHenry090
|
|
737 |
self runRegex: #('(a|)*' nil)
|
|
738 |
!
|
|
739 |
|
|
740 |
testHenry091
|
|
741 |
self runRegex: #('(a*|b)*' nil)
|
|
742 |
!
|
|
743 |
|
|
744 |
testHenry092
|
|
745 |
self runRegex: #('(a+|b)*'
|
|
746 |
'ab' true (1 'ab' 2 'b'))
|
|
747 |
!
|
|
748 |
|
|
749 |
testHenry093
|
|
750 |
self runRegex: #('(a+|b)+'
|
|
751 |
'ab' true (1 'ab' 2 'b'))
|
|
752 |
!
|
|
753 |
|
|
754 |
testHenry094
|
|
755 |
self runRegex: #('(a+|b)?'
|
|
756 |
'ab' true (1 'a' 2 'a'))
|
|
757 |
!
|
|
758 |
|
|
759 |
testHenry095
|
|
760 |
self runRegex: #('[^ab]*'
|
|
761 |
'cde' true (1 'cde'))
|
|
762 |
!
|
|
763 |
|
|
764 |
testHenry096
|
|
765 |
self runRegex: #('(^)*' nil)
|
|
766 |
!
|
|
767 |
|
|
768 |
testHenry097
|
|
769 |
self runRegex: #('(ab|)*' nil)
|
|
770 |
!
|
|
771 |
|
|
772 |
testHenry098
|
|
773 |
self runRegex: #(')(' nil)
|
|
774 |
!
|
|
775 |
|
|
776 |
testHenry099
|
|
777 |
self runRegex: #('' 'abc' true (1 ''))
|
|
778 |
!
|
|
779 |
|
|
780 |
testHenry100
|
|
781 |
self runRegex: #('abc' '' false nil)
|
|
782 |
! !
|
|
783 |
|
1865
|
784 |
!RxTests methodsFor:'test suite - new'!
|
|
785 |
|
|
786 |
test001
|
|
787 |
"patt. input match-expected matched-expression
|
|
788 |
abc abc y & abc
|
|
789 |
abc xbc n - -
|
|
790 |
abc axc n - -
|
|
791 |
abc abx n - -
|
|
792 |
abc xabcy y & abc
|
|
793 |
abc ababc y & abc
|
|
794 |
"
|
1868
|
795 |
|
1865
|
796 |
|matcher|
|
|
797 |
|
1868
|
798 |
self
|
2409
|
799 |
should:[ (matcher := self compileRegex:'abc' into:Regex::RxMatcher) ~= nil ].
|
1865
|
800 |
self should:[ (matcher search:'abc') = true ].
|
|
801 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
802 |
self should:[ (matcher search:'xbc') = false ].
|
|
803 |
self should:[ (matcher search:'axc') = false ].
|
|
804 |
self should:[ (matcher search:'abx') = false ].
|
|
805 |
self should:[ (matcher search:'xabcy') = true ].
|
|
806 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
807 |
self should:[ (matcher search:'ababc') = true ].
|
|
808 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
809 |
|
|
810 |
"
|
|
811 |
self new test01
|
|
812 |
"
|
|
813 |
!
|
|
814 |
|
|
815 |
test002
|
|
816 |
"patt. input match-expected matched-expression
|
|
817 |
ab*c abc y & abc
|
|
818 |
"
|
1868
|
819 |
|
1865
|
820 |
|matcher|
|
|
821 |
|
1868
|
822 |
self
|
2409
|
823 |
should:[ (matcher := self compileRegex:'ab*c' into:self matcherClass) ~= nil ].
|
1865
|
824 |
self should:[ (matcher search:'abc') = true ].
|
|
825 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
826 |
|
|
827 |
"
|
|
828 |
self new test02
|
|
829 |
"
|
|
830 |
!
|
|
831 |
|
|
832 |
test003
|
|
833 |
"patt. input match-expected matched-expression
|
|
834 |
ab*bc abc y & abc
|
|
835 |
ab*bc abbc y & abbc
|
|
836 |
ab*bc abbbbc y & abbbbc
|
|
837 |
"
|
1868
|
838 |
|
1865
|
839 |
|matcher|
|
|
840 |
|
1868
|
841 |
self
|
2409
|
842 |
should:[ (matcher := self compileRegex:'ab*bc' into:self matcherClass) ~= nil ].
|
1865
|
843 |
self should:[ (matcher search:'abc') = true ].
|
|
844 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
845 |
self should:[ (matcher search:'abbc') = true ].
|
|
846 |
self should:[ (matcher subexpression:1) = 'abbc' ].
|
|
847 |
self should:[ (matcher search:'abbbbc') = true ].
|
|
848 |
self should:[ (matcher subexpression:1) = 'abbbbc' ].
|
|
849 |
|
|
850 |
"
|
|
851 |
self new test02
|
|
852 |
"
|
|
853 |
!
|
|
854 |
|
|
855 |
test004
|
|
856 |
"patt. input match-expected matched-expression
|
|
857 |
ab+bc abbc y & abbc
|
|
858 |
ab+bc abc n - -
|
|
859 |
ab+bc abq n - -
|
|
860 |
ab+bc abbbbc y & abbbbc
|
|
861 |
"
|
1868
|
862 |
|
1865
|
863 |
|matcher|
|
|
864 |
|
1868
|
865 |
self
|
2409
|
866 |
should:[ (matcher := self compileRegex:'ab+bc' into:self matcherClass) ~= nil ].
|
1865
|
867 |
self should:[ (matcher search:'abbc') = true ].
|
|
868 |
self should:[ (matcher subexpression:1) = 'abbc' ].
|
|
869 |
self should:[ (matcher search:'abc') = false ].
|
|
870 |
self should:[ (matcher search:'abq') = false ].
|
|
871 |
self should:[ (matcher search:'abbbbc') = true ].
|
|
872 |
self should:[ (matcher subexpression:1) = 'abbbbc' ].
|
|
873 |
|
|
874 |
"
|
|
875 |
self new test04
|
|
876 |
"
|
|
877 |
!
|
|
878 |
|
|
879 |
test005
|
|
880 |
"patt. input match-expected matched-expression
|
|
881 |
ab?bc abbc y & abbc
|
|
882 |
ab?bc abc y & abc
|
|
883 |
ab?bc abbbbc n - -
|
|
884 |
"
|
1868
|
885 |
|
1865
|
886 |
|matcher|
|
|
887 |
|
1868
|
888 |
self
|
2409
|
889 |
should:[ (matcher := self compileRegex:'ab?bc' into:self matcherClass) ~= nil ].
|
1865
|
890 |
self should:[ (matcher search:'abbc') = true ].
|
|
891 |
self should:[ (matcher subexpression:1) = 'abbc' ].
|
|
892 |
self should:[ (matcher search:'abc') = true ].
|
|
893 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
894 |
self should:[ (matcher search:'abbbbc') = false ].
|
|
895 |
|
|
896 |
"
|
|
897 |
self new test05
|
|
898 |
"
|
|
899 |
!
|
|
900 |
|
|
901 |
test005b
|
|
902 |
"patt. input match-expected matched-expression
|
|
903 |
ab?c abc y & abc
|
|
904 |
"
|
1868
|
905 |
|
1865
|
906 |
|matcher|
|
|
907 |
|
1868
|
908 |
self
|
2409
|
909 |
should:[ (matcher := self compileRegex:'ab?c' into:self matcherClass) ~= nil ].
|
1865
|
910 |
self should:[ (matcher search:'abc') = true ].
|
|
911 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
912 |
|
|
913 |
"
|
|
914 |
self new test05b
|
|
915 |
"
|
|
916 |
!
|
|
917 |
|
|
918 |
test006
|
|
919 |
"patt. input match-expected matched-expression
|
|
920 |
^abc$ abc y & abc
|
|
921 |
^abc$ abcc n - -
|
|
922 |
^abc$ aabc n - -
|
|
923 |
"
|
1868
|
924 |
|
1865
|
925 |
|matcher|
|
|
926 |
|
1868
|
927 |
self
|
2409
|
928 |
should:[ (matcher := self compileRegex:'^abc$' into:self matcherClass) ~= nil ].
|
1865
|
929 |
self should:[ (matcher search:'abc') = true ].
|
|
930 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
931 |
self should:[ (matcher search:'abcc') = false ].
|
|
932 |
self should:[ (matcher search:'aabc') = false ].
|
|
933 |
|
|
934 |
"
|
|
935 |
self new test06
|
|
936 |
"
|
|
937 |
!
|
|
938 |
|
|
939 |
test007
|
|
940 |
"patt. input match-expected matched-expression
|
|
941 |
^abc abcc y & abc
|
|
942 |
"
|
1868
|
943 |
|
1865
|
944 |
|matcher|
|
|
945 |
|
1868
|
946 |
self
|
2409
|
947 |
should:[ (matcher := self compileRegex:'^abc' into:self matcherClass) ~= nil ].
|
1865
|
948 |
self should:[ (matcher search:'abcc') = true ].
|
|
949 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
950 |
|
|
951 |
"
|
|
952 |
self new test07
|
|
953 |
"
|
|
954 |
!
|
|
955 |
|
|
956 |
test008
|
|
957 |
"patt. input match-expected matched-expression
|
|
958 |
abc$ aabc y & abc
|
|
959 |
"
|
1868
|
960 |
|
1865
|
961 |
|matcher|
|
|
962 |
|
1868
|
963 |
self
|
2409
|
964 |
should:[ (matcher := self compileRegex:'abc$' into:self matcherClass) ~= nil ].
|
1865
|
965 |
self should:[ (matcher search:'aabc') = true ].
|
|
966 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
967 |
|
|
968 |
"
|
|
969 |
self new test08
|
|
970 |
"
|
|
971 |
!
|
|
972 |
|
|
973 |
test009
|
|
974 |
"patt. input match-expected matched-expression
|
1868
|
975 |
^ abc y &
|
1865
|
976 |
"
|
1868
|
977 |
|
1865
|
978 |
|matcher|
|
|
979 |
|
2409
|
980 |
self should:[ (matcher := self compileRegex:'^' into:self matcherClass) ~= nil ].
|
1865
|
981 |
self should:[ (matcher search:'abc') = true ].
|
|
982 |
|
|
983 |
"
|
|
984 |
self new test09
|
|
985 |
"
|
|
986 |
!
|
|
987 |
|
|
988 |
test010
|
|
989 |
"patt. input match-expected matched-expression
|
1868
|
990 |
$ abc y &
|
1865
|
991 |
"
|
1868
|
992 |
|
1865
|
993 |
|matcher|
|
|
994 |
|
2409
|
995 |
self should:[ (matcher := self compileRegex:'$' into:self matcherClass) ~= nil ].
|
1865
|
996 |
self should:[ (matcher search:'abc') = true ].
|
|
997 |
|
|
998 |
"
|
|
999 |
self new test10
|
|
1000 |
"
|
|
1001 |
!
|
|
1002 |
|
|
1003 |
test011
|
|
1004 |
|matcher|
|
|
1005 |
|
1868
|
1006 |
self
|
2409
|
1007 |
should:[ (matcher := self compileRegex:'a.c' into:self matcherClass) ~= nil ].
|
1865
|
1008 |
self should:[ (matcher search:'abc') = true ].
|
|
1009 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
1010 |
self should:[ (matcher search:'axc') = true ].
|
|
1011 |
self should:[ (matcher subexpression:1) = 'axc' ].
|
|
1012 |
!
|
|
1013 |
|
|
1014 |
test012
|
|
1015 |
|matcher|
|
|
1016 |
|
1868
|
1017 |
self
|
2409
|
1018 |
should:[ (matcher := self compileRegex:'a.*c' into:self matcherClass) ~= nil ].
|
1865
|
1019 |
self should:[ (matcher search:'axyzc') = true ].
|
|
1020 |
self should:[ (matcher subexpression:1) = 'axyzc' ].
|
|
1021 |
self should:[ (matcher search:'axy zc') = true ].
|
|
1022 |
self should:[ (matcher subexpression:1) = 'axy zc' ].
|
1868
|
1023 |
self
|
2409
|
1024 |
should:[
|
|
1025 |
(matcher search:'axy
|
|
1026 |
zc')
|
|
1027 |
= false
|
|
1028 |
].
|
1865
|
1029 |
self should:[ (matcher search:'axyzd') = false ].
|
|
1030 |
!
|
|
1031 |
|
|
1032 |
test013
|
|
1033 |
|matcher|
|
|
1034 |
|
1868
|
1035 |
self
|
2409
|
1036 |
should:[ (matcher := self compileRegex:'.a.*' into:self matcherClass) ~= nil ].
|
1865
|
1037 |
self should:[ (matcher search:'1234abc') = true ].
|
|
1038 |
self should:[ (matcher subexpression:1) = '4abc' ].
|
|
1039 |
self should:[ (matcher search:'abcd') = false ].
|
|
1040 |
!
|
|
1041 |
|
|
1042 |
test014
|
|
1043 |
|matcher|
|
|
1044 |
|
1868
|
1045 |
self
|
2409
|
1046 |
should:[ (matcher := self compileRegex:'a\w+c' into:self matcherClass) ~= nil ].
|
1865
|
1047 |
self should:[ (matcher search:' abbbbc ') = true ].
|
|
1048 |
self should:[ (matcher subexpression:1) = 'abbbbc' ].
|
|
1049 |
self should:[ (matcher search:'abb bc') = false ].
|
|
1050 |
!
|
|
1051 |
|
|
1052 |
test015
|
|
1053 |
|matcher|
|
|
1054 |
|
1868
|
1055 |
self
|
2409
|
1056 |
should:[ (matcher := self compileRegex:'\w+' into:self matcherClass) ~= nil ].
|
1865
|
1057 |
self should:[ (matcher search:' foobar quux') = true ].
|
|
1058 |
self should:[ (matcher subexpression:1) = 'foobar' ].
|
|
1059 |
self should:[ (matcher search:' ~!!@#$%^&*()-+=\|/?.>,<') = false ].
|
|
1060 |
!
|
|
1061 |
|
|
1062 |
test016
|
|
1063 |
|matcher|
|
|
1064 |
|
1868
|
1065 |
self
|
2409
|
1066 |
should:[ (matcher := self compileRegex:'a\W+c' into:self matcherClass) ~= nil ].
|
1865
|
1067 |
self should:[ (matcher search:'a c') = true ].
|
|
1068 |
self should:[ (matcher subexpression:1) = 'a c' ].
|
|
1069 |
self should:[ (matcher search:'a bc') = false ].
|
|
1070 |
!
|
|
1071 |
|
|
1072 |
test017
|
|
1073 |
|matcher|
|
|
1074 |
|
1868
|
1075 |
self
|
2409
|
1076 |
should:[ (matcher := self compileRegex:'\W+' into:self matcherClass) ~= nil ].
|
1865
|
1077 |
self should:[ (matcher search:'foo!!@#$bar') = true ].
|
|
1078 |
self should:[ (matcher subexpression:1) = '!!@#$' ].
|
|
1079 |
self should:[ (matcher search:'foobar') = false ].
|
|
1080 |
!
|
|
1081 |
|
|
1082 |
test018
|
|
1083 |
|matcher|
|
|
1084 |
|
1868
|
1085 |
self
|
2409
|
1086 |
should:[ (matcher := self compileRegex:'a\s*c' into:self matcherClass) ~= nil ].
|
1865
|
1087 |
self should:[ (matcher search:'a c') = true ].
|
|
1088 |
self should:[ (matcher subexpression:1) = 'a c' ].
|
|
1089 |
self should:[ (matcher search:'a bc') = false ].
|
|
1090 |
!
|
|
1091 |
|
|
1092 |
test019
|
|
1093 |
|matcher|
|
|
1094 |
|
1868
|
1095 |
self
|
2409
|
1096 |
should:[ (matcher := self compileRegex:'\s+' into:self matcherClass) ~= nil ].
|
1865
|
1097 |
self should:[ (matcher search:'abc3457 sd') = true ].
|
|
1098 |
self should:[ (matcher subexpression:1) = ' ' ].
|
|
1099 |
self should:[ (matcher search:'1234$^*^&asdfb') = false ].
|
|
1100 |
!
|
|
1101 |
|
|
1102 |
test020
|
|
1103 |
|matcher|
|
|
1104 |
|
1868
|
1105 |
self
|
2409
|
1106 |
should:[ (matcher := self compileRegex:'a\S*c' into:self matcherClass) ~= nil ].
|
1865
|
1107 |
self should:[ (matcher search:'aqwertyc') = true ].
|
|
1108 |
self should:[ (matcher subexpression:1) = 'aqwertyc' ].
|
|
1109 |
self should:[ (matcher search:'ab c') = false ].
|
|
1110 |
!
|
|
1111 |
|
|
1112 |
test021
|
|
1113 |
|matcher|
|
|
1114 |
|
1868
|
1115 |
self
|
2409
|
1116 |
should:[ (matcher := self compileRegex:'\S+' into:self matcherClass) ~= nil ].
|
1865
|
1117 |
self should:[ (matcher search:' asdf ') = true ].
|
|
1118 |
self should:[ (matcher subexpression:1) = 'asdf' ].
|
1868
|
1119 |
self
|
2409
|
1120 |
should:[ (matcher search:'
|
|
1121 |
') = false ].
|
1865
|
1122 |
!
|
|
1123 |
|
|
1124 |
test022
|
|
1125 |
|matcher|
|
|
1126 |
|
1868
|
1127 |
self
|
2409
|
1128 |
should:[ (matcher := self compileRegex:'a\d+c' into:self matcherClass) ~= nil ].
|
1865
|
1129 |
self should:[ (matcher search:'a0123456789c') = true ].
|
|
1130 |
self should:[ (matcher subexpression:1) = 'a0123456789c' ].
|
|
1131 |
self should:[ (matcher search:'a12b34c') = false ].
|
|
1132 |
!
|
|
1133 |
|
|
1134 |
test023
|
|
1135 |
|matcher|
|
|
1136 |
|
1868
|
1137 |
self
|
2409
|
1138 |
should:[ (matcher := self compileRegex:'\d+' into:self matcherClass) ~= nil ].
|
1865
|
1139 |
self should:[ (matcher search:'foo@#$%123ASD #$$%^&') = true ].
|
|
1140 |
self should:[ (matcher subexpression:1) = '123' ].
|
|
1141 |
self should:[ (matcher search:'foo!!@#$asdfl;') = false ].
|
|
1142 |
!
|
|
1143 |
|
|
1144 |
test024
|
|
1145 |
|matcher|
|
|
1146 |
|
1868
|
1147 |
self
|
2409
|
1148 |
should:[ (matcher := self compileRegex:'a\D+c' into:self matcherClass) ~= nil ].
|
1865
|
1149 |
self should:[ (matcher search:'aqwertyc') = true ].
|
|
1150 |
self should:[ (matcher subexpression:1) = 'aqwertyc' ].
|
|
1151 |
self should:[ (matcher search:'aqw6ertc') = false ].
|
|
1152 |
!
|
|
1153 |
|
|
1154 |
test025
|
|
1155 |
|matcher|
|
|
1156 |
|
1868
|
1157 |
self
|
2409
|
1158 |
should:[ (matcher := self compileRegex:'\D+' into:self matcherClass) ~= nil ].
|
1865
|
1159 |
self should:[ (matcher search:'1234 abc 456') = true ].
|
|
1160 |
self should:[ (matcher subexpression:1) = ' abc ' ].
|
|
1161 |
self should:[ (matcher search:'1234567890') = false ].
|
|
1162 |
!
|
|
1163 |
|
|
1164 |
test026
|
|
1165 |
|matcher|
|
|
1166 |
|
1868
|
1167 |
self
|
2409
|
1168 |
should:[ (matcher := self compileRegex:'(f|o)+\b' into:self matcherClass) ~= nil ].
|
1865
|
1169 |
self should:[ (matcher search:'foo') = true ].
|
|
1170 |
self should:[ (matcher subexpression:1) = 'foo' ].
|
|
1171 |
self should:[ (matcher search:' foo ') = true ].
|
|
1172 |
self should:[ (matcher subexpression:1) = 'foo' ].
|
|
1173 |
!
|
|
1174 |
|
|
1175 |
test027
|
|
1176 |
|matcher|
|
|
1177 |
|
1868
|
1178 |
self
|
2409
|
1179 |
should:[ (matcher := self compileRegex:'\ba\w+' into:self matcherClass) ~= nil ].
|
1865
|
1180 |
self should:[ (matcher search:'land ancient') = true ].
|
|
1181 |
self should:[ (matcher subexpression:1) = 'ancient' ].
|
|
1182 |
self should:[ (matcher search:'antique vase') = true ].
|
|
1183 |
self should:[ (matcher subexpression:1) = 'antique' ].
|
|
1184 |
self should:[ (matcher search:'goofy foobar') = false ].
|
|
1185 |
!
|
|
1186 |
|
|
1187 |
test028
|
|
1188 |
|matcher|
|
|
1189 |
|
1868
|
1190 |
self
|
2409
|
1191 |
should:[ (matcher := self compileRegex:'(f|o)+\B' into:self matcherClass) ~= nil ].
|
1865
|
1192 |
self should:[ (matcher search:'quuxfoobar') = true ].
|
|
1193 |
self should:[ (matcher subexpression:1) = 'foo' ].
|
|
1194 |
self should:[ (matcher search:'quuxfoo ') = true ].
|
|
1195 |
self should:[ (matcher subexpression:1) = 'fo' ].
|
|
1196 |
!
|
|
1197 |
|
|
1198 |
test029
|
|
1199 |
|matcher|
|
|
1200 |
|
1868
|
1201 |
self
|
2409
|
1202 |
should:[ (matcher := self compileRegex:'\Ba\w+' into:self matcherClass) ~= nil ].
|
1865
|
1203 |
self should:[ (matcher search:'land ancient') = true ].
|
|
1204 |
self should:[ (matcher subexpression:1) = 'and' ].
|
|
1205 |
self should:[ (matcher search:'antique vase') = true ].
|
|
1206 |
self should:[ (matcher subexpression:1) = 'ase' ].
|
|
1207 |
self should:[ (matcher search:'smalltalk shall overcome') = true ].
|
|
1208 |
self should:[ (matcher subexpression:1) = 'alltalk' ].
|
|
1209 |
self should:[ (matcher search:'foonix is better') = false ].
|
|
1210 |
!
|
|
1211 |
|
|
1212 |
test030
|
|
1213 |
|matcher|
|
|
1214 |
|
1868
|
1215 |
self
|
2409
|
1216 |
should:[ (matcher := self compileRegex:'fooa\>.*' into:self matcherClass) ~= nil ].
|
1865
|
1217 |
self should:[ (matcher search:'fooa ') = true ].
|
|
1218 |
self should:[ (matcher search:'fooa123') = false ].
|
|
1219 |
self should:[ (matcher search:'fooa bar') = true ].
|
|
1220 |
self should:[ (matcher search:'fooa') = true ].
|
|
1221 |
self should:[ (matcher search:'fooargh') = false ].
|
|
1222 |
!
|
|
1223 |
|
|
1224 |
test031
|
|
1225 |
|matcher|
|
|
1226 |
|
1868
|
1227 |
self
|
2409
|
1228 |
should:[ (matcher := self compileRegex:'\>.+abc' into:self matcherClass) ~= nil ].
|
1865
|
1229 |
self should:[ (matcher search:' abcde fg') = false ].
|
|
1230 |
self should:[ (matcher search:'foo abcde') = true ].
|
|
1231 |
self should:[ (matcher subexpression:1) = ' abc' ].
|
|
1232 |
self should:[ (matcher search:'abcde') = false ].
|
|
1233 |
!
|
|
1234 |
|
|
1235 |
test032
|
|
1236 |
|matcher|
|
|
1237 |
|
1868
|
1238 |
self
|
2409
|
1239 |
should:[ (matcher := self compileRegex:'\<foo.*' into:self matcherClass) ~= nil ].
|
1865
|
1240 |
self should:[ (matcher search:'foo') = true ].
|
|
1241 |
self should:[ (matcher search:'foobar') = true ].
|
|
1242 |
self should:[ (matcher search:'qfoobarq foonix') = true ].
|
|
1243 |
self should:[ (matcher subexpression:1) = 'foonix' ].
|
|
1244 |
self should:[ (matcher search:' foo') = true ].
|
|
1245 |
self should:[ (matcher search:' 12foo') = false ].
|
|
1246 |
self should:[ (matcher search:'barfoo') = false ].
|
|
1247 |
!
|
|
1248 |
|
|
1249 |
test033
|
|
1250 |
|matcher|
|
|
1251 |
|
1868
|
1252 |
self
|
2409
|
1253 |
should:[ (matcher := self compileRegex:'.+\<foo' into:self matcherClass) ~= nil ].
|
1865
|
1254 |
self should:[ (matcher search:'foo') = false ].
|
|
1255 |
self should:[ (matcher search:'ab foo') = true ].
|
|
1256 |
self should:[ (matcher subexpression:1) = 'ab foo' ].
|
|
1257 |
self should:[ (matcher search:'abfoo') = false ].
|
|
1258 |
!
|
|
1259 |
|
|
1260 |
test034
|
|
1261 |
|matcher|
|
|
1262 |
|
1868
|
1263 |
self
|
2409
|
1264 |
should:[ (matcher := self compileRegex:'a[bc]d' into:self matcherClass) ~= nil ].
|
1865
|
1265 |
self should:[ (matcher search:'abc') = false ].
|
|
1266 |
self should:[ (matcher search:'abd') = true ].
|
|
1267 |
self should:[ (matcher subexpression:1) = 'abd' ].
|
|
1268 |
!
|
|
1269 |
|
|
1270 |
test035
|
|
1271 |
|matcher|
|
|
1272 |
|
1868
|
1273 |
self
|
2409
|
1274 |
should:[ (matcher := self compileRegex:'a[b-d]e' into:self matcherClass) ~= nil ].
|
1865
|
1275 |
self should:[ (matcher search:'abd') = false ].
|
|
1276 |
self should:[ (matcher search:'ace') = true ].
|
|
1277 |
self should:[ (matcher subexpression:1) = 'ace' ].
|
|
1278 |
!
|
|
1279 |
|
|
1280 |
test036
|
|
1281 |
|matcher|
|
|
1282 |
|
1868
|
1283 |
self
|
2409
|
1284 |
should:[ (matcher := self compileRegex:'a[b-d]' into:self matcherClass) ~= nil ].
|
1865
|
1285 |
self should:[ (matcher search:'aac') = true ].
|
|
1286 |
self should:[ (matcher subexpression:1) = 'ac' ].
|
|
1287 |
!
|
|
1288 |
|
|
1289 |
test037
|
|
1290 |
|matcher|
|
|
1291 |
|
1868
|
1292 |
self
|
2409
|
1293 |
should:[ (matcher := self compileRegex:'a[-b]' into:self matcherClass) ~= nil ].
|
1865
|
1294 |
self should:[ (matcher search:'a-') = true ].
|
|
1295 |
self should:[ (matcher subexpression:1) = 'a-' ].
|
|
1296 |
!
|
|
1297 |
|
|
1298 |
test038
|
|
1299 |
|matcher|
|
|
1300 |
|
1868
|
1301 |
self
|
2409
|
1302 |
should:[ (matcher := self compileRegex:'a[b-]' into:self matcherClass) ~= nil ].
|
1865
|
1303 |
self should:[ (matcher search:'a-') = true ].
|
|
1304 |
self should:[ (matcher subexpression:1) = 'a-' ].
|
|
1305 |
!
|
|
1306 |
|
|
1307 |
test039
|
|
1308 |
|matcher|
|
|
1309 |
|
1868
|
1310 |
self
|
2409
|
1311 |
should:[ (matcher := self compileRegex:'a[a-b-c]' into:self matcherClass) = nil ].
|
1865
|
1312 |
!
|
|
1313 |
|
|
1314 |
test040
|
|
1315 |
|matcher|
|
|
1316 |
|
1868
|
1317 |
self
|
2409
|
1318 |
should:[ (matcher := self compileRegex:'[k]' into:self matcherClass) ~= nil ].
|
1865
|
1319 |
self should:[ (matcher search:'ab') = false ].
|
|
1320 |
!
|
|
1321 |
|
|
1322 |
test041
|
|
1323 |
|matcher|
|
|
1324 |
|
1868
|
1325 |
self
|
2409
|
1326 |
should:[ (matcher := self compileRegex:'a[b-a]' into:self matcherClass) = nil ].
|
1865
|
1327 |
!
|
|
1328 |
|
|
1329 |
test042
|
|
1330 |
|matcher|
|
|
1331 |
|
1868
|
1332 |
self
|
2409
|
1333 |
should:[ (matcher := self compileRegex:'a[]b' into:self matcherClass) = nil ].
|
1865
|
1334 |
!
|
|
1335 |
|
|
1336 |
test043
|
|
1337 |
|matcher|
|
|
1338 |
|
2409
|
1339 |
self should:[ (matcher := self compileRegex:'a[' into:self matcherClass) = nil ].
|
1865
|
1340 |
!
|
|
1341 |
|
|
1342 |
test044
|
|
1343 |
|matcher|
|
|
1344 |
|
2409
|
1345 |
self should:[ (matcher := self compileRegex:'a]' into:self matcherClass) ~= nil ].
|
1865
|
1346 |
self should:[ (matcher search:'a]') = true ].
|
|
1347 |
self should:[ (matcher subexpression:1) = 'a]' ].
|
|
1348 |
!
|
|
1349 |
|
|
1350 |
test045
|
|
1351 |
|matcher|
|
|
1352 |
|
1868
|
1353 |
self
|
2409
|
1354 |
should:[ (matcher := self compileRegex:'a[]]b' into:self matcherClass) ~= nil ].
|
1865
|
1355 |
self should:[ (matcher search:'a]b') = true ].
|
|
1356 |
self should:[ (matcher subexpression:1) = 'a]b' ].
|
|
1357 |
!
|
|
1358 |
|
|
1359 |
test046
|
|
1360 |
|matcher|
|
|
1361 |
|
1868
|
1362 |
self
|
2409
|
1363 |
should:[ (matcher := self compileRegex:'a[^bc]d' into:self matcherClass) ~= nil ].
|
1865
|
1364 |
self should:[ (matcher search:'aed') = true ].
|
|
1365 |
self should:[ (matcher subexpression:1) = 'aed' ].
|
|
1366 |
self should:[ (matcher search:'abd') = false ].
|
|
1367 |
!
|
|
1368 |
|
|
1369 |
test047
|
|
1370 |
|matcher|
|
|
1371 |
|
1868
|
1372 |
self
|
2409
|
1373 |
should:[ (matcher := self compileRegex:'a[^-b]c' into:self matcherClass) ~= nil ].
|
1865
|
1374 |
self should:[ (matcher search:'adc') = true ].
|
|
1375 |
self should:[ (matcher subexpression:1) = 'adc' ].
|
|
1376 |
self should:[ (matcher search:'a-c') = false ].
|
|
1377 |
!
|
|
1378 |
|
|
1379 |
test048
|
|
1380 |
|matcher|
|
|
1381 |
|
1868
|
1382 |
self
|
2409
|
1383 |
should:[ (matcher := self compileRegex:'a[^]b]c' into:self matcherClass) ~= nil ].
|
1865
|
1384 |
self should:[ (matcher search:'a]c') = false ].
|
|
1385 |
self should:[ (matcher search:'adc') = true ].
|
|
1386 |
self should:[ (matcher subexpression:1) = 'adc' ].
|
|
1387 |
!
|
|
1388 |
|
|
1389 |
test049
|
|
1390 |
|matcher|
|
|
1391 |
|
1868
|
1392 |
self
|
2409
|
1393 |
should:[ (matcher := self compileRegex:'[\de]+' into:self matcherClass) ~= nil ].
|
1865
|
1394 |
self should:[ (matcher search:'01234') = true ].
|
|
1395 |
self should:[ (matcher subexpression:1) = '01234' ].
|
|
1396 |
self should:[ (matcher search:'0123e456') = true ].
|
|
1397 |
self should:[ (matcher subexpression:1) = '0123e456' ].
|
|
1398 |
self should:[ (matcher search:'0123e45g78') = true ].
|
|
1399 |
self should:[ (matcher subexpression:1) = '0123e45' ].
|
|
1400 |
!
|
|
1401 |
|
|
1402 |
test050
|
|
1403 |
|matcher|
|
|
1404 |
|
1868
|
1405 |
self
|
2409
|
1406 |
should:[ (matcher := self compileRegex:'[e\d]+' into:self matcherClass) ~= nil ].
|
1865
|
1407 |
self should:[ (matcher search:'01234') = true ].
|
|
1408 |
self should:[ (matcher subexpression:1) = '01234' ].
|
|
1409 |
self should:[ (matcher search:'0123e456') = true ].
|
|
1410 |
self should:[ (matcher subexpression:1) = '0123e456' ].
|
|
1411 |
self should:[ (matcher search:'0123e45g78') = true ].
|
|
1412 |
self should:[ (matcher subexpression:1) = '0123e45' ].
|
|
1413 |
!
|
|
1414 |
|
|
1415 |
test051
|
|
1416 |
|matcher|
|
|
1417 |
|
1868
|
1418 |
self
|
2409
|
1419 |
should:[ (matcher := self compileRegex:'[\D]+' into:self matcherClass) ~= nil ].
|
1865
|
1420 |
self should:[ (matcher search:'123abc45def78') = true ].
|
|
1421 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
1422 |
!
|
|
1423 |
|
|
1424 |
test052
|
|
1425 |
|matcher|
|
|
1426 |
|
1868
|
1427 |
self
|
2409
|
1428 |
should:[ (matcher := self compileRegex:'[[:digit:]e]+' into:self matcherClass) ~= nil ].
|
1865
|
1429 |
self should:[ (matcher search:'01234') = true ].
|
|
1430 |
self should:[ (matcher subexpression:1) = '01234' ].
|
|
1431 |
self should:[ (matcher search:'0123e456') = true ].
|
|
1432 |
self should:[ (matcher subexpression:1) = '0123e456' ].
|
|
1433 |
self should:[ (matcher search:'0123e45g78') = true ].
|
|
1434 |
self should:[ (matcher subexpression:1) = '0123e45' ].
|
|
1435 |
!
|
|
1436 |
|
|
1437 |
test053
|
|
1438 |
|matcher|
|
|
1439 |
|
1868
|
1440 |
self
|
2409
|
1441 |
should:[ (matcher := self compileRegex:'[\s]+' into:self matcherClass) ~= nil ].
|
1865
|
1442 |
self should:[ (matcher search:'2 spaces') = true ].
|
|
1443 |
self should:[ (matcher subexpression:1) = ' ' ].
|
|
1444 |
!
|
|
1445 |
|
|
1446 |
test054
|
|
1447 |
|matcher|
|
|
1448 |
|
1868
|
1449 |
self
|
2409
|
1450 |
should:[ (matcher := self compileRegex:'[\S]+' into:self matcherClass) ~= nil ].
|
1865
|
1451 |
self should:[ (matcher search:' word12!!@#$ ') = true ].
|
|
1452 |
self should:[ (matcher subexpression:1) = 'word12!!@#$' ].
|
|
1453 |
!
|
|
1454 |
|
|
1455 |
test055
|
|
1456 |
|matcher|
|
|
1457 |
|
1868
|
1458 |
self
|
2409
|
1459 |
should:[ (matcher := self compileRegex:'[\w]+' into:self matcherClass) ~= nil ].
|
1865
|
1460 |
self should:[ (matcher search:' foo123bar 45') = true ].
|
|
1461 |
self should:[ (matcher subexpression:1) = 'foo123bar' ].
|
|
1462 |
!
|
|
1463 |
|
|
1464 |
test056
|
|
1465 |
|matcher|
|
|
1466 |
|
1868
|
1467 |
self
|
2409
|
1468 |
should:[ (matcher := self compileRegex:'[\W]+' into:self matcherClass) ~= nil ].
|
1865
|
1469 |
self should:[ (matcher search:'fii234!!@#$34f') = true ].
|
|
1470 |
self should:[ (matcher subexpression:1) = '!!@#$' ].
|
|
1471 |
!
|
|
1472 |
|
|
1473 |
test057
|
|
1474 |
|matcher|
|
|
1475 |
|
1868
|
1476 |
self
|
2409
|
1477 |
should:[ (matcher := self compileRegex:'[^[:alnum:]]+' into:self matcherClass) ~= nil ].
|
1865
|
1478 |
self should:[ (matcher search:'fii234!!@#$34f') = true ].
|
|
1479 |
self should:[ (matcher subexpression:1) = '!!@#$' ].
|
|
1480 |
!
|
|
1481 |
|
|
1482 |
test058
|
|
1483 |
|matcher|
|
|
1484 |
|
1868
|
1485 |
self
|
|
1486 |
should:[
|
2409
|
1487 |
(matcher := self compileRegex:'[%&[:alnum:]]+' into:self matcherClass) ~= nil
|
1868
|
1488 |
].
|
1865
|
1489 |
self should:[ (matcher search:'foo%3') = true ].
|
|
1490 |
self should:[ (matcher subexpression:1) = 'foo%3' ].
|
|
1491 |
self should:[ (matcher search:'foo34&rt4$57a') = true ].
|
|
1492 |
self should:[ (matcher subexpression:1) = 'foo34&rt4' ].
|
|
1493 |
self should:[ (matcher search:'!!@#$') = false ].
|
|
1494 |
!
|
|
1495 |
|
|
1496 |
test059
|
|
1497 |
|matcher|
|
|
1498 |
|
1868
|
1499 |
self
|
2409
|
1500 |
should:[ (matcher := self compileRegex:'[[:alpha:]]+' into:self matcherClass) ~= nil ].
|
1865
|
1501 |
self should:[ (matcher search:' 123foo3 ') = true ].
|
|
1502 |
self should:[ (matcher subexpression:1) = 'foo' ].
|
|
1503 |
self should:[ (matcher search:'123foo') = true ].
|
|
1504 |
self should:[ (matcher subexpression:1) = 'foo' ].
|
|
1505 |
self should:[ (matcher search:'foo1b') = true ].
|
|
1506 |
self should:[ (matcher subexpression:1) = 'foo' ].
|
|
1507 |
!
|
|
1508 |
|
|
1509 |
test060
|
|
1510 |
|matcher|
|
|
1511 |
|
1868
|
1512 |
self
|
2409
|
1513 |
should:[ (matcher := self compileRegex:'[[:cntrl:]]+' into:self matcherClass) ~= nil ].
|
1865
|
1514 |
self should:[ (matcher search:' a 1234asdf') = false ].
|
|
1515 |
!
|
|
1516 |
|
|
1517 |
test061
|
|
1518 |
|matcher|
|
|
1519 |
|
1868
|
1520 |
self
|
2409
|
1521 |
should:[ (matcher := self compileRegex:'[[:lower:]]+' into:self matcherClass) ~= nil ].
|
1865
|
1522 |
self should:[ (matcher search:'UPPERlower1234') = true ].
|
|
1523 |
self should:[ (matcher subexpression:1) = 'lower' ].
|
|
1524 |
self should:[ (matcher search:'lowerUPPER') = true ].
|
|
1525 |
self should:[ (matcher subexpression:1) = 'lower' ].
|
|
1526 |
!
|
|
1527 |
|
|
1528 |
test062
|
|
1529 |
|matcher|
|
|
1530 |
|
1868
|
1531 |
self
|
2409
|
1532 |
should:[ (matcher := self compileRegex:'[[:upper:]]+' into:self matcherClass) ~= nil ].
|
1865
|
1533 |
self should:[ (matcher search:'UPPERlower1234') = true ].
|
|
1534 |
self should:[ (matcher subexpression:1) = 'UPPER' ].
|
|
1535 |
self should:[ (matcher search:'lowerUPPER ') = true ].
|
|
1536 |
self should:[ (matcher subexpression:1) = 'UPPER' ].
|
|
1537 |
!
|
|
1538 |
|
|
1539 |
test063
|
|
1540 |
|matcher|
|
|
1541 |
|
1868
|
1542 |
self
|
2409
|
1543 |
should:[ (matcher := self compileRegex:'[[:space:]]+' into:self matcherClass) ~= nil ].
|
1865
|
1544 |
self should:[ (matcher search:'2 spaces') = true ].
|
|
1545 |
self should:[ (matcher subexpression:1) = ' ' ].
|
|
1546 |
!
|
|
1547 |
|
|
1548 |
test064
|
|
1549 |
|matcher|
|
|
1550 |
|
1868
|
1551 |
self
|
2409
|
1552 |
should:[ (matcher := self compileRegex:'[^[:space:]]+' into:self matcherClass) ~= nil ].
|
1865
|
1553 |
self should:[ (matcher search:' word12!!@#$ ') = true ].
|
|
1554 |
self should:[ (matcher subexpression:1) = 'word12!!@#$' ].
|
|
1555 |
!
|
|
1556 |
|
|
1557 |
test065
|
|
1558 |
|matcher|
|
|
1559 |
|
1868
|
1560 |
self
|
2409
|
1561 |
should:[ (matcher := self compileRegex:'[[:graph:]]+' into:self matcherClass) ~= nil ].
|
1865
|
1562 |
self should:[ (matcher search:'abc') = true ].
|
|
1563 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
1564 |
!
|
|
1565 |
|
|
1566 |
test066
|
|
1567 |
|matcher|
|
|
1568 |
|
1868
|
1569 |
self
|
2409
|
1570 |
should:[ (matcher := self compileRegex:'[[:print:]]+' into:self matcherClass) ~= nil ].
|
1865
|
1571 |
self should:[ (matcher search:'abc') = true ].
|
|
1572 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
1573 |
!
|
|
1574 |
|
|
1575 |
test067
|
|
1576 |
|matcher|
|
|
1577 |
|
1868
|
1578 |
self
|
2409
|
1579 |
should:[ (matcher := self compileRegex:'[^[:punct:]]+' into:self matcherClass) ~= nil ].
|
1865
|
1580 |
self should:[ (matcher search:'!!hello,world!!') = true ].
|
|
1581 |
self should:[ (matcher subexpression:1) = 'hello' ].
|
|
1582 |
!
|
|
1583 |
|
|
1584 |
test068
|
|
1585 |
|matcher|
|
|
1586 |
|
1868
|
1587 |
self
|
2409
|
1588 |
should:[ (matcher := self compileRegex:'[[:xdigit:]]+' into:self matcherClass) ~= nil ].
|
1865
|
1589 |
self should:[ (matcher search:' x10FCD ') = true ].
|
|
1590 |
self should:[ (matcher subexpression:1) = '10FCD' ].
|
|
1591 |
self should:[ (matcher search:' hgfedcba0123456789ABCDEFGH ') = true ].
|
|
1592 |
self should:[ (matcher subexpression:1) = 'fedcba0123456789ABCDEF' ].
|
|
1593 |
!
|
|
1594 |
|
|
1595 |
test069
|
|
1596 |
|matcher|
|
|
1597 |
|
1868
|
1598 |
self
|
2409
|
1599 |
should:[ (matcher := self compileRegex:'ab|cd' into:self matcherClass) ~= nil ].
|
1865
|
1600 |
self should:[ (matcher search:'abc') = true ].
|
|
1601 |
self should:[ (matcher subexpression:1) = 'ab' ].
|
|
1602 |
self should:[ (matcher search:'abcd') = true ].
|
|
1603 |
self should:[ (matcher subexpression:1) = 'ab' ].
|
|
1604 |
!
|
|
1605 |
|
|
1606 |
test070
|
|
1607 |
|matcher|
|
|
1608 |
|
1868
|
1609 |
self
|
2409
|
1610 |
should:[ (matcher := self compileRegex:'()ef' into:self matcherClass) ~= nil ].
|
1865
|
1611 |
self should:[ (matcher search:'def') = true ].
|
|
1612 |
self should:[ (matcher subexpression:1) = 'ef' ].
|
|
1613 |
self should:[ (matcher subexpression:2) = '' ].
|
|
1614 |
!
|
|
1615 |
|
|
1616 |
test071
|
|
1617 |
|matcher|
|
|
1618 |
|
2409
|
1619 |
self should:[ (matcher := self compileRegex:'()*' into:self matcherClass) = nil ].
|
1865
|
1620 |
!
|
|
1621 |
|
|
1622 |
test072
|
|
1623 |
|matcher|
|
|
1624 |
|
2409
|
1625 |
self should:[ (matcher := self compileRegex:'*a' into:self matcherClass) = nil ].
|
1865
|
1626 |
!
|
|
1627 |
|
|
1628 |
test073
|
|
1629 |
|matcher|
|
|
1630 |
|
2409
|
1631 |
self should:[ (matcher := self compileRegex:'^*' into:self matcherClass) = nil ].
|
1865
|
1632 |
!
|
|
1633 |
|
|
1634 |
test074
|
|
1635 |
|matcher|
|
|
1636 |
|
2409
|
1637 |
self should:[ (matcher := self compileRegex:'$*' into:self matcherClass) = nil ].
|
1865
|
1638 |
!
|
|
1639 |
|
|
1640 |
test075
|
|
1641 |
|matcher|
|
|
1642 |
|
1868
|
1643 |
self
|
2409
|
1644 |
should:[ (matcher := self compileRegex:'(*)b' into:self matcherClass) = nil ].
|
1865
|
1645 |
!
|
|
1646 |
|
|
1647 |
test076
|
|
1648 |
|matcher|
|
|
1649 |
|
2409
|
1650 |
self should:[ (matcher := self compileRegex:'$b' into:self matcherClass) ~= nil ].
|
1865
|
1651 |
self should:[ (matcher search:'b') = false ].
|
|
1652 |
!
|
|
1653 |
|
|
1654 |
test077
|
|
1655 |
|matcher|
|
|
1656 |
|
2409
|
1657 |
self should:[ (matcher := self compileRegex:'a\' into:self matcherClass) = nil ].
|
1865
|
1658 |
!
|
|
1659 |
|
|
1660 |
test078
|
|
1661 |
|matcher|
|
|
1662 |
|
1868
|
1663 |
self
|
2409
|
1664 |
should:[ (matcher := self compileRegex:'a\(b' into:self matcherClass) ~= nil ].
|
1865
|
1665 |
self should:[ (matcher search:'a(b') = true ].
|
|
1666 |
self should:[ (matcher subexpression:1) = 'a(b' ].
|
|
1667 |
!
|
|
1668 |
|
|
1669 |
test079
|
|
1670 |
|matcher|
|
|
1671 |
|
1868
|
1672 |
self
|
2409
|
1673 |
should:[ (matcher := self compileRegex:'a\(*b' into:self matcherClass) ~= nil ].
|
1865
|
1674 |
self should:[ (matcher search:'ab') = true ].
|
|
1675 |
self should:[ (matcher subexpression:1) = 'ab' ].
|
|
1676 |
self should:[ (matcher search:'a((b') = true ].
|
|
1677 |
self should:[ (matcher subexpression:1) = 'a((b' ].
|
|
1678 |
!
|
|
1679 |
|
|
1680 |
test080
|
|
1681 |
|matcher|
|
|
1682 |
|
1868
|
1683 |
self
|
2409
|
1684 |
should:[ (matcher := self compileRegex:'a\\b' into:self matcherClass) ~= nil ].
|
1865
|
1685 |
self should:[ (matcher search:'a\b') = true ].
|
|
1686 |
self should:[ (matcher subexpression:1) = 'a\b' ].
|
|
1687 |
!
|
|
1688 |
|
|
1689 |
test081
|
|
1690 |
|matcher|
|
|
1691 |
|
1868
|
1692 |
self
|
2409
|
1693 |
should:[ (matcher := self compileRegex:'abc)' into:self matcherClass) = nil ].
|
1865
|
1694 |
!
|
|
1695 |
|
|
1696 |
test082
|
|
1697 |
|matcher|
|
|
1698 |
|
1868
|
1699 |
self
|
2409
|
1700 |
should:[ (matcher := self compileRegex:'(abc' into:self matcherClass) = nil ].
|
1865
|
1701 |
!
|
|
1702 |
|
|
1703 |
test083
|
|
1704 |
|matcher|
|
|
1705 |
|
1868
|
1706 |
self
|
2409
|
1707 |
should:[ (matcher := self compileRegex:'((a))' into:self matcherClass) ~= nil ].
|
1865
|
1708 |
self should:[ (matcher search:'abc') = true ].
|
|
1709 |
self should:[ (matcher subexpression:1) = 'a' ].
|
|
1710 |
self should:[ (matcher subexpression:2) = 'a' ].
|
|
1711 |
self should:[ (matcher subexpression:3) = 'a' ].
|
|
1712 |
!
|
|
1713 |
|
|
1714 |
test084
|
|
1715 |
|matcher|
|
|
1716 |
|
1868
|
1717 |
self
|
2409
|
1718 |
should:[ (matcher := self compileRegex:'(a)b(c)' into:self matcherClass) ~= nil ].
|
1865
|
1719 |
self should:[ (matcher search:'abc') = true ].
|
|
1720 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
1721 |
self should:[ (matcher subexpression:2) = 'a' ].
|
|
1722 |
self should:[ (matcher subexpression:3) = 'c' ].
|
|
1723 |
!
|
|
1724 |
|
|
1725 |
test085
|
|
1726 |
|matcher|
|
|
1727 |
|
1868
|
1728 |
self
|
2409
|
1729 |
should:[ (matcher := self compileRegex:'a+b+c' into:self matcherClass) ~= nil ].
|
1865
|
1730 |
self should:[ (matcher search:'aabbabc') = true ].
|
|
1731 |
self should:[ (matcher subexpression:1) = 'abc' ].
|
|
1732 |
!
|
|
1733 |
|
|
1734 |
test086
|
|
1735 |
|matcher|
|
|
1736 |
|
2409
|
1737 |
self should:[ (matcher := self compileRegex:'a**' into:self matcherClass) = nil ].
|
1865
|
1738 |
!
|
|
1739 |
|
|
1740 |
test087
|
|
1741 |
|matcher|
|
|
1742 |
|
2409
|
1743 |
self should:[ (matcher := self compileRegex:'a*?' into:self matcherClass) = nil ].
|
1865
|
1744 |
!
|
|
1745 |
|
|
1746 |
test088
|
|
1747 |
|matcher|
|
|
1748 |
|
1868
|
1749 |
self
|
2409
|
1750 |
should:[ (matcher := self compileRegex:'(a*)*' into:self matcherClass) = nil ].
|
1865
|
1751 |
!
|
|
1752 |
|
|
1753 |
test089
|
|
1754 |
|matcher|
|
|
1755 |
|
1868
|
1756 |
self
|
2409
|
1757 |
should:[ (matcher := self compileRegex:'(a*)+' into:self matcherClass) = nil ].
|
1865
|
1758 |
!
|
|
1759 |
|
|
1760 |
test090
|
|
1761 |
|matcher|
|
|
1762 |
|
1868
|
1763 |
self
|
2409
|
1764 |
should:[ (matcher := self compileRegex:'(a|)*' into:self matcherClass) = nil ].
|
1865
|
1765 |
!
|
|
1766 |
|
|
1767 |
test091
|
|
1768 |
|matcher|
|
|
1769 |
|
1868
|
1770 |
self
|
2409
|
1771 |
should:[ (matcher := self compileRegex:'(a*|b)*' into:self matcherClass) = nil ].
|
1865
|
1772 |
!
|
|
1773 |
|
|
1774 |
test092
|
|
1775 |
|matcher|
|
|
1776 |
|
1868
|
1777 |
self
|
2409
|
1778 |
should:[ (matcher := self compileRegex:'(a+|b)*' into:self matcherClass) ~= nil ].
|
1865
|
1779 |
self should:[ (matcher search:'ab') = true ].
|
|
1780 |
self should:[ (matcher subexpression:1) = 'ab' ].
|
|
1781 |
self should:[ (matcher subexpression:2) = 'b' ].
|
|
1782 |
!
|
|
1783 |
|
|
1784 |
test093
|
|
1785 |
|matcher|
|
|
1786 |
|
1868
|
1787 |
self
|
2409
|
1788 |
should:[ (matcher := self compileRegex:'(a+|b)+' into:self matcherClass) ~= nil ].
|
1865
|
1789 |
self should:[ (matcher search:'ab') = true ].
|
|
1790 |
self should:[ (matcher subexpression:1) = 'ab' ].
|
|
1791 |
self should:[ (matcher subexpression:2) = 'b' ].
|
|
1792 |
!
|
|
1793 |
|
|
1794 |
test094
|
|
1795 |
|matcher|
|
|
1796 |
|
1868
|
1797 |
self
|
2409
|
1798 |
should:[ (matcher := self compileRegex:'(a+|b)?' into:self matcherClass) ~= nil ].
|
1865
|
1799 |
self should:[ (matcher search:'ab') = true ].
|
|
1800 |
self should:[ (matcher subexpression:1) = 'a' ].
|
|
1801 |
self should:[ (matcher subexpression:2) = 'a' ].
|
|
1802 |
!
|
|
1803 |
|
|
1804 |
test095
|
|
1805 |
|matcher|
|
|
1806 |
|
1868
|
1807 |
self
|
2409
|
1808 |
should:[ (matcher := self compileRegex:'[^ab]*' into:self matcherClass) ~= nil ].
|
1865
|
1809 |
self should:[ (matcher search:'cde') = true ].
|
|
1810 |
self should:[ (matcher subexpression:1) = 'cde' ].
|
|
1811 |
!
|
|
1812 |
|
|
1813 |
test096
|
|
1814 |
|matcher|
|
|
1815 |
|
1868
|
1816 |
self
|
2409
|
1817 |
should:[ (matcher := self compileRegex:'(^)*' into:self matcherClass) = nil ].
|
1865
|
1818 |
!
|
|
1819 |
|
|
1820 |
test097
|
|
1821 |
|matcher|
|
|
1822 |
|
1868
|
1823 |
self
|
2409
|
1824 |
should:[ (matcher := self compileRegex:'(ab|)*' into:self matcherClass) = nil ].
|
1865
|
1825 |
!
|
|
1826 |
|
|
1827 |
test098
|
|
1828 |
|matcher|
|
|
1829 |
|
2409
|
1830 |
self should:[ (matcher := self compileRegex:')(' into:self matcherClass) = nil ].
|
1865
|
1831 |
!
|
|
1832 |
|
|
1833 |
test099
|
|
1834 |
|matcher|
|
|
1835 |
|
2409
|
1836 |
self should:[ (matcher := self compileRegex:'' into:self matcherClass) ~= nil ].
|
1865
|
1837 |
self should:[ (matcher search:'abc') = true ].
|
|
1838 |
self should:[ (matcher subexpression:1) = '' ].
|
|
1839 |
!
|
|
1840 |
|
|
1841 |
test100
|
|
1842 |
| matcher |
|
|
1843 |
|
2409
|
1844 |
self should: [ (matcher := self compileRegex: 'abc' into:self matcherClass) ~= nil ].
|
1865
|
1845 |
self should: [ (matcher search: '') = false ].
|
|
1846 |
|
|
1847 |
"
|
|
1848 |
self new test100
|
|
1849 |
"
|
|
1850 |
!
|
|
1851 |
|
|
1852 |
test101
|
|
1853 |
| matcher |
|
|
1854 |
|
2409
|
1855 |
self should: [ (matcher := self compileRegex: 'a*' into:self matcherClass) ~= nil ].
|
1865
|
1856 |
self should: [ (matcher search: '') = true ].
|
|
1857 |
|
|
1858 |
"
|
|
1859 |
self new test101
|
|
1860 |
"
|
|
1861 |
!
|
|
1862 |
|
|
1863 |
test102
|
|
1864 |
| matcher |
|
|
1865 |
|
2409
|
1866 |
self should: [ (matcher := self compileRegex: 'abcd' into:self matcherClass) ~= nil ].
|
1865
|
1867 |
self should: [ (matcher search: 'abcd') = true ].
|
|
1868 |
self should: [ (matcher subexpression: 1) = 'abcd' ].
|
|
1869 |
|
|
1870 |
"
|
|
1871 |
self new test102
|
|
1872 |
"
|
|
1873 |
!
|
|
1874 |
|
|
1875 |
test103
|
|
1876 |
| matcher |
|
|
1877 |
|
2409
|
1878 |
self should: [ (matcher := self compileRegex: 'a(bc)d' into:self matcherClass) ~= nil ].
|
1865
|
1879 |
self should: [ (matcher search: 'abcd') = true ].
|
|
1880 |
self should: [ (matcher subexpression: 1) = 'abcd' ].
|
|
1881 |
self should: [ (matcher subexpression: 2) = 'bc' ].
|
|
1882 |
|
|
1883 |
"
|
|
1884 |
self new test103
|
|
1885 |
"
|
|
1886 |
!
|
|
1887 |
|
|
1888 |
test104
|
1868
|
1889 |
| matcher |
|
|
1890 |
|
|
1891 |
|
2409
|
1892 |
self should: [ (matcher := self compileRegex: '([abc])*d' into:self matcherClass) ~= nil ].
|
1868
|
1893 |
self should: [ (matcher search: 'abbbcd') = true ].
|
|
1894 |
self should: [ (matcher subexpression: 1) = 'abbbcd' ].
|
|
1895 |
self should: [ (matcher subexpression: 2) = 'c' ].
|
1865
|
1896 |
!
|
|
1897 |
|
|
1898 |
test105
|
1868
|
1899 |
| matcher |
|
|
1900 |
|
|
1901 |
|
2409
|
1902 |
self should: [ (matcher := self compileRegex: '([abc])*bcd' into:self matcherClass) ~= nil ].
|
1868
|
1903 |
self should: [ (matcher search: 'abcd') = true ].
|
|
1904 |
self should: [ (matcher subexpression: 1) = 'abcd' ].
|
|
1905 |
self should: [ (matcher subexpression: 2) = 'a' ].
|
1865
|
1906 |
!
|
|
1907 |
|
|
1908 |
test106
|
1868
|
1909 |
| matcher |
|
|
1910 |
|
|
1911 |
|
2409
|
1912 |
self should: [ (matcher := self compileRegex: 'a|b|c|d|e' into:self matcherClass) ~= nil ].
|
1868
|
1913 |
self should: [ (matcher search: 'e') = true ].
|
|
1914 |
self should: [ (matcher subexpression: 1) = 'e' ].
|
1865
|
1915 |
!
|
|
1916 |
|
|
1917 |
test107
|
1868
|
1918 |
| matcher |
|
|
1919 |
|
|
1920 |
|
2409
|
1921 |
self should: [ (matcher := self compileRegex: '(a|b|c|d|e)f' into:self matcherClass) ~= nil ].
|
1868
|
1922 |
self should: [ (matcher search: 'ef') = true ].
|
|
1923 |
self should: [ (matcher subexpression: 1) = 'ef' ].
|
|
1924 |
self should: [ (matcher subexpression: 2) = 'e' ].
|
1865
|
1925 |
!
|
|
1926 |
|
|
1927 |
test108
|
1868
|
1928 |
| matcher |
|
|
1929 |
|
|
1930 |
|
2409
|
1931 |
self should: [ (matcher := self compileRegex: 'abcd*efg' into:self matcherClass) ~= nil ].
|
1868
|
1932 |
self should: [ (matcher search: 'abcdefg') = true ].
|
|
1933 |
self should: [ (matcher subexpression: 1) = 'abcdefg' ].
|
1865
|
1934 |
!
|
|
1935 |
|
|
1936 |
test109
|
1868
|
1937 |
| matcher |
|
|
1938 |
|
|
1939 |
|
2409
|
1940 |
self should: [ (matcher := self compileRegex: 'ab*' into:self matcherClass) ~= nil ].
|
1868
|
1941 |
self should: [ (matcher search: 'xabyabbbz') = true ].
|
|
1942 |
self should: [ (matcher subexpression: 1) = 'ab' ].
|
|
1943 |
self should: [ (matcher search: 'xayabbbz') = true ].
|
|
1944 |
self should: [ (matcher subexpression: 1) = 'a' ].
|
1865
|
1945 |
!
|
|
1946 |
|
|
1947 |
test110
|
1868
|
1948 |
| matcher |
|
|
1949 |
|
|
1950 |
|
2409
|
1951 |
self should: [ (matcher := self compileRegex: '(ab|cd)e' into:self matcherClass) ~= nil ].
|
1868
|
1952 |
self should: [ (matcher search: 'abcde') = true ].
|
|
1953 |
self should: [ (matcher subexpression: 1) = 'cde' ].
|
|
1954 |
self should: [ (matcher subexpression: 2) = 'cd' ].
|
1865
|
1955 |
!
|
|
1956 |
|
|
1957 |
test111
|
1868
|
1958 |
| matcher |
|
|
1959 |
|
|
1960 |
|
2409
|
1961 |
self should: [ (matcher := self compileRegex: '[abhgefdc]ij' into:self matcherClass) ~= nil ].
|
1868
|
1962 |
self should: [ (matcher search: 'hij') = true ].
|
|
1963 |
self should: [ (matcher subexpression: 1) = 'hij' ].
|
1865
|
1964 |
!
|
|
1965 |
|
|
1966 |
test112
|
1868
|
1967 |
| matcher |
|
|
1968 |
|
|
1969 |
|
2409
|
1970 |
self should: [ (matcher := self compileRegex: '^(ab|cd)e' into:self matcherClass) ~= nil ].
|
1868
|
1971 |
self should: [ (matcher search: 'abcde') = false ].
|
1865
|
1972 |
!
|
|
1973 |
|
|
1974 |
test113
|
1868
|
1975 |
| matcher |
|
|
1976 |
|
|
1977 |
|
2409
|
1978 |
self should: [ (matcher := self compileRegex: '(abc|)def' into:self matcherClass) ~= nil ].
|
1868
|
1979 |
self should: [ (matcher search: 'abcdef') = true ].
|
1865
|
1980 |
!
|
|
1981 |
|
|
1982 |
test114
|
1868
|
1983 |
| matcher |
|
|
1984 |
|
|
1985 |
|
2409
|
1986 |
self should: [ (matcher := self compileRegex: '(a|b)c*d' into:self matcherClass) ~= nil ].
|
1868
|
1987 |
self should: [ (matcher search: 'abcd') = true ].
|
|
1988 |
self should: [ (matcher subexpression: 1) = 'bcd' ].
|
|
1989 |
self should: [ (matcher subexpression: 2) = 'b' ].
|
1865
|
1990 |
!
|
|
1991 |
|
|
1992 |
test115
|
1868
|
1993 |
| matcher |
|
|
1994 |
|
|
1995 |
|
2409
|
1996 |
self should: [ (matcher := self compileRegex: '(ab|ab*)bc' into:self matcherClass) ~= nil ].
|
1868
|
1997 |
self should: [ (matcher search: 'abc') = true ].
|
|
1998 |
self should: [ (matcher subexpression: 1) = 'abc' ].
|
|
1999 |
self should: [ (matcher subexpression: 2) = 'a' ].
|
1865
|
2000 |
!
|
|
2001 |
|
|
2002 |
test116
|
1868
|
2003 |
| matcher |
|
|
2004 |
|
|
2005 |
|
2409
|
2006 |
self should: [ (matcher := self compileRegex: 'a([bc]*)c*' into:self matcherClass) ~= nil ].
|
1868
|
2007 |
self should: [ (matcher search: 'abc') = true ].
|
|
2008 |
self should: [ (matcher subexpression: 1) = 'abc' ].
|
|
2009 |
self should: [ (matcher subexpression: 2) = 'bc' ].
|
1865
|
2010 |
!
|
|
2011 |
|
|
2012 |
test117
|
1868
|
2013 |
| matcher |
|
|
2014 |
|
|
2015 |
|
2409
|
2016 |
self should: [ (matcher := self compileRegex: 'a([bc]*)(c*d)' into:self matcherClass) ~= nil ].
|
1868
|
2017 |
self should: [ (matcher search: 'abcd') = true ].
|
|
2018 |
self should: [ (matcher subexpression: 1) = 'abcd' ].
|
|
2019 |
self should: [ (matcher subexpression: 2) = 'bc' ].
|
|
2020 |
self should: [ (matcher subexpression: 3) = 'd' ].
|
1865
|
2021 |
!
|
|
2022 |
|
|
2023 |
test118
|
1868
|
2024 |
| matcher |
|
|
2025 |
|
|
2026 |
|
2409
|
2027 |
self should: [ (matcher := self compileRegex: 'a([bc]+)(c*d)' into:self matcherClass) ~= nil ].
|
1868
|
2028 |
self should: [ (matcher search: 'abcd') = true ].
|
|
2029 |
self should: [ (matcher subexpression: 1) = 'abcd' ].
|
|
2030 |
self should: [ (matcher subexpression: 2) = 'bc' ].
|
|
2031 |
self should: [ (matcher subexpression: 3) = 'd' ].
|
1865
|
2032 |
!
|
|
2033 |
|
|
2034 |
test119
|
1868
|
2035 |
| matcher |
|
|
2036 |
|
|
2037 |
|
2409
|
2038 |
self should: [ (matcher := self compileRegex: 'a([bc]*)(c+d)' into:self matcherClass) ~= nil ].
|
1868
|
2039 |
self should: [ (matcher search: 'abcd') = true ].
|
|
2040 |
self should: [ (matcher subexpression: 1) = 'abcd' ].
|
|
2041 |
self should: [ (matcher subexpression: 2) = 'b' ].
|
|
2042 |
self should: [ (matcher subexpression: 3) = 'cd' ].
|
1865
|
2043 |
!
|
|
2044 |
|
|
2045 |
test120
|
1868
|
2046 |
| matcher |
|
|
2047 |
|
|
2048 |
|
2409
|
2049 |
self should: [ (matcher := self compileRegex: 'a[bcd]*dcdcde' into:self matcherClass) ~= nil ].
|
1868
|
2050 |
self should: [ (matcher search: 'adcdcde') = true ].
|
|
2051 |
self should: [ (matcher subexpression: 1) = 'adcdcde' ].
|
1865
|
2052 |
!
|
|
2053 |
|
|
2054 |
test121
|
1868
|
2055 |
| matcher |
|
|
2056 |
|
|
2057 |
|
2409
|
2058 |
self should: [ (matcher := self compileRegex: 'a[bcd]+dcdcde' into:self matcherClass) ~= nil ].
|
1868
|
2059 |
self should: [ (matcher search: 'adcdcde') = false ].
|
1865
|
2060 |
!
|
|
2061 |
|
|
2062 |
test122
|
1868
|
2063 |
| matcher |
|
|
2064 |
|
|
2065 |
|
2409
|
2066 |
self should: [ (matcher := self compileRegex: '(ab|a)b*c' into:self matcherClass) ~= nil ].
|
1868
|
2067 |
self should: [ (matcher search: 'abc') = true ].
|
|
2068 |
self should: [ (matcher subexpression: 1) = 'abc' ].
|
1865
|
2069 |
!
|
|
2070 |
|
|
2071 |
test123
|
1868
|
2072 |
| matcher |
|
|
2073 |
|
|
2074 |
|
2409
|
2075 |
self should: [ (matcher := self compileRegex: '((a)(b)c)(d)' into:self matcherClass) ~= nil ].
|
1868
|
2076 |
self should: [ (matcher search: 'abcd') = true ].
|
|
2077 |
self should: [ (matcher subexpression: 1) = 'abcd' ].
|
|
2078 |
self should: [ (matcher subexpression: 3) = 'a' ].
|
|
2079 |
self should: [ (matcher subexpression: 4) = 'b' ].
|
|
2080 |
self should: [ (matcher subexpression: 5) = 'd' ].
|
1865
|
2081 |
!
|
|
2082 |
|
|
2083 |
test124
|
1868
|
2084 |
| matcher |
|
|
2085 |
|
|
2086 |
|
2409
|
2087 |
self should: [ (matcher := self compileRegex: '[ -~]*' into:self matcherClass) ~= nil ].
|
1868
|
2088 |
self should: [ (matcher search: 'abc') = true ].
|
|
2089 |
self should: [ (matcher subexpression: 1) = 'abc' ].
|
1865
|
2090 |
!
|
|
2091 |
|
|
2092 |
test125
|
1868
|
2093 |
| matcher |
|
|
2094 |
|
|
2095 |
|
2409
|
2096 |
self should: [ (matcher := self compileRegex: '[ -~ -~]*' into:self matcherClass) ~= nil ].
|
1868
|
2097 |
self should: [ (matcher search: 'abc') = true ].
|
|
2098 |
self should: [ (matcher subexpression: 1) = 'abc' ].
|
1865
|
2099 |
!
|
|
2100 |
|
|
2101 |
test126
|
1868
|
2102 |
| matcher |
|
|
2103 |
|
|
2104 |
|
2409
|
2105 |
self should: [ (matcher := self compileRegex: '[ -~ -~ -~]*' into:self matcherClass) ~= nil ].
|
1868
|
2106 |
self should: [ (matcher search: 'abc') = true ].
|
|
2107 |
self should: [ (matcher subexpression: 1) = 'abc' ].
|
1865
|
2108 |
!
|
|
2109 |
|
|
2110 |
test127
|
1868
|
2111 |
| matcher |
|
|
2112 |
|
|
2113 |
|
2409
|
2114 |
self should: [ (matcher := self compileRegex: '[ -~ -~ -~ -~]*' into:self matcherClass) ~= nil ].
|
1868
|
2115 |
self should: [ (matcher search: 'abc') = true ].
|
|
2116 |
self should: [ (matcher subexpression: 1) = 'abc' ].
|
1865
|
2117 |
!
|
|
2118 |
|
|
2119 |
test128
|
1868
|
2120 |
| matcher |
|
|
2121 |
|
|
2122 |
|
2409
|
2123 |
self should: [ (matcher := self compileRegex: '[ -~ -~ -~ -~ -~]*' into:self matcherClass) ~= nil ].
|
1868
|
2124 |
self should: [ (matcher search: 'abc') = true ].
|
|
2125 |
self should: [ (matcher subexpression: 1) = 'abc' ].
|
1865
|
2126 |
!
|
|
2127 |
|
|
2128 |
test129
|
1868
|
2129 |
| matcher |
|
|
2130 |
|
|
2131 |
|
2409
|
2132 |
self should: [ (matcher := self compileRegex: '[ -~ -~ -~ -~ -~ -~]*' into:self matcherClass) ~= nil ].
|
1868
|
2133 |
self should: [ (matcher search: 'abc') = true ].
|
|
2134 |
self should: [ (matcher subexpression: 1) = 'abc' ].
|
1865
|
2135 |
!
|
|
2136 |
|
|
2137 |
test130
|
1868
|
2138 |
| matcher |
|
|
2139 |
|
|
2140 |
|
2409
|
2141 |
self should: [ (matcher := self compileRegex: '[ -~ -~ -~ -~ -~ -~ -~]*' into:self matcherClass) ~= nil ].
|
1868
|
2142 |
self should: [ (matcher search: 'abc') = true ].
|
|
2143 |
self should: [ (matcher subexpression: 1) = 'abc' ].
|
1865
|
2144 |
!
|
|
2145 |
|
|
2146 |
test131
|
1868
|
2147 |
| matcher |
|
|
2148 |
|
|
2149 |
|
2409
|
2150 |
self should: [ (matcher := self compileRegex: '[a-zA-Z_][a-zA-Z0-9_]*' into:self matcherClass) ~= nil ].
|
1868
|
2151 |
self should: [ (matcher search: 'alpha') = true ].
|
|
2152 |
self should: [ (matcher subexpression: 1) = 'alpha' ].
|
1865
|
2153 |
!
|
|
2154 |
|
|
2155 |
test132
|
2409
|
2156 |
| matcher |
|
|
2157 |
|
|
2158 |
self should: [ (matcher := self compileRegex: '^a(bc+|b[eh])g|.h$' into:self matcherClass) ~= nil ].
|
|
2159 |
self should: [ (matcher search: 'abh') = true ].
|
|
2160 |
self should: [ (matcher subexpression: 1) = 'bh' ].
|
|
2161 |
self should: [ (matcher subexpression: 2) = '' ].
|
1865
|
2162 |
!
|
|
2163 |
|
|
2164 |
test133
|
2409
|
2165 |
| matcher |
|
|
2166 |
|
|
2167 |
self should: [ (matcher := self compileRegex: '(bc+d$|ef*g.|h?i(j|k))' into:self matcherClass) ~= nil ].
|
|
2168 |
self should: [ (matcher search: 'effgz') = true ].
|
|
2169 |
self should: [ (matcher subexpression: 1) = 'effgz' ].
|
|
2170 |
self should: [ (matcher subexpression: 2) = 'effgz' ].
|
|
2171 |
self should: [ (matcher subexpression: 3) = '' ].
|
|
2172 |
self should: [ (matcher search: 'ij') = true ].
|
|
2173 |
self should: [ (matcher subexpression: 1) = 'ij' ].
|
|
2174 |
self should: [ (matcher subexpression: 2) = 'ij' ].
|
|
2175 |
self should: [ (matcher subexpression: 3) = 'j' ].
|
|
2176 |
self should: [ (matcher search: 'effg') = false ].
|
|
2177 |
self should: [ (matcher search: 'bcdd') = false ].
|
|
2178 |
self should: [ (matcher search: 'reffgz') = true ].
|
|
2179 |
self should: [ (matcher subexpression: 1) = 'effgz' ].
|
|
2180 |
self should: [ (matcher subexpression: 2) = 'effgz' ].
|
|
2181 |
self should: [ (matcher subexpression: 3) = '' ].
|
1865
|
2182 |
!
|
|
2183 |
|
|
2184 |
test134
|
2409
|
2185 |
| matcher |
|
|
2186 |
|
|
2187 |
self should: [ (matcher := self compileRegex: '(((((((((a)))))))))' into:self matcherClass) ~= nil ].
|
|
2188 |
self should: [ (matcher search: 'a') = true ].
|
|
2189 |
self should: [ (matcher subexpression: 1) = 'a' ].
|
1865
|
2190 |
!
|
|
2191 |
|
|
2192 |
test135
|
2409
|
2193 |
| matcher |
|
|
2194 |
|
|
2195 |
self should: [ (matcher := self compileRegex: 'multiple words of text' into:self matcherClass) ~= nil ].
|
|
2196 |
self should: [ (matcher search: 'uh-uh') = false ].
|
|
2197 |
self should: [ (matcher search: 'multiple words of text, yeah') = true ].
|
|
2198 |
self should: [ (matcher subexpression: 1) = 'multiple words of text' ].
|
1865
|
2199 |
!
|
|
2200 |
|
|
2201 |
test136
|
2409
|
2202 |
| matcher |
|
|
2203 |
|
|
2204 |
self should: [ (matcher := self compileRegex: '(.*)c(.*)' into:self matcherClass) ~= nil ].
|
|
2205 |
self should: [ (matcher search: 'abcde') = true ].
|
|
2206 |
self should: [ (matcher subexpression: 1) = 'abcde' ].
|
|
2207 |
self should: [ (matcher subexpression: 2) = 'ab' ].
|
|
2208 |
self should: [ (matcher subexpression: 3) = 'de' ].
|
1865
|
2209 |
!
|
|
2210 |
|
|
2211 |
test137
|
2409
|
2212 |
| matcher |
|
|
2213 |
|
|
2214 |
self should: [ (matcher := self compileRegex: '\((.*), (.*)\)' into:self matcherClass) ~= nil ].
|
|
2215 |
self should: [ (matcher search: '(a, b)') = true ].
|
|
2216 |
self should: [ (matcher subexpression: 2) = 'a' ].
|
|
2217 |
self should: [ (matcher subexpression: 3) = 'b' ].
|
1865
|
2218 |
!
|
|
2219 |
|
2323
|
2220 |
test138
|
|
2221 |
| matcher |
|
|
2222 |
|
|
2223 |
matcher := 'aa*' asRegex.
|
|
2224 |
self assert:(matcher matches:'a').
|
|
2225 |
self assert:(matcher matches:'aa').
|
|
2226 |
self assert:(matcher matches:'aaa').
|
|
2227 |
self deny:(matcher matches:'ab').
|
|
2228 |
self deny:(matcher matches:'b').
|
|
2229 |
|
|
2230 |
"Created: / 15-06-2019 / 09:44:56 / Claus Gittinger"
|
|
2231 |
!
|
|
2232 |
|
1865
|
2233 |
test199
|
|
2234 |
|matcher|
|
|
2235 |
|
1868
|
2236 |
self
|
2409
|
2237 |
should:[ (matcher := self compileRegex:'a{}b' into:self matcherClass) = nil ].
|
1865
|
2238 |
!
|
|
2239 |
|
|
2240 |
test200
|
2409
|
2241 |
| matcher |
|
|
2242 |
|
|
2243 |
self should: [ (matcher := self compileRegex: '\d{2,5}' into:self matcherClass) ~= nil ].
|
|
2244 |
self should: [ (matcher search: '1') = false ].
|
|
2245 |
self should: [ (matcher search: '12') = true ].
|
|
2246 |
self should: [ (matcher search: '123') = true ].
|
|
2247 |
self should: [ (matcher search: '1234') = true ].
|
|
2248 |
self should: [ (matcher search: '12356') = true ].
|
|
2249 |
self should: [ (matcher search: '123456') = true ].
|
|
2250 |
self should: [ (matcher subexpression: 1) = '12345' ].
|
1865
|
2251 |
!
|
|
2252 |
|
|
2253 |
test201
|
2409
|
2254 |
| matcher |
|
|
2255 |
|
|
2256 |
self should: [ (matcher := self compileRegex: '[0-9]{2,5}' into:self matcherClass) ~= nil ].
|
|
2257 |
self should: [ (matcher search: '1') = false ].
|
|
2258 |
self should: [ (matcher search: '12') = true ].
|
|
2259 |
self should: [ (matcher search: '123') = true ].
|
|
2260 |
self should: [ (matcher search: '1234') = true ].
|
|
2261 |
self should: [ (matcher search: '12356') = true ].
|
|
2262 |
self should: [ (matcher search: '123456') = true ].
|
|
2263 |
self should: [ (matcher subexpression: 1) = '12345' ].
|
1865
|
2264 |
!
|
|
2265 |
|
|
2266 |
test202
|
2409
|
2267 |
| matcher |
|
|
2268 |
|
|
2269 |
self assert: ( (matcher := self compileRegex: '([0-9]{2,4}\s){2}' into:self matcherClass) ~= nil ).
|
|
2270 |
self deny: ( matcher matches: '1 1 ').
|
|
2271 |
self assert: ( matcher matches: '12 12 ' ).
|
|
2272 |
self assert: ( matcher matches: '12 123 ' ).
|
|
2273 |
self assert: ( matcher matches: '123 12 ' ).
|
|
2274 |
self assert: ( matcher matches: '123 123 ' ).
|
|
2275 |
self assert: ( matcher matches: '1234 12 ' ).
|
|
2276 |
self deny: ( matcher matches: '123456 12 ' ).
|
|
2277 |
self deny: ( matcher matches: '12356 12 ' ).
|
1865
|
2278 |
!
|
|
2279 |
|
|
2280 |
testProtocol
|
1869
|
2281 |
| matcher |
|
|
2282 |
|
|
2283 |
self should: [ (matcher := Regex::RxMatcher forString: '\w+') ~= nil ].
|
|
2284 |
self should: [ (matcher matchesIn: 'now is the time') asArray = #('now' 'is' 'the' 'time') ].
|
|
2285 |
self should: [ (matcher copy: 'now is the time ' translatingMatchesUsing: [:s | s reverse]) = 'won si eht emit ' ].
|
|
2286 |
|
|
2287 |
"See that the match context is preserved while copying stuff between matches:"
|
|
2288 |
|
|
2289 |
self should: [ ((Regex::RxMatcher forString: '\<\d\D+')
|
|
2290 |
copy: '9aaa1bbb 8ccc'
|
|
2291 |
replacingMatchesWith: 'foo') = 'foo1bbb foo' ].
|
1865
|
2292 |
!
|
|
2293 |
|
2409
|
2294 |
testSubExpression001
|
|
2295 |
|matcher|
|
|
2296 |
|
|
2297 |
matcher := Regex::RxMatcher new
|
|
2298 |
initializeFromString:'(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[ ]+(:isDigit::isDigit:?)[ ]*,[ ]*19(:isDigit::isDigit:)'
|
|
2299 |
ignoreCase:false.
|
|
2300 |
self assert:(matcher matches:'Aug 6, 1996').
|
|
2301 |
self assert:(matcher subexpression:2) = 'Aug'
|
|
2302 |
!
|
|
2303 |
|
1865
|
2304 |
testTermination001
|
|
2305 |
self assert:(('' allRegexMatches:'\S*') asArray = #('')).
|
2409
|
2306 |
self assert:(('t' allRegexMatches:'\S*') asArray = #('t' '')).
|
|
2307 |
self assert:(('the' allRegexMatches:'\S*') asArray = #('the' '')).
|
|
2308 |
self assert:(('the time' allRegexMatches:'\S*') asArray = #('the' 'time' '')).
|
1865
|
2309 |
|
|
2310 |
self assert:(('the time' allRegexMatches:'\S*') size >= 2).
|
|
2311 |
|
|
2312 |
"Created: / 04-05-2017 / 19:45:04 / mawalch"
|
|
2313 |
"Modified (format): / 07-06-2017 / 10:06:59 / mawalch"
|
|
2314 |
! !
|
|
2315 |
|
|
2316 |
!RxTests methodsFor:'test suite - old'!
|
|
2317 |
|
|
2318 |
testCadrMatching
|
|
2319 |
"self debug: #testCadrMatching"
|
|
2320 |
|
|
2321 |
"A bit more complex example is the following expression, matching the
|
|
2322 |
name of any of the Lisp-style `car', `cdr', `caar', `cadr',
|
|
2323 |
... functions:"
|
|
2324 |
|
|
2325 |
self assert: ( 'car' matchesRegex: 'c(a|d)+r').
|
|
2326 |
self assert: ( 'cdr' matchesRegex: 'c(a|d)+r').
|
|
2327 |
self assert: ( 'caar' matchesRegex: 'c(a|d)+r').
|
|
2328 |
self assert: ( 'cadr' matchesRegex: 'c(a|d)+r').
|
|
2329 |
self assert: ( 'caddar' matchesRegex: 'c(a|d)+r').
|
|
2330 |
!
|
|
2331 |
|
2409
|
2332 |
testCaseInsensitive
|
|
2333 |
| matcher |
|
|
2334 |
matcher := self matcherClass forString: 'the quick brown fox' ignoreCase: true.
|
|
2335 |
self
|
|
2336 |
assert: (matcher search: 'the quick brown fox');
|
|
2337 |
assert: (matcher search: 'The quick brown FOX');
|
|
2338 |
assert: (matcher search: 'What do you know about the quick brown fox?');
|
|
2339 |
assert: (matcher search: 'What do you know about THE QUICK BROWN FOX?')
|
|
2340 |
!
|
|
2341 |
|
|
2342 |
testCaseSensitive
|
|
2343 |
| matcher |
|
|
2344 |
matcher := self matcherClass forString: 'the quick brown fox' ignoreCase: false.
|
|
2345 |
self assert: (matcher search: 'the quick brown fox').
|
|
2346 |
self deny: (matcher search: 'The quick brown FOX').
|
|
2347 |
self assert: (matcher search: 'What do you know about the quick brown fox?').
|
|
2348 |
self deny: (matcher search: 'What do you know about THE QUICK BROWN FOX?')
|
|
2349 |
!
|
|
2350 |
|
1865
|
2351 |
testCharacterSet
|
|
2352 |
"self debug: #testCharacterSet"
|
1868
|
2353 |
|
1865
|
2354 |
"So far, we have used only characters as the 'smallest' components of
|
|
2355 |
regular expressions. There are other, more `interesting', components.
|
|
2356 |
A character set is a string of characters enclosed in square
|
|
2357 |
brackets. It matches any single character if it appears between the
|
|
2358 |
brackets. For example, `[01]' matches either `0' or `1':"
|
|
2359 |
|
1868
|
2360 |
self assert: ('0' matchesRegex: '[01]').
|
|
2361 |
self deny: ('3' matchesRegex: '[01]').
|
1865
|
2362 |
self deny: ('11' matchesRegex: '[01]'). "-- false: a set matches only one character"
|
2340
|
2363 |
self assert: ('[01]' asRegex hasMatchesIn:'11' ). "-- true"
|
1865
|
2364 |
self deny: ('01' matchesRegex: '[01]').
|
|
2365 |
!
|
|
2366 |
|
|
2367 |
testCharacterSetBinaryNumber
|
|
2368 |
"self debug: #testCharacterSetBinaryNumber"
|
1868
|
2369 |
|
1865
|
2370 |
"Using plus operator, we can build the following binary number
|
|
2371 |
recognizer:"
|
1868
|
2372 |
self assert: ('10010100' matchesRegex: '[01]+').
|
|
2373 |
self deny: ('10001210' matchesRegex: '[01]+')
|
1865
|
2374 |
!
|
|
2375 |
|
|
2376 |
testCharacterSetInversion
|
|
2377 |
"self debug: #testCharacterSetInversion"
|
1868
|
2378 |
|
1865
|
2379 |
"If the first character after the opening bracket is `^', the set is
|
|
2380 |
inverted: it matches any single character *not* appearing between the
|
|
2381 |
brackets:"
|
1868
|
2382 |
|
|
2383 |
self deny: ('0' matchesRegex: '[^01]').
|
1865
|
2384 |
"0 appears in 01 so there is no match"
|
1868
|
2385 |
|
1865
|
2386 |
self assert: ('3' matchesRegex: '[^01]').
|
|
2387 |
"3 is not in 01 so it matches"
|
1868
|
2388 |
|
|
2389 |
|
|
2390 |
self deny: ('30' matchesRegex: '[^01]').
|
|
2391 |
self deny: ('33333333333333333333333330' matchesRegex: '[^01]').
|
1865
|
2392 |
"there is one zero so it does not match"
|
|
2393 |
!
|
|
2394 |
|
|
2395 |
testCharacterSetRange
|
|
2396 |
"self debug: #testCharacterSetRange"
|
1868
|
2397 |
|
1865
|
2398 |
"For convenience, a set may include ranges: pairs of characters
|
|
2399 |
separated with `-'. This is equivalent to listing all characters
|
1868
|
2400 |
between them: `[0-9]' is the same as `[0123456789]'. "
|
|
2401 |
|
|
2402 |
self assert: ('0' matchesRegex: '[0-9]').
|
|
2403 |
self assert: ('9' matchesRegex: '[0-9]').
|
1865
|
2404 |
self deny: ('a' matchesRegex: '[0-9]').
|
1868
|
2405 |
self deny: ('01' matchesRegex: '[0-9]').
|
|
2406 |
self assert: ('01442128629839374565' matchesRegex: '[0-9]+').
|
1865
|
2407 |
!
|
|
2408 |
|
2409
|
2409 |
testCopyReplacingMatches
|
|
2410 |
"See that the match context is preserved while copying stuff between matches:"
|
|
2411 |
|
|
2412 |
| matcher |
|
|
2413 |
matcher := self matcherClass forString: '\<\d\D+'.
|
|
2414 |
self
|
|
2415 |
assert: (matcher copy: '9aaa1bbb 8ccc' replacingMatchesWith: 'foo') equals: 'foo1bbb foo'
|
|
2416 |
!
|
|
2417 |
|
|
2418 |
testCopyTranslatingMatches
|
|
2419 |
| matcher |
|
|
2420 |
matcher := self matcherClass forString: '\w+'.
|
|
2421 |
self assert: (matcher copy: 'now is the time ' translatingMatchesUsing: [ :each | each reversed ]) equals: 'won si eht emit '
|
|
2422 |
!
|
|
2423 |
|
|
2424 |
testEmptyStringAtBeginningOfLine
|
|
2425 |
| matcher result |
|
|
2426 |
|
|
2427 |
matcher := self matcherClass forString: '^'.
|
|
2428 |
result := (matcher copy: 'foo1 bar1' , String cr , 'foo2 bar2' replacingMatchesWith: '*').
|
|
2429 |
self
|
|
2430 |
assert: result = ('*foo1 bar1' , String cr , '*foo2 bar2')
|
|
2431 |
description: 'An empty string at the beginning of a line'
|
|
2432 |
!
|
|
2433 |
|
|
2434 |
testEmptyStringAtBeginningOfWord
|
|
2435 |
| matcher result |
|
|
2436 |
|
|
2437 |
matcher := self matcherClass forString: '\<'.
|
|
2438 |
result := (matcher copy: 'foo bar' replacingMatchesWith: '*').
|
|
2439 |
self
|
|
2440 |
assert: result = '*foo *bar'
|
|
2441 |
description: 'An empty string at the beginning of a word'
|
|
2442 |
!
|
|
2443 |
|
|
2444 |
testEmptyStringAtEndOfLine
|
|
2445 |
| matcher |
|
|
2446 |
|
|
2447 |
matcher := self matcherClass forString: '$'.
|
|
2448 |
self
|
|
2449 |
assert: (matcher copy: 'foo1 bar1' , String cr , 'foo2 bar2' replacingMatchesWith: '*')
|
|
2450 |
= ('foo1 bar1*', String cr , 'foo2 bar2*')
|
|
2451 |
description: 'An empty string at the end of a line'
|
|
2452 |
!
|
|
2453 |
|
|
2454 |
testEmptyStringAtEndOfWord
|
|
2455 |
| matcher |
|
|
2456 |
|
|
2457 |
matcher := self matcherClass forString: '\>'.
|
|
2458 |
self
|
|
2459 |
assert: (matcher copy: 'foo bar' replacingMatchesWith: '*')
|
|
2460 |
= 'foo* bar*'
|
|
2461 |
description: 'An empty string at the end of a word'
|
|
2462 |
!
|
|
2463 |
|
|
2464 |
testEmptyStringAtWordBoundary
|
|
2465 |
| matcher result |
|
|
2466 |
|
|
2467 |
matcher := self matcherClass forString: '\b'.
|
|
2468 |
result := (matcher copy: 'foo bar' replacingMatchesWith: '*').
|
|
2469 |
self
|
|
2470 |
assert: result = '*foo* *bar*'
|
|
2471 |
description: 'An empty string at a word boundary'
|
|
2472 |
!
|
|
2473 |
|
|
2474 |
testEmptyStringNotAtWordBoundary
|
|
2475 |
| matcher |
|
|
2476 |
|
|
2477 |
matcher := self matcherClass forString: '\B'.
|
|
2478 |
self
|
|
2479 |
assert: (matcher copy: 'foo bar' replacingMatchesWith: '*')
|
|
2480 |
= 'f*o*o b*a*r'
|
|
2481 |
description: 'An empty string not at a word boundary'
|
|
2482 |
!
|
|
2483 |
|
1865
|
2484 |
testMatchesInwW
|
|
2485 |
"self debug: #testMatchesInwW"
|
1868
|
2486 |
|
1865
|
2487 |
"1. Backslash escapes similar to those in Perl are allowed in patterns:
|
|
2488 |
\w any word constituent character (equivalent to [a-zA-Z0-9_])
|
|
2489 |
\W any character but a word constituent (equivalent to [^a-xA-Z0-9_]"
|
|
2490 |
|
|
2491 |
self assert: ('\w+' asRegex matchesIn: 'now is the time') asArray = #('now' 'is' 'the' 'time').
|
|
2492 |
self assert: ('\W+' asRegex matchesIn: 'now is the time') asArray = #(' ' ' ' ' ').
|
1868
|
2493 |
|
|
2494 |
|
1865
|
2495 |
"/ self halt.
|
|
2496 |
"why do we get that"
|
|
2497 |
self assert: ('\w' asRegex matchesIn: 'now') asArray = #('n' 'o' 'w').
|
|
2498 |
!
|
|
2499 |
|
|
2500 |
testOrOperator
|
|
2501 |
"self debug: #testOrOperator"
|
1868
|
2502 |
|
1865
|
2503 |
"The last operator is `|' meaning `or'. It is placed between two
|
|
2504 |
regular expressions, and the resulting expression matches if one of
|
|
2505 |
the expressions matches. It has the lowest possible precedence (lower
|
|
2506 |
than sequencing). For example, `ab*|ba*' means `a followed by any
|
|
2507 |
number of b's, or b followed by any number of a's':"
|
|
2508 |
|
1868
|
2509 |
self assert: ('abb' matchesRegex: 'ab*|ba*').
|
|
2510 |
self assert: ('baa' matchesRegex: 'ab*|ba*').
|
1865
|
2511 |
self deny: ('baab' matchesRegex: 'ab*|ba*').
|
1868
|
2512 |
|
1865
|
2513 |
|
|
2514 |
"It is possible to write an expression matching an empty string, for
|
|
2515 |
example: `a|'. However, it is an error to apply `*', `+', or `?' to
|
|
2516 |
such expression: `(a|)*' is an invalid expression."
|
|
2517 |
|
|
2518 |
self should: ['(a|)*' asRegex] raise: Error.
|
|
2519 |
!
|
|
2520 |
|
|
2521 |
testQuotingOperators
|
|
2522 |
"self debug: #testQuotingOperators"
|
1868
|
2523 |
|
1865
|
2524 |
"As we have seen, characters `*', `+', `?', `(', and `)' have special
|
|
2525 |
meaning in regular expressions. If one of them is to be used
|
|
2526 |
literally, it should be quoted: preceded with a backslash. (Thus,
|
|
2527 |
backslash is also special character, and needs to be quoted for a
|
|
2528 |
literal match--as well as any other special character described
|
|
2529 |
further)."
|
|
2530 |
|
|
2531 |
self deny: ('ab*' matchesRegex: 'ab*'). " -- false: star in the right string is special"
|
1868
|
2532 |
self assert: ('ab*' matchesRegex: 'ab\*').
|
|
2533 |
self assert: ('a\c' matchesRegex: 'a\\c').
|
1865
|
2534 |
!
|
|
2535 |
|
|
2536 |
testSimpleMatchesRegex
|
|
2537 |
"self debug: #testSimpleMatchesRegex"
|
1868
|
2538 |
|
1865
|
2539 |
"The simplest regular expression is a single character. It matches
|
|
2540 |
exactly that character. A sequence of characters matches a string with
|
|
2541 |
exactly the same sequence of characters:"
|
|
2542 |
|
|
2543 |
self assert: ('a' matchesRegex: 'a').
|
|
2544 |
self assert: ('foobar' matchesRegex: 'foobar') .
|
|
2545 |
self deny: ('blorple' matchesRegex: 'foobar')
|
|
2546 |
!
|
|
2547 |
|
|
2548 |
testSimpleMatchesRegexWithStar
|
|
2549 |
"self debug: #testSimpleMatchesRegexWithStar"
|
1868
|
2550 |
|
1865
|
2551 |
"The above paragraph in testSimpleMatchesRegex introduced a primitive regular expression (a
|
|
2552 |
character), and an operator (sequencing). Operators are applied to
|
|
2553 |
regular expressions to produce more complex regular expressions.
|
|
2554 |
Sequencing (placing expressions one after another) as an operator is,
|
|
2555 |
in a certain sense, `invisible'--yet it is arguably the most common.
|
|
2556 |
A more `visible' operator is Kleene closure, more often simply
|
|
2557 |
referred to as `a star'. A regular expression followed by an asterisk
|
|
2558 |
matches any number (including 0) of matches of the original
|
|
2559 |
expression. For example:"
|
|
2560 |
|
1868
|
2561 |
self assert: ('ab' matchesRegex: 'a*b').
|
|
2562 |
self assert: ('aaaaab' matchesRegex: 'a*b').
|
|
2563 |
self assert: ('b' matchesRegex: 'a*b').
|
|
2564 |
self deny: ('aac' matchesRegex: 'a*b').
|
1865
|
2565 |
!
|
|
2566 |
|
|
2567 |
testSpecialCharacterInSetRange
|
|
2568 |
"self debug: #testSpecialCharacterInSetRange"
|
1868
|
2569 |
|
1865
|
2570 |
"Special characters within a set are `^', `-', and `]' that closes the
|
|
2571 |
set. Below are the examples of how to literally use them in a set:
|
|
2572 |
[01^] -- put the caret anywhere except the beginning
|
|
2573 |
[01-] -- put the dash as the last character
|
1868
|
2574 |
[]01] -- put the closing bracket as the first character
|
1865
|
2575 |
[^]01] (thus, empty and universal sets cannot be specified)"
|
|
2576 |
|
|
2577 |
self assert: ('0' matchesRegex: '[01^]').
|
|
2578 |
self assert: ('1' matchesRegex: '[01^]').
|
|
2579 |
self assert: ('^' matchesRegex: '[01^]').
|
1868
|
2580 |
|
1865
|
2581 |
self deny: ('0' matchesRegex: '[^01]').
|
|
2582 |
self deny: ('1' matchesRegex: '[^01]').
|
1868
|
2583 |
|
1865
|
2584 |
"[^abc] means that everything except abc is matche"
|
|
2585 |
self assert: ('^' matchesRegex: '[^01]').
|
|
2586 |
!
|
|
2587 |
|
2409
|
2588 |
testSplitJoinBoundaryCases
|
|
2589 |
"Empty splitter, joiner or sequence."
|
|
2590 |
self assert: ('' join: ('.' asRegex split: '')) equals: ''. "NB: Doesn't work with empty regex"
|
|
2591 |
!
|
|
2592 |
|
|
2593 |
testSplitStringOnRegex
|
|
2594 |
self assert: ('foobar' splitOn: '[aeiou]+' asRegex)
|
|
2595 |
equals: #('f' 'b' 'r') asOrderedCollection
|
|
2596 |
!
|
|
2597 |
|
1865
|
2598 |
testStarPlusQuestionMark
|
|
2599 |
"self debug: #testStarPlusQuestionMark"
|
1868
|
2600 |
|
1865
|
2601 |
"Two other operators similar to `*' are `+' and `?'. `+' (positive
|
|
2602 |
closure, or simply `plus') matches one or more occurrences of the
|
|
2603 |
original expression. `?' (`optional') matches zero or one, but never
|
|
2604 |
more, occurrences."
|
|
2605 |
|
1868
|
2606 |
self assert: ('ac' matchesRegex: 'ab*c').
|
1865
|
2607 |
self deny: ('ac' matchesRegex: 'ab+c'). "-- false: need at least one b"
|
1868
|
2608 |
self assert: ('abbc' matchesRegex: 'ab+c').
|
|
2609 |
self assert: ('abbbbbbc' matchesRegex: 'ab+c').
|
1865
|
2610 |
self deny: ('abbc' matchesRegex: 'ab?c') "-- false: too many b's"
|
|
2611 |
!
|
|
2612 |
|
|
2613 |
testStarPrecedence
|
|
2614 |
"self debug: #testStarPrecedence"
|
1868
|
2615 |
|
1865
|
2616 |
"A star's precedence is higher than that of sequencing. A star applies
|
|
2617 |
to the shortest possible subexpression that precedes it. For example,
|
|
2618 |
'ab*' means `a followed by zero or more occurrences of b', not `zero
|
|
2619 |
or more occurrences of ab':"
|
|
2620 |
|
1868
|
2621 |
self assert: ('abbb' matchesRegex: 'ab*').
|
|
2622 |
self deny: ('abab' matchesRegex: 'ab*').
|
|
2623 |
|
1865
|
2624 |
"To actually make a regex matching `zero or more occurrences of ab',
|
|
2625 |
`ab' is enclosed in parentheses:"
|
1868
|
2626 |
self assert: ('abab' matchesRegex: '(ab)*').
|
1865
|
2627 |
self deny: ('abcab' matchesRegex: '(ab)*')
|
|
2628 |
!
|
|
2629 |
|
|
2630 |
testTranslatingMatchesUsing
|
|
2631 |
"self debug: #testTranslatingMatchesUsing"
|
1868
|
2632 |
|
1865
|
2633 |
|
|
2634 |
self assert: ('\<t\w+' asRegexIgnoringCase
|
1868
|
2635 |
copy: 'now is the Time'
|
|
2636 |
translatingMatchesUsing: [:match | match asUppercase]) = 'now is THE TIME'.
|
1865
|
2637 |
|
|
2638 |
"the regular expression matches words beginning with either an uppercase or a lowercase T"
|
|
2639 |
!
|
|
2640 |
|
|
2641 |
xtest1
|
1868
|
2642 |
self runTestsForMatcher: Regex::RxMatcher
|
1865
|
2643 |
!
|
|
2644 |
|
|
2645 |
xtest: aMatcher with: testString expect: expected withSubexpressions: subexpr
|
|
2646 |
|
1868
|
2647 |
| got |
|
|
2648 |
Transcript tab;
|
|
2649 |
show: 'Matching: ';
|
|
2650 |
show: testString printString;
|
|
2651 |
show: ' expected: ';
|
|
2652 |
show: expected printString;
|
|
2653 |
show: ' got: '.
|
|
2654 |
got := aMatcher search: testString.
|
|
2655 |
Transcript show: got printString.
|
|
2656 |
got ~= expected
|
|
2657 |
ifTrue: [^false].
|
|
2658 |
(subexpr notNil and: [aMatcher supportsSubexpressions])
|
|
2659 |
ifFalse:
|
|
2660 |
[^true]
|
|
2661 |
ifTrue:
|
|
2662 |
[ | isOK |
|
|
2663 |
isOK := true.
|
|
2664 |
1 to: subexpr size by: 2 do: [: i |
|
|
2665 |
| sub subExpect subGot |
|
|
2666 |
sub := subexpr at: i.
|
|
2667 |
subExpect := subexpr at: i + 1.
|
|
2668 |
subGot := aMatcher subexpression: sub.
|
|
2669 |
Transcript cr; tab; tab;
|
|
2670 |
show: 'Subexpression: ', sub printString;
|
|
2671 |
show: ' expected: ';
|
|
2672 |
show: subExpect printString;
|
|
2673 |
show: ' got: ';
|
|
2674 |
show: subGot printString.
|
|
2675 |
subExpect ~= subGot
|
|
2676 |
ifTrue:
|
|
2677 |
[Transcript show: ' -- MISMATCH'.
|
|
2678 |
isOK := false]].
|
|
2679 |
^isOK]
|
1865
|
2680 |
!
|
|
2681 |
|
|
2682 |
xtestSuite
|
|
2683 |
"Answer an array of test clauses. Each clause is an array with a regex source
|
|
2684 |
string followed by sequence of 3-tuples. Each three-element
|
1868
|
2685 |
group is one test to try against the regex, and includes:
|
|
2686 |
1) test string;
|
|
2687 |
2) expected result;
|
|
2688 |
3) expected subexpression as an array of (index, substring), or nil.
|
1865
|
2689 |
The test suite is based on the one in Henry Spencer's regexp.c package."
|
|
2690 |
|
1868
|
2691 |
^#(
|
|
2692 |
('abc'
|
|
2693 |
'abc' true (1 'abc')
|
|
2694 |
'xbc' false nil
|
|
2695 |
'axc' false nil
|
|
2696 |
'abx' false nil
|
|
2697 |
'xabcy' true (1 'abc')
|
|
2698 |
'ababc' true (1 'abc'))
|
|
2699 |
('ab*c'
|
|
2700 |
'abc' true (1 'abc'))
|
|
2701 |
('ab*bc'
|
|
2702 |
'abc' true (1 'abc')
|
|
2703 |
'abbc' true (1 'abbc')
|
|
2704 |
'abbbbc' true (1 'abbbbc'))
|
|
2705 |
('ab+bc'
|
|
2706 |
'abbc' true (1 'abbc')
|
|
2707 |
'abc' false nil
|
|
2708 |
'abq' false nil
|
|
2709 |
'abbbbc' true (1 'abbbbc'))
|
|
2710 |
('ab?bc'
|
|
2711 |
'abbc' true (1 'abbc')
|
|
2712 |
'abc' true (1 'abc')
|
|
2713 |
'abbbbc' false nil
|
|
2714 |
'abc' true (1 'abc'))
|
|
2715 |
('ab?c' "added 08-Jan-2004 by cg "
|
|
2716 |
'abc' true (1 'abc'))
|
|
2717 |
('^abc$'
|
|
2718 |
'abc' true (1 'abc')
|
|
2719 |
'abcc' false nil
|
|
2720 |
'aabc' false nil)
|
|
2721 |
('^abc'
|
|
2722 |
'abcc' true (1 'abc'))
|
|
2723 |
('abc$'
|
|
2724 |
'aabc' true (1 'abc'))
|
|
2725 |
('^'
|
|
2726 |
'abc' true nil)
|
|
2727 |
('$'
|
|
2728 |
'abc' true nil)
|
|
2729 |
('a.c'
|
|
2730 |
'abc' true (1 'abc')
|
|
2731 |
'axc' true (1 'axc'))
|
|
2732 |
('a.*c'
|
|
2733 |
'axyzc' true (1 'axyzc')
|
|
2734 |
'axy zc' true (1 'axy zc') "testing that a dot matches a space"
|
|
2735 |
'axy
|
|
2736 |
zc' false nil "testing that a dot does not match a newline"
|
|
2737 |
'axyzd' false nil)
|
|
2738 |
('.a.*'
|
|
2739 |
'1234abc' true (1 '4abc')
|
|
2740 |
'abcd' false nil)
|
|
2741 |
('a\w+c'
|
|
2742 |
' abbbbc ' true (1 'abbbbc')
|
|
2743 |
'abb bc' false nil)
|
|
2744 |
('\w+'
|
|
2745 |
' foobar quux' true (1 'foobar')
|
|
2746 |
' ~!!@#$%^&*()-+=\|/?.>,<' false nil)
|
|
2747 |
('a\W+c'
|
|
2748 |
'a c' true (1 'a c')
|
|
2749 |
'a bc' false nil)
|
|
2750 |
('\W+'
|
|
2751 |
'foo!!@#$bar' true (1 '!!@#$')
|
|
2752 |
'foobar' false nil)
|
|
2753 |
('a\s*c'
|
|
2754 |
'a c' true (1 'a c')
|
|
2755 |
'a bc' false nil)
|
|
2756 |
('\s+'
|
|
2757 |
'abc3457 sd' true (1 ' ')
|
|
2758 |
'1234$^*^&asdfb' false nil)
|
|
2759 |
('a\S*c'
|
|
2760 |
'aqwertyc' true (1 'aqwertyc')
|
|
2761 |
'ab c' false nil)
|
|
2762 |
('\S+'
|
|
2763 |
' asdf ' true (1 'asdf')
|
|
2764 |
'
|
|
2765 |
' false nil)
|
|
2766 |
('a\d+c'
|
|
2767 |
'a0123456789c' true (1 'a0123456789c')
|
|
2768 |
'a12b34c' false nil)
|
|
2769 |
('\d+'
|
|
2770 |
'foo@#$%123ASD #$$%^&' true (1 '123')
|
|
2771 |
'foo!!@#$asdfl;' false nil)
|
|
2772 |
('a\D+c'
|
|
2773 |
'aqwertyc' true (1 'aqwertyc')
|
|
2774 |
'aqw6ertc' false nil)
|
|
2775 |
('\D+'
|
|
2776 |
'1234 abc 456' true (1 ' abc ')
|
|
2777 |
'1234567890' false nil)
|
|
2778 |
('(f|o)+\b'
|
|
2779 |
'foo' true (1 'foo')
|
|
2780 |
' foo ' true (1 'foo'))
|
|
2781 |
('\ba\w+' "a word beginning with an A"
|
|
2782 |
'land ancient' true (1 'ancient')
|
|
2783 |
'antique vase' true (1 'antique')
|
|
2784 |
'goofy foobar' false nil)
|
|
2785 |
('(f|o)+\B'
|
|
2786 |
'quuxfoobar' true (1 'foo')
|
|
2787 |
'quuxfoo ' true (1 'fo'))
|
|
2788 |
('\Ba\w+' "a word with an A in the middle, match at A and further"
|
|
2789 |
'land ancient' true (1 'and')
|
|
2790 |
'antique vase' true (1 'ase')
|
|
2791 |
'smalltalk shall overcome' true (1 'alltalk')
|
|
2792 |
'foonix is better' false nil)
|
|
2793 |
('fooa\>.*'
|
|
2794 |
'fooa ' true nil
|
|
2795 |
'fooa123' false nil
|
|
2796 |
'fooa bar' true nil
|
|
2797 |
'fooa' true nil
|
|
2798 |
'fooargh' false nil)
|
|
2799 |
('\>.+abc'
|
|
2800 |
' abcde fg' false nil
|
|
2801 |
'foo abcde' true (1 ' abc')
|
|
2802 |
'abcde' false nil)
|
|
2803 |
('\<foo.*'
|
|
2804 |
'foo' true nil
|
|
2805 |
'foobar' true nil
|
|
2806 |
'qfoobarq foonix' true (1 'foonix')
|
|
2807 |
' foo' true nil
|
|
2808 |
' 12foo' false nil
|
|
2809 |
'barfoo' false nil)
|
|
2810 |
('.+\<foo'
|
|
2811 |
'foo' false nil
|
|
2812 |
'ab foo' true (1 'ab foo')
|
|
2813 |
'abfoo' false nil)
|
|
2814 |
('a[bc]d'
|
|
2815 |
'abc' false nil
|
|
2816 |
'abd' true (1 'abd'))
|
|
2817 |
('a[b-d]e'
|
|
2818 |
'abd' false nil
|
|
2819 |
'ace' true (1 'ace'))
|
|
2820 |
('a[b-d]'
|
|
2821 |
'aac' true (1 'ac'))
|
|
2822 |
('a[-b]'
|
|
2823 |
'a-' true (1 'a-'))
|
|
2824 |
('a[b-]'
|
|
2825 |
'a-' true (1 'a-'))
|
|
2826 |
('a[a-b-c]' nil)
|
|
2827 |
('[k]'
|
|
2828 |
'ab' false nil)
|
|
2829 |
('a[b-a]' nil)
|
|
2830 |
('a[]b' nil)
|
|
2831 |
('a[' nil)
|
|
2832 |
('a]'
|
|
2833 |
'a]' true (1 'a]'))
|
|
2834 |
('a[]]b'
|
|
2835 |
'a]b' true (1 'a]b'))
|
|
2836 |
('a[^bc]d'
|
|
2837 |
'aed' true (1 'aed')
|
|
2838 |
'abd' false nil)
|
|
2839 |
('a[^-b]c'
|
|
2840 |
'adc' true (1 'adc')
|
|
2841 |
'a-c' false nil)
|
|
2842 |
('a[^]b]c'
|
|
2843 |
'a]c' false nil
|
|
2844 |
'adc' true (1 'adc'))
|
|
2845 |
('[\de]+'
|
|
2846 |
'01234' true (1 '01234')
|
|
2847 |
'0123e456' true (1 '0123e456')
|
|
2848 |
'0123e45g78' true (1 '0123e45'))
|
|
2849 |
('[e\d]+' "reversal of the above, should be the same"
|
|
2850 |
'01234' true (1 '01234')
|
|
2851 |
'0123e456' true (1 '0123e456')
|
|
2852 |
'0123e45g78' true (1 '0123e45'))
|
|
2853 |
('[\D]+'
|
|
2854 |
'123abc45def78' true (1 'abc'))
|
|
2855 |
('[[:digit:]e]+'
|
|
2856 |
'01234' true (1 '01234')
|
|
2857 |
'0123e456' true (1 '0123e456')
|
|
2858 |
'0123e45g78' true (1 '0123e45'))
|
|
2859 |
('[\s]+'
|
|
2860 |
'2 spaces' true (1 ' '))
|
|
2861 |
('[\S]+'
|
|
2862 |
' word12!!@#$ ' true (1 'word12!!@#$'))
|
|
2863 |
('[\w]+'
|
|
2864 |
' foo123bar 45' true (1 'foo123bar'))
|
|
2865 |
('[\W]+'
|
|
2866 |
'fii234!!@#$34f' true (1 '!!@#$'))
|
|
2867 |
('[^[:alnum:]]+'
|
|
2868 |
'fii234!!@#$34f' true (1 '!!@#$'))
|
|
2869 |
('[%&[:alnum:]]+'
|
|
2870 |
'foo%3' true (1 'foo%3')
|
|
2871 |
'foo34&rt4$57a' true (1 'foo34&rt4')
|
|
2872 |
'!!@#$' false nil)
|
|
2873 |
('[[:alpha:]]+'
|
|
2874 |
' 123foo3 ' true (1 'foo')
|
|
2875 |
'123foo' true (1 'foo')
|
|
2876 |
'foo1b' true (1 'foo'))
|
|
2877 |
('[[:blank:]]+'
|
|
2878 |
'2 blanks' true (1 ' '))
|
|
2879 |
('[^[:blank:]]+'
|
|
2880 |
' word12!!@#$ ' true (1 'word12!!@#$'))
|
|
2881 |
('[[:cntrl:]]+'
|
|
2882 |
' a 1234asdf' false nil)
|
|
2883 |
('[[:lower:]]+'
|
|
2884 |
'UPPERlower1234' true (1 'lower')
|
|
2885 |
'lowerUPPER' true (1 'lower'))
|
|
2886 |
('[[:upper:]]+'
|
|
2887 |
'UPPERlower1234' true (1 'UPPER')
|
|
2888 |
'lowerUPPER ' true (1 'UPPER'))
|
|
2889 |
('[[:space:]]+'
|
|
2890 |
'2 spaces' true (1 ' '))
|
|
2891 |
('[^[:space:]]+'
|
|
2892 |
' word12!!@#$ ' true (1 'word12!!@#$'))
|
|
2893 |
('[[:graph:]]+'
|
|
2894 |
'abc' true (1 'abc'))
|
|
2895 |
('[[:print:]]+'
|
|
2896 |
'abc' true (1 'abc'))
|
|
2897 |
('[^[:punct:]]+'
|
|
2898 |
'!!hello,world!!' true (1 'hello'))
|
|
2899 |
('[[:xdigit:]]+'
|
|
2900 |
' x10FCD ' true (1 '10FCD')
|
|
2901 |
' hgfedcba0123456789ABCDEFGH '
|
|
2902 |
true (1 'fedcba0123456789ABCDEF'))
|
|
2903 |
('ab|cd'
|
|
2904 |
'abc' true (1 'ab')
|
|
2905 |
'abcd' true (1 'ab'))
|
|
2906 |
('()ef'
|
|
2907 |
'def' true (1 'ef' 2 ''))
|
|
2908 |
('()*' nil)
|
|
2909 |
('*a' nil)
|
|
2910 |
('^*' nil)
|
|
2911 |
('$*' nil)
|
|
2912 |
('(*)b' nil)
|
|
2913 |
('$b' 'b' false nil)
|
|
2914 |
('a\' nil)
|
|
2915 |
('a\(b'
|
|
2916 |
'a(b' true (1 'a(b'))
|
|
2917 |
('a\(*b'
|
|
2918 |
'ab' true (1 'ab')
|
|
2919 |
'a((b' true (1 'a((b'))
|
|
2920 |
('a\\b'
|
|
2921 |
'a\b' true (1 'a\b'))
|
|
2922 |
('abc)' nil)
|
|
2923 |
('(abc' nil)
|
|
2924 |
('((a))'
|
|
2925 |
'abc' true (1 'a' 2 'a' 3 'a'))
|
|
2926 |
('(a)b(c)'
|
|
2927 |
'abc' true (1 'abc' 2 'a' 3 'c'))
|
|
2928 |
('a+b+c'
|
|
2929 |
'aabbabc' true (1 'abc'))
|
|
2930 |
('a**' nil)
|
|
2931 |
('a*?' nil)
|
|
2932 |
('(a*)*' nil)
|
|
2933 |
('(a*)+' nil)
|
|
2934 |
('(a|)*' nil)
|
|
2935 |
('(a*|b)*' nil)
|
|
2936 |
('(a+|b)*'
|
|
2937 |
'ab' true (1 'ab' 2 'b'))
|
|
2938 |
('(a+|b)+'
|
|
2939 |
'ab' true (1 'ab' 2 'b'))
|
|
2940 |
('(a+|b)?'
|
|
2941 |
'ab' true (1 'a' 2 'a'))
|
|
2942 |
('[^ab]*'
|
|
2943 |
'cde' true (1 'cde'))
|
|
2944 |
|
|
2945 |
('(^)*' nil)
|
|
2946 |
('(ab|)*' nil)
|
|
2947 |
(')(' nil)
|
|
2948 |
('' 'abc' true (1 ''))
|
|
2949 |
('abc' '' false nil)
|
|
2950 |
('a*'
|
|
2951 |
'' true '')
|
|
2952 |
('abcd'
|
|
2953 |
'abcd' true (1 'abcd'))
|
|
2954 |
('a(bc)d'
|
|
2955 |
'abcd' true (1 'abcd' 2 'bc'))
|
|
2956 |
('([abc])*d'
|
|
2957 |
'abbbcd' true (1 'abbbcd' 2 'c'))
|
|
2958 |
('([abc])*bcd'
|
|
2959 |
'abcd' true (1 'abcd' 2 'a'))
|
|
2960 |
('a|b|c|d|e' 'e' true (1 'e'))
|
|
2961 |
('(a|b|c|d|e)f' 'ef' true (1 'ef' 2 'e'))
|
|
2962 |
" ((a*|b))* - c - -"
|
|
2963 |
('abcd*efg' 'abcdefg' true (1 'abcdefg'))
|
|
2964 |
('ab*'
|
|
2965 |
'xabyabbbz' true (1 'ab')
|
|
2966 |
'xayabbbz' true (1 'a'))
|
|
2967 |
('(ab|cd)e' 'abcde' true (1 'cde' 2 'cd'))
|
|
2968 |
('[abhgefdc]ij' 'hij' true (1 'hij'))
|
|
2969 |
('^(ab|cd)e' 'abcde' false nil)
|
|
2970 |
('(abc|)def' 'abcdef' true nil)
|
|
2971 |
('(a|b)c*d' 'abcd' true (1 'bcd' 2 'b'))
|
|
2972 |
('(ab|ab*)bc' 'abc' true (1 'abc' 2 'a'))
|
|
2973 |
('a([bc]*)c*' 'abc' true (1 'abc' 2 'bc'))
|
|
2974 |
('a([bc]*)(c*d)' 'abcd' true (1 'abcd' 2 'bc' 3 'd'))
|
|
2975 |
('a([bc]+)(c*d)' 'abcd' true (1 'abcd' 2 'bc' 3 'd'))
|
|
2976 |
('a([bc]*)(c+d)' 'abcd' true (1 'abcd' 2 'b' 3 'cd'))
|
|
2977 |
('a[bcd]*dcdcde' 'adcdcde' true (1 'adcdcde'))
|
|
2978 |
('a[bcd]+dcdcde' 'adcdcde' false nil)
|
|
2979 |
('(ab|a)b*c' 'abc' true (1 'abc'))
|
|
2980 |
('((a)(b)c)(d)' 'abcd' true (1 'abcd' 3 'a' 4 'b' 5 'd'))
|
|
2981 |
('[ -~]*' 'abc' true (1 'abc'))
|
|
2982 |
('[ -~ -~]*' 'abc' true (1 'abc'))
|
|
2983 |
('[ -~ -~ -~]*' 'abc' true (1 'abc'))
|
|
2984 |
('[ -~ -~ -~ -~]*' 'abc' true (1 'abc'))
|
|
2985 |
('[ -~ -~ -~ -~ -~]*' 'abc' true (1 'abc'))
|
|
2986 |
('[ -~ -~ -~ -~ -~ -~]*' 'abc' true (1 'abc'))
|
|
2987 |
('[ -~ -~ -~ -~ -~ -~ -~]*' 'abc' true (1 'abc'))
|
|
2988 |
('[a-zA-Z_][a-zA-Z0-9_]*' 'alpha' true (1 'alpha'))
|
|
2989 |
('^a(bc+|b[eh])g|.h$' 'abh' true (1 'bh' 2 ''))
|
|
2990 |
('(bc+d$|ef*g.|h?i(j|k))'
|
|
2991 |
'effgz' true (1 'effgz' 2 'effgz' 3 '')
|
|
2992 |
'ij' true (1 'ij' 2 'ij' 3 'j')
|
|
2993 |
'effg' false nil
|
|
2994 |
'bcdd' false nil
|
|
2995 |
'reffgz' true (1 'effgz' 2 'effgz' 3 ''))
|
|
2996 |
('(((((((((a)))))))))' 'a' true (1 'a'))
|
|
2997 |
('multiple words of text'
|
|
2998 |
'uh-uh' false nil
|
|
2999 |
'multiple words of text, yeah' true (1 'multiple words of text'))
|
|
3000 |
('(.*)c(.*)' 'abcde' true (1 'abcde' 2 'ab' 3 'de'))
|
|
3001 |
('\((.*), (.*)\)' '(a, b)' true (2 'a' 3 'b'))
|
|
3002 |
|
|
3003 |
)
|
1865
|
3004 |
! !
|
|
3005 |
|
|
3006 |
!RxTests methodsFor:'test suite - string interface'!
|
|
3007 |
|
|
3008 |
testS001
|
|
3009 |
self assert:( 'abc' matchesRegex:'abc' ).
|
|
3010 |
self assert:( 'abc' matchesRegex:'ab.' ).
|
|
3011 |
self assert:( 'abc' matchesRegex:'ab.*' ).
|
|
3012 |
self assert:( 'abc' matchesRegex:'a.*' ).
|
|
3013 |
self assert:( 'abc' matchesRegex:'.*' ).
|
|
3014 |
self assert:( 'abc' matchesRegex:'[ab].*' ).
|
|
3015 |
self assert:( 'bca' matchesRegex:'[ab].*' ).
|
|
3016 |
self assert:( 'cab' matchesRegex:'[ab].*' ) not.
|
|
3017 |
|
|
3018 |
"
|
|
3019 |
self new testS001
|
|
3020 |
"
|
|
3021 |
!
|
|
3022 |
|
|
3023 |
testS002
|
|
3024 |
self assert:( 'abc' matchesRegexIgnoringCase:'abc' ).
|
|
3025 |
self assert:( 'ABC' matchesRegexIgnoringCase:'abc' ).
|
|
3026 |
self assert:( 'ABC' matchesRegex:'abc' ) not.
|
|
3027 |
self assert:( 'aBc' matchesRegexIgnoringCase:'abc' ).
|
|
3028 |
self assert:( 'aBc' matchesRegex:'abc' ) not.
|
|
3029 |
|
|
3030 |
self assert:( 'abc' matchesRegexIgnoringCase:'ab.' ).
|
|
3031 |
self assert:( 'ABC' matchesRegexIgnoringCase:'ab.' ).
|
|
3032 |
self assert:( 'ABC' matchesRegex:'ab.' ) not.
|
|
3033 |
self assert:( 'aBc' matchesRegexIgnoringCase:'ab.' ).
|
|
3034 |
self assert:( 'aBc' matchesRegex:'ab.' ) not.
|
|
3035 |
|
|
3036 |
self assert:( 'abc' matchesRegexIgnoringCase:'ab.*' ).
|
|
3037 |
self assert:( 'ABC' matchesRegexIgnoringCase:'ab.*' ).
|
|
3038 |
self assert:( 'ABC' matchesRegex:'ab.*' ) not.
|
|
3039 |
self assert:( 'aBc' matchesRegexIgnoringCase:'ab.*' ).
|
|
3040 |
self assert:( 'aBc' matchesRegex:'ab.*' ) not.
|
|
3041 |
|
|
3042 |
self assert:( 'abc' matchesRegexIgnoringCase:'a.*' ).
|
|
3043 |
self assert:( 'ABC' matchesRegexIgnoringCase:'a.*' ).
|
|
3044 |
self assert:( 'ABC' matchesRegex:'a.*' ) not.
|
|
3045 |
self assert:( 'aBc' matchesRegexIgnoringCase:'a.*' ).
|
|
3046 |
self assert:( 'aBc' matchesRegex:'a.*' ).
|
|
3047 |
|
|
3048 |
self assert:( 'abc' matchesRegexIgnoringCase:'.*' ).
|
|
3049 |
self assert:( 'ABC' matchesRegexIgnoringCase:'.*' ).
|
|
3050 |
self assert:( 'ABC' matchesRegex:'.*' ).
|
|
3051 |
self assert:( 'aBc' matchesRegexIgnoringCase:'.*' ).
|
|
3052 |
self assert:( 'aBc' matchesRegex:'.*' ).
|
|
3053 |
|
|
3054 |
self assert:( 'abc' matchesRegexIgnoringCase:'[ab].*' ).
|
|
3055 |
self assert:( 'ABC' matchesRegexIgnoringCase:'[ab].*' ).
|
|
3056 |
self assert:( 'ABC' matchesRegex:'[ab].*' ) not.
|
|
3057 |
self assert:( 'aBc' matchesRegexIgnoringCase:'[ab].*' ).
|
|
3058 |
self assert:( 'aBc' matchesRegex:'[ab].*' ).
|
|
3059 |
|
|
3060 |
self assert:( 'bca' matchesRegexIgnoringCase:'[ab].*' ).
|
|
3061 |
self assert:( 'BCA' matchesRegexIgnoringCase:'[ab].*' ).
|
|
3062 |
self assert:( 'BCA' matchesRegex:'[ab].*' ) not.
|
|
3063 |
self assert:( 'Bca' matchesRegexIgnoringCase:'[ab].*' ).
|
|
3064 |
self assert:( 'Bca' matchesRegex:'[ab].*' ) not.
|
|
3065 |
|
|
3066 |
self assert:( 'cab' matchesRegexIgnoringCase:'[ab].*' ) not.
|
|
3067 |
self assert:( 'CAB' matchesRegexIgnoringCase:'[ab].*' ) not.
|
|
3068 |
self assert:( 'CAB' matchesRegex:'[ab].*' ) not.
|
|
3069 |
self assert:( 'caB' matchesRegexIgnoringCase:'[ab].*' ) not.
|
|
3070 |
self assert:( 'caB' matchesRegex:'[ab].*' ) not.
|
|
3071 |
|
|
3072 |
"
|
|
3073 |
self new testS002
|
|
3074 |
"
|
|
3075 |
! !
|
|
3076 |
|
|
3077 |
!RxTests methodsFor:'test suite conversion'!
|
|
3078 |
|
|
3079 |
writeAllTests
|
1868
|
3080 |
"Build individual tests from the test suite."
|
|
3081 |
|
|
3082 |
| aTest matcherClass rxSource matcher isOK subexpr |
|
|
3083 |
|
|
3084 |
matcherClass := Regex::RxMatcher.
|
|
3085 |
|
|
3086 |
1 to: self xtestSuite size do: [ :n |
|
|
3087 |
aTest := self xtestSuite at: n.
|
|
3088 |
Transcript
|
|
3089 |
show: 'test', n printString; cr;
|
|
3090 |
tab; show: '| matcher |'; cr; cr;
|
|
3091 |
tab; show: 'self should: [ (matcher := Regex::RxParser compileRegex: ''', aTest first, ''' into:Regex::RxMatcher)'.
|
|
3092 |
(aTest at: 2) isNil
|
|
3093 |
ifTrue: [ Transcript show: ' = nil ].'; cr ]
|
|
3094 |
ifFalse: [
|
|
3095 |
Transcript show: ' ~= nil ].'; cr.
|
|
3096 |
2 to: aTest size by: 3 do:
|
|
3097 |
[:i |
|
|
3098 |
Transcript tab; show: 'self should: [ (matcher search: ', (aTest at: i) printString, ') = ',
|
|
3099 |
(aTest at: i+1) printString, ' ].'; cr.
|
|
3100 |
(aTest at: i+1) ~= nil ifTrue: [
|
|
3101 |
subexpr := aTest at: i+2.
|
|
3102 |
1 to: subexpr size by: 2 do: [ :j |
|
|
3103 |
Transcript tab; show: 'self should: [ (matcher subexpression: ',
|
|
3104 |
(subexpr at: j) printString, ') = ', (subexpr at: j+1) printString,
|
|
3105 |
' ].'; cr ]]]]]
|
1865
|
3106 |
! !
|
|
3107 |
|
2409
|
3108 |
!RxTests methodsFor:'testing'!
|
|
3109 |
|
|
3110 |
testRegex001
|
|
3111 |
self runRegex: #('^.*$'
|
|
3112 |
'' true (1 '')
|
|
3113 |
'a' true (1 'a')
|
|
3114 |
'abc' true (1 'abc'))
|
|
3115 |
!
|
|
3116 |
|
|
3117 |
testRegex002
|
|
3118 |
self runRegex: #('a\w+c'
|
|
3119 |
' abb_bbc ' true (1 'abb_bbc')
|
|
3120 |
'abb-bc' false nil)
|
|
3121 |
!
|
|
3122 |
|
|
3123 |
testRegex003
|
|
3124 |
self runRegex: #('a\W+c'
|
|
3125 |
' abb_bbc ' false nil
|
|
3126 |
'abb-bc' false nil
|
|
3127 |
'a.,:;-&!!"#%/()={[]}+?\~*''c' true (1 'a.,:;-&!!"#%/()={[]}+?\~*''c'))
|
|
3128 |
!
|
|
3129 |
|
|
3130 |
testRegex004
|
|
3131 |
self runRegex: #(':isVowel:'
|
|
3132 |
'aei' true nil
|
|
3133 |
'xyz' false nil)
|
|
3134 |
! !
|
|
3135 |
|
|
3136 |
!RxTests methodsFor:'testing-extensions'!
|
|
3137 |
|
|
3138 |
testStringAllRangesOfRegexMatches
|
|
3139 |
| result |
|
|
3140 |
result := 'aabbcc' allRangesOfRegexMatches: 'b+'.
|
|
3141 |
self
|
|
3142 |
assert: result size equals: 1;
|
|
3143 |
assert: result first first equals: 3;
|
|
3144 |
assert: result first last equals: 4
|
|
3145 |
|
|
3146 |
!
|
|
3147 |
|
|
3148 |
testStringAllRegexMatches
|
|
3149 |
| result |
|
|
3150 |
result := 'aabbcc' allRegexMatches: 'b+'.
|
|
3151 |
self
|
|
3152 |
assert: result size equals: 1;
|
|
3153 |
assert: result first equals: 'bb'
|
|
3154 |
!
|
|
3155 |
|
|
3156 |
testStringAsRegex
|
|
3157 |
|
|
3158 |
self assert: 'b+' asRegex class equals: Regex::RxParser preferredMatcherClass
|
|
3159 |
!
|
|
3160 |
|
|
3161 |
testStringAsRegexIgnoringCase
|
|
3162 |
|
|
3163 |
self assert: 'b+' asRegexIgnoringCase class equals: Regex::RxParser preferredMatcherClass
|
|
3164 |
!
|
|
3165 |
|
|
3166 |
testStringCopyWithRegexMatchesReplacedWith
|
|
3167 |
|
|
3168 |
self assert: ('aabbcc' copyWithRegex: 'b+' matchesReplacedWith: 'X') equals: 'aaXcc'
|
|
3169 |
!
|
|
3170 |
|
|
3171 |
testStringCopyWithRegexMatchesTranslatedUsing
|
|
3172 |
self assert: ('aabbcc'
|
|
3173 |
copyWithRegex: 'b+'
|
|
3174 |
matchesTranslatedUsing: [ :each |
|
|
3175 |
self assert: each equals: 'bb'.
|
|
3176 |
'X' ]) equals: 'aaXcc'
|
|
3177 |
!
|
|
3178 |
|
|
3179 |
testStringMatchesRegex
|
|
3180 |
self deny: ('aabbcc' matchesRegex: 'a+').
|
|
3181 |
self deny: ('aabbcc' matchesRegex: 'b+c+').
|
|
3182 |
self assert: ('aabbcc' matchesRegex: 'a+b+c+')
|
|
3183 |
!
|
|
3184 |
|
|
3185 |
testStringMatchesRegexIgnoringCase
|
|
3186 |
self deny: ('AABBCC' matchesRegexIgnoringCase: 'a+').
|
|
3187 |
self deny: ('AABBCC' matchesRegexIgnoringCase: 'b+c+').
|
|
3188 |
self assert: ('AABBCC' matchesRegexIgnoringCase: 'a+b+c+')
|
|
3189 |
!
|
|
3190 |
|
|
3191 |
testStringPrefixMatchesRegex
|
|
3192 |
self assert: ('aabbcc' prefixMatchesRegex: 'a+').
|
|
3193 |
self deny: ('aabbcc' prefixMatchesRegex: 'b+')
|
|
3194 |
!
|
|
3195 |
|
|
3196 |
testStringPrefixMatchesRegexIgnoringCase
|
|
3197 |
self assert: ('AABBCC' prefixMatchesRegexIgnoringCase: 'a+').
|
|
3198 |
self deny: ('AABBCC' prefixMatchesRegexIgnoringCase: 'b+')
|
|
3199 |
!
|
|
3200 |
|
|
3201 |
testStringRegexMatchesCollect
|
|
3202 |
| result |
|
|
3203 |
result := 'aabbcc' regex: 'b+' matchesCollect: [ :each | each asUppercase ].
|
|
3204 |
self
|
|
3205 |
assert: result size equals: 1;
|
|
3206 |
assert: result first equals: 'BB'
|
|
3207 |
!
|
|
3208 |
|
|
3209 |
testStringRegexMatchesDo
|
|
3210 |
| result |
|
|
3211 |
result := OrderedCollection new.
|
|
3212 |
'aabbcc' regex: 'b+' matchesDo: [ :each | result add: each ].
|
|
3213 |
self
|
|
3214 |
assert: result size equals: 1;
|
|
3215 |
assert: result first equals: 'bb'
|
|
3216 |
! !
|
|
3217 |
|
|
3218 |
!RxTests methodsFor:'testing-henry'!
|
|
3219 |
|
|
3220 |
henryReadme
|
|
3221 |
self error: 'The tests in this category are based on the ones in Henry Spencer''s regexp.c package.'
|
|
3222 |
!
|
|
3223 |
|
|
3224 |
testHenry013
|
|
3225 |
self runRegex: #('.a.*'
|
|
3226 |
'1234abc' true (1 '4abc')
|
|
3227 |
'abcd' false nil)
|
|
3228 |
!
|
|
3229 |
|
|
3230 |
testHenry059
|
|
3231 |
self runRegex: #('[[:alpha:]]+'
|
|
3232 |
' 123foo3 ' true (1 'foo')
|
|
3233 |
'123foo' true (1 'foo')
|
|
3234 |
'foo1b' true (1 'foo'))
|
|
3235 |
!
|
|
3236 |
|
|
3237 |
testHenry101
|
|
3238 |
self runRegex: #('a*'
|
|
3239 |
'' true '')
|
|
3240 |
!
|
|
3241 |
|
|
3242 |
testHenry102
|
|
3243 |
self runRegex: #('abcd'
|
|
3244 |
'abcd' true (1 'abcd'))
|
|
3245 |
!
|
|
3246 |
|
|
3247 |
testHenry103
|
|
3248 |
self runRegex: #('a(bc)d'
|
|
3249 |
'abcd' true (1 'abcd' 2 'bc'))
|
|
3250 |
!
|
|
3251 |
|
|
3252 |
testHenry104
|
|
3253 |
self runRegex: #('([abc])*d'
|
|
3254 |
'abbbcd' true (1 'abbbcd' 2 'c'))
|
|
3255 |
!
|
|
3256 |
|
|
3257 |
testHenry105
|
|
3258 |
self runRegex: #('([abc])*bcd'
|
|
3259 |
'abcd' true (1 'abcd' 2 'a'))
|
|
3260 |
!
|
|
3261 |
|
|
3262 |
testHenry106
|
|
3263 |
self runRegex: #('a|b|c|d|e' 'e' true (1 'e'))
|
|
3264 |
!
|
|
3265 |
|
|
3266 |
testHenry107
|
|
3267 |
self runRegex: #('(a|b|c|d|e)f'
|
|
3268 |
'ef' true (1 'ef' 2 'e'))
|
|
3269 |
" ((a*|b))* - c - -"
|
|
3270 |
!
|
|
3271 |
|
|
3272 |
testHenry108
|
|
3273 |
self runRegex: #('abcd*efg'
|
|
3274 |
'abcdefg' true (1 'abcdefg'))
|
|
3275 |
!
|
|
3276 |
|
|
3277 |
testHenry109
|
|
3278 |
self runRegex: #('ab*'
|
|
3279 |
'xabyabbbz' true (1 'ab')
|
|
3280 |
'xayabbbz' true (1 'a'))
|
|
3281 |
!
|
|
3282 |
|
|
3283 |
testHenry110
|
|
3284 |
self runRegex: #('(ab|cd)e' 'abcde' true (1 'cde' 2 'cd'))
|
|
3285 |
!
|
|
3286 |
|
|
3287 |
testHenry111
|
|
3288 |
self runRegex: #('[abhgefdc]ij' 'hij' true (1 'hij'))
|
|
3289 |
!
|
|
3290 |
|
|
3291 |
testHenry112
|
|
3292 |
self runRegex: #('^(ab|cd)e' 'abcde' false nil)
|
|
3293 |
|
|
3294 |
!
|
|
3295 |
|
|
3296 |
testHenry113
|
|
3297 |
self runRegex: #('(abc|)def' 'abcdef' true nil)
|
|
3298 |
|
|
3299 |
!
|
|
3300 |
|
|
3301 |
testHenry114
|
|
3302 |
self runRegex: #('(a|b)c*d' 'abcd' true (1 'bcd' 2 'b'))
|
|
3303 |
|
|
3304 |
!
|
|
3305 |
|
|
3306 |
testHenry115
|
|
3307 |
self runRegex: #('(ab|ab*)bc' 'abc' true (1 'abc' 2 'a'))
|
|
3308 |
|
|
3309 |
!
|
|
3310 |
|
|
3311 |
testHenry116
|
|
3312 |
self runRegex: #('a([bc]*)c*' 'abc' true (1 'abc' 2 'bc'))
|
|
3313 |
|
|
3314 |
!
|
|
3315 |
|
|
3316 |
testHenry117
|
|
3317 |
self runRegex: #('a([bc]*)(c*d)' 'abcd' true (1 'abcd' 2 'bc' 3 'd'))
|
|
3318 |
|
|
3319 |
!
|
|
3320 |
|
|
3321 |
testHenry118
|
|
3322 |
self runRegex: #('a([bc]+)(c*d)' 'abcd' true (1 'abcd' 2 'bc' 3 'd'))
|
|
3323 |
|
|
3324 |
!
|
|
3325 |
|
|
3326 |
testHenry119
|
|
3327 |
self runRegex: #('a([bc]*)(c+d)' 'abcd' true (1 'abcd' 2 'b' 3 'cd'))
|
|
3328 |
|
|
3329 |
!
|
|
3330 |
|
|
3331 |
testHenry120
|
|
3332 |
self runRegex: #('a[bcd]*dcdcde' 'adcdcde' true (1 'adcdcde'))
|
|
3333 |
|
|
3334 |
!
|
|
3335 |
|
|
3336 |
testHenry121
|
|
3337 |
self runRegex: #('a[bcd]+dcdcde' 'adcdcde' false nil)
|
|
3338 |
|
|
3339 |
!
|
|
3340 |
|
|
3341 |
testHenry122
|
|
3342 |
self runRegex: #('(ab|a)b*c' 'abc' true (1 'abc'))
|
|
3343 |
|
|
3344 |
!
|
|
3345 |
|
|
3346 |
testHenry123
|
|
3347 |
self runRegex: #('((a)(b)c)(d)' 'abcd' true (1 'abcd' 3 'a' 4 'b' 5 'd'))
|
|
3348 |
|
|
3349 |
!
|
|
3350 |
|
|
3351 |
testHenry124
|
|
3352 |
self runRegex: #('[ -~]*' 'abc' true (1 'abc'))
|
|
3353 |
|
|
3354 |
!
|
|
3355 |
|
|
3356 |
testHenry125
|
|
3357 |
self runRegex: #('[ -~ -~]*' 'abc' true (1 'abc'))
|
|
3358 |
|
|
3359 |
!
|
|
3360 |
|
|
3361 |
testHenry126
|
|
3362 |
self runRegex: #('[ -~ -~ -~]*' 'abc' true (1 'abc'))
|
|
3363 |
|
|
3364 |
!
|
|
3365 |
|
|
3366 |
testHenry127
|
|
3367 |
self runRegex: #('[ -~ -~ -~ -~]*' 'abc' true (1 'abc'))
|
|
3368 |
|
|
3369 |
!
|
|
3370 |
|
|
3371 |
testHenry128
|
|
3372 |
self runRegex: #('[ -~ -~ -~ -~ -~]*' 'abc' true (1 'abc'))
|
|
3373 |
|
|
3374 |
!
|
|
3375 |
|
|
3376 |
testHenry129
|
|
3377 |
self runRegex: #('[ -~ -~ -~ -~ -~ -~]*' 'abc' true (1 'abc'))
|
|
3378 |
|
|
3379 |
!
|
|
3380 |
|
|
3381 |
testHenry130
|
|
3382 |
self runRegex: #('[ -~ -~ -~ -~ -~ -~ -~]*' 'abc' true (1 'abc'))
|
|
3383 |
|
|
3384 |
!
|
|
3385 |
|
|
3386 |
testHenry131
|
|
3387 |
self runRegex: #('[a-zA-Z_][a-zA-Z0-9_]*' 'alpha' true (1 'alpha'))
|
|
3388 |
|
|
3389 |
!
|
|
3390 |
|
|
3391 |
testHenry132
|
|
3392 |
self runRegex: #('^a(bc+|b[eh])g|.h$' 'abh' true (1 'bh' 2 nil))
|
|
3393 |
|
|
3394 |
!
|
|
3395 |
|
|
3396 |
testHenry133
|
|
3397 |
self runRegex: #('(bc+d$|ef*g.|h?i(j|k))'
|
|
3398 |
'effgz' true (1 'effgz' 2 'effgz' 3 nil)
|
|
3399 |
'ij' true (1 'ij' 2 'ij' 3 'j')
|
|
3400 |
'effg' false nil
|
|
3401 |
'bcdd' false nil
|
|
3402 |
'reffgz' true (1 'effgz' 2 'effgz' 3 nil))
|
|
3403 |
!
|
|
3404 |
|
|
3405 |
testHenry134
|
|
3406 |
self runRegex: #('(((((((((a)))))))))' 'a' true (1 'a'))
|
|
3407 |
!
|
|
3408 |
|
|
3409 |
testHenry135
|
|
3410 |
self runRegex: #('multiple words of text'
|
|
3411 |
'uh-uh' false nil
|
|
3412 |
'multiple words of text, yeah' true (1 'multiple words of text'))
|
|
3413 |
!
|
|
3414 |
|
|
3415 |
testHenry136
|
|
3416 |
self runRegex: #('(.*)c(.*)' 'abcde' true (1 'abcde' 2 'ab' 3 'de'))
|
|
3417 |
!
|
|
3418 |
|
|
3419 |
testHenry137
|
|
3420 |
self runRegex: #('\((.*), (.*)\)' '(a, b)' true (2 'a' 3 'b'))
|
|
3421 |
! !
|
|
3422 |
|
|
3423 |
!RxTests methodsFor:'testing-protocol'!
|
|
3424 |
|
|
3425 |
testMatches
|
|
3426 |
| matcher |
|
|
3427 |
matcher := self matcherClass forString: '\w+'.
|
|
3428 |
self assert: (matcher matches: 'now').
|
|
3429 |
self deny: (matcher matches: 'now is')
|
|
3430 |
!
|
|
3431 |
|
|
3432 |
testMatchesIn
|
|
3433 |
| matcher |
|
|
3434 |
matcher := self matcherClass forString: '\w+'.
|
|
3435 |
self assert: (matcher matchesIn: 'now is the time') asArray
|
|
3436 |
= #('now' 'is' 'the' 'time')
|
|
3437 |
!
|
|
3438 |
|
|
3439 |
testMatchesInCollect
|
|
3440 |
| matcher |
|
|
3441 |
matcher := self matcherClass forString: '\w+'.
|
|
3442 |
self assert: (matcher
|
|
3443 |
matchesIn: 'now is the time'
|
|
3444 |
collect: [ :each | each reversed ]) asArray
|
|
3445 |
= #('won' 'si' 'eht' 'emit')
|
|
3446 |
!
|
|
3447 |
|
|
3448 |
testMatchesInDo
|
|
3449 |
| matcher expected |
|
|
3450 |
matcher := self matcherClass forString: '\w+'.
|
|
3451 |
expected := #('now' 'is' 'the' 'time') asOrderedCollection.
|
|
3452 |
matcher matchesIn: 'now is the time' do: [ :each | self assert: each = expected removeFirst ].
|
|
3453 |
self assertEmpty: expected
|
|
3454 |
!
|
|
3455 |
|
|
3456 |
testMatchesOnStream
|
|
3457 |
| matcher |
|
|
3458 |
matcher := self matcherClass forString: '\w+'.
|
|
3459 |
self assert: (matcher matchesOnStream: 'now is the time' readStream) asArray
|
|
3460 |
= #('now' 'is' 'the' 'time')
|
|
3461 |
!
|
|
3462 |
|
|
3463 |
testMatchesOnStreamCollect
|
|
3464 |
| matcher |
|
|
3465 |
matcher := self matcherClass forString: '\w+'.
|
|
3466 |
self assert: (matcher
|
|
3467 |
matchesOnStream: 'now is the time' readStream
|
|
3468 |
collect: [ :each | each reversed ]) asArray
|
|
3469 |
= #('won' 'si' 'eht' 'emit')
|
|
3470 |
!
|
|
3471 |
|
|
3472 |
testMatchesOnStreamDo
|
|
3473 |
| matcher expected |
|
|
3474 |
matcher := self matcherClass forString: '\w+'.
|
|
3475 |
expected := #('now' 'is' 'the' 'time') asOrderedCollection.
|
|
3476 |
matcher matchesOnStream: 'now is the time' readStream do: [ :each | self assert: each = expected removeFirst ].
|
|
3477 |
self assertEmpty: expected
|
|
3478 |
!
|
|
3479 |
|
|
3480 |
testMatchesStream
|
|
3481 |
| matcher |
|
|
3482 |
matcher := self matcherClass forString: '\w+'.
|
|
3483 |
self assert: (matcher matchesStream: 'now' readStream).
|
|
3484 |
self deny: (matcher matchesStream: 'now is' readStream)
|
|
3485 |
!
|
|
3486 |
|
|
3487 |
testMatchingRangesIn
|
|
3488 |
| matcher expected |
|
|
3489 |
matcher := self matcherClass forString: '\w+'.
|
|
3490 |
expected := #(1 3 5 6 8 10 12 15) asOrderedCollection.
|
|
3491 |
(matcher matchingRangesIn: 'now is the time')
|
|
3492 |
do: [ :range |
|
|
3493 |
self assert: range first = expected removeFirst.
|
|
3494 |
self assert: range last = expected removeFirst ].
|
|
3495 |
self assertEmpty: expected
|
|
3496 |
!
|
|
3497 |
|
|
3498 |
testSubexpressionCount
|
|
3499 |
| matcher |
|
|
3500 |
#(('a' 1) ('a(b)' 2) ('a(b(c))' 3) ('(a)(b)' 3) ('(a(b))*' 3)) do: [ :pair |
|
|
3501 |
matcher := self matcherClass forString: pair first.
|
|
3502 |
matcher supportsSubexpressions
|
|
3503 |
ifTrue: [ self assert: matcher subexpressionCount equals: pair last ] ]
|
|
3504 |
! !
|
|
3505 |
|
1865
|
3506 |
!RxTests class methodsFor:'documentation'!
|
|
3507 |
|
|
3508 |
version
|
|
3509 |
^ '$Header$'
|
|
3510 |
!
|
|
3511 |
|
|
3512 |
version_CVS
|
|
3513 |
^ '$Header$'
|
|
3514 |
! !
|
1869
|
3515 |
|