]> git.saurik.com Git - wxWidgets.git/blame - tests/regex/reg.test
Add new animate sample to the distribution (probably more steps from technote #1...
[wxWidgets.git] / tests / regex / reg.test
CommitLineData
e70833fb
VS
1# reg.test --
2#
3# This file contains a collection of tests for one or more of the Tcl
4# built-in commands. Sourcing this file into Tcl runs the tests and
5# generates output for errors. No output means no errors were found.
6# (Don't panic if you are seeing this as part of the reg distribution
7# and aren't using Tcl -- reg's own regression tester also knows how
8# to read this file, ignoring the Tcl-isms.)
9#
10# Copyright (c) 1998, 1999 Henry Spencer. All rights reserved.
11#
12# RCS: @(#) $Id$
13
14if {[lsearch [namespace children] ::tcltest] == -1} {
15 package require tcltest 2
16 namespace import -force ::tcltest::*
17}
18
19# All tests require the testregexp command, return if this
20# command doesn't exist
21
22::tcltest::testConstraint testregexp \
23 [expr {[info commands testregexp] != {}}]
24::tcltest::testConstraint localeRegexp 0
25
26# This file uses some custom procedures, defined below, for regexp regression
27# testing. The name of the procedure indicates the general nature of the
28# test:
29# e compile error expected
30# f match failure expected
31# m successful match
32# i successful match with -indices (used in checking things like
33# nonparticipating subexpressions)
34# p unsuccessful match with -indices (!!) (used in checking
35# partial-match reporting)
36# There is also "doing" which sets up title and major test number for each
37# block of tests.
38
39# The first 3 arguments are constant: a minor number (which often gets
40# a letter or two suffixed to it internally), some flags, and the RE itself.
41# For e, the remaining argument is the name of the compile error expected,
42# less the leading "REG_". For the rest, the next argument is the string
43# to try the match against. Remaining arguments are the substring expected
44# to be matched, and any substrings expected to be matched by subexpressions.
45# (For f, these arguments are optional, and if present are ignored except
46# that they indicate how many subexpressions should be present in the RE.)
47# It is an error for the number of subexpression arguments to be wrong.
48# Cases involving nonparticipating subexpressions, checking where empty
49# substrings are located, etc. should be done using i and p.
50
51# The flag characters are complex and a bit eclectic. Generally speaking,
52# lowercase letters are compile options, uppercase are expected re_info
53# bits, and nonalphabetics are match options, controls for how the test is
54# run, or testing options. The one small surprise is that AREs are the
55# default, and you must explicitly request lesser flavors of RE. The flags
56# are as follows. It is admitted that some are not very mnemonic.
57# There are some others which are purely debugging tools and are not
58# useful in this file.
59#
60# - no-op (placeholder)
61# + provide fake xy equivalence class and ch collating element
62# % force small state-set cache in matcher (to test cache replace)
63# ^ beginning of string is not beginning of line
64# $ end of string is not end of line
65# * test is Unicode-specific, needs big character set
66#
67# & test as both ARE and BRE
68# b BRE
69# e ERE
70# a turn advanced-features bit on (error unless ERE already)
71# q literal string, no metacharacters at all
72#
73# i case-independent matching
74# o ("opaque") no subexpression capture
75# p newlines are half-magic, excluded from . and [^ only
76# w newlines are half-magic, significant to ^ and $ only
77# n newlines are fully magic, both effects
78# x expanded RE syntax
79# t incomplete-match reporting
80#
81# A backslash-_a_lphanumeric seen
82# B ERE/ARE literal-_b_race heuristic used
83# E backslash (_e_scape) seen within []
84# H looka_h_ead constraint seen
85# I _i_mpossible to match
86# L _l_ocale-specific construct seen
87# M unportable (_m_achine-specific) construct seen
88# N RE can match empty (_n_ull) string
89# P non-_P_OSIX construct seen
90# Q {} _q_uantifier seen
91# R back _r_eference seen
92# S POSIX-un_s_pecified syntax seen
93# T prefers shortest (_t_iny)
94# U saw original-POSIX botch: unmatched right paren in ERE (_u_gh)
95
96# The one area we can't easily test is memory-allocation failures (which
97# are hard to provoke on command). Embedded NULs also are not tested at
98# the moment, but this is a historical accident which should be fixed.
99
100
101
102# test procedures and related
103
104set ask "about"
105set xflags "xflags"
106set testbypassed 0
107
108# re_info abbreviation mapping table
109set infonames(A) "REG_UBSALNUM"
110set infonames(B) "REG_UBRACES"
111set infonames(E) "REG_UBBS"
112set infonames(H) "REG_ULOOKAHEAD"
113set infonames(I) "REG_UIMPOSSIBLE"
114set infonames(L) "REG_ULOCALE"
115set infonames(M) "REG_UUNPORT"
116set infonames(N) "REG_UEMPTYMATCH"
117set infonames(P) "REG_UNONPOSIX"
118set infonames(Q) "REG_UBOUNDS"
119set infonames(R) "REG_UBACKREF"
120set infonames(S) "REG_UUNSPEC"
121set infonames(T) "REG_USHORTEST"
122set infonames(U) "REG_UPBOTCH"
123set infonameorder "RHQBAUEPSMLNIT" ;# must match bit order, lsb first
124
125# set major test number and description
126proc doing {major desc} {
127 global prefix description testbypassed
128
129 if {$testbypassed != 0} {
130 puts stdout "!!! bypassed $testbypassed tests in\
131 $prefix, `$description'"
132 }
133
134 set prefix reg-$major
135 set description "reg $desc"
136 set testbypassed 0
137}
138
139# build test number (internal)
140proc tno {testid} {
141 return [join $testid .]
142}
143
144# build description, with possible modifiers (internal)
145proc desc {testid} {
146 global description
147
148 set d $description
149 if {[llength $testid] > 1} {
150 set d "([lreplace $testid 0 0]) $d"
151 }
152 return $d
153}
154
155# build trailing options and flags argument from a flags string (internal)
156proc flags {fl} {
157 global xflags
158
159 set args [list]
160 set flags ""
161 foreach f [split $fl ""] {
162 switch -exact -- $f {
163 "i" { lappend args "-nocase" }
164 "x" { lappend args "-expanded" }
165 "n" { lappend args "-line" }
166 "p" { lappend args "-linestop" }
167 "w" { lappend args "-lineanchor" }
168 "-" { }
169 default { append flags $f }
170 }
171 }
172 if {[string compare $flags ""] != 0} {
173 lappend args -$xflags $flags
174 }
175 return $args
176}
177
178# build info-flags list from a flags string (internal)
179proc infoflags {fl} {
180 global infonames infonameorder
181
182 set ret [list]
183 foreach f [split $infonameorder ""] {
184 if {[string first $f $fl] >= 0} {
185 lappend ret $infonames($f)
186 }
187 }
188 return $ret
189}
190
191# compilation error expected
192proc e {testid flags re err} {
193 global prefix ask errorCode
194
195 # Tcl locale stuff doesn't do the ch/xy test fakery yet
196 if {[string first "+" $flags] >= 0} {
197 # This will register as a skipped test
198 test $prefix.[tno $testid] [desc $testid] localeRegexp {} {}
199 return
200 }
201
202 # if &, test as both ARE and BRE
203 set amp [string first "&" $flags]
204 if {$amp >= 0} {
205 set f [string range $flags 0 [expr $amp - 1]]
206 append f [string range $flags [expr $amp + 1] end]
207 e [linsert $testid end ARE] ${f} $re $err
208 e [linsert $testid end BRE] ${f}b $re $err
209 return
210 }
211
212 set cmd [concat [list testregexp -$ask] [flags $flags] [list $re]]
213 set run "list \[catch \{$cmd\}\] \[lindex \$errorCode 1\]"
214 test $prefix.[tno $testid] [desc $testid] \
215 {testregexp} $run [list 1 REG_$err]
216}
217
218# match failure expected
219proc f {testid flags re target args} {
220 global prefix description ask
221
222 # Tcl locale stuff doesn't do the ch/xy test fakery yet
223 if {[string first "+" $flags] >= 0} {
224 # This will register as a skipped test
225 test $prefix.[tno $testid] [desc $testid] localeRegexp {} {}
226 return
227 }
228
229 # if &, test as both ARE and BRE
230 set amp [string first "&" $flags]
231 if {$amp >= 0} {
232 set f [string range $flags 0 [expr $amp - 1]]
233 append f [string range $flags [expr $amp + 1] end]
234 eval [linsert $args 0 f [linsert $testid end ARE] ${f} $re \
235 $target]
236 eval [linsert $args 0 f [linsert $testid end BRE] ${f}b $re \
237 $target]
238 return
239 }
240
241 set f [flags $flags]
242 set infoflags [infoflags $flags]
243 set ccmd [concat [list testregexp -$ask] $f [list $re]]
244 set nsub [expr [llength $args] - 1]
245 if {$nsub == -1} {
246 # didn't tell us number of subexps
247 set ccmd "lreplace \[$ccmd\] 0 0"
248 set info [list $infoflags]
249 } else {
250 set info [list $nsub $infoflags]
251 }
252 lappend testid "compile"
253 test $prefix.[tno $testid] [desc $testid] {testregexp} $ccmd $info
254
255 set testid [lreplace $testid end end "execute"]
256 set ecmd [concat [list testregexp] $f [list $re $target]]
257 test $prefix.[tno $testid] [desc $testid] {testregexp} $ecmd 0
258}
259
260# match expected, internal routine that does the work
261# parameters like the "real" routines except they don't have "opts",
262# which is a possibly-empty list of switches for the regexp match attempt
263# The ! flag is used to indicate expected match failure (for REG_EXPECT,
264# which wants argument testing even in the event of failure).
265proc matchexpected {opts testid flags re target args} {
266 global prefix description ask regBug
267
268 if {[info exists regBug] && $regBug} {
269 # This will register as a skipped test
270 test $prefix.[tno $testid] [desc $testid] knownBug {format 0} {1}
271 return
272 }
273
274 # Tcl locale stuff doesn't do the ch/xy test fakery yet
275 if {[string first "+" $flags] >= 0} {
276 # This will register as a skipped test
277 test $prefix.[tno $testid] [desc $testid] localeRegexp {} {}
278 return
279 }
280
281 # if &, test as both BRE and ARE
282 set amp [string first "&" $flags]
283 if {$amp >= 0} {
284 set f [string range $flags 0 [expr $amp - 1]]
285 append f [string range $flags [expr $amp + 1] end]
286 eval [concat [list matchexpected $opts \
287 [linsert $testid end ARE] ${f} $re $target] $args]
288 eval [concat [list matchexpected $opts \
289 [linsert $testid end BRE] ${f}b $re $target] $args]
290 return
291 }
292
293 set f [flags $flags]
294 set infoflags [infoflags $flags]
295 set ccmd [concat [list testregexp -$ask] $f [list $re]]
296 set ecmd [concat [list testregexp] $opts $f [list $re $target]]
297
298 set nsub [expr [llength $args] - 1]
299 set names [list]
300 set refs ""
301 for {set i 0} {$i <= $nsub} {incr i} {
302 if {$i == 0} {
303 set name match
304 } else {
305 set name sub$i
306 }
307 lappend names $name
308 append refs " \$$name"
309 set $name ""
310 }
311 if {[string first "o" $flags] >= 0} { ;# REG_NOSUB kludge
312 set nsub 0 ;# unsigned value cannot be -1
313 }
314 if {[string first "t" $flags] >= 0} { ;# REG_EXPECT
315 incr nsub -1 ;# the extra does not count
316 }
317 set ecmd [concat $ecmd $names]
318 set erun "list \[$ecmd\] $refs"
319 set retcode [list 1]
320 if {[string first "!" $flags] >= 0} {
321 set retcode [list 0]
322 }
323 set result [concat $retcode $args]
324
325 set info [list $nsub $infoflags]
326 lappend testid "compile"
327 test $prefix.[tno $testid] [desc $testid] {testregexp} $ccmd $info
328 set testid [lreplace $testid end end "execute"]
329 test $prefix.[tno $testid] [desc $testid] {testregexp} $erun $result
330}
331
332# match expected (no missing, empty, or ambiguous submatches)
333# m testno flags re target mat submat ...
334proc m {args} {
335 eval matchexpected [linsert $args 0 [list]]
336}
337
338# match expected (full fanciness)
339# i testno flags re target mat submat ...
340proc i {args} {
341 eval matchexpected [linsert $args 0 [list "-indices"]]
342}
343
344# partial match expected
345# p testno flags re target mat "" ...
346# Quirk: number of ""s must be one more than number of subREs.
347proc p {args} {
348 set f [lindex $args 1] ;# add ! flag
349 set args [lreplace $args 1 1 "!$f"]
350 eval matchexpected [linsert $args 0 [list "-indices"]]
351}
352
353# test is a knownBug
354proc knownBug {args} {
355 set ::regBug 1
356 uplevel #0 $args
357 set ::regBug 0
358}
359
360
361
362# the tests themselves
363
364
365
366# support functions and preliminary misc.
367# This is sensitive to changes in message wording, but we really have to
368# test the code->message expansion at least once.
369test reg-0.1 "regexp error reporting" {
370 list [catch {regexp (*) ign} msg] $msg
371} {1 {couldn't compile regular expression pattern: quantifier operand invalid}}
372
373
374
375doing 1 "basic sanity checks"
376m 1 & abc abc abc
377f 2 & abc def
378m 3 & abc xyabxabce abc
379
380
381
382doing 2 "invalid option combinations"
383e 1 qe a INVARG
384e 2 qa a INVARG
385e 3 qx a INVARG
386e 4 qn a INVARG
387e 5 ba a INVARG
388
389
390
391doing 3 "basic syntax"
392i 1 &NS "" a {0 -1}
393m 2 NS a| a a
394m 3 - a|b a a
395m 4 - a|b b b
396m 5 NS a||b b b
397m 6 & ab ab ab
398
399
400
401doing 4 "parentheses"
402m 1 - (a)e ae ae a
403m 2 o (a)e ae
404m 3 b {\(a\)b} ab ab a
405m 4 - a((b)c) abc abc bc b
406m 5 - a(b)(c) abc abc b c
407e 6 - a(b EPAREN
408e 7 b {a\(b} EPAREN
409# sigh, we blew it on the specs here... someday this will be fixed in POSIX,
410# but meanwhile, it's fixed in AREs
411m 8 eU a)b a)b a)b
412e 9 - a)b EPAREN
413e 10 b {a\)b} EPAREN
414m 11 P a(?:b)c abc abc
415e 12 e a(?:b)c BADRPT
416i 13 S a()b ab {0 1} {1 0}
417m 14 SP a(?:)b ab ab
418i 15 S a(|b)c ac {0 1} {1 0}
419m 16 S a(b|)c abc abc b
420
421
422
423doing 5 "simple one-char matching"
424# general case of brackets done later
425m 1 & a.b axb axb
426f 2 &n "a.b" "a\nb"
427m 3 & {a[bc]d} abd abd
428m 4 & {a[bc]d} acd acd
429f 5 & {a[bc]d} aed
430f 6 & {a[^bc]d} abd
431m 7 & {a[^bc]d} aed aed
432f 8 &p "a\[^bc]d" "a\nd"
433
434
435
436doing 6 "context-dependent syntax"
437# plus odds and ends
438e 1 - * BADRPT
439m 2 b * * *
440m 3 b {\(*\)} * * *
441e 4 - (*) BADRPT
442m 5 b ^* * *
443e 6 - ^* BADRPT
444f 7 & ^b ^b
445m 8 b x^ x^ x^
446f 9 I x^ x
447m 10 n "\n^" "x\nb" "\n"
448f 11 bS {\(^b\)} ^b
449m 12 - (^b) b b b
450m 13 & {x$} x x
451m 14 bS {\(x$\)} x x x
452m 15 - {(x$)} x x x
453m 16 b {x$y} "x\$y" "x\$y"
454f 17 I {x$y} xy
455m 18 n "x\$\n" "x\n" "x\n"
456e 19 - + BADRPT
457e 20 - ? BADRPT
458
459
460
461doing 7 "simple quantifiers"
462m 1 &N a* aa aa
463i 2 &N a* b {0 -1}
464m 3 - a+ aa aa
465m 4 - a?b ab ab
466m 5 - a?b b b
467e 6 - ** BADRPT
468m 7 bN ** *** ***
469e 8 & a** BADRPT
470e 9 & a**b BADRPT
471e 10 & *** BADRPT
472e 11 - a++ BADRPT
473e 12 - a?+ BADRPT
474e 13 - a?* BADRPT
475e 14 - a+* BADRPT
476e 15 - a*+ BADRPT
477
478
479
480doing 8 "braces"
481m 1 NQ "a{0,1}" "" ""
482m 2 NQ "a{0,1}" ac a
483e 3 - "a{1,0}" BADBR
484e 4 - "a{1,2,3}" BADBR
485e 5 - "a{257}" BADBR
486e 6 - "a{1000}" BADBR
487e 7 - "a{1" EBRACE
488e 8 - "a{1n}" BADBR
489m 9 BS "a{b" "a\{b" "a\{b"
490m 10 BS "a{" "a\{" "a\{"
491m 11 bQ "a\\{0,1\\}b" cb b
492e 12 b "a\\{0,1" EBRACE
493e 13 - "a{0,1\\" BADBR
494m 14 Q "a{0}b" ab b
495m 15 Q "a{0,0}b" ab b
496m 16 Q "a{0,1}b" ab ab
497m 17 Q "a{0,2}b" b b
498m 18 Q "a{0,2}b" aab aab
499m 19 Q "a{0,}b" aab aab
500m 20 Q "a{1,1}b" aab ab
501m 21 Q "a{1,3}b" aaaab aaab
502f 22 Q "a{1,3}b" b
503m 23 Q "a{1,}b" aab aab
504f 24 Q "a{2,3}b" ab
505m 25 Q "a{2,3}b" aaaab aaab
506f 26 Q "a{2,}b" ab
507m 27 Q "a{2,}b" aaaab aaaab
508
509
510
511doing 9 "brackets"
512m 1 & {a[bc]} ac ac
513m 2 & {a[-]} a- a-
514m 3 & {a[[.-.]]} a- a-
515m 4 &L {a[[.zero.]]} a0 a0
516m 5 &LM {a[[.zero.]-9]} a2 a2
517m 6 &M {a[0-[.9.]]} a2 a2
518m 7 &+L {a[[=x=]]} ax ax
519m 8 &+L {a[[=x=]]} ay ay
520f 9 &+L {a[[=x=]]} az
521e 10 & {a[0-[=x=]]} ERANGE
522m 11 &L {a[[:digit:]]} a0 a0
523e 12 & {a[[:woopsie:]]} ECTYPE
524f 13 &L {a[[:digit:]]} ab
525e 14 & {a[0-[:digit:]]} ERANGE
526m 15 &LP {[[:<:]]a} a a
527m 16 &LP {a[[:>:]]} a a
528e 17 & {a[[..]]b} ECOLLATE
529e 18 & {a[[==]]b} ECOLLATE
530e 19 & {a[[::]]b} ECTYPE
531e 20 & {a[[.a} EBRACK
532e 21 & {a[[=a} EBRACK
533e 22 & {a[[:a} EBRACK
534e 23 & {a[} EBRACK
535e 24 & {a[b} EBRACK
536e 25 & {a[b-} EBRACK
537e 26 & {a[b-c} EBRACK
538m 27 &M {a[b-c]} ab ab
539m 28 & {a[b-b]} ab ab
540m 29 &M {a[1-2]} a2 a2
541e 30 & {a[c-b]} ERANGE
542e 31 & {a[a-b-c]} ERANGE
543m 32 &M {a[--?]b} a?b a?b
544m 33 & {a[---]b} a-b a-b
545m 34 & {a[]b]c} a]c a]c
546m 35 EP {a[\]]b} a]b a]b
547f 36 bE {a[\]]b} a]b
548m 37 bE {a[\]]b} "a\\]b" "a\\]b"
549m 38 eE {a[\]]b} "a\\]b" "a\\]b"
550m 39 EP {a[\\]b} "a\\b" "a\\b"
551m 40 eE {a[\\]b} "a\\b" "a\\b"
552m 41 bE {a[\\]b} "a\\b" "a\\b"
553e 42 - {a[\Z]b} EESCAPE
554m 43 & {a[[b]c} "a\[c" "a\[c"
555m 44 EMP* {a[\u00fe-\u0507][\u00ff-\u0300]b} \
556 "a\u0102\u02ffb" "a\u0102\u02ffb"
557
558
559
560doing 10 "anchors and newlines"
561m 1 & ^a a a
562f 2 &^ ^a a
563i 3 &N ^ a {0 -1}
564i 4 & {a$} aba {2 2}
565f 5 {&$} {a$} a
566i 6 &N {$} ab {2 1}
567m 7 &n ^a a a
568m 8 &n "^a" "b\na" "a"
569i 9 &w "^a" "a\na" {0 0}
570i 10 &n^ "^a" "a\na" {2 2}
571m 11 &n {a$} a a
572m 12 &n "a\$" "a\nb" "a"
573i 13 &n "a\$" "a\na" {0 0}
574i 14 N ^^ a {0 -1}
575m 15 b ^^ ^ ^
576i 16 N {$$} a {1 0}
577m 17 b {$$} "\$" "\$"
578m 18 &N {^$} "" ""
579f 19 &N {^$} a
580i 20 &nN "^\$" "a\n\nb" {2 1}
581m 21 N {$^} "" ""
582m 22 b {$^} "\$^" "\$^"
583m 23 P {\Aa} a a
584m 24 ^P {\Aa} a a
585f 25 ^nP {\Aa} "b\na"
586m 26 P {a\Z} a a
587m 27 {$P} {a\Z} a a
588f 28 {$nP} {a\Z} "a\nb"
589e 29 - ^* BADRPT
590e 30 - {$*} BADRPT
591e 31 - {\A*} BADRPT
592e 32 - {\Z*} BADRPT
593
594
595
596doing 11 "boundary constraints"
597m 1 &LP {[[:<:]]a} a a
598m 2 &LP {[[:<:]]a} -a a
599f 3 &LP {[[:<:]]a} ba
600m 4 &LP {a[[:>:]]} a a
601m 5 &LP {a[[:>:]]} a- a
602f 6 &LP {a[[:>:]]} ab
603m 7 bLP {\<a} a a
604f 8 bLP {\<a} ba
605m 9 bLP {a\>} a a
606f 10 bLP {a\>} ab
607m 11 LP {\ya} a a
608f 12 LP {\ya} ba
609m 13 LP {a\y} a a
610f 14 LP {a\y} ab
611m 15 LP {a\Y} ab a
612f 16 LP {a\Y} a-
613f 17 LP {a\Y} a
614f 18 LP {-\Y} -a
615m 19 LP {-\Y} -% -
616f 20 LP {\Y-} a-
617e 21 - {[[:<:]]*} BADRPT
618e 22 - {[[:>:]]*} BADRPT
619e 23 b {\<*} BADRPT
620e 24 b {\>*} BADRPT
621e 25 - {\y*} BADRPT
622e 26 - {\Y*} BADRPT
623m 27 LP {\ma} a a
624f 28 LP {\ma} ba
625m 29 LP {a\M} a a
626f 30 LP {a\M} ab
627f 31 ILP {\Ma} a
628f 32 ILP {a\m} a
629
630
631
632doing 12 "character classes"
633m 1 LP {a\db} a0b a0b
634f 2 LP {a\db} axb
635f 3 LP {a\Db} a0b
636m 4 LP {a\Db} axb axb
637m 5 LP "a\\sb" "a b" "a b"
638m 6 LP "a\\sb" "a\tb" "a\tb"
639m 7 LP "a\\sb" "a\nb" "a\nb"
640f 8 LP {a\sb} axb
641m 9 LP {a\Sb} axb axb
642f 10 LP "a\\Sb" "a b"
643m 11 LP {a\wb} axb axb
644f 12 LP {a\wb} a-b
645f 13 LP {a\Wb} axb
646m 14 LP {a\Wb} a-b a-b
647m 15 LP {\y\w+z\y} adze-guz guz
648m 16 LPE {a[\d]b} a1b a1b
649m 17 LPE "a\[\\s]b" "a b" "a b"
650m 18 LPE {a[\w]b} axb axb
651
652
653
654doing 13 "escapes"
655e 1 & "a\\" EESCAPE
656m 2 - {a\<b} a<b a<b
657m 3 e {a\<b} a<b a<b
658m 4 bAS {a\wb} awb awb
659m 5 eAS {a\wb} awb awb
660m 6 PL "a\\ab" "a\007b" "a\007b"
661m 7 P "a\\bb" "a\bb" "a\bb"
662m 8 P {a\Bb} "a\\b" "a\\b"
663m 9 MP "a\\chb" "a\bb" "a\bb"
664m 10 MP "a\\cHb" "a\bb" "a\bb"
665m 11 LMP "a\\e" "a\033" "a\033"
666m 12 P "a\\fb" "a\fb" "a\fb"
667m 13 P "a\\nb" "a\nb" "a\nb"
668m 14 P "a\\rb" "a\rb" "a\rb"
669m 15 P "a\\tb" "a\tb" "a\tb"
670m 16 P "a\\u0008x" "a\bx" "a\bx"
671e 17 - {a\u008x} EESCAPE
672m 18 P "a\\u00088x" "a\b8x" "a\b8x"
673m 19 P "a\\U00000008x" "a\bx" "a\bx"
674e 20 - {a\U0000008x} EESCAPE
675m 21 P "a\\vb" "a\vb" "a\vb"
676m 22 MP "a\\x08x" "a\bx" "a\bx"
677e 23 - {a\xq} EESCAPE
678m 24 MP "a\\x0008x" "a\bx" "a\bx"
679e 25 - {a\z} EESCAPE
680m 26 MP "a\\010b" "a\bb" "a\bb"
681
682
683
684doing 14 "back references"
685# ugh
686m 1 RP {a(b*)c\1} abbcbb abbcbb bb
687m 2 RP {a(b*)c\1} ac ac ""
688f 3 RP {a(b*)c\1} abbcb
689m 4 RP {a(b*)\1} abbcbb abb b
690m 5 RP {a(b|bb)\1} abbcbb abb b
691m 6 RP {a([bc])\1} abb abb b
692f 7 RP {a([bc])\1} abc
693m 8 RP {a([bc])\1} abcabb abb b
694f 9 RP {a([bc])*\1} abc
695f 10 RP {a([bc])\1} abB
696m 11 iRP {a([bc])\1} abB abB b
697m 12 RP {a([bc])\1+} abbb abbb b
698m 13 QRP "a(\[bc])\\1{3,4}" abbbb abbbb b
699f 14 QRP "a(\[bc])\\1{3,4}" abbb
700m 15 RP {a([bc])\1*} abbb abbb b
701m 16 RP {a([bc])\1*} ab ab b
702m 17 RP {a([bc])(\1*)} ab ab b ""
703e 18 - {a((b)\1)} ESUBREG
704e 19 - {a(b)c\2} ESUBREG
705m 20 bR {a\(b*\)c\1} abbcbb abbcbb bb
706
707
708
709doing 15 "octal escapes vs back references"
710# initial zero is always octal
711m 1 MP "a\\010b" "a\bb" "a\bb"
712m 2 MP "a\\0070b" "a\0070b" "a\0070b"
713m 3 MP "a\\07b" "a\007b" "a\007b"
714m 4 MP "a(b)(b)(b)(b)(b)(b)(b)(b)(b)(b)\\07c" "abbbbbbbbbb\007c" \
715 "abbbbbbbbbb\007c" "b" "b" "b" "b" "b" "b" \
716 "b" "b" "b" "b"
717# a single digit is always a backref
718e 5 - {a\7b} ESUBREG
719# otherwise it's a backref only if within range (barf!)
720m 6 MP "a\\10b" "a\bb" "a\bb"
721m 7 MP {a\101b} aAb aAb
722m 8 RP {a(b)(b)(b)(b)(b)(b)(b)(b)(b)(b)\10c} abbbbbbbbbbbc \
723 abbbbbbbbbbbc b b b b b b b \
724 b b b
725# but we're fussy about border cases -- guys who want octal should use the zero
726e 9 - {a((((((((((b\10))))))))))c} ESUBREG
727# BREs don't have octal, EREs don't have backrefs
728m 10 MP "a\\12b" "a\nb" "a\nb"
729e 11 b {a\12b} ESUBREG
730m 12 eAS {a\12b} a12b a12b
731
732
733
734doing 16 "expanded syntax"
735m 1 xP "a b c" "abc" "abc"
736m 2 xP "a b #oops\nc\td" "abcd" "abcd"
737m 3 x "a\\ b\\\tc" "a b\tc" "a b\tc"
738m 4 xP "a b\\#c" "ab#c" "ab#c"
739m 5 xP "a b\[c d]e" "ab e" "ab e"
740m 6 xP "a b\[c#d]e" "ab#e" "ab#e"
741m 7 xP "a b\[c#d]e" "abde" "abde"
742m 8 xSPB "ab{ d" "ab\{d" "ab\{d"
743m 9 xPQ "ab{ 1 , 2 }c" "abc" "abc"
744
745
746
747doing 17 "misc syntax"
748m 1 P a(?#comment)b ab ab
749
750
751
752doing 18 "unmatchable REs"
753f 1 I a^b ab
754
755
756
757doing 19 "case independence"
758m 1 &i ab Ab Ab
759m 2 &i {a[bc]} aC aC
760f 3 &i {a[^bc]} aB
761m 4 &iM {a[b-d]} aC aC
762f 5 &iM {a[^b-d]} aC
763
764
765
766doing 20 "directors and embedded options"
767e 1 & ***? BADPAT
768m 2 q ***? ***? ***?
769m 3 &P ***=a*b a*b a*b
770m 4 q ***=a*b ***=a*b ***=a*b
771m 5 bLP {***:\w+} ab ab
772m 6 eLP {***:\w+} ab ab
773e 7 & ***:***=a*b BADRPT
774m 8 &P ***:(?b)a+b a+b a+b
775m 9 P (?b)a+b a+b a+b
776e 10 e {(?b)\w+} BADRPT
777m 11 bAS {(?b)\w+} (?b)w+ (?b)w+
778m 12 iP (?c)a a a
779f 13 iP (?c)a A
780m 14 APS {(?e)\W+} WW WW
781m 15 P (?i)a+ Aa Aa
782f 16 P "(?m)a.b" "a\nb"
783m 17 P "(?m)^b" "a\nb" "b"
784f 18 P "(?n)a.b" "a\nb"
785m 19 P "(?n)^b" "a\nb" "b"
786f 20 P "(?p)a.b" "a\nb"
787f 21 P "(?p)^b" "a\nb"
788m 22 P (?q)a+b a+b a+b
789m 23 nP "(?s)a.b" "a\nb" "a\nb"
790m 24 xP "(?t)a b" "a b" "a b"
791m 25 P "(?w)a.b" "a\nb" "a\nb"
792m 26 P "(?w)^b" "a\nb" "b"
793m 27 P "(?x)a b" "ab" "ab"
794e 28 - (?z)ab BADOPT
795m 29 P (?ici)a+ Aa Aa
796e 30 P (?i)(?q)a+ BADRPT
797m 31 P (?q)(?i)a+ (?i)a+ (?i)a+
798m 32 P (?qe)a+ a a
799m 33 xP "(?q)a b" "a b" "a b"
800m 34 P "(?qx)a b" "a b" "a b"
801m 35 P (?qi)ab Ab Ab
802
803
804
805doing 21 "capturing"
806m 1 - a(b)c abc abc b
807m 2 P a(?:b)c xabc abc
808m 3 - a((b))c xabcy abc b b
809m 4 P a(?:(b))c abcy abc b
810m 5 P a((?:b))c abc abc b
811m 6 P a(?:(?:b))c abc abc
812i 7 Q "a(b){0}c" ac {0 1} {-1 -1}
813m 8 - a(b)c(d)e abcde abcde b d
814m 9 - (b)c(d)e bcde bcde b d
815m 10 - a(b)(d)e abde abde b d
816m 11 - a(b)c(d) abcd abcd b d
817m 12 - (ab)(cd) xabcdy abcd ab cd
818m 13 - a(b)?c xabcy abc b
819i 14 - a(b)?c xacy {1 2} {-1 -1}
820m 15 - a(b)?c(d)?e xabcdey abcde b d
821i 16 - a(b)?c(d)?e xacdey {1 4} {-1 -1} {3 3}
822i 17 - a(b)?c(d)?e xabcey {1 4} {2 2} {-1 -1}
823i 18 - a(b)?c(d)?e xacey {1 3} {-1 -1} {-1 -1}
824m 19 - a(b)*c xabcy abc b
825i 20 - a(b)*c xabbbcy {1 5} {4 4}
826i 21 - a(b)*c xacy {1 2} {-1 -1}
827m 22 - a(b*)c xabbbcy abbbc bbb
828m 23 - a(b*)c xacy ac ""
829f 24 - a(b)+c xacy
830m 25 - a(b)+c xabcy abc b
831i 26 - a(b)+c xabbbcy {1 5} {4 4}
832m 27 - a(b+)c xabbbcy abbbc bbb
833i 28 Q "a(b){2,3}c" xabbbcy {1 5} {4 4}
834i 29 Q "a(b){2,3}c" xabbcy {1 4} {3 3}
835f 30 Q "a(b){2,3}c" xabcy
836m 31 LP "\\y(\\w+)\\y" "-- abc-" "abc" "abc"
837m 32 - a((b|c)d+)+ abacdbd acdbd bd b
838m 33 N (.*).* abc abc abc
839m 34 N (a*)* bc "" ""
840
841
842
843doing 22 "multicharacter collating elements"
844# again ugh
845m 1 &+L {a[c]e} ace ace
846f 2 &+IL {a[c]h} ach
847m 3 &+L {a[[.ch.]]} ach ach
848f 4 &+L {a[[.ch.]]} ace
849m 5 &+L {a[c[.ch.]]} ac ac
850m 6 &+L {a[c[.ch.]]} ace ac
851m 7 &+L {a[c[.ch.]]} ache ach
852f 8 &+L {a[^c]e} ace
853m 9 &+L {a[^c]e} abe abe
854m 10 &+L {a[^c]e} ache ache
855f 11 &+L {a[^[.ch.]]} ach
856m 12 &+L {a[^[.ch.]]} ace ac
857m 13 &+L {a[^[.ch.]]} ac ac
858m 14 &+L {a[^[.ch.]]} abe ab
859f 15 &+L {a[^c[.ch.]]} ach
860f 16 &+L {a[^c[.ch.]]} ace
861f 17 &+L {a[^c[.ch.]]} ac
862m 18 &+L {a[^c[.ch.]]} abe ab
863m 19 &+L {a[^b]} ac ac
864m 20 &+L {a[^b]} ace ac
865m 21 &+L {a[^b]} ach ach
866f 22 &+L {a[^b]} abe
867
868
869
870doing 23 "lookahead constraints"
871m 1 HP a(?=b)b* ab ab
872f 2 HP a(?=b)b* a
873m 3 HP a(?=b)b*(?=c)c* abc abc
874f 4 HP a(?=b)b*(?=c)c* ab
875f 5 HP a(?!b)b* ab
876m 6 HP a(?!b)b* a a
877m 7 HP (?=b)b b b
878f 8 HP (?=b)b a
879
880
881
882doing 24 "non-greedy quantifiers"
883m 1 PT ab+? abb ab
884m 2 PT ab+?c abbc abbc
885m 3 PT ab*? abb a
886m 4 PT ab*?c abbc abbc
887m 5 PT ab?? ab a
888m 6 PT ab??c abc abc
889m 7 PQT "ab{2,4}?" abbbb abb
890m 8 PQT "ab{2,4}?c" abbbbc abbbbc
891m 9 - 3z* 123zzzz456 3zzzz
892m 10 PT 3z*? 123zzzz456 3
893m 11 - z*4 123zzzz456 zzzz4
894m 12 PT z*?4 123zzzz456 zzzz4
895
896
897
898doing 25 "mixed quantifiers"
899# this is very incomplete as yet
900# should include |
901m 1 PNT {^(.*?)(a*)$} xyza xyza xyz a
902m 2 PNT {^(.*?)(a*)$} xyzaa xyzaa xyz aa
903m 3 PNT {^(.*?)(a*)$} xyz xyz xyz ""
904
905
906
907doing 26 "tricky cases"
908# attempts to trick the matcher into accepting a short match
909m 1 - (week|wee)(night|knights) weeknights weeknights \
910 wee knights
911m 2 RP {a(bc*).*\1} abccbccb abccbccb b
912m 3 - {a(b.[bc]*)+} abcbd abcbd bd
913
914
915
916doing 27 "implementation misc."
917# duplicate arcs are suppressed
918m 1 P a(?:b|b)c abc abc
919# make color/subcolor relationship go back and forth
920m 2 & {[ab][ab][ab]} aba aba
921m 3 & {[ab][ab][ab][ab][ab][ab][ab]} abababa abababa
922
923
924
925doing 28 "boundary busters etc."
926# color-descriptor allocation changes at 10
927m 1 & abcdefghijkl abcdefghijkl abcdefghijkl
928# so does arc allocation
929m 2 P a(?:b|c|d|e|f|g|h|i|j|k|l|m)n agn agn
930# subexpression tracking also at 10
931m 3 - a(((((((((((((b)))))))))))))c abc abc b b b b b b b b b b b b b
932# state-set handling changes slightly at unsigned size (might be 64...)
933# (also stresses arc allocation)
934m 4 Q "ab{1,100}c" abbc abbc
935m 5 Q "ab{1,100}c" abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc \
936 abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc
937m 6 Q "ab{1,100}c" \
938 abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc \
939 abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc
940# force small cache and bust it, several ways
941m 7 LP {\w+abcdefgh} xyzabcdefgh xyzabcdefgh
942m 8 %LP {\w+abcdefgh} xyzabcdefgh xyzabcdefgh
943m 9 %LP {\w+abcdefghijklmnopqrst} xyzabcdefghijklmnopqrst \
944 xyzabcdefghijklmnopqrst
945i 10 %LP {\w+(abcdefgh)?} xyz {0 2} {-1 -1}
946i 11 %LP {\w+(abcdefgh)?} xyzabcdefg {0 9} {-1 -1}
947i 12 %LP {\w+(abcdefghijklmnopqrst)?} xyzabcdefghijklmnopqrs \
948 {0 21} {-1 -1}
949
950
951
952doing 29 "incomplete matches"
953p 1 t def abc {3 2} ""
954p 2 t bcd abc {1 2} ""
955p 3 t abc abab {0 3} ""
956p 4 t abc abdab {3 4} ""
957i 5 t abc abc {0 2} {0 2}
958i 6 t abc xyabc {2 4} {2 4}
959p 7 t abc+ xyab {2 3} ""
960i 8 t abc+ xyabc {2 4} {2 4}
961knownBug i 9 t abc+ xyabcd {2 4} {6 5}
962i 10 t abc+ xyabcdd {2 4} {7 6}
963p 11 tPT abc+? xyab {2 3} ""
964# the retain numbers in these two may look wrong, but they aren't
965i 12 tPT abc+? xyabc {2 4} {5 4}
966i 13 tPT abc+? xyabcc {2 4} {6 5}
967i 14 tPT abc+? xyabcd {2 4} {6 5}
968i 15 tPT abc+? xyabcdd {2 4} {7 6}
969i 16 t abcd|bc xyabc {3 4} {2 4}
970p 17 tn .*k "xx\nyyy" {3 5} ""
971
972
973doing 30 "misc. oddities and old bugs"
974e 1 & *** BADRPT
975m 2 N a?b* abb abb
976m 3 N a?b* bb bb
977m 4 & a*b aab aab
978m 5 & ^a*b aaaab aaaab
979m 6 &M {[0-6][1-2][0-3][0-6][1-6][0-6]} 010010 010010
980# temporary REG_BOSONLY kludge
981m 7 s abc abcd abc
982f 8 s abc xabcd
983# back to normal stuff
984m 9 HLP {(?n)^(?![t#])\S+} "tk\n\n#\n#\nit0" it0
985
986
987# flush any leftover complaints
988doing 0 "flush"
989
990# Tests resulting from bugs reported by users
991test reg-31.1 {[[:xdigit:]] behaves correctly when followed by [[:space:]]} {
992 set str {2:::DebugWin32}
993 set re {([[:xdigit:]])([[:space:]]*)}
994 list [regexp $re $str match xdigit spaces] $match $xdigit $spaces
995 # Code used to produce {1 2:::DebugWin32 2 :::DebugWin32} !!!
996} {1 2 2 {}}
997
998test reg-32.1 {canmatch functionality -- at end} {
999 set pat {blah}
1000 set line "asd asd"
1001 # can match at the final d, if '%' follows
1002 set res [testregexp -xflags -- c $pat $line resvar]
1003 lappend res $resvar
1004} {0 7}
1005
1006test reg-32.2 {canmatch functionality -- at end} {
1007 set pat {s%$}
1008 set line "asd asd"
1009 # can only match after the end of the string
1010 set res [testregexp -xflags -- c $pat $line resvar]
1011 lappend res $resvar
1012} {0 7}
1013
1014test reg-32.3 {canmatch functionality -- not last char} {
1015 set pat {[^d]%$}
1016 set line "asd asd"
1017 # can only match after the end of the string
1018 set res [testregexp -xflags -- c $pat $line resvar]
1019 lappend res $resvar
1020} {0 7}
1021
1022test reg-32.3.1 {canmatch functionality -- no match} {
1023 set pat {\Zx}
1024 set line "asd asd"
1025 # can match the last char, if followed by x
1026 set res [testregexp -xflags -- c $pat $line resvar]
1027 lappend res $resvar
1028} {0 -1}
1029
1030test reg-32.4 {canmatch functionality -- last char} {knownBug} {
1031 set pat {.x}
1032 set line "asd asd"
1033 # can match the last char, if followed by x
1034 set res [testregexp -xflags -- c $pat $line resvar]
1035 lappend res $resvar
1036} {0 6}
1037
1038test reg-32.4.1 {canmatch functionality -- last char} {knownBug} {
1039 set pat {.x$}
1040 set line "asd asd"
1041 # can match the last char, if followed by x
1042 set res [testregexp -xflags -- c $pat $line resvar]
1043 lappend res $resvar
1044} {0 6}
1045
1046test reg-32.5 {canmatch functionality -- last char} {knownBug} {
1047 set pat {.[^d]x$}
1048 set line "asd asd"
1049 # can match the last char, if followed by not-d and x.
1050 set res [testregexp -xflags -- c $pat $line resvar]
1051 lappend res $resvar
1052} {0 6}
1053
1054test reg-32.6 {canmatch functionality -- last char} {knownBug} {
1055 set pat {[^a]%[^\r\n]*$}
1056 set line "asd asd"
1057 # can match at the final d, if '%' follows
1058 set res [testregexp -xflags -- c $pat $line resvar]
1059 lappend res $resvar
1060} {0 6}
1061
1062test reg-32.7 {canmatch functionality -- last char} {knownBug} {
1063 set pat {[^a]%$}
1064 set line "asd asd"
1065 # can match at the final d, if '%' follows
1066 set res [testregexp -xflags -- c $pat $line resvar]
1067 lappend res $resvar
1068} {0 6}
1069
1070test reg-32.8 {canmatch functionality -- last char} {knownBug} {
1071 set pat {[^x]%$}
1072 set line "asd asd"
1073 # can match at the final d, if '%' follows
1074 set res [testregexp -xflags -- c $pat $line resvar]
1075 lappend res $resvar
1076} {0 6}
1077
1078test reg-32.9 {canmatch functionality -- more complex case} {knownBug} {
1079 set pat {((\B\B|\Bh+line)[ \t]*|[^\B]%[^\r\n]*)$}
1080 set line "asd asd"
1081 # can match at the final d, if '%' follows
1082 set res [testregexp -xflags -- c $pat $line resvar]
1083 lappend res $resvar
1084} {0 6}
1085
1086# Tests reg-33.*: Checks for bug fixes
1087
1088test reg-33.1 {Bug 230589} {
1089 regexp {[ ]*(^|[^%])%V} "*%V2" m s
1090} 1
1091
1092test reg-33.2 {Bug 504785} {
1093 regexp -inline {([^_.]*)([^.]*)\.(..)(.).*} bbcos_001_c01.q1la
1094} {bbcos_001_c01.q1la bbcos _001_c01 q1 l}
1095
1096test reg-33.3 {Bug 505048} {
1097 regexp {\A\s*[^<]*\s*<([^>]+)>} a<a>
1098} 1
1099
1100test reg-33.4 {Bug 505048} {
1101 regexp {\A\s*([^b]*)b} ab
1102} 1
1103
1104test reg-33.5 {Bug 505048} {
1105 regexp {\A\s*[^b]*(b)} ab
1106} 1
1107
1108test reg-33.6 {Bug 505048} {
1109 regexp {\A(\s*)[^b]*(b)} ab
1110} 1
1111
1112test reg-33.7 {Bug 505048} {
1113 regexp {\A\s*[^b]*b} ab
1114} 1
1115
1116test reg-33.8 {Bug 505048} {
1117 regexp -inline {\A\s*[^b]*b} ab
1118} ab
1119
1120test reg-33.9 {Bug 505048} {
1121 regexp -indices -inline {\A\s*[^b]*b} ab
1122} {{0 1}}
1123
1124test reg-33.10 {Bug 840258} {
1125 regsub {(^|\n)+\.*b} \n.b {} tmp
1126} 1
1127
1128test reg-33.11 {Bug 840258} {
1129 regsub {(^|[\n\r]+)\.*\?<.*?(\n|\r)+} \
1130 "TQ\r\n.?<5000267>Test already stopped\r\n" {} tmp
1131} 1
1132
1133# cleanup
1134::tcltest::cleanupTests
1135return