-
Notifications
You must be signed in to change notification settings - Fork 0
/
retest.rex
499 lines (401 loc) · 17.2 KB
/
retest.rex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
/* RexxRE test suite.
*
* In contrast to, say, the RegUtil test suite, if this reports failure,
* there's something wrong.
*
* Copyright 2003, Patrick TJ McPhee
* Distributed under the Mozilla Public Licence.
* $Header: C:/ptjm/rexx/rexxre/RCS/retest.rex 1.6 2003/05/01 15:50:26 ptjm Rel $
*/
rcc = rxfuncquery('reloadfuncs')
if rcc then do
rcc = rxfuncadd('reloadfuncs', 'rexxre', 'reloadfuncs')
if rcc then fail('load' rxfuncerrmsg())
end
call reloadfuncs
say '****' parse tests
rcc = reparse('[a-z][a-z]*', 'noodles are poodles', 'v', 'n', 'a', 'p', 'd', 'x')
test = 'parse with v flag'
if \rcc then fail(test)
if n \= 'noodles' then fail(test', first variable' n)
if a \= 'are' then fail(test', second variable' a)
if p \= 'poodles' then fail(test', third variable' p)
if d \= '' then fail(test', extra variable' d)
if x \= '' then fail(test', last variable' x)
say 'pass' test
rcc = reparse('([a-z]+) ([a-z]+) ([a-z]+) ([a-z]+) ([a-z]+)', 'I go to the store', 'xs', 'n', 'a', 'p', 'd', 'x')
test = 'parse with s flag'
if \rcc then fail(test)
if n \= 'I' then fail(test', first variable' n)
if a \= 'go' then fail(test', second variable' a)
if p \= 'to' then fail(test', third variable' p)
if d \= 'the' then fail(test', fourth variable' d)
if x \= 'store' then fail(test', last variable' x)
say 'pass' test
rcc = reparse('([a-z]+) ([a-z]+) ([a-z]+) ([a-z]+) ([a-z]+)', 'I go to the store', 'xst', 'bo')
test = 'parse with s and t flags'
if \rcc then fail(test)
if bo.0 \= 5 then fail(test', bo.0' bo.0)
if bo.1 \= 'I' then fail(test', first variable' bo.1)
if bo.2 \= 'go' then fail(test', second variable' bo.2)
if bo.3 \= 'to' then fail(test', third variable' bo.3)
if bo.4 \= 'the' then fail(test', fourth variable' bo.4)
if bo.5 \= 'store' then fail(test', last variable' bo.5)
say 'pass' test
rcc = reparse('([a-z]+) ([a-z]+) ([a-z]+) ([a-z]+) ([a-z]+)', 'I go to the store', 'xsc', 'n', 'a', 'p', 'd', 'x')
test = 'parse with s and c flags'
if rcc then fail(test)
if n \= '' then fail(test', first variable' n)
if a \= '' then fail(test', second variable' a)
if p \= '' then fail(test', third variable' p)
if d \= '' then fail(test', fourth variable' d)
if x \= '' then fail(test', last variable' x)
say 'pass' test
rcc = reparse(' *[0-9]+ *', '17 Captions 18 Frogs 23 Legs 17 Subtitles 28 French 30 German', 'x', 'n', 'a', 'p', 'd', 'x', '.')
test = 'parse with no flags, trailing dot'
if \rcc then fail(test)
if n \= '' then fail(test', first variable' n)
if a \= 'Captions' then fail(test', second variable' a)
if p \= 'Frogs' then fail(test', third variable' p)
if d \= 'Legs' then fail(test', fourth variable' d)
if x \= 'Subtitles' then fail(test', last variable' x)
say 'pass' test
rcc = reparse(' *[0-9]+ *', '17 Captions 18 Frogs 23 Legs 17 Subtitles 28 French 30 German', 'x', 'n', 'a', 'p', 'd', 'x')
test = 'parse with no flags'
if \rcc then fail(test)
if n \= '' then fail(test', first variable' n)
if a \= 'Captions' then fail(test', second variable' a)
if p \= 'Frogs' then fail(test', third variable' p)
if d \= 'Legs' then fail(test', fourth variable' d)
if x \= 'Subtitles 28 French 30 German' then fail(test', last variable' x)
say 'pass' test
rcc = reparse(' *[0-9]+ *', '17 Captions 18 Frogs 23 Legs 17 Subtitles 28 French 30 German', 'xt', 'bo')
test = 'parse with t flag'
if \rcc then fail(test)
if bo.0 \= 7 then fail(test', wrong count' bo.0)
if bo.1 \= '' then fail(test', first variable' bo.1)
if bo.2 \= 'Captions' then fail(test', second variable' bo.2)
if bo.3 \= 'Frogs' then fail(test', third variable' bo.3)
if bo.4 \= 'Legs' then fail(test', fourth variable' bo.4)
if bo.5 \= 'Subtitles' then fail(test', fifth variable' bo.5)
if bo.6 \= 'French' then fail(test', sixth variable' bo.6)
if bo.7 \= 'German' then fail(test', seventh variable' bo.7)
say 'pass' test
rcc = reparse('[a-z]+', '17 Captions 18 Frogs 23 Legs 17 Subtitles 28 French 30 German', 'xv', 'n', 'a', 'p', 'd', 'x')
test = 'parse with v flag'
if \rcc then fail(test)
if n \= 'Captions' then fail(test', second variable' n)
if a \= 'Frogs' then fail(test', third variable' a)
if p \= 'Legs' then fail(test', fourth variable' p)
if d \= 'Subtitles' then fail(test', last variable' d)
if x \= ' 28 French 30 German' then fail(test', last variable' x)
say 'pass' test
rcc = reparse('[a-z]+', '17 Captions 18 Frogs 23 Legs 17 Subtitles 28 French 30 German', 'xvt', 'bo')
test = 'parse with t and v flags'
if \rcc then fail(test)
if bo.0 \= 6 then fail(test', wrong count' bo.0)
if bo.1 \= 'Captions' then fail(test', first variable' bo.1)
if bo.2 \= 'Frogs' then fail(test', second variable' bo.2)
if bo.3 \= 'Legs' then fail(test', third variable' bo.3)
if bo.4 \= 'Subtitles' then fail(test', fourth variable' bo.4)
if bo.5 \= 'French' then fail(test', fifth variable' bo.5)
if bo.6 \= 'German' then fail(test', sixth variable' bo.6)
say 'pass' test
say '****' 'compiled parse tests'
cre = ReComp('[a-z][a-z]*')
test = 'compile basic'
if left(cre,1) then fail(test)
say 'pass' test
rcc = reparse(cre, 'noodles are poodles', 'v', 'n', 'a', 'p', 'd', 'x')
test = 'parse with v flag'
if \rcc then fail(test)
if n \= 'noodles' then fail(test', first variable' n)
if a \= 'are' then fail(test', second variable' a)
if p \= 'poodles' then fail(test', third variable' p)
if d \= '' then fail(test', extra variable' d)
if x \= '' then fail(test', last variable' x)
say 'pass' test
call ReFree cre
cre = ReComp('([a-z]+) ([a-z]+) ([a-z]+) ([a-z]+) ([a-z]+)', 'x')
test = 'compile extended with subexpressions'
if left(cre,1) then fail(test)
say 'pass' test
rcc = reparse(cre, 'I go to the store', 'xs', 'n', 'a', 'p', 'd', 'x')
test = 'parse with s flag'
if \rcc then fail(test)
if n \= 'I' then fail(test', first variable' n)
if a \= 'go' then fail(test', second variable' a)
if p \= 'to' then fail(test', third variable' p)
if d \= 'the' then fail(test', fourth variable' d)
if x \= 'store' then fail(test', last variable' x)
say 'pass' test
rcc = reparse(cre, 'I go to the store', 'xst', 'bo')
test = 'parse with s and t flags'
if \rcc then fail(test)
if bo.0 \= 5 then fail(test', bo.0' bo.0)
if bo.1 \= 'I' then fail(test', first variable' bo.1)
if bo.2 \= 'go' then fail(test', second variable' bo.2)
if bo.3 \= 'to' then fail(test', third variable' bo.3)
if bo.4 \= 'the' then fail(test', fourth variable' bo.4)
if bo.5 \= 'store' then fail(test', last variable' bo.5)
say 'pass' test
call ReFree cre
cre = ReComp('([a-z]+) ([a-z]+) ([a-z]+) ([a-z]+) ([a-z]+)', 'xc')
test = 'compile extended with subexpressions, case-sensitive'
if left(cre,1) then fail(test)
say 'pass' test
rcc = reparse(cre, 'I go to the store', 'xsc', 'n', 'a', 'p', 'd', 'x')
test = 'parse with s and c flags'
if rcc then fail(test)
if n \= '' then fail(test', first variable' n)
if a \= '' then fail(test', second variable' a)
if p \= '' then fail(test', third variable' p)
if d \= '' then fail(test', fourth variable' d)
if x \= '' then fail(test', last variable' x)
say 'pass' test
call ReFree cre
cre = ReComp(' *[0-9]+ *', 'x')
test = 'compile extended delimiter'
if left(cre,1) then fail(test)
say 'pass' test
rcc = reparse(cre, '17 Captions 18 Frogs 23 Legs 17 Subtitles 28 French 30 German', 'x', 'n', 'a', 'p', 'd', 'x', '.')
test = 'parse with no flags, trailing dot'
if \rcc then fail(test)
if n \= '' then fail(test', first variable' n)
if a \= 'Captions' then fail(test', second variable' a)
if p \= 'Frogs' then fail(test', third variable' p)
if d \= 'Legs' then fail(test', fourth variable' d)
if x \= 'Subtitles' then fail(test', last variable' x)
say 'pass' test
rcc = reparse(cre, '17 Captions 18 Frogs 23 Legs 17 Subtitles 28 French 30 German', 'x', 'n', 'a', 'p', 'd', 'x')
test = 'parse with no flags'
if \rcc then fail(test)
if n \= '' then fail(test', first variable' n)
if a \= 'Captions' then fail(test', second variable' a)
if p \= 'Frogs' then fail(test', third variable' p)
if d \= 'Legs' then fail(test', fourth variable' d)
if x \= 'Subtitles 28 French 30 German' then fail(test', last variable' x)
say 'pass' test
rcc = reparse(cre, '17 Captions 18 Frogs 23 Legs 17 Subtitles 28 French 30 German', 'xt', 'bo')
test = 'parse with t flag'
if \rcc then fail(test)
if bo.0 \= 7 then fail(test', wrong count' bo.0)
if bo.1 \= '' then fail(test', first variable' bo.1)
if bo.2 \= 'Captions' then fail(test', second variable' bo.2)
if bo.3 \= 'Frogs' then fail(test', third variable' bo.3)
if bo.4 \= 'Legs' then fail(test', fourth variable' bo.4)
if bo.5 \= 'Subtitles' then fail(test', fifth variable' bo.5)
if bo.6 \= 'French' then fail(test', sixth variable' bo.6)
if bo.7 \= 'German' then fail(test', seventh variable' bo.7)
say 'pass' test
call ReFree cre
cre = ReComp('[a-z]+', 'x')
test = 'compile extended'
if left(cre,1) then fail(test)
say 'pass' test
rcc = reparse(cre, '17 Captions 18 Frogs 23 Legs 17 Subtitles 28 French 30 German', 'xv', 'n', 'a', 'p', 'd', 'x')
test = 'parse with v flag'
if \rcc then fail(test)
if n \= 'Captions' then fail(test', second variable' n)
if a \= 'Frogs' then fail(test', third variable' a)
if p \= 'Legs' then fail(test', fourth variable' p)
if d \= 'Subtitles' then fail(test', last variable' d)
if x \= ' 28 French 30 German' then fail(test', last variable' x)
say 'pass' test
rcc = reparse(cre, '17 Captions 18 Frogs 23 Legs 17 Subtitles 28 French 30 German', 'xvt', 'bo')
test = 'parse with t and v flags'
if \rcc then fail(test)
if bo.0 \= 6 then fail(test', wrong count' bo.0)
if bo.1 \= 'Captions' then fail(test', first variable' bo.1)
if bo.2 \= 'Frogs' then fail(test', second variable' bo.2)
if bo.3 \= 'Legs' then fail(test', third variable' bo.3)
if bo.4 \= 'Subtitles' then fail(test', fourth variable' bo.4)
if bo.5 \= 'French' then fail(test', fifth variable' bo.5)
if bo.6 \= 'German' then fail(test', sixth variable' bo.6)
say 'pass' test
call ReFree cre
rec = recomp('C[auo]t[a-z]*', 'c')
test = 'compile case sensitive'
if left(rec, 1) then fail(test ReError(rec))
say 'pass' test
rei = recomp('C[auo]t[a-z]*')
test = 'compile case insensitive'
if left(rei, 1) then fail(test ReError(rei))
say 'pass' test
target = 'On the cot, a catatonic cat named Catherine cut things.'
test = 'parse repeatedly with v flag, case sensitive, pass 1'
rcc = ReParse(rec, target, 'v', 'match', 'target')
if \rcc then fail(test)
if match \= 'Catherine' then fail(test', matched' match)
if target \= ' cut things.' then fail(test', remainder' target)
say 'pass' test
test = 'parse repeatedly with v flag, case sensitive, pass 2'
rcc = ReParse(rec, target, 'v', 'match', 'target')
if rcc then fail(test)
if match \= '' then fail(test', matched' match)
if target \= ' cut things.' then fail(test', remainder' target)
say 'pass' test
target = 'On the cot, a catatonic cat named Catherine cut things.'
test = 'parse repeatedly with v flag, case insensitive, pass 1'
rcc = ReParse(rei, target, 'v', 'match', 'target')
if \rcc then fail(test)
if match \= 'cot' then fail(test', matched' match)
if target \= ', a catatonic cat named Catherine cut things.' then fail(test', remainder' target)
say 'pass' test
test = 'parse repeatedly with v flag, case insensitive, pass 2'
rcc = ReParse(rei, target, 'v', 'match', 'target')
if \rcc then fail(test)
if match \= 'catatonic' then fail(test', matched' match)
if target \= ' cat named Catherine cut things.' then fail(test', remainder' target)
say 'pass' test
test = 'parse repeatedly with v flag, case insensitive, pass 3'
rcc = ReParse(rei, target, 'v', 'match', 'target')
if \rcc then fail(test)
if match \= 'cat' then fail(test', matched' match)
if target \= ' named Catherine cut things.' then fail(test', remainder' target)
say 'pass' test
test = 'parse repeatedly with v flag, case insensitive, pass 4'
rcc = ReParse(rei, target, 'v', 'match', 'target')
if \rcc then fail(test)
if match \= 'Catherine' then fail(test', matched' match)
if target \= ' cut things.' then fail(test', remainder' target)
say 'pass' test
test = 'parse repeatedly with v flag, case insensitive, pass 5'
rcc = ReParse(rei, target, 'v', 'match', 'target')
if \rcc then fail(test)
if match \= 'cut' then fail(test', matched' match)
if target \= ' things.' then fail(test', remainder' target)
say 'pass' test
test = 'parse repeatedly with v flag, case insensitive, pass 6'
rcc = ReParse(rei, target, 'v', 'match', 'target')
if rcc then fail(test)
if match \= '' then fail(test', matched' match)
if target \= ' things.' then fail(test', remainder' target)
say 'pass' test
call ReFree rec, rei
cre = ReComp('[[:blank:]][[:blank:]]*')
test = 'compile basic with character class'
if left(cre,1) then fail(test)
say 'pass' test
target = 'On the cot, a catatonic cat named Catherine cut things.'
test = 'parse repeatedly with no flags, pass 1'
rcc = ReParse(cre, target, , 'match', 'target')
if \rcc then fail(test)
if match \= 'On' then fail(test', matched' match)
if target \= 'the cot, a catatonic cat named Catherine cut things.' then fail(test', remainder' target)
say 'pass' test
test = 'parse repeatedly with no flags, pass 2'
rcc = ReParse(cre, target, , 'match', 'target')
if \rcc then fail(test)
if match \= 'the' then fail(test', matched' match)
if target \= 'cot, a catatonic cat named Catherine cut things.' then fail(test', remainder' target)
say 'pass' test
test = 'parse repeatedly with no flags, pass 3'
rcc = ReParse(cre, target, , 'match', 'target')
if \rcc then fail(test)
if match \= 'cot,' then fail(test', matched' match)
if target \= 'a catatonic cat named Catherine cut things.' then fail(test', remainder' target)
say 'pass' test
test = 'parse repeatedly with no flags, pass 4'
rcc = ReParse(cre, target, , 'match', 'target')
if \rcc then fail(test)
if match \= 'a' then fail(test', matched' match)
if target \= 'catatonic cat named Catherine cut things.' then fail(test', remainder' target)
say 'pass' test
test = 'parse repeatedly with no flags, pass 5'
rcc = ReParse(cre, target, , 'match', 'target')
if \rcc then fail(test)
if match \= 'catatonic' then fail(test', matched' match)
if target \= 'cat named Catherine cut things.' then fail(test', remainder' target)
say 'pass' test
test = 'parse repeatedly with no flags, pass 6'
rcc = ReParse(cre, target, , 'match', 'target')
if \rcc then fail(test)
if match \= 'cat' then fail(test', matched' match)
if target \= 'named Catherine cut things.' then fail(test', remainder' target)
say 'pass' test
test = 'parse repeatedly with no flags, pass 7'
rcc = ReParse(cre, target, , 'match', 'target')
if \rcc then fail(test)
if match \= 'named' then fail(test', matched' match)
if target \= 'Catherine cut things.' then fail(test', remainder' target)
say 'pass' test
test = 'parse repeatedly with no flags, pass 8'
rcc = ReParse(cre, target, , 'match', 'target')
if \rcc then fail(test)
if match \= 'Catherine' then fail(test', matched' match)
if target \= 'cut things.' then fail(test', remainder' target)
say 'pass' test
test = 'parse repeatedly with no flags, pass 9'
rcc = ReParse(cre, target, , 'match', 'target')
if \rcc then fail(test)
if match \= 'cut' then fail(test', matched' match)
if target \= 'things.' then fail(test', remainder' target)
say 'pass' test
test = 'parse repeatedly with no flags, pass 10'
rcc = ReParse(cre, target, , 'match', 'target')
if \rcc then fail(test)
if match \= 'things.' then fail(test', matched' match)
if target \= '' then fail(test', remainder' target)
say 'pass' test
test = 'parse repeatedly with no flags, pass 11'
rcc = ReParse(cre, target, , 'match', 'target')
if \rcc then fail(test)
if match \= '' then fail(test', matched' match)
if target \= '' then fail(test', remainder' target)
say 'pass' test
call ReFree cre
say '****' 'exec tests'
re = recomp('([[:digit:]]+) +([[:digit:]]+)', 'x')
test = 'compile with character class'
if left(re, 1) then fail(test ReError(re))
say 'pass' test
rcc = reexec(re, '234 159', 'bo')
test = 'exec no flags'
if \rcc then fail(test)
if bo.0 \= 2 then fail(test', count' bo.0)
if bo.1 \= 234 then fail(test', first match' bo.1)
if bo.2 \= 159 then fail(test', second match' bo.2)
if bo.!match \= '234 159' then fail(test', full match' bo.!match)
say 'pass' test
rcc = reexec(re, '234 159', 'bo', 'p')
test = 'exec p flag'
if \rcc then fail(test)
if bo.0 \= 2 then fail(test', count' bo.0)
if bo.1 \= '1 3' then fail(test', first match' bo.1)
if bo.2 \= '5 3' then fail(test', second match' bo.2)
if bo.!match \= '1 7' then fail(test', full match' bo.!match)
say 'pass' test
call ReFree re
rec = recomp('C[auo]t', 'c')
test = 'compile case sensitive'
if left(rec, 1) then fail(test ReError(rec))
say 'pass' test
rei = recomp('C[auo]t')
test = 'compile case insensitive'
if left(rei, 1) then fail(test ReError(rei))
say 'pass' test
target = 'On the cot, a catatonic cat named Catherine cut things.'
test = 'exec case sensitive'
if \ReExec(rec, target, 'bo') then fail(test)
if bo.!match \= 'Cat' then fail(test', matched' bo.!match)
say 'pass' test
test = 'exec case insensitive'
if \ReExec(rei, target, 'bo') then fail(test)
if bo.!match \= 'cot' then fail(test', matched' bo.!match)
say 'pass' test
test = 'exec positions case sensitive'
if \ReExec(rec, target, 'bo', 'p') then fail(test)
if bo.!match \= '35 3' then fail(test', matched' bo.!match)
say 'pass' test
test = 'exec positions case insensitive'
if \ReExec(rei, target, 'bo', 'p') then fail(test)
if bo.!match \= '8 3' then fail(test', matched' bo.!match)
say 'pass' test
call ReFree rec, rei
say '**** All tests passed'
exit 0
fail:
parse arg reason
say 'fail' reason 'at line' sigl
exit 1