Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/tests/regexpComp.test @ 47

Last change on this file since 47 was 25, checked in by landauf, 17 years ago

added tcl to libs

File size: 25.2 KB
Line 
1# Commands covered:  regexp, regsub
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#
7# Copyright (c) 1991-1993 The Regents of the University of California.
8# Copyright (c) 1998 Sun Microsystems, Inc.
9# Copyright (c) 1998-1999 by Scriptics Corporation.
10#
11# See the file "license.terms" for information on usage and redistribution
12# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13#
14# RCS: @(#) $Id$
15
16if {[lsearch [namespace children] ::tcltest] == -1} {
17    package require tcltest 2
18    namespace import -force ::tcltest::*
19}
20
21# Procedure to evaluate a script within a proc, to test compilation
22# functionality
23
24proc evalInProc { script } {
25    proc testProc {} $script
26    set status [catch {
27        testProc
28    } result]
29    rename testProc {}
30    return $result
31    #return [list $status $result]
32}
33
34catch {unset foo}
35test regexpComp-1.1 {basic regexp operation} {
36    evalInProc {
37        regexp ab*c abbbc
38    }
39} 1
40test regexpComp-1.2 {basic regexp operation} {
41    evalInProc {
42        regexp ab*c ac
43    }
44} 1
45test regexpComp-1.3 {basic regexp operation} {
46    evalInProc {   
47        regexp ab*c ab
48    }
49} 0
50test regexpComp-1.4 {basic regexp operation} {
51    evalInProc {
52        regexp -- -gorp abc-gorpxxx
53    }
54} 1
55test regexpComp-1.5 {basic regexp operation} {
56    evalInProc {
57        regexp {^([^ ]*)[ ]*([^ ]*)} "" a
58    }
59} 1
60test regexpComp-1.6 {basic regexp operation} {
61    list [catch {regexp {} abc} msg] $msg
62} {0 1}
63test regexpComp-1.7 {regexp utf compliance} {
64    # if not UTF-8 aware, result is "0 1"
65    evalInProc {
66        set foo "\u4e4eb q"
67        regexp "\u4e4eb q" "a\u4e4eb qw\u5e4e\x4e wq" bar
68        list [string compare $foo $bar] [regexp 4 $bar]
69    }
70} {0 0}
71
72test regexpComp-2.1 {getting substrings back from regexp} {
73    evalInProc {
74        set foo {}
75        list [regexp ab*c abbbbc foo] $foo
76    }
77} {1 abbbbc}
78test regexpComp-2.2 {getting substrings back from regexp} {
79    evalInProc {
80        set foo {}
81        set f2 {}
82        list [regexp a(b*)c abbbbc foo f2] $foo $f2
83    }
84} {1 abbbbc bbbb}
85test regexpComp-2.3 {getting substrings back from regexp} {
86    evalInProc {
87        set foo {}
88        set f2 {}
89        list [regexp a(b*)(c) abbbbc foo f2] $foo $f2
90    }
91} {1 abbbbc bbbb}
92test regexpComp-2.4 {getting substrings back from regexp} {
93    evalInProc {
94        set foo {}
95        set f2 {}
96        set f3 {}
97        list [regexp a(b*)(c) abbbbc foo f2 f3] $foo $f2 $f3
98    }
99} {1 abbbbc bbbb c}
100test regexpComp-2.5 {getting substrings back from regexp} {
101    evalInProc {
102        set foo {}; set f1 {}; set f2 {}; set f3 {}; set f4 {}; set f5 {};
103        set f6 {}; set f7 {}; set f8 {}; set f9 {}; set fa {}; set fb {};
104        list [regexp (1*)(2*)(3*)(4*)(5*)(6*)(7*)(8*)(9*)(a*)(b*) \
105                12223345556789999aabbb \
106                foo f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb] $foo $f1 $f2 $f3 $f4 $f5 \
107                $f6 $f7 $f8 $f9 $fa $fb
108    }
109} {1 12223345556789999aabbb 1 222 33 4 555 6 7 8 9999 aa bbb}
110test regexpComp-2.6 {getting substrings back from regexp} {
111    evalInProc {
112        set foo 2; set f2 2; set f3 2; set f4 2
113        list [regexp (a)(b)? xay foo f2 f3 f4] $foo $f2 $f3 $f4
114    }
115} {1 a a {} {}}
116test regexpComp-2.7 {getting substrings back from regexp} {
117    evalInProc {
118        set foo 1; set f2 1; set f3 1; set f4 1
119        list [regexp (a)(b)?(c) xacy foo f2 f3 f4] $foo $f2 $f3 $f4
120    }
121} {1 ac a {} c}
122test regexpComp-2.8 {getting substrings back from regexp} {
123    evalInProc {
124        set match {}
125        list [regexp {^a*b} aaaab match] $match
126    }
127} {1 aaaab}
128
129test regexpComp-3.1 {-indices option to regexp} {
130    evalInProc {
131        set foo {}
132        list [regexp -indices ab*c abbbbc foo] $foo
133    }
134} {1 {0 5}}
135test regexpComp-3.2 {-indices option to regexp} {
136    evalInProc {
137        set foo {}
138        set f2 {}
139        list [regexp -indices a(b*)c abbbbc foo f2] $foo $f2
140    }
141} {1 {0 5} {1 4}}
142test regexpComp-3.3 {-indices option to regexp} {
143    evalInProc {
144        set foo {}
145        set f2 {}
146        list [regexp -indices a(b*)(c) abbbbc foo f2] $foo $f2
147    }
148} {1 {0 5} {1 4}}
149test regexpComp-3.4 {-indices option to regexp} {
150    evalInProc {
151        set foo {}
152        set f2 {}
153        set f3 {}
154        list [regexp -indices a(b*)(c) abbbbc foo f2 f3] $foo $f2 $f3
155    }
156} {1 {0 5} {1 4} {5 5}}
157test regexpComp-3.5 {-indices option to regexp} {
158    evalInProc {
159        set foo {}; set f1 {}; set f2 {}; set f3 {}; set f4 {}; set f5 {};
160        set f6 {}; set f7 {}; set f8 {}; set f9 {}
161        list [regexp -indices (1*)(2*)(3*)(4*)(5*)(6*)(7*)(8*)(9*) \
162                12223345556789999 \
163                foo f1 f2 f3 f4 f5 f6 f7 f8 f9] $foo $f1 $f2 $f3 $f4 $f5 \
164                $f6 $f7 $f8 $f9
165    }
166} {1 {0 16} {0 0} {1 3} {4 5} {6 6} {7 9} {10 10} {11 11} {12 12} {13 16}}
167test regexpComp-3.6 {getting substrings back from regexp} {
168    evalInProc {
169        set foo 2; set f2 2; set f3 2; set f4 2
170        list [regexp -indices (a)(b)? xay foo f2 f3 f4] $foo $f2 $f3 $f4
171    }
172} {1 {1 1} {1 1} {-1 -1} {-1 -1}}
173test regexpComp-3.7 {getting substrings back from regexp} {
174    evalInProc {
175        set foo 1; set f2 1; set f3 1; set f4 1
176        list [regexp -indices (a)(b)?(c) xacy foo f2 f3 f4] $foo $f2 $f3 $f4
177    }
178} {1 {1 2} {1 1} {-1 -1} {2 2}}
179
180test regexpComp-4.1 {-nocase option to regexp} {
181    evalInProc {
182        regexp -nocase foo abcFOo
183    }
184} 1
185test regexpComp-4.2 {-nocase option to regexp} {
186    evalInProc {
187        set f1 22
188        set f2 33
189        set f3 44
190        list [regexp -nocase {a(b*)([xy]*)z} aBbbxYXxxZ22 f1 f2 f3] $f1 $f2 $f3
191    }
192} {1 aBbbxYXxxZ Bbb xYXxx}
193test regexpComp-4.3 {-nocase option to regexp} {
194    evalInProc {
195        regexp -nocase FOo abcFOo
196    }
197} 1
198set ::x abcdefghijklmnopqrstuvwxyz1234567890
199set ::x $x$x$x$x$x$x$x$x$x$x$x$x
200test regexpComp-4.4 {case conversion in regexp} {
201    evalInProc {
202        list [regexp -nocase $::x $::x foo] $foo
203    }
204} "1 $x"
205catch {unset ::x}
206
207test regexpComp-5.1 {exercise cache of compiled expressions} {
208    evalInProc {
209        regexp .*a b
210        regexp .*b c
211        regexp .*c d
212        regexp .*d e
213        regexp .*e f
214        regexp .*a bbba
215    }
216} 1
217test regexpComp-5.2 {exercise cache of compiled expressions} {
218    evalInProc {
219        regexp .*a b
220        regexp .*b c
221        regexp .*c d
222        regexp .*d e
223        regexp .*e f
224        regexp .*b xxxb
225    }
226} 1
227test regexpComp-5.3 {exercise cache of compiled expressions} {
228    evalInProc {
229        regexp .*a b
230        regexp .*b c
231        regexp .*c d
232        regexp .*d e
233        regexp .*e f
234        regexp .*c yyyc
235    }
236} 1
237test regexpComp-5.4 {exercise cache of compiled expressions} {
238    evalInProc {
239        regexp .*a b
240        regexp .*b c
241        regexp .*c d
242        regexp .*d e
243        regexp .*e f
244        regexp .*d 1d
245    }
246} 1
247test regexpComp-5.5 {exercise cache of compiled expressions} {
248    evalInProc {
249        regexp .*a b
250        regexp .*b c
251        regexp .*c d
252        regexp .*d e
253        regexp .*e f
254        regexp .*e xe
255    }
256} 1
257
258test regexpComp-6.1 {regexp errors} {
259    evalInProc {
260        list [catch {regexp a} msg] $msg
261    }
262} {1 {wrong # args: should be "regexp ?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?"}}
263test regexpComp-6.2 {regexp errors} {
264    evalInProc {
265        list [catch {regexp -nocase a} msg] $msg
266    }
267} {1 {wrong # args: should be "regexp ?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?"}}
268test regexpComp-6.3 {regexp errors} {
269    evalInProc {
270        list [catch {regexp -gorp a} msg] $msg
271    }
272} {1 {bad switch "-gorp": must be -all, -about, -indices, -inline, -expanded, -line, -linestop, -lineanchor, -nocase, -start, or --}}
273test regexpComp-6.4 {regexp errors} {
274    evalInProc {
275        list [catch {regexp a( b} msg] $msg
276    }
277} {1 {couldn't compile regular expression pattern: parentheses () not balanced}}
278test regexpComp-6.5 {regexp errors} {
279    evalInProc {
280        list [catch {regexp a( b} msg] $msg
281    }
282} {1 {couldn't compile regular expression pattern: parentheses () not balanced}}
283test regexpComp-6.6 {regexp errors} {
284    evalInProc {
285        list [catch {regexp a a f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1} msg] $msg
286    }
287} {0 1}
288test regexpComp-6.7 {regexp errors} {
289    evalInProc {
290        list [catch {regexp (x)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.) xyzzy} msg] $msg
291    }
292} {0 0}
293test regexpComp-6.8 {regexp errors} {
294    evalInProc {
295        catch {unset f1}
296        set f1 44
297        list [catch {regexp abc abc f1(f2)} msg] $msg
298    }
299} {1 {couldn't set variable "f1(f2)"}}
300test regexpComp-6.9 {regexp errors, -start bad int check} {
301    evalInProc {
302        list [catch {regexp -start bogus {^$} {}} msg] $msg
303    }
304} {1 {bad index "bogus": must be integer?[+-]integer? or end?[+-]integer?}}
305
306test regexpComp-7.1 {basic regsub operation} {
307    evalInProc {
308        list [regsub aa+ xaxaaaxaa 111&222 foo] $foo
309    }
310} {1 xax111aaa222xaa}
311test regexpComp-7.2 {basic regsub operation} {
312    evalInProc {
313        list [regsub aa+ aaaxaa &111 foo] $foo
314    }
315} {1 aaa111xaa}
316test regexpComp-7.3 {basic regsub operation} {
317    evalInProc {
318        list [regsub aa+ xaxaaa 111& foo] $foo
319    }
320} {1 xax111aaa}
321test regexpComp-7.4 {basic regsub operation} {
322    evalInProc {
323        list [regsub aa+ aaa 11&2&333 foo] $foo
324    }
325} {1 11aaa2aaa333}
326test regexpComp-7.5 {basic regsub operation} {
327    evalInProc {
328        list [regsub aa+ xaxaaaxaa &2&333 foo] $foo
329    }
330} {1 xaxaaa2aaa333xaa}
331test regexpComp-7.6 {basic regsub operation} {
332    evalInProc {
333        list [regsub aa+ xaxaaaxaa 1&22& foo] $foo
334    }
335} {1 xax1aaa22aaaxaa}
336test regexpComp-7.7 {basic regsub operation} {
337    evalInProc {
338        list [regsub a(a+) xaxaaaxaa {1\122\1} foo] $foo
339    }
340} {1 xax1aa22aaxaa}
341test regexpComp-7.8 {basic regsub operation} {
342    evalInProc {
343        list [regsub a(a+) xaxaaaxaa {1\\\122\1} foo] $foo
344    }
345} "1 {xax1\\aa22aaxaa}"
346test regexpComp-7.9 {basic regsub operation} {
347    evalInProc {
348        list [regsub a(a+) xaxaaaxaa {1\\122\1} foo] $foo
349    }
350} "1 {xax1\\122aaxaa}"
351test regexpComp-7.10 {basic regsub operation} {
352    evalInProc {
353        list [regsub a(a+) xaxaaaxaa {1\\&\1} foo] $foo
354    }
355} "1 {xax1\\aaaaaxaa}"
356test regexpComp-7.11 {basic regsub operation} {
357    evalInProc {
358        list [regsub a(a+) xaxaaaxaa {1\&\1} foo] $foo
359    }
360} {1 xax1&aaxaa}
361test regexpComp-7.12 {basic regsub operation} {
362    evalInProc {
363        list [regsub a(a+) xaxaaaxaa {\1\1\1\1&&} foo] $foo
364    }
365} {1 xaxaaaaaaaaaaaaaaxaa}
366test regexpComp-7.13 {basic regsub operation} {
367    evalInProc {
368        set foo xxx
369        list [regsub abc xyz 111 foo] $foo
370    }
371} {0 xyz}
372test regexpComp-7.14 {basic regsub operation} {
373    evalInProc {
374        set foo xxx
375        list [regsub ^ xyz "111 " foo] $foo
376    }
377} {1 {111 xyz}}
378test regexpComp-7.15 {basic regsub operation} {
379    evalInProc {
380        set foo xxx
381        list [regsub -- -foo abc-foodef "111 " foo] $foo
382    }
383} {1 {abc111 def}}
384test regexpComp-7.16 {basic regsub operation} {
385    evalInProc {
386        set foo xxx
387        list [regsub x "" y foo] $foo
388    }
389} {0 {}}
390test regexpComp-7.17 {regsub utf compliance} {
391    evalInProc {
392        # if not UTF-8 aware, result is "0 1"
393        set foo "xyz555ijka\u4e4ebpqr"
394        regsub a\u4e4eb xyza\u4e4ebijka\u4e4ebpqr 555 bar
395        list [string compare $foo $bar] [regexp 4 $bar]
396    }
397} {0 0}
398
399test regexpComp-8.1 {case conversion in regsub} {
400    evalInProc {
401        list [regsub -nocase a(a+) xaAAaAAay & foo] $foo
402    }
403} {1 xaAAaAAay}
404test regexpComp-8.2 {case conversion in regsub} {
405    evalInProc {
406        list [regsub -nocase a(a+) xaAAaAAay & foo] $foo
407    }
408} {1 xaAAaAAay}
409test regexpComp-8.3 {case conversion in regsub} {
410    evalInProc {
411        set foo 123
412        list [regsub a(a+) xaAAaAAay & foo] $foo
413    }
414} {0 xaAAaAAay}
415test regexpComp-8.4 {case conversion in regsub} {
416    evalInProc {
417        set foo 123
418        list [regsub -nocase a CaDE b foo] $foo
419    }
420} {1 CbDE}
421test regexpComp-8.5 {case conversion in regsub} {
422    evalInProc {
423        set foo 123
424        list [regsub -nocase XYZ CxYzD b foo] $foo
425    }
426} {1 CbD}
427test regexpComp-8.6 {case conversion in regsub} {
428    evalInProc {
429        set x abcdefghijklmnopqrstuvwxyz1234567890
430        set x $x$x$x$x$x$x$x$x$x$x$x$x
431        set foo 123
432        list [regsub -nocase $x $x b foo] $foo
433    }
434} {1 b}
435
436test regexpComp-9.1 {-all option to regsub} {
437    evalInProc {
438        set foo 86
439        list [regsub -all x+ axxxbxxcxdx |&| foo] $foo
440    }
441} {4 a|xxx|b|xx|c|x|d|x|}
442test regexpComp-9.2 {-all option to regsub} {
443    evalInProc {
444        set foo 86
445        list [regsub -nocase -all x+ aXxXbxxcXdx |&| foo] $foo
446    }
447} {4 a|XxX|b|xx|c|X|d|x|}
448test regexpComp-9.3 {-all option to regsub} {
449    evalInProc {
450        set foo 86
451        list [regsub x+ axxxbxxcxdx |&| foo] $foo
452    }
453} {1 a|xxx|bxxcxdx}
454test regexpComp-9.4 {-all option to regsub} {
455    evalInProc {
456        set foo 86
457        list [regsub -all bc axxxbxxcxdx |&| foo] $foo
458    }
459} {0 axxxbxxcxdx}
460test regexpComp-9.5 {-all option to regsub} {
461    evalInProc {
462        set foo xxx
463        list [regsub -all node "node node more" yy foo] $foo
464    }
465} {2 {yy yy more}}
466test regexpComp-9.6 {-all option to regsub} {
467    evalInProc {
468        set foo xxx
469        list [regsub -all ^ xxx 123 foo] $foo
470    }
471} {1 123xxx}
472
473test regexpComp-10.1 {expanded syntax in regsub} {
474    evalInProc {
475        set foo xxx
476        list [regsub -expanded ". \#comment\n  . \#comment2" abc def foo] $foo
477    }
478} {1 defc}
479test regexpComp-10.2 {newline sensitivity in regsub} {
480    evalInProc {
481        set foo xxx
482        list [regsub -line {^a.*b$} "dabc\naxyb\n" 123 foo] $foo
483    }
484} "1 {dabc\n123\n}"
485test regexpComp-10.3 {newline sensitivity in regsub} {
486    evalInProc {
487        set foo xxx
488        list [regsub -line {^a.*b$} "dabc\naxyb\nxb" 123 foo] $foo
489    }
490} "1 {dabc\n123\nxb}"
491test regexpComp-10.4 {partial newline sensitivity in regsub} {
492    evalInProc {
493        set foo xxx
494        list [regsub -lineanchor {^a.*b$} "da\naxyb\nxb" 123 foo] $foo
495    }
496} "1 {da\n123}"
497test regexpComp-10.5 {inverse partial newline sensitivity in regsub} {
498    evalInProc {
499        set foo xxx
500        list [regsub -linestop {a.*b} "da\nbaxyb\nxb" 123 foo] $foo
501    }
502} "1 {da\nb123\nxb}"
503
504test regexpComp-11.1 {regsub errors} {
505    evalInProc {
506        list [catch {regsub a b} msg] $msg
507    }
508} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}}
509test regexpComp-11.2 {regsub errors} {
510    evalInProc {
511        list [catch {regsub -nocase a b} msg] $msg
512    }
513} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}}
514test regexpComp-11.3 {regsub errors} {
515    evalInProc {
516        list [catch {regsub -nocase -all a b} msg] $msg
517    }
518} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}}
519test regexpComp-11.4 {regsub errors} {
520    evalInProc {
521        list [catch {regsub a b c d e f} msg] $msg
522    }
523} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}}
524test regexpComp-11.5 {regsub errors} {
525    evalInProc {
526        list [catch {regsub -gorp a b c} msg] $msg
527    }
528} {1 {bad switch "-gorp": must be -all, -nocase, -expanded, -line, -linestop, -lineanchor, -start, or --}}
529test regexpComp-11.6 {regsub errors} {
530    evalInProc {
531        list [catch {regsub -nocase a( b c d} msg] $msg
532    }
533} {1 {couldn't compile regular expression pattern: parentheses () not balanced}}
534test regexpComp-11.7 {regsub errors} {
535    evalInProc {
536        catch {unset f1}
537        set f1 44
538        list [catch {regsub -nocase aaa aaa xxx f1(f2)} msg] $msg
539    }
540} {1 {couldn't set variable "f1(f2)"}}
541test regexpComp-11.8 {regsub errors, -start bad int check} {
542    evalInProc {
543        list [catch {regsub -start bogus pattern string rep var} msg] $msg
544    }
545} {1 {bad index "bogus": must be integer?[+-]integer? or end?[+-]integer?}}
546
547# This test crashes on the Mac unless you increase the Stack Space to about 1
548# Meg.  This is probably bigger than most users want...
549# 8.2.3 regexp reduced stack space requirements, but this should be
550# tested again
551test regexpComp-12.1 {Tcl_RegExpExec: large number of subexpressions} {macCrash} {
552    evalInProc {
553        list [regexp (.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.) abcdefghijklmnopqrstuvwxyz all a b c d e f g h i j k l m n o p q r s t u v w x y z] $all $a $b $c $d $e $f $g $h $i $j $k $l $m $n $o $p $q $r $s $t $u $v $w $x $y $z
554    }
555} {1 abcdefghijklmnopqrstuvwxyz a b c d e f g h i j k l m n o p q r s t u v w x y z}
556
557test regexpComp-13.1 {regsub of a very large string} {
558    # This test is designed to stress the memory subsystem in order
559    # to catch Bug #933.  It only fails if the Tcl memory allocator
560    # is in use.
561
562    set line {BEGIN_TABLE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; END_TABLE}
563    set filedata [string repeat $line 200]
564    for {set i 1} {$i<10} {incr i} {
565        regsub -all "BEGIN_TABLE " $filedata "" newfiledata
566    }
567    set x done
568} {done}
569
570test regexpComp-14.1 {CompileRegexp: regexp cache} {
571    evalInProc {
572        regexp .*a b
573        regexp .*b c
574        regexp .*c d
575        regexp .*d e
576        regexp .*e f
577        set x .
578        append x *a
579        regexp $x bbba
580    }
581} 1
582test regexpComp-14.2 {CompileRegexp: regexp cache, different flags} {
583    evalInProc {
584        regexp .*a b
585        regexp .*b c
586        regexp .*c d
587        regexp .*d e
588        regexp .*e f
589        set x .
590        append x *a
591        regexp -nocase $x bbba
592    }
593} 1
594
595testConstraint exec [llength [info commands exec]]
596test regexpComp-14.3 {CompileRegexp: regexp cache, empty regexp and empty cache} -constraints {
597        exec
598} -setup {
599    set junk [makeFile {puts [regexp {} foo]} junk.tcl]
600} -body {
601    exec [interpreter] $junk
602} -cleanup {
603    removeFile junk.tcl
604} -result 1
605
606test regexpComp-15.1 {regexp -start} {
607    catch {unset x}
608    list [regexp -start -10 {\d} 1abc2de3 x] $x
609} {1 1}
610test regexpComp-15.2 {regexp -start} {
611    catch {unset x}
612    list [regexp -start 2 {\d} 1abc2de3 x] $x
613} {1 2}
614test regexpComp-15.3 {regexp -start} {
615    catch {unset x}
616    list [regexp -start 4 {\d} 1abc2de3 x] $x
617} {1 2}
618test regexpComp-15.4 {regexp -start} {
619    catch {unset x}
620    list [regexp -start 5 {\d} 1abc2de3 x] $x
621} {1 3}
622test regexpComp-15.5 {regexp -start, over end of string} {
623    catch {unset x}
624    list [regexp -start [string length 1abc2de3] {\d} 1abc2de3 x] [info exists x]
625} {0 0}
626test regexpComp-15.6 {regexp -start, loss of ^$ behavior} {
627    list [regexp -start 2 {^$} {}]
628} {0}
629
630test regexpComp-16.1 {regsub -start} {
631    catch {unset x}
632    list [regsub -all -start 2 {\d} a1b2c3d4e5 {/&} x] $x
633} {4 a1b/2c/3d/4e/5}
634test regexpComp-16.2 {regsub -start} {
635    catch {unset x}
636    list [regsub -all -start -25 {z} hello {/&} x] $x
637} {0 hello}
638test regexpComp-16.3 {regsub -start} {
639    catch {unset x}
640    list [regsub -all -start 3 {z} hello {/&} x] $x
641} {0 hello}
642test regexpComp-16.4 {regsub -start, \A behavior} {
643    set out {}
644    lappend out [regsub -start 0 -all {\A(\w)} {abcde} {/\1} x] $x
645    lappend out [regsub -start 2 -all {\A(\w)} {abcde} {/\1} x] $x
646} {5 /a/b/c/d/e 3 ab/c/d/e}
647
648test regexpComp-17.1 {regexp -inline} {
649    regexp -inline b ababa
650} {b}
651test regexpComp-17.2 {regexp -inline} {
652    regexp -inline (b) ababa
653} {b b}
654test regexpComp-17.3 {regexp -inline -indices} {
655    regexp -inline -indices (b) ababa
656} {{1 1} {1 1}}
657test regexpComp-17.4 {regexp -inline} {
658    regexp -inline {\w(\d+)\w} "   hello 23 there456def "
659} {e456d 456}
660test regexpComp-17.5 {regexp -inline no matches} {
661    regexp -inline {\w(\d+)\w} ""
662} {}
663test regexpComp-17.6 {regexp -inline no matches} {
664    regexp -inline hello goodbye
665} {}
666test regexpComp-17.7 {regexp -inline, no matchvars allowed} {
667    list [catch {regexp -inline b abc match} msg] $msg
668} {1 {regexp match variables not allowed when using -inline}}
669
670test regexpComp-18.1 {regexp -all} {
671    regexp -all b bbbbb
672} {5}
673test regexpComp-18.2 {regexp -all} {
674    regexp -all b abababbabaaaaaaaaaab
675} {6}
676test regexpComp-18.3 {regexp -all -inline} {
677    regexp -all -inline b abababbabaaaaaaaaaab
678} {b b b b b b}
679test regexpComp-18.4 {regexp -all -inline} {
680    regexp -all -inline {\w(\w)} abcdefg
681} {ab b cd d ef f}
682test regexpComp-18.5 {regexp -all -inline} {
683    regexp -all -inline {\w(\w)$} abcdefg
684} {fg g}
685test regexpComp-18.6 {regexp -all -inline} {
686    regexp -all -inline {\d+} 10:20:30:40
687} {10 20 30 40}
688test regexpComp-18.7 {regexp -all -inline} {
689    list [catch {regexp -all -inline b abc match} msg] $msg
690} {1 {regexp match variables not allowed when using -inline}}
691test regexpComp-18.8 {regexp -all} {
692    # This should not cause an infinite loop
693    regexp -all -inline {a*} a
694} {a}
695test regexpComp-18.9 {regexp -all} {
696    # Yes, the expected result is {a {}}.  Here's why:
697    # Start at index 0; a* matches the "a" there then stops.
698    # Go to index 1; a* matches the lambda (or {}) there then stops.  Recall
699    #   that a* matches zero or more "a"'s; thus it matches the string "b", as
700    #   there are zero or more "a"'s there.
701    # Go to index 2; this is past the end of the string, so stop.
702    regexp -all -inline {a*} ab
703} {a {}}
704test regexpComp-18.10 {regexp -all} {
705    # Yes, the expected result is {a {} a}.  Here's why:
706    # Start at index 0; a* matches the "a" there then stops.
707    # Go to index 1; a* matches the lambda (or {}) there then stops.   Recall
708    #   that a* matches zero or more "a"'s; thus it matches the string "b", as
709    #   there are zero or more "a"'s there.
710    # Go to index 2; a* matches the "a" there then stops.
711    # Go to index 3; this is past the end of the string, so stop.
712    regexp -all -inline {a*} aba
713} {a {} a}
714test regexpComp-18.11 {regexp -all} {
715    evalInProc {
716        regexp -all -inline {^a} aaaa
717    }
718} {a}
719test regexpComp-18.12 {regexp -all -inline -indices} {
720    evalInProc {
721        regexp -all -inline -indices a(b(c)d|e(f)g)h abcdhaefgh
722    }
723} {{0 4} {1 3} {2 2} {-1 -1} {5 9} {6 8} {-1 -1} {7 7}}
724
725test regexpComp-19.1 {regsub null replacement} {
726    evalInProc {
727        regsub -all {@} {@hel@lo@} "\0a\0" result
728        list $result [string length $result]
729    }
730} "\0a\0hel\0a\0lo\0a\0 14"
731
732test regexpComp-20.1 {regsub shared object shimmering} {
733    evalInProc {
734        # Bug #461322
735        set a abcdefghijklmnopqurstuvwxyz
736        set b $a
737        set c abcdefghijklmnopqurstuvwxyz0123456789
738        regsub $a $c $b d
739        list $d [string length $d] [string bytelength $d]
740    }
741} [list abcdefghijklmnopqurstuvwxyz0123456789 37 37]
742test regexpComp-20.2 {regsub shared object shimmering with -about} {
743    evalInProc {
744        eval regexp -about abc
745    }
746} {0 {}}
747
748test regexpComp-21.1 {regexp command compiling tests} {
749    evalInProc {
750        regexp foo bar
751    }
752} 0
753test regexpComp-21.2 {regexp command compiling tests} {
754    evalInProc {
755        regexp {^foo$} dogfood
756    }
757} 0
758test regexpComp-21.3 {regexp command compiling tests} {
759    evalInProc {
760        set a foo
761        regexp {^foo$} $a
762    }
763} 1
764test regexpComp-21.4 {regexp command compiling tests} {
765    evalInProc {
766        regexp foo dogfood
767    }
768} 1
769test regexpComp-21.5 {regexp command compiling tests} {
770    evalInProc {
771        regexp -nocase FOO dogfod
772    }
773} 0
774test regexpComp-21.6 {regexp command compiling tests} {
775    evalInProc {
776        regexp -n foo dogfoOd
777    }
778} 1
779test regexpComp-21.7 {regexp command compiling tests} {
780    evalInProc {
781        regexp -no -- FoO dogfood
782    }
783} 1
784test regexpComp-21.8 {regexp command compiling tests} {
785    evalInProc {
786        regexp -- foo dogfod
787    }
788} 0
789test regexpComp-21.9 {regexp command compiling tests} {
790    evalInProc {
791        list [catch {regexp -- -nocase foo dogfod} msg] $msg
792    }
793} {0 0}
794test regexpComp-21.10 {regexp command compiling tests} {
795    evalInProc {
796        list [regsub -all "" foo bar str] $str
797    }
798} {3 barfbarobaro}
799test regexpComp-21.11 {regexp command compiling tests} {
800    evalInProc {
801        list [regsub -all "" "" bar str] $str
802    }
803} {0 {}}
804
805test regexpComp-22.0.1 {Bug 1810038} {
806    evalInProc {
807        regexp ($|^X)* {}
808    }
809} 1
810
811test regexpComp-22.0.2 {regexp compile and backrefs, Bug 1857126} {
812    evalInProc {
813        regexp -- {([bc])\1} bb
814    }
815} 1
816
817set i 0
818foreach {str exp result} {
819    foo         ^foo            1
820    foobar      ^foobar$        1
821    foobar      bar$            1
822    foobar      ^$              0
823    ""          ^$              1
824    anything    $               1
825    anything    ^.*$            1
826    anything    ^.*a$           0
827    anything    ^.*a.*$         1
828    anything    ^.*.*$          1
829    anything    ^.*..*$         1
830    anything    ^.*b$           0
831    anything    ^a.*$           1
832} {
833    test regexpComp-22.[incr i] {regexp command compiling tests} \
834             [subst {evalInProc {set a "$str"; regexp {$exp} \$a}}] $result
835}
836
837set i 0
838foreach {str exp result} {
839    foo         ^foo            1
840    foobar      ^foobar$        1
841    foobar      bar$            1
842    foobar      ^$              0
843    ""          ^$              1
844    anything    $               1
845    anything    ^.*$            1
846    anything    ^.*a$           0
847    anything    ^.*a.*$         1
848    anything    ^.*.*$          1
849    anything    ^.*..*$         1
850    anything    ^.*b$           0
851    anything    ^a.*$           1
852} {
853    test regexpComp-23.[incr i] {regexp command compiling tests INST_REGEXP} \
854        [subst {evalInProc {set a "$str"; set re "$exp"; regexp \$re \$a}}] $result
855}
856
857test regexpComp-24.1 {regexp command compiling tests} {
858    evalInProc {
859        set re foo
860        regexp -nocase $re bar
861    }
862} 0
863test regexpComp-24.2 {regexp command compiling tests} {
864    evalInProc {
865        set re {^foo$}
866        regexp $re dogfood
867    }
868} 0
869test regexpComp-24.3 {regexp command compiling tests} {
870    evalInProc {
871        set a foo
872        set re {^foo$}
873        regexp $re $a
874    }
875} 1
876test regexpComp-24.4 {regexp command compiling tests} {
877    evalInProc {
878        set re foo
879        regexp $re dogfood
880    }
881} 1
882test regexpComp-24.5 {regexp command compiling tests} {
883    evalInProc {
884        set re FOO
885        regexp -nocase $re dogfod
886    }
887} 0
888test regexpComp-24.6 {regexp command compiling tests} {
889    evalInProc {
890        set re foo
891        regexp -n $re dogfoOd
892    }
893} 1
894test regexpComp-24.7 {regexp command compiling tests} {
895    evalInProc {
896        set re FoO
897        regexp -no -- $re dogfood
898    }
899} 1
900test regexpComp-24.8 {regexp command compiling tests} {
901    evalInProc {
902        set re foo
903        regexp -- $re dogfod
904    }
905} 0
906test regexpComp-24.9 {regexp command compiling tests} {
907    evalInProc {
908        set re "("
909        list [catch {regexp -- $re dogfod} msg] $msg
910    }
911} {1 {couldn't compile regular expression pattern: parentheses () not balanced}}
912test regexpComp-24.10 {regexp command compiling tests} {
913    # Bug 1902436 - last * escaped
914    evalInProc {
915        set text {this is *bold* !}
916        set re {\*bold\*}
917        regexp -- $re $text
918    }
919} 1
920test regexpComp-24.11 {regexp command compiling tests} {
921    # Bug 1902436 - last * escaped
922    evalInProc {
923        set text {this is *bold* !}
924        set re {\*bold\*.*!}
925        regexp -- $re $text
926    }
927} 1
928
929# cleanup
930::tcltest::cleanupTests
931return
Note: See TracBrowser for help on using the repository browser.