tagged release 0.6.4
[parrot.git] / languages / tcl / t / cmd_regexp.t
blobbb486e2431567e2fc9009e222fa3ea30636f5540
1 #!perl
3 # Copyright (C) 2005-2007, The Perl Foundation.
4 # $Id$
6 # the following lines re-execute this as a tcl script
7 # the \ at the end of these lines makes them a comment in tcl \
8 use lib qw(languages/tcl/lib tcl/lib lib ../lib ../../lib); # \
9 use Tcl::Test; #\
10 __DATA__
12 source lib/test_more.tcl
13 plan 14
15 proc regexp_is {pattern string reason} {
16     eval_is "regexp {$pattern} {$string}" 1 $reason
19 proc regexp_isnt {pattern string reason} {
20     eval_is "regexp {$pattern} {$string}" 0 $reason
23 set usage {wrong # args: should be "regexp ?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?"}
24 eval_is {regexp} $usage {no args}
25 eval_is {regexp a} $usage {one args}
27 eval_is {regexp -bork a b} \
28   {bad switch "-bork": must be -all, -about, -indices, -inline, -expanded, -line, -linestop, -lineanchor, -nocase, -start, or --} \
29   {bad switch}
31 catch {unset t1}
32 regexp a+b baaabd t1
33 is $t1 aaab matchVar
35 catch {unset t1 t2}
36 regexp a+b baaabd t1 t2
37 is [list $t1 $t2] {aaab {}} {submatch var but no actual sub match}
39 catch {unset t1}
40 regexp a(.*)a abbba t1
41 is $t1 {abbba} {submatch with no sub var}
43 catch {unset t1 t2}
44 regexp a(.*)a abbba t1 t2
45 is [list $t1 $t2] {abbba bbb} {submatch with var}
47 catch {unset t1 t2}
48 regexp -indices aa(b+)aa aabbbbbbbbaa t1 t2
49 is [list $t1 $t2] {{0 11} {2 9}} -indices
51 # http://www.tcl.tk/man/tcl8.5/TclCmd/re_syntax.htm
53 regexp_is   asdf asdf "literal, t"
54 regexp_isnt asdf fdsa "literal, f"
56 regexp_is a* bbb   "*, true"
57 regexp_is a* bab   "*, true"
58 regexp_is a* baab  "*, true"
59 regexp_is a* baaab "*, true"
61 # +
63 # ?
65 # {m}
67 # {m,}
69 # {m,n}
71 # *?
73 # +?
75 # {m}?
77 # {m,}?
79 # {m,n}?
81 # m,n - restricted to 0, 255
83 #(re)
85 #(?:re)
87 #()
89 #(?:)
91 #[]
93 #[^]
95 #[a-z]
97 #[a-c-e] (boom)
99 #[:joe:]
101 #[[:<:]]
103 #[[:>:]]
119 #(?=re)
121 #(?!re)
123 # Re may NOT end with \
125 # \a
127 # \b
129 # \B
131 # \cX
133 # \e
135 # \f
137 # \n
139 # \r
141 # \t
143 # \uwxyz
145 # \Ustuvwxyz
147 # \v
149 # \xhhh
151 # \0
153 # \xy
155 # \xyz
157 # \d
159 # \s
161 # \w
163 # \D
165 # \S
167 # \W
169 # Interaction of [] and \d: e.g. [a-c\d] vs. [a-c\D]
171 # \A
173 # \m
175 # \M
177 # \y
179 # \Y
181 # \Z
183 # \m
185 # \mnn
187 # ***  (ARE)
189 # ***= (literal)
191 # (?b)
193 # (?c)
195 # (?e)
197 # (?i)
199 # (?m)
201 # (?n)
203 # (?p)
205 # (?q)
207 # (?s)
209 # (?t)
211 # (?w)
213 # (?x)
215 # Match earliest.
217 # Match longest
219 # BRE: |
221 # BRE: +
223 # BRE: ?
225 # BRE: \{
227 # BRE: \}
229 # BRE: \(
231 # BRE: \)
233 # BRE: ^
235 # BRE: $
237 # BRE: *
239 # BRE: \<
241 # BRE: \>
243 # -expanded
245 # -indices
247 # -line
249 # -linestop
251 # -lineanchor
253 # -nocase
255 # -all
257 # -inline
259 # -start
261 # --
263 # Local Variables:
264 #   mode: cperl
265 #   cperl-indent-level: 4
266 #   fill-column: 100
267 # End:
268 # vim: expandtab shiftwidth=4: