Debian Codegraph @

lib/_irregex/test/test-irregex-from-gauche.scm

raw symbols SCIP
1 ;;; This test suite is derived from Gauche's regex tests.
2
3 (define-syntax let1
4 (syntax-rules ()
5 ((let1 var val body ...)
6 (let ((var val))
7 body ...))))
8
9 (define rxmatch irregex-search)
10 (define (rxmatch-start m . o)
11 (irregex-match-start-index m (if (pair? o) (car o) 0)))
12 (define (rxmatch-end m . o)
13 (irregex-match-end-index m (if (pair? o) (car o) 0)))
14
15 (define (match&list pat input)
16 (let ((irx (irregex pat)))
17 (cond ((irregex-search irx input)
18 => (lambda (match)
19 (map (lambda (n) (irregex-match-substring match n))
20 (iota (+ 1 (irregex-num-submatches irx))))))
21 (else #f))))
22
23 (define (rxmatch-after m . o)
24 (substring (car (irregex-match-start-chunk m 0))
25 (irregex-match-end-index m (if (pair? o) (car o) 0))
26 (string-length (car (irregex-match-start-chunk m 0)))))
27
28 (define (rxmatch-before m . o)
29 (substring (car (irregex-match-start-chunk m 0))
30 0
31 (irregex-match-start-index m (if (pair? o) (car o) 0))))
32
33 (define (rxmatch-substring pat input . o)
34 (let ((i (if (pair? o) (car o) 0)))
35 (cond ((irregex-search pat input)
36 => (lambda (match)
37 (irregex-match-substring match i)))
38 (else #f))))
39
40 (test-begin "from-gauche")
41
42 (test "a(b)c" '("abc" "b")
43 (match&list "a(b)c" "abc"))
44 (test "a((b)(c))" '("abc" "bc" "b" "c")
45 (match&list "a((b)(c))" "abc"))
46 (test "a((((b))))c" '("abc" "b" "b" "b" "b")
47 (match&list "a((((b))))c" "abc"))
48 (test "a((((b))))c" '#f
49 (match&list "a((((b))))c" "a(b)c"))
50 (test "a\\(" '("a(")
51 (match&list "a\\(" "a("))
52 (test "a()b" '("ab" "")
53 (match&list "a()b" "ab"))
54 (test "a()()b" '("ab" "" "")
55 (match&list "a()()b" "ab"))
56 (test "(we|wee|week|frob)(knights|night|day)"
57 '("weeknights" "wee" "knights")
58 (match&list "(we|wee|week|frob)(knights|night|day)"
59 "weeknights"))
60 (test "aa|(bb)|cc" '("aa" #f)
61 (match&list "aa|(bb)|cc" "aabb"))
62 (test "aa|(bb)|cc" '("bb" "bb")
63 (match&list "aa|(bb)|cc" "abbaa"))
64 (test "aa|(bb)|cc" '("cc" #f)
65 (match&list "aa|(bb)|cc" "bccaa"))
66 (test "aa|a(b)|cc" '("ab" "b")
67 (match&list "aa|a(b)|cc" "abaab"))
68 (test "aa|a(b)" '("ab" "b")
69 (match&list "aa|a(b)" "abaab"))
70 (test "aa|(a(b))|ac" '("ab" "ab" "b")
71 (match&list "aa|(a(b))|cc" "abaabcc"))
72 (test "(ab)|ac" '("ab" "ab")
73 (match&list "(ab)|ac" "aaaabcc"))
74 (test "(a(b))|ac" '("ab" "ab" "b")
75 (match&list "(a(b))|ac" "abaabcc"))
76 (test "ab|(ac)" '("ab" #f)
77 (match&list "ab|(ac)" "aaaabcc"))
78 (test "ab|(ac)" '("ac" "ac")
79 (match&list "ab|(ac)" "aaaacbc"))
80 (test "aa|(ab|(ac))|ad" '("ac" "ac" "ac")
81 (match&list "aa|(ab|(ac))|ad" "cac"))
82 (test "(aa|(a(b)|a(c))|ad)" '("ac" "ac" "ac" #f "c")
83 (match&list "(aa|(a(b)|a(c))|ad)" "cac"))
84 (test "(.)*" '("abc" "c")
85 (match&list "(.)*" "abc"))
86 (test "(a([^a])*)*" '("abcaBC" "aBC" "C")
87 (match&list "(a([^a])*)*" "abcaBC"))
88 (test "b|()|a" '("" "")
89 (match&list "b|()|a" "cac"))
90
91 ;;-------------------------------------------------------------------------
92 ;;(test-section "simple meta")
93
94 (test "a.c" '("abc")
95 (match&list "a.c" "abc"))
96 (test "a.." '("abc")
97 (match&list "a.." "abc"))
98 (test "a.." #f
99 (match&list "a.." "ab"))
100 (test "..." #f
101 (match&list "..." "ab"))
102 (test "." '("a")
103 (match&list "." "abc"))
104 (test "." #f
105 (match&list "." ""))
106
107 ;;-------------------------------------------------------------------------
108 ;;(test-section "anchors")
109
110 (test "^abc" '("abc")
111 (match&list "^abc" "abcd"))
112 (test "^abc" #f
113 (match&list "^abc" "aabcd"))
114
115 ;;;; Gauche doesn't treat the ^$ anchors as anchors when they occur in
116 ;;;; positions that couldn't possibly match. This seems a little
117 ;;;; strange to me, so I'm commenting out these tests.
118 ;; (test "^^" '("^")
119 ;; (match&list "^^" "^^abc"))
120 ;; (test "^^" #f
121 ;; (match&list "^^" "a^^c"))
122 (test "^abc|def" '("abc")
123 (match&list "^abc|def" "abc"))
124 (test "^abc|def" #f
125 (match&list "^abc|def" "zabc"))
126 (test "^abc|def" '("def")
127 (match&list "^abc|def" "zabcdef"))
128 (test "abc|^def" '("def")
129 (match&list "abc|^def" "defabc"))
130 (test "abc|^def" '("abc")
131 (match&list "abc|^def" "abcdef"))
132 (test "abc|^def" '("def")
133 (match&list "abc|^def" "defabbc"))
134 (test "abc|^def" #f
135 (match&list "abc|^def" "adefbc"))
136 (test "^(abc|def)" '("abc" "abc")
137 (match&list "^(abc|def)" "abc"))
138 (test "^(abc|def)" #f
139 (match&list "^(abc|def)" "aabc"))
140 (test "(^abc|def)" '("abc" "abc")
141 (match&list "(^abc|def)" "abcdef"))
142 (test "(^abc|def)" '("def" "def")
143 (match&list "(^abc|def)" "^abcdef"))
144 ;; (test "a(^bc|def)" '("a^bc" "^bc")
145 ;; (match&list "a(^bc|def)" "a^bcdef"))
146 ;; (test "a(^bc|def)" #f
147 ;; (match&list "a(^bc|def)" "abcdef"))
148 (test "^" '("")
149 (match&list "^" "hoge"))
150 (test "$" '("")
151 (match&list "$" "hoge"))
152 (test "abc$" '("abc")
153 (match&list "abc$" "bcabc"))
154 (test "abc$" #f
155 (match&list "abc$" "abcab"))
156 (test "^abc$" '("abc")
157 (match&list "^abc$" "abc"))
158 ;; (test "abc$$" #f
159 ;; (match&list "abc$$" "abc"))
160 ;; (test "abc$$" '("abc$")
161 ;; (match&list "abc$$" "abc$"))
162 ;; (test "$$" '("$")
163 ;; (match&list "$$" "abc$"))
164 (test "^$" '("")
165 (match&list "^$" ""))
166 (test "^$" #f
167 (match&list "^$" "a"))
168 ;; (test "^^$$" '("^$")
169 ;; (match&list "^^$$" "^$"))
170 (test "abc$|def" '("abc")
171 (match&list "abc$|def" "abc"))
172 (test "abc$|def" '("def")
173 (match&list "abc$|def" "defabc"))
174 (test "^abc|def$" '("abc")
175 (match&list "^abc|def$" "abcdef"))
176 (test "^abc|def$" #f
177 (match&list "^abc|def$" "defabc"))
178 (test "^abc|def$" #f
179 (match&list "^abc|def$" "defabc"))
180 (test "(^abc|def$)" '("def" "def")
181 (match&list "(^abc|def$)" "aaadef"))
182 ;; (test "(^abc|def$)$" #f
183 ;; (match&list "(^abc|def$)$" "aaadef"))
184 ;; (test "(^abc|def$)$" '("def$" "def$")
185 ;; (match&list "(^abc|def$)$" "aaadef$"))
186 ;; (test "(abc$|def)$" #f
187 ;; (match&list "(abc$|def)$" "aaabc"))
188 ;; (test "(abc$|def)$" '("abc$" "abc$")
189 ;; (match&list "(abc$|def)$" "aaabc$"))
190 ;; (test "a$b" '("a$b")
191 ;; (match&list "a$b" "aa$bb"))
192 (test "ab\\$" '("ab$")
193 (match&list "ab\\$" "ab$cd"))
194
195 ;;-------------------------------------------------------------------------
196 ;;(test-section "backslash escape")
197
198 (test "a\\*c" '("a*c")
199 (match&list "a\\*c" "a*c"))
200 (test "a\\.c" '("a.c")
201 (match&list "a\\.c" "a.c"))
202 (test "a\\.c" #f
203 (match&list "a\\.c" "abc"))
204 (test "a\\\\b" '("a\\b")
205 (match&list "a\\\\b" "a\\b"))
206 (test "a\\\\\\*b" '("a\\*b")
207 (match&list "a\\\\\\*b" "a\\*b"))
208 ;;;; I don't like \<alpha> - we should at least warn about it.
209 ;; (test "a\\jc" '("ajc")
210 ;; (match&list "a\\jc" "ajc"))
211 (test "a\\\\bc" '("a\\bc")
212 (match&list "a\\\\bc" "a\\bc"))
213 (test "a\\[b" '("a[b")
214 (match&list "a\\[b" "a[b"))
215
216 ;;-------------------------------------------------------------------------
217 ;;(test-section "word boundary")
218
219 (test ".z\\b" '("oz")
220 (match&list ".z\\b" "bzbazoz ize"))
221 (test "\\b.z" '("iz")
222 (match&list "\\b.z" "brzbazoz ize"))
223 (test ".z\\B" '("iz")
224 (match&list ".z\\B" "bz baz oz ize"))
225 (test "\\B.z" '("az")
226 (match&list "\\B.z" "bz baz oz ize"))
227
228 ;;-------------------------------------------------------------------------
229 ;;(test-section "repetitions")
230
231 (test "ab*c" '("abc")
232 (match&list "ab*c" "abc"))
233 (test "ab*c" '("ac")
234 (match&list "ab*c" "ac"))
235 (test "ab*c" '("abbbc")
236 (match&list "ab*c" "abbbc"))
237 (test "ab*c" '("abbc")
238 (match&list "ab*c" "abbabaabbc"))
239 (test "ab+c" '("abc")
240 (match&list "ab+c" "abc"))
241 (test "ab+c" '("abbc")
242 (match&list "ab+c" "abbc"))
243 (test "ab+c" '("abbc")
244 (match&list "ab+c" "abbabaabbc"))
245 (test "ab?c" '("abc")
246 (match&list "ab?c" "abc"))
247 (test "ab?c" '("ac")
248 (match&list "ab?c" "abbaac"))
249 (test "a.*c" '("abc")
250 (match&list "a.*c" "abc"))
251 (test "a.*c" '("aabcabcabcabcc")
252 (match&list "a.*c" "zaabcabcabcabcczab"))
253 (test "a(b*|c)d" '("abbd" "bb")
254 (match&list "a(b*|c)d" "abbd"))
255 (test "a(b*|c)d" '("ad" "")
256 (match&list "a(b*|c)d" "ad"))
257 (test "a(b*|c)d" '("acd" "c")
258 (match&list "a(b*|c)d" "acd"))
259 (test "a(b*|c)d" #f
260 (match&list "a(b*|c)d" "abcd"))
261 (test "a.*c" '("ac")
262 (match&list "a.*c" "bacbababbbbadbaba"))
263 (test "a.*c" #f
264 (match&list "a.*c" "abaaaabababbadbabdba"))
265
266 ;;-------------------------------------------------------------------------
267 ;;(test-section "repetitions (non-greedy)")
268
269 (test "ab*?." '("ab")
270 (match&list "ab*?." "abc"))
271 (test "ab*?." '("ac")
272 (match&list "ab*?." "ac"))
273 (test "a.*?c" '("abbbc")
274 (match&list "a.*?c" "abbbc"))
275 (test "a.*?a" '("abba")
276 (match&list "a.*?a" "abbabaabbc"))
277 (test "<.*?>" '("<tag1>")
278 (match&list "<.*?>" "<tag1><tag2><tag3>"))
279
280 (test "ab+?." '("abc")
281 (match&list "ab+?." "abc"))
282 (test "ab+?." '("abb")
283 (match&list "ab+?." "abbc"))
284 (test "a.+?a" '("abba")
285 (match&list "a.+?a" "abbabaabbc"))
286 (test "<.+?>" '("<><tag1>")
287 (match&list "<.+?>" " <><tag1><tag2>"))
288
289 (test "ab??c" '("abc")
290 (match&list "ab??c" "abc"))
291 (test "ab??c" '("ac")
292 (match&list "ab??c" "abbaac"))
293 (test "ab??." '("ab")
294 (match&list "ab??." "abbaac"))
295 (test "a(hoge)??hoge" '("ahoge" #f)
296 (match&list "a(hoge)??hoge" "ahogehoge"))
297 (test "(foo)??bar" '("foobar" "foo")
298 (match&list "(foo)??bar" "foobar"))
299 (test "(foo)??bar" '("foobar" "foo")
300 (match&list "(foo)??bar" "foofoobar"))
301 (test "(foo)*?bar" '("foofoobar" "foo")
302 (match&list "(foo)*?bar" "foofoobar"))
303
304 ;;-------------------------------------------------------------------------
305 ;;(test-section "character class")
306
307 (test "a[bc]d" '("abd")
308 (match&list "a[bc]d" "abd"))
309 (test "a[bc]d" '("acd")
310 (match&list "a[bc]d" "acd"))
311 (test "a[bc]d" #f
312 (match&list "a[bc]d" "aed"))
313 (test "a[a-z]d" '("aed")
314 (match&list "a[a-z]d" "aed"))
315 (test "a[a-z]d" #f
316 (match&list "a[a-z]d" "aEd"))
317 (test "a[]]d" '("a]d")
318 (match&list "a[]]d" "a]d"))
319 (test "a[]-]d" '("a-d")
320 (match&list "a[]-]d" "a-d"))
321 (test "a[]-^]d" #f
322 (match&list "a[]-^]d" "a-d"))
323 (test "a[]-^]d" '("a]d")
324 (match&list "a[]-^]d" "a]d"))
325 (test "a[a-z-]d" '("a-d")
326 (match&list "a[a-z-]d" "a-d"))
327 (test "a[a-z-]d" '("afd")
328 (match&list "a[a-z-]d" "afd"))
329 (test "a[az-]d" '("a-d")
330 (match&list "a[az-]d" "a-d"))
331 (test "a[a-]d" '("a-d")
332 (match&list "a[a-]d" "a-d"))
333 (test "a[az-]d" #f
334 (match&list "a[az-]d" "afd"))
335 (test "a[az-]d" '("azd")
336 (match&list "a[az-]d" "azd"))
337 (test "a[^ab]c" '("acc")
338 (match&list "a[^ab]c" "abacc"))
339 (test "a[^]]c" '("abc")
340 (match&list "a[^]]c" "abc"))
341 (test "a[^]]c" #f
342 (match&list "a[^]]c" "a]c"))
343 (test "a[^^]c" '("abc")
344 (match&list "a[^^]c" "abc"))
345 (test "a[^^]c" #f
346 (match&list "a[^^]c" "a^c"))
347 (test "a[Bc]*d" '("aBccBd")
348 (match&list "a[Bc]*d" "aBccBd"))
349 (test "[a]b[c]" '("abc")
350 (match&list "[a]b[c]" "abc"))
351 (test "[abc]b[abc]" '("abc")
352 (match&list "[abc]b[abc]" "abc"))
353 (test "a[bc]d" '("abd")
354 (match&list "a[bc]d" "xyzaaabcaababdacd"))
355 ;; (test "a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab](wee|week)(knights|night)"
356 ;; '("aaaaabaaaabaaaabaaaabweeknights" "wee" "knights")
357 ;; (match&list "a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab](wee|week)(knights|night)"
358 ;; "aaaaabaaaabaaaabaaaabweeknights"))
359 ;; shorter version for quicker testing
360 (test "a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab](wee|week)(knights|night)"
361 '("aaaaabaaaabweeknights" "wee" "knights")
362 (match&list "a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab](wee|week)(knights|night)"
363 "aaaaabaaaabweeknights"))
364 (test "[ab][cd][ef][gh][ij][kl][mn]"
365 '("acegikm")
366 (match&list "[ab][cd][ef][gh][ij][kl][mn]"
367 "xacegikmoq"))
368 (test "[ab][cd][ef][gh][ij][kl][mn][op]"
369 '("acegikmo")
370 (match&list "[ab][cd][ef][gh][ij][kl][mn][op]"
371 "xacegikmoq"))
372 (test "[ab][cd][ef][gh][ij][kl][mn][op][qr]"
373 '("acegikmoq")
374 (match&list "[ab][cd][ef][gh][ij][kl][mn][op][qr]"
375 "xacegikmoqy"))
376 (test "[ab][cd][ef][gh][ij][kl][mn][op][q]"
377 '("acegikmoq")
378 (match&list "[ab][cd][ef][gh][ij][kl][mn][op][q]"
379 "xacegikmoqy"))
380
381 ;; this tests optimizer
382 (test "[^a]*." '("b")
383 (match&list "[^a]*." "b"))
384
385 (test "\\s" '(" ") (match&list "\\s" " "))
386 (test "\\s" '(" ") (match&list "\\s\\s" " "))
387 (test "\\s" '("\t") (match&list "\\s" "\t "))
388 (test "\\s" #f (match&list "\\s\\s" "\\s"))
389 (test "\\\\s" '("\\s ") (match&list "\\\\s\\s" "\\s "))
390 (test "\\s\\S" '("\txyz " "\t" "xyz" " ")
391 (match&list "(\\s*)(\\S+)(\\s*)" "\txyz abc"))
392 (test "\\d\\D" '("1234) 5678-9012" "1234" ") " "5678" "-" "9012")
393 (match&list "(\\d+)(\\D+)(\\d+)(\\D+)(\\d+)"
394 " (1234) 5678-9012 "))
395 (test "\\w\\W" '("three o" "three" " " "o")
396 (match&list "(\\w+)(\\W+)(\\w+)"
397 "three o'clock"))
398
399 (test "[ab\\sc]+" '(" ba ") (match&list "[ab\\sc]+" "d ba e"))
400 (test "[\\sa-c]+" '(" ba ") (match&list "[\\sabc]+" "d ba e"))
401 (test "[\\S\\t]+" '("\tab") (match&list "[\\S\\t]+" "\tab cd"))
402 (test "[\\s\\d]+" '(" 1 2 3 ")
403 (match&list "[\\s\\d]+" "a 1 2 3 b "))
404 (test "[\\s\\D]+" '("a ")
405 (match&list "[\\s\\D]+" "a 1 2 3 b "))
406
407 ;; this tests optimizer
408 (test "^\\[?([^\\]]*)\\]?:(\\d+)$" '("127.0.0.1:80" "127.0.0.1" "80")
409 (match&list "^\\[?([^\\]]*)\\]?:(\\d+)$" "127.0.0.1:80"))
410 (test "^\\[?([^\\]]*)\\]?:(\\d+)$" '("[127.0.0.1:80" "127.0.0.1" "80")
411 (match&list "^\\[?([^\\]]*)\\]?:(\\d+)$" "[127.0.0.1:80"))
412 (test "^\\[?([^\\]]*)\\]?:(\\d+)$" '("[127.0.0.1]:80" "127.0.0.1" "80")
413 (match&list "^\\[?([^\\]]*)\\]?:(\\d+)$" "[127.0.0.1]:80"))
414
415 ;;-------------------------------------------------------------------------
416 ;;(test-section "{n,m}")
417
418 (test "a{2}" "aabaa" (rxmatch-after (irregex-search "a{2}" "abaaaabaa")))
419 (test "a{2,}" "baa" (rxmatch-after (irregex-search "a{2,}" "abaaaabaa")))
420 (test "a{1,2}" "baaaabaa" (rxmatch-after (irregex-search "a{1,2}" "abaaaabaa")))
421 (test "a{2,3}" "abaa" (rxmatch-after (irregex-search "a{2,3}" "abaaaabaa")))
422 (test "a{b,c}" "def" (rxmatch-after (irregex-search "a{b,c}" "za{b,c}def")))
423 (test-error (rxmatch-after (irregex-search "a{,2}*" "za{,2}}def")))
424
425 (test "(ab){2}" "abba" (rxmatch-after (irregex-search "(ab){2}" "babbabababba")))
426 (test "(ab){2,2}" "abba" (rxmatch-after (irregex-search "(ab){2,2}" "babbabababba")))
427 (test "(ab){2,}" "ba" (rxmatch-after (irregex-search "(ab){2,}" "babbabababba")))
428 (test "(ab){1,2}" "babababba" (rxmatch-after (irregex-search "(ab){1,2}" "babbabababba")))
429 (test "(ab){2,3}" "ba" (rxmatch-after (irregex-search "(ab){2,3}" "babbabababba")))
430 (test "(ab){b,c}" "def" (rxmatch-after (irregex-search "(ab){b,c}" "zab{b,c}def")))
431
432 (test "(\\d{2})(\\d{2})" '("1234" "12" "34")
433 (match&list "(\\d{2})(\\d{2})" "a12345b"))
434 (test "(\\d{2,})(\\d{2,})" '("12345" "123" "45")
435 (match&list "(\\d{2,})(\\d{2,})" "a12345b"))
436 (test "(\\d{2})(\\d{2,})" '("12345" "12" "345")
437 (match&list "(\\d{2})(\\d{2,})" "a12345b"))
438 (test "(\\d{1,3})(\\d{2,})" '("1234" "12" "34")
439 (match&list "(\\d{1,3})(\\d{2,})" "a1234b"))
440 (test "(\\d{1,3})(\\d{0,2})" '("1234" "123" "4")
441 (match&list "(\\d{1,3})(\\d{0,2})" "a1234b"))
442 (test "(\\d{2}){2}" '("1234" "34")
443 (match&list "(\\d{2}){2}" "a12345b"))
444
445 (test-error (irregex "{2}"))
446 ;;;; Another case where we're more strict.
447 ;; (test "{z}" #t (regexp? (string->regexp "{z}")))
448 ;; (test "{-1}" #t (regexp? (string->regexp "{-1}")))
449 (test-error (irregex "{300}"))
450 (test-error (irregex "{3,1}"))
451
452 ;;-------------------------------------------------------------------------
453 ;;(test-section "{n,m} (non-greedy)")
454
455 (test "a{2}?" "aabaa" (rxmatch-after (irregex-search "a{2}?" "abaaaabaa")))
456 (test "a{2,}?" "aabaa" (rxmatch-after (irregex-search "a{2,}?" "abaaaabaa")))
457 (test "a{1,2}?" "baaaabaa" (rxmatch-after (irregex-search "a{1,2}?" "abaaaabaa")))
458 (test "a{2,3}?" "aabaa" (rxmatch-after (irregex-search "a{2,3}?" "abaaaabaa")))
459
460 (test "(ab){2}?" "abba" (rxmatch-after (irregex-search "(ab){2}?" "babbabababba")))
461 (test "(ab){2,2}?" "abba" (rxmatch-after (irregex-search "(ab){2,2}?" "babbabababba")))
462 (test "(ab){2,}?" "abba" (rxmatch-after (irregex-search "(ab){2,}?" "babbabababba")))
463 (test "(ab){1,2}?" "babababba" (rxmatch-after (irregex-search "(ab){1,2}?" "babbabababba")))
464 (test "(ab){2,3}?" "abba" (rxmatch-after (irregex-search "(ab){2,3}?" "babbabababba")))
465
466 (test "(\\d{2,}?)(\\d{2,}?)" '("1234" "12" "34")
467 (match&list "(\\d{2,}?)(\\d{2,}?)" "a12345b"))
468 (test "(\\d{2,})(\\d{2,}?)" '("12345" "123" "45")
469 (match&list "(\\d{2,})(\\d{2,}?)" "a12345b"))
470 (test "(\\d{2,}?)(\\d{2,})" '("12345" "12" "345")
471 (match&list "(\\d{2,}?)(\\d{2,})" "a12345b"))
472 (test "(\\d{1,3}?)(\\d{2,}?)" '("123" "1" "23")
473 (match&list "(\\d{1,3}?)(\\d{2,}?)" "a1234b"))
474 (test "(\\d{1,3}?)(\\d{0,2}?)" '("1" "1" "")
475 (match&list "(\\d{1,3}?)(\\d{0,2}?)" "a1234b"))
476
477 ;;-------------------------------------------------------------------------
478 ;;(test-section "uncapturing group")
479
480 (test "a(?:b)*c(d)" "d"
481 (rxmatch-substring "a(?:b)*c(d)" "abcdbcdefg" 1))
482 (test "a(?:bcd)*e(f)" "f"
483 (rxmatch-substring "a(?:bcd)*e(f)" "abcdbcdefg" 1))
484 (test "a(?:bcd)*e(f)" "f"
485 (rxmatch-substring "a(?:bcd)*e(f)" "aefg" 1))
486 (test "a(?:bcd)+e(f)" #f
487 (rxmatch-substring "a(?:bcd)+e(f)" "aefg" 1))
488 (test "a(?:bc(de(?:fg)?hi)jk)?l" "defghi"
489 (rxmatch-substring "a(?:bc(de(?:fg)?hi)jk)?l" "abcdefghijkl" 1))
490 (test "a(?:bc(de(?:fg)?hi)jk)?l" "dehi"
491 (rxmatch-substring "a(?:bc(de(?:fg)?hi)jk)?l" "abcdehijkl" 1))
492
493 (test "a(?i:bc)d" "aBCd"
494 (rxmatch-substring "a(?i:bc)d" "!aBCd!"))
495 (test "a(?i:bc)d" #f
496 (rxmatch-substring "a(?i:bc)d" "!aBCD!"))
497 (test "a(?i:[a-z]+)d" "aBcd"
498 (rxmatch-substring "a(?i:[a-z]+)d" "!aBcd!"))
499 (test "a(?i:[a-z]+)d" #f
500 (rxmatch-substring "a(?i:[a-z]+)d" "!ABcd!"))
501
502 (test "A(?-i:Bc)D" "ABcD"
503 (rxmatch-substring "A(?-i:Bc)D" "!ABcD!"))
504 (test "A(?-i:Bc)D" #f
505 (rxmatch-substring "A(?-i:Bc)D" "!ABcd!"))
506 (test "A(?-i:[A-Z]+)D" "ABCD"
507 (rxmatch-substring "A(?-i:[A-Z]+)D" "!ABCD!"))
508 (test "A(?-i:[A-Z]+)D" #f
509 (rxmatch-substring "A(?-i:[A-Z]+)D" "!abCD!"))
510
511 (test "A(?-i:Bc)D/i" "aBcd"
512 (rxmatch-substring "(?i)A(?-i:Bc)D" "!aBcd!"))
513 (test "A(?-i:Bc)D/i" #f
514 (rxmatch-substring "(?i)A(?-i:Bc)D" "!abCd!"))
515 (test "A(?-i:[A-Z]+)D/i" "aBCd"
516 (rxmatch-substring "(?i)A(?-i:[A-Z]+)D" "!aBCd!"))
517 (test "A(?-i:[A-Z]+)D/i" #f
518 (rxmatch-substring "(?i)A(?-i:[A-Z]+)D" "!abcd!"))
519
520 ;; these test optimizer
521 (test "^(?i:a*).$" "b"
522 (rxmatch-substring "^(?i:a*).$" "b"))
523 (test "^(?i:a*).$" "a"
524 (rxmatch-substring "^(?i:a*).$" "a"))
525 (test "^(?i:a*).$" "A"
526 (rxmatch-substring "^(?i:a*).$" "A"))
527 (test "^(?i:a*).$" "Ab"
528 (rxmatch-substring "^(?i:a*).$" "Ab"))
529
530 ;;-------------------------------------------------------------------------
531 ;;(test-section "backreference")
532 (test "^(.)\\1$" '("aa" "a")
533 (match&list "^(.)\\1$" "aa"))
534 (test "^(.)\\1$" #f
535 (match&list "^(.)\\1$" "ab"))
536 (test "(.+)\\1" '("123123" "123")
537 (match&list "(.+)\\1" "a123123j"))
538 (test "/(.+)\\1/i" '("AbCaBC" "AbC")
539 (match&list "(?i)(.+)\\1" "AbCaBC"))
540 (test "/(.+)\\1/i" #f
541 (match&list "(.+)\\1" "AbCAb1"))
542 (test-error (string->irregex "^\\1(.)"))
543 (test-error (string->irregex "^(\\1)$"))
544
545 ;;-------------------------------------------------------------------------
546 ;;(test-section "independent subexpression")
547 (test "(?>.*\\/)foo" #f
548 (match&list "(?>.*\\/)foo" "/this/is/a/long/line/"))
549 (test "(?>.*\\/)foo" '("/this/is/a/long/line/foo")
550 (match&list "(?>.*\\/)foo" "/this/is/a/long/line/foo"))
551 (test "(?>(\\.\\d\\d[1-9]?))\\d+" '(".230003938" ".23")
552 (match&list "(?>(\\.\\d\\d[1-9]?))\\d+" "1.230003938"))
553 (test "(?>(\\.\\d\\d[1-9]?))\\d+" '(".875000282" ".875")
554 (match&list "(?>(\\.\\d\\d[1-9]?))\\d+" "1.875000282"))
555 (test "(?>(\\.\\d\\d[1-9]?))\\d+" #f
556 (match&list "(?>(\\.\\d\\d[1-9]?))\\d+" "1.235"))
557 (test "^((?>\\w+)|(?>\\s+))*$" '("foo bar" "bar")
558 (match&list "^((?>\\w+)|(?>\\s+))*$" "foo bar"))
559 ;;;; Non-standard shortcut for atomic expressions.
560 ;; (test "a*+a" #f
561 ;; (match&list "a*+a" "aaa"))
562 ;; (test "a*+b" '("aab")
563 ;; (match&list "a*+b" "aab"))
564 ;; (test "a++a" #f
565 ;; (match&list "a++a" "aaa"))
566 ;; (test "a++b" '("aab")
567 ;; (match&list "a++b" "aab"))
568 ;; (test "(a?+)a" #f
569 ;; (match&list "a?+a" "a"))
570 ;; (test "(a?+)b" '("ab")
571 ;; (match&list "a?+b" "ab"))
572
573 ;;-------------------------------------------------------------------------
574 ;;(test-section "lookahead assertion")
575
576 (test "^(?=ab(de))(abd)(e)" '("abde" "de" "abd" "e")
577 (match&list "^(?=ab(de))(abd)(e)" "abde"))
578 (test "^(?!(ab)de|x)(abd)(f)" '("abdf" #f "abd" "f")
579 (match&list "^(?!(ab)de|x)(abd)(f)" "abdf"))
580 (test "^(?=(ab(cd)))(ab)" '("ab" "abcd" "cd" "ab")
581 (match&list "^(?=(ab(cd)))(ab)" "abcd"))
582 (test "\\w+(?=\\t)" '("brown")
583 (match&list "\\w+(?=\t)" "the quick brown\t fox"))
584 (test "foo(?!bar)(.*)" '("foolish see?" "lish see?")
585 (match&list "foo(?!bar)(.*)" "foobar is foolish see?"))
586 (test "(?:(?!foo)...|^.{0,2})bar(.*)" '("rowbar etc" " etc")
587 (match&list "(?:(?!foo)...|^.{0,2})bar(.*)" "foobar crowbar etc"))
588 (test "(?:(?!foo)...|^.{0,2})bar(.*)" '("barrel" "rel")
589 (match&list "(?:(?!foo)...|^.{0,2})bar(.*)" "barrel"))
590 (test "(?:(?!foo)...|^.{0,2})bar(.*)" '("2barrel" "rel")
591 (match&list "(?:(?!foo)...|^.{0,2})bar(.*)" "2barrel"))
592 (test "(?:(?!foo)...|^.{0,2})bar(.*)" '("A barrel" "rel")
593 (match&list "(?:(?!foo)...|^.{0,2})bar(.*)" "A barrel"))
594 (test "^(\\D*)(?=\\d)(?!123)" '("abc" "abc")
595 (match&list "^(\\D*)(?=\\d)(?!123)" "abc456"))
596 (test "^(\\D*)(?=\\d)(?!123)" #f
597 (match&list "^(\\D*)(?=\\d)(?!123)" "abc123"))
598 (test "(?!^)abc" '("abc")
599 (match&list "(?!^)abc" "the abc"))
600 (test "(?!^)abc" #f
601 (match&list "(?!^)abc" "abc"))
602 (test "(?=^)abc" '("abc")
603 (match&list "(?=^)abc" "abc"))
604 (test "(?=^)abc" #f
605 (match&list "(?=^)abc" "the abc"))
606 (test "(\\.\\d\\d((?=0)|\\d(?=\\d)))" '(".23" ".23" "")
607 (match&list "(\\.\\d\\d((?=0)|\\d(?=\\d)))" "1.230003938"))
608 (test "(\\.\\d\\d((?=0)|\\d(?=\\d)))" '(".875" ".875" "5")
609 (match&list "(\\.\\d\\d((?=0)|\\d(?=\\d)))" "1.875000282"))
610 (test "(\\.\\d\\d((?=0)|\\d(?=\\d)))" #f
611 (match&list "(\\.\\d\\d((?=0)|\\d(?=\\d)))" "1.235"))
612 (test "^\\D*(?!123)" '("AB")
613 (match&list "^\\D*(?!123)" "ABC123"))
614 (test "^(\\D*)(?=\\d)(?!123)" '("ABC" "ABC")
615 (match&list "^(\\D*)(?=\\d)(?!123)" "ABC445"))
616 (test "^(\\D*)(?=\\d)(?!123)" #f
617 (match&list "^(\\D*)(?=\\d)(?!123)" "ABC123"))
618 (test "a(?!b)." '("ad")
619 (match&list "a(?!b)." "abad"))
620 (test "a(?!b)" '("a")
621 (match&list "a(?!b)" "abad"))
622 (test "a(?=d)." '("ad")
623 (match&list "a(?=d)." "abad"))
624 (test "a(?=c|d)." '("ad")
625 (match&list "a(?=c|d)." "abad"))
626
627 ;;-------------------------------------------------------------------------
628 ;;(test-section "lookbehind assertion")
629 (test "(?<=a)b" #f
630 (match&list "(?<=a)b" "b"))
631 (test "(?<=a)b" '("b")
632 (match&list "(?<=a)b" "ab"))
633 (test "(?<=a+)b" '("b")
634 (match&list "(?<=a+)b" "aab"))
635 (test "(?<=x[yz])b" '("b")
636 (match&list "(?<=x[yz])b" "xzb"))
637 (test "(?<=zyx)b" #f
638 (match&list "(?<=zyx)b" "xyzb"))
639 (test "(?<=[ab]+)c" '("c")
640 (match&list "(?<=[ab]+)c" "abc"))
641 (test "(?<!<[^>]*)foo" #f
642 (match&list "(?<!<[^>]*)foo" "<foo>"))
643 ;; (test "(?<!<[^>]*)foo" '("foo")
644 ;; (match&list "(?<!<[^>]*)foo" "<bar>foo"))
645 (test "(?<=^a)b" '("b")
646 (match&list "(?<=^a)b" "ab"))
647 (test "(?<=^)b" #f
648 (match&list "(?<=^)b" "ab"))
649 (test "(?<=^)b" '("b")
650 (match&list "(?<=^)b" "b"))
651 (test ".(?<=\\^)b" '("^b")
652 (match&list ".(?<=\\^)b" "a^b"))
653 (test "(?<=^a$)" '("")
654 (match&list "(?<=^a$)" "a"))
655 (test "(?<=^a\\$)b" '("b")
656 (match&list "(?<=^a\\$)b" "a$b"))
657 (test "(?<=(a))b" '("b" "a")
658 (match&list "(?<=(a))b" "ab"))
659 (test "(?<=(a)(b))c" '("c" "a" "b")
660 (match&list "(?<=(a)(b))c" "abc"))
661 (test "(?<=(a)|(b))c" '("c" #f "b")
662 (match&list "(?<=(a)|(b))c" "bc"))
663 (test "(?<=(?<!foo)bar)baz" '("baz")
664 (match&list "(?<=(?<!foo)bar)baz" "abarbaz"))
665 (test "(?<=(?<!foo)bar)baz" #f
666 (match&list "(?<=(?<!foo)bar)baz" "foobarbaz"))
667 (test "(?<=\\d{3})(?<!999)foo" '("foo")
668 (match&list "(?<=\\d{3})(?<!999)foo" "865foo"))
669 (test "(?<=\\d{3})(?<!999)foo" #f
670 (match&list "(?<=\\d{3})(?<!999)foo" "999foo"))
671 ;; not an error, we allow variable-length look-behinds
672 ;; (test-error (string->irregex "(?<=(?>a*))"))
673 (test "(abc)...(?<=\\1)" '("abcabc" "abc")
674 (match&list "(abc)...(?<=\\1)" "abcabc"))
675 (test "/(abC)...(?<=\\1)/i" '("abCAbc" "abC")
676 (match&list "(?i)(abC)...(?<=\\1)" "abCAbc"))
677
678 ;;-------------------------------------------------------------------------
679 ;;(test-section "named group")
680 (test "(?<foo>a)" '("a" "a")
681 (match&list "(?<foo>a)" "a"))
682 (test "(?<foo>a)" "a"
683 (let1 m (irregex-search "(?<foo>a)" "a")
684 (irregex-match-substring m 'foo)))
685 (test "(?<foo>a)" #f
686 (let1 m (irregex-search "(?<foo>a)?" "b")
687 (irregex-match-substring m 'foo)))
688 (test "(?<foo>a)(?<bar>.*)" '("a" "bcd")
689 (let1 m (irregex-search "(?<foo>a)(?<bar>.*)" "abcd")
690 (list (irregex-match-substring m 'foo)
691 (irregex-match-substring m 'bar))))
692 (test "(?<foo>a)(?<bar>.*)" '("abcd" "a" "bcd")
693 (match&list "(?<foo>a)(?<bar>.*)" "abcd"))
694 (test-error
695 (let1 m (irregex-search "(?<foo>a)" "abcd")
696 (irregex-match-substring m 'bar)))
697 (test "(?<foo>^a$)" '("a" "a")
698 (match&list "(?<foo>^a$)" "a"))
699 (test "(?<foo>^a$)" #f
700 (match&list "(?<foo>^a$)" "ab"))
701 (test "(?<name-with-hyphen>a)" '("a" "a")
702 (match&list "(?<name-with-hyphen>a)" "a"))
703 ;;;; wtf? multiple instances of the same name?
704 ;; (test "(?<host>\\d+.\\d+.\\d+.\\d+)|(?<host>[\\w.]+)"
705 ;; '("127.0.0.1" "127.0.0.1" #f "127.0.0.1")
706 ;; (let1 m (irregex-search "(?<host>\\d+.\\d+.\\d+.\\d+)|(?<host>[\\w.]+)" "127.0.0.1")
707 ;; (list (irregex-match-substring m 0)
708 ;; (irregex-match-substring m 1)
709 ;; (irregex-match-substring m 2)
710 ;; (irregex-match-substring m 'host))))
711 ;; (test "(?<host>\\d+.\\d+.\\d+.\\d+)|(?<host>[\\w.]+)"
712 ;; '("foo.com" #f "foo.com" "foo.com")
713 ;; (let1 m (irregex-search "(?<host>\\d+.\\d+.\\d+.\\d+)|(?<host>[\\w.]+)" "foo.com")
714 ;; (list (irregex-match-substring m 0)
715 ;; (irregex-match-substring m 1)
716 ;; (irregex-match-substring m 2)
717 ;; (irregex-match-substring m 'host))))
718 (test "(?<foo>.+)\\k<foo>" '("abcabc" "abc")
719 (match&list "(?<foo>.+)\\k<foo>" "abcabc"))
720 (test "(?<foo>.+)\\k<foo>" #f
721 (match&list "(?<foo>.+)\\k<foo>" "abcdef"))
722 (test-error (irregex "\\k<foo>"))
723 (test "rxmatch-before" "abc"
724 (rxmatch-before (irregex-search "(?<foo>def)" "abcdefghi") 'foo))
725 (test "rxmatch-after" "ghi"
726 (rxmatch-after (irregex-search "(?<foo>def)" "abcdefghi") 'foo))
727 (test "rxmatch-start" 3
728 (rxmatch-start (irregex-search "(?<foo>def)" "abcdefghi") 'foo))
729 (test "rxmatch-end" 6
730 (rxmatch-end (irregex-search "(?<foo>def)" "abcdefghi") 'foo))
731
732 ;;-------------------------------------------------------------------------
733 ;;(test-section "conditional subexpression")
734 (test "(a)(?(1)b)" '("ab" "a")
735 (match&list "(a)(?(1)b)" "ab"))
736 (test "(a)(?(1)b)" #f
737 (match&list "(a)(?(1)b)" "aa"))
738 (test "(a)(?(1)b|c)" #f
739 (match&list "(a)(?(1)b)" "ac"))
740 (test "(a)?(?(1)b|c)" #f
741 (match&list "(a)?(?(1)b|c)" "xb"))
742 (test "(a)?(?(1)b|c)" '("c" #f)
743 (match&list "(a)?(?(1)b|c)" "xc"))
744 (test "(?(?<=a)b)" '("b")
745 (match&list "(?(?<=a)b)" "ab"))
746 (test "(?(?<=a)b)" #f
747 (match&list "(?(?<=a)b)" "ac"))
748 (test "(?(?<=a)b)" #f
749 (match&list "(?(?<=a)b)" "xb"))
750 (test "(?(?<=a)b|c)" '("b")
751 (match&list "(?(?<=a)b)" "ab"))
752 (test "(?(?<=a)b|c)" #f
753 (match&list "(?(?<=a)b)" "ac"))
754 (test-error (irregex "(?(?a)b|c)"))
755 (test "()(?(1))" '("" "")
756 (match&list "()(?(1))" ""))
757
758 (test-error (irregex "()((?("))
759 (test-error (irregex "()((?(1"))
760 ;; (test-error (irregex "()(?(1)b|c|d)"))
761
762 ;;-------------------------------------------------------------------------
763 ;;(test-section "regexp macros")
764
765 ;; (test "rxmatch-let" '("23:59:58" "23" "59" "58")
766 ;; (rxmatch-let (rxmatch "(\d+):(\d+):(\d+)"
767 ;; "Jan 1 23:59:58, 2001")
768 ;; (time hh mm ss)
769 ;; (list time hh mm ss)))
770 ;; (test "rxmatch-let" '("23" "59")
771 ;; (rxmatch-let (rxmatch "(\d+):(\d+):(\d+)"
772 ;; "Jan 1 23:59:58, 2001")
773 ;; (#f hh mm)
774 ;; (list hh mm)))
775
776 ;; (test "rxmatch-if" "time is 11:22"
777 ;; (rxmatch-if (rxmatch "(\d+:\d+)" "Jan 1 11:22:33")
778 ;; (time)
779 ;; (format #f "time is ~a" time)
780 ;; "unknown time"))
781 ;; (test "rxmatch-if" "unknown time"
782 ;; (rxmatch-if (rxmatch "(\d+:\d+)" "Jan 1 11-22-33")
783 ;; (time)
784 ;; (format #f "time is ~a" time)
785 ;; "unknown time"))
786
787 ;; (define (test-parse-date str)
788 ;; (rxmatch-cond
789 ;; (test (not (string? str)) #f)
790 ;; ((rxmatch "^(\d\d?)\/(\d\d?)\/(\d\d\d\d)$" str)
791 ;; (#f mm dd yyyy)
792 ;; (map string->number (list yyyy mm dd)))
793 ;; ((rxmatch "^(\d\d\d\d)\/(\d\d?)\/(\d\d?)$" str)
794 ;; (#f yyyy mm dd)
795 ;; (map string->number (list yyyy mm dd)))
796 ;; ((rxmatch "^\d+\/\d+\/\d+$" str)
797 ;; (#f)
798 ;; (error "ambiguous:" str))
799 ;; (else (error "bogus:" str))))
800
801 ;; (test "rxmatch-cond" '(2001 2 3)
802 ;; (test-parse-date "2001/2/3"))
803 ;; (test "rxmatch-cond" '(1999 12 25)
804 ;; (test-parse-date "1999/12/25"))
805 ;; (test "rxmatch-cond" #f
806 ;; (test-parse-date 'abc))
807
808 ;; (define (test-parse-date2 str)
809 ;; (rxmatch-case str
810 ;; (test (lambda (s) (not (string? s))) #f)
811 ;; ("^(\d\d?)\/(\d\d?)\/(\d\d\d\d)$" (#f mm dd yyyy)
812 ;; (map string->number (list yyyy mm dd)))
813 ;; ("^(\d\d\d\d)\/(\d\d?)\/(\d\d?)$" (#f yyyy mm dd)
814 ;; (map string->number (list yyyy mm dd)))
815 ;; ("^\d+\/\d+\/\d+$" (#f) (error "ambiguous:" str))
816 ;; (else (error "bogus:" str))))
817
818 ;; (test "rxmatch-case" '(2001 2 3)
819 ;; (test-parse-date2 "2001/2/3"))
820 ;; (test "rxmatch-case" '(1999 12 25)
821 ;; (test-parse-date2 "1999/12/25"))
822 ;; (test "rxmatch-case" #f
823 ;; (test-parse-date2 'abc))
824
825 ;; (test "regexp-replace" "abc|def|ghi"
826 ;; (regexp-replace "def|DEF" "abcdefghi" "|\\0|"))
827
828 ;; (test "regexp-replace" "abc|\\0|ghi"
829 ;; (regexp-replace "def|DEF" "abcdefghi" "|\\\\0|"))
830
831 ;; (test "regexp-replace" "abc|def|ghi"
832 ;; (regexp-replace "(?<match>def|DEF)" "abcdefghi" "|\\k<match>|"))
833
834 ;; (test "regexp-replace" *test-error*
835 ;; (regexp-replace "(?<match>def|DEF)" "abcdefghi" "|\\k<matchee>|"))
836
837 ;; (test "regexp-replace" "abraabra**brabra**brabrabracadabrabrabra"
838 ;; (regexp-replace "a((bra)+)cadabra"
839 ;; "abraabraabrabracadabrabrabrabracadabrabrabra"
840 ;; "**\\1**"))
841
842 ;; (test "regexp-replace-all" "abraabra**brabra**br**brabra**brabra"
843 ;; (regexp-replace-all "a((bra)+)cadabra"
844 ;; "abraabraabrabracadabrabrabrabracadabrabrabra"
845 ;; "**\\1**"))
846
847 ;; (test "regexp-replace-all" "abraabra**brabra**br**brabra**brabra"
848 ;; (regexp-replace-all "a(?<match>(bra)+)cadabra"
849 ;; "abraabraabrabracadabrabrabrabracadabrabrabra"
850 ;; "**\\k<match>**"))
851
852 ;; (test "regexp-replace" "abfedhi"
853 ;; (regexp-replace "c(.*)g" "abcdefghi"
854 ;; (lambda (m)
855 ;; (list->string
856 ;; (reverse
857 ;; (string->list (rxmatch-substring m 1)))))))
858
859 ;; (test "regexp-replace-all" "abraabra(bra^2)br(bra^2)brabra"
860 ;; (regexp-replace-all "a((bra)+)cadabra"
861 ;; "abraabraabrabracadabrabrabrabracadabrabrabra"
862 ;; (lambda (m)
863 ;; (format #f "(bra^~a)"
864 ;; (/ (string-length (rxmatch-substring m 1))
865 ;; 3)))))
866
867 ;; (test "regexp-replace-all" *test-error*
868 ;; (regexp-replace-all "\d*" "abcdef" "X"))
869 ;; (test "regexp-replace-all" *test-error*
870 ;; (regexp-replace-all "\d*" "123abcdef" "X"))
871
872 ;; (test "regexp-replace*" "cbazzbc"
873 ;; (regexp-replace* "abcbabc"
874 ;; "abc" "cba"
875 ;; "aba" "abc"
876 ;; "bc" "zz"))
877
878 ;; (test "regexp-replace-all*" "cbazzccbazz"
879 ;; (regexp-replace-all* "abcbacabcbc"
880 ;; "abc" "cba"
881 ;; "aba" "abc"
882 ;; "bc" "zz"))
883
884 ;;-------------------------------------------------------------------------
885 ;;(test-section "regexp cimatch")
886
887 (test "regexp/ci" "BC"
888 (cond ((rxmatch "(?i)bc" "ABCD")
889 => irregex-match-substring)
890 (else #f)))
891 (test "regexp/ci" "bC"
892 (cond ((rxmatch "(?i)Bc" "AbCD")
893 => irregex-match-substring)
894 (else #f)))
895 (test "regexp/ci" "bc"
896 (cond ((rxmatch "(?i)BC" "AbcD")
897 => irregex-match-substring)
898 (else #f)))
899 (test "regexp/ci" #f
900 (cond ((rxmatch "Bc" "AbCD")
901 => irregex-match-substring)
902 (else #f)))
903 (test "regexp/ci" #f
904 (cond ((rxmatch "BC" "ABcD")
905 => irregex-match-substring)
906 (else #f)))
907 (test "regexp/ci" "PAD"
908 (cond ((rxmatch "(?i)p[a-z]d" "PAD")
909 => irregex-match-substring)
910 (else #f)))
911 (test "regexp/ci" "pad"
912 (cond ((rxmatch "(?i)P[A-Z]D" "pad")
913 => irregex-match-substring)
914 (else #f)))
915 (test "regexp/ci" "bad"
916 (cond ((rxmatch "(?i).[a-pQ-Z][A-Pq-z]" "bad")
917 => irregex-match-substring)
918 (else #f)))
919 (test "regexp/ci" #f
920 (cond ((rxmatch "p[a-z]d" "PAD")
921 => irregex-match-substring)
922 (else #f)))
923 (test "regexp/ci" #f
924 (cond ((rxmatch "P[A-Z]D" "pad")
925 => irregex-match-substring)
926 (else #f)))
927 (test "regexp/ci" #f
928 (cond ((rxmatch ".[a-pQ-Z][A-Pq-z]" "bad")
929 => irregex-match-substring)
930 (else #f)))
931 (test "regexp/ci" "pad"
932 (cond ((rxmatch (string->irregex "p[A-Z]d" 'case-insensitive) "pad")
933 => irregex-match-substring)
934 (else #f)))
935 (test "regexp/ci" #f
936 (cond ((rxmatch (string->irregex "p[A-Z]d") "pad")
937 => irregex-match-substring)
938 (else #f)))
939
940 ;;-------------------------------------------------------------------------
941 ;;(test-section "applicable regexp")
942
943 ;; (define match #f)
944
945 ;; (test "object-apply regexp" #t
946 ;; (begin
947 ;; (set! match ("(\d+)\.(\d+)" "pi=3.14..."))
948 ;; (regmatch? match)))
949
950 ;; (test "object-apply regmatch (index)" '("3.14" "3" "14")
951 ;; (list (match) (match 1) (match 2)))
952
953 ;; (test "object-apply regmatch (symbol)" '("..." ".14..." "pi=" "pi=3.")
954 ;; (list (match 'after) (match 'after 1)
955 ;; (match 'before) (match 'before 2)))
956
957 ;; (set! match ("(?<int>\d+)\.(?<frac>\d+)" "pi=3.14..."))
958
959 ;; (test "object-apply regmatch (index)" '("3.14" "3" "14" "3" "14")
960 ;; (list (match) (match 1) (match 2)
961 ;; (match 'int) (match 'frac)))
962
963 ;; (test "object-apply regmatch (symbol)"
964 ;; '("..." ".14..." ".14..." "pi=" "pi=3." "pi=3.")
965 ;; (list (match 'after) (match 'after 1) (match 'after 'int)
966 ;; (match 'before) (match 'before 2) (match 'before 'frac)))
967
968 ;; (test "object-apply regmatch (named submatch)"
969 ;; '("..." ".14..." ".14..." "pi=" "pi=3." "pi=3.")
970 ;; (list (match 'after) (match 'after 1) (match 'after 'int)
971 ;; (match 'before) (match 'before 2) (match 'before 'frac)))
972
973 ;;-------------------------------------------------------------------------
974 ;;(test-section "regexp quote")
975
976 (test-assert "regexp-quote"
977 (let ((str "^(#$%#}{)\\-+?^$"))
978 (irregex-match (string->irregex (irregex-quote str)) str)))
979
980 ;;-------------------------------------------------------------------------
981 ;;(test-section "regexp comparison")
982
983 ;; (test "equal "abc/ #/abc"" #t
984 ;; (equal? "abc/ #/abc"))
985 ;; (test "not equal "abc/ #/a(bc)"" #f
986 ;; (equal? "abc/ #/a(bc)"))
987 ;; (test "not equal "abc/ #/abc"i" #f
988 ;; (equal? "abc/ #/abc"i))
989 ;; (test "not equal "abc/i #/abc"" #f
990 ;; (equal? "abc/i #/abc"))
991 ;; (test "equal "abc/i #/abc"i" #t
992 ;; (equal? "abc/i #/abc"i))
993
994 (test-end)