Debian Codegraph @

tests/switch.test

raw
1 # Commands covered: switch
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) 1993 The Regents of the University of California.
8 # Copyright (c) 1994 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 if {"::tcltest" ni [namespace children]} {
15 package require tcltest 2.5
16 namespace import -force ::tcltest::*
17 }
18
19 test switch-1.1 {simple patterns} {
20 switch a a {subst 1} b {subst 2} c {subst 3} default {subst 4}
21 } 1
22 test switch-1.2 {simple patterns} {
23 switch b a {subst 1} b {subst 2} c {subst 3} default {subst 4}
24 } 2
25 test switch-1.3 {simple patterns} {
26 switch x a {subst 1} b {subst 2} c {subst 3} default {subst 4}
27 } 4
28 test switch-1.4 {simple patterns} {
29 switch x a {subst 1} b {subst 2} c {subst 3}
30 } {}
31 test switch-1.5 {simple pattern matches many times} {
32 switch b a {subst 1} b {subst 2} b {subst 3} b {subst 4}
33 } 2
34 test switch-1.6 {simple patterns} {
35 switch default a {subst 1} default {subst 2} c {subst 3} default {subst 4}
36 } 2
37 test switch-1.7 {simple patterns} {
38 switch x a {subst 1} default {subst 2} c {subst 3} default {subst 4}
39 } 4
40 test switch-1.8 {simple patterns with -nocase} {
41 switch -nocase b a {subst 1} b {subst 2} c {subst 3} default {subst 4}
42 } 2
43 test switch-1.9 {simple patterns with -nocase} {
44 switch -nocase B a {subst 1} b {subst 2} c {subst 3} default {subst 4}
45 } 2
46 test switch-1.10 {simple patterns with -nocase} {
47 switch -nocase b a {subst 1} B {subst 2} c {subst 3} default {subst 4}
48 } 2
49 test switch-1.11 {simple patterns with -nocase} {
50 switch -nocase x a {subst 1} default {subst 2} c {subst 3} default {subst 4}
51 } 4
52
53 test switch-2.1 {single-argument form for pattern/command pairs} {
54 switch b {
55 a {subst 1}
56 b {subst 2}
57 default {subst 6}
58 }
59 } {2}
60 test switch-2.2 {single-argument form for pattern/command pairs} -body {
61 switch z {a 2 b}
62 } -returnCodes error -result {extra switch pattern with no body}
63
64 test switch-3.1 {-exact vs. -glob vs. -regexp} {
65 switch -exact aaaab {
66 ^a*b$ {subst regexp}
67 *b {subst glob}
68 aaaab {subst exact}
69 default {subst none}
70 }
71 } exact
72 test switch-3.2 {-exact vs. -glob vs. -regexp} {
73 switch -regexp aaaab {
74 ^a*b$ {subst regexp}
75 *b {subst glob}
76 aaaab {subst exact}
77 default {subst none}
78 }
79 } regexp
80 test switch-3.3 {-exact vs. -glob vs. -regexp} {
81 switch -glob aaaab {
82 ^a*b$ {subst regexp}
83 *b {subst glob}
84 aaaab {subst exact}
85 default {subst none}
86 }
87 } glob
88 test switch-3.4 {-exact vs. -glob vs. -regexp} {
89 switch aaaab {^a*b$} {subst regexp} *b {subst glob} \
90 aaaab {subst exact} default {subst none}
91 } exact
92 test switch-3.5 {-exact vs. -glob vs. -regexp} {
93 switch -- -glob {
94 ^g.*b$ {subst regexp}
95 -* {subst glob}
96 -glob {subst exact}
97 default {subst none}
98 }
99 } exact
100 test switch-3.6 {-exact vs. -glob vs. -regexp} -body {
101 switch -foo a b c
102 } -returnCodes error -result {bad option "-foo": must be -exact, -glob, -indexvar, -matchvar, -nocase, -regexp, or --}
103 test switch-3.7 {-exact vs. -glob vs. -regexp with -nocase} {
104 switch -exact -nocase aaaab {
105 ^a*b$ {subst regexp}
106 *b {subst glob}
107 aaaab {subst exact}
108 default {subst none}
109 }
110 } exact
111 test switch-3.8 {-exact vs. -glob vs. -regexp with -nocase} {
112 switch -regexp -nocase aaaab {
113 ^a*b$ {subst regexp}
114 *b {subst glob}
115 aaaab {subst exact}
116 default {subst none}
117 }
118 } regexp
119 test switch-3.9 {-exact vs. -glob vs. -regexp with -nocase} {
120 switch -glob -nocase aaaab {
121 ^a*b$ {subst regexp}
122 *b {subst glob}
123 aaaab {subst exact}
124 default {subst none}
125 }
126 } glob
127 test switch-3.10 {-exact vs. -glob vs. -regexp with -nocase} {
128 switch -nocase aaaab {^a*b$} {subst regexp} *b {subst glob} \
129 aaaab {subst exact} default {subst none}
130 } exact
131 test switch-3.11 {-exact vs. -glob vs. -regexp with -nocase} {
132 switch -nocase -- -glob {
133 ^g.*b$ {subst regexp}
134 -* {subst glob}
135 -glob {subst exact}
136 default {subst none}
137 }
138 } exact
139 test switch-3.12 {-exact vs. -glob vs. -regexp} {
140 switch -exa Foo Foo {set result OK}
141 } OK
142 test switch-3.13 {-exact vs. -glob vs. -regexp} {
143 switch -gl Foo Fo? {set result OK}
144 } OK
145 test switch-3.14 {-exact vs. -glob vs. -regexp} {
146 switch -re Foo Fo. {set result OK}
147 } OK
148 test switch-3.15 {-exact vs. -glob vs. -regexp} -body {
149 switch -exact -exact Foo Foo {set result OK}
150 } -returnCodes error -result {bad option "-exact": -exact option already found}
151 test switch-3.16 {-exact vs. -glob vs. -regexp} -body {
152 switch -exact -glob Foo Foo {set result OK}
153 } -returnCodes error -result {bad option "-glob": -exact option already found}
154 test switch-3.17 {-exact vs. -glob vs. -regexp} -body {
155 switch -glob -regexp Foo Foo {set result OK}
156 } -returnCodes error -result {bad option "-regexp": -glob option already found}
157 test switch-3.18 {-exact vs. -glob vs. -regexp} -body {
158 switch -regexp -glob Foo Foo {set result OK}
159 } -returnCodes error -result {bad option "-glob": -regexp option already found}
160
161 test switch-4.1 {error in executed command} {
162 list [catch {switch a a {error "Just a test"} default {subst 1}} msg] \
163 $msg $::errorInfo
164 } {1 {Just a test} {Just a test
165 while executing
166 "error "Just a test""
167 ("a" arm line 1)
168 invoked from within
169 "switch a a {error "Just a test"} default {subst 1}"}}
170 test switch-4.2 {error: not enough args} -returnCodes error -body {
171 switch
172 } -result {wrong # args: should be "switch ?-option ...? string ?pattern body ...? ?default body?"}
173 test switch-4.3 {error: pattern with no body} -body {
174 switch a b
175 } -returnCodes error -result {extra switch pattern with no body}
176 test switch-4.4 {error: pattern with no body} -body {
177 switch a b {subst 1} c
178 } -returnCodes error -result {extra switch pattern with no body}
179 test switch-4.5 {error in default command} {
180 list [catch {switch foo a {error switch1} b {error switch 3} \
181 default {error switch2}} msg] $msg $::errorInfo
182 } {1 switch2 {switch2
183 while executing
184 "error switch2"
185 ("default" arm line 1)
186 invoked from within
187 "switch foo a {error switch1} b {error switch 3} default {error switch2}"}}
188
189 test switch-5.1 {errors in -regexp matching} -returnCodes error -body {
190 switch -regexp aaaab {
191 *b {subst glob}
192 aaaab {subst exact}
193 default {subst none}
194 }
195 } -result {couldn't compile regular expression pattern: quantifier operand invalid}
196
197 test switch-6.1 {backslashes in patterns} {
198 switch -exact {\a\$\.\[} {
199 \a\$\.\[ {subst first}
200 \a\\$\.\\[ {subst second}
201 \\a\\$\\.\\[ {subst third}
202 {\a\\$\.\\[} {subst fourth}
203 {\\a\\$\\.\\[} {subst fifth}
204 default {subst none}
205 }
206 } third
207 test switch-6.2 {backslashes in patterns} {
208 switch -exact {\a\$\.\[} {
209 \a\$\.\[ {subst first}
210 {\a\$\.\[} {subst second}
211 {{\a\$\.\[}} {subst third}
212 default {subst none}
213 }
214 } second
215
216 test switch-7.1 {"-" bodies} {
217 switch a {
218 a -
219 b -
220 c {subst 1}
221 default {subst 2}
222 }
223 } 1
224 test switch-7.2 {"-" bodies} -body {
225 switch a {
226 a -
227 b -
228 c -
229 }
230 } -returnCodes error -result {no body specified for pattern "c"}
231 test switch-7.3 {"-" bodies} -body {
232 switch a {
233 a -
234 b -foo
235 c -
236 }
237 } -returnCodes error -result {no body specified for pattern "c"}
238 test switch-7.4 {"-" bodies} -body {
239 switch a {
240 a -
241 b -foo
242 c {}
243 }
244 } -returnCodes error -result {invalid command name "-foo"}
245
246 test switch-8.1 {empty body} {
247 set msg {}
248 switch {2} {
249 1 {set msg 1}
250 2 {}
251 default {set msg 2}
252 }
253 } {}
254 proc test_switch_body {} {
255 return "INVOKED"
256 }
257 test switch-8.2 {weird body text, variable} {
258 set cmd {test_switch_body}
259 switch Foo {
260 Foo $cmd
261 }
262 } {INVOKED}
263 test switch-8.3 {weird body text, variable} {
264 set cmd {test_switch_body}
265 switch Foo {
266 Foo {$cmd}
267 }
268 } {INVOKED}
269
270 test switch-9.1 {empty pattern/body list} -returnCodes error -body {
271 switch x
272 } -result {wrong # args: should be "switch ?-option ...? string ?pattern body ...? ?default body?"}
273 test switch-9.2 {unpaired pattern} -returnCodes error -body {
274 switch -- x
275 } -result {extra switch pattern with no body}
276 test switch-9.3 {empty pattern/body list} -body {
277 switch x {}
278 } -returnCodes error -result {wrong # args: should be "switch ?-option ...? string {?pattern body ...? ?default body?}"}
279 test switch-9.4 {empty pattern/body list} -body {
280 switch -- x {}
281 } -returnCodes error -result {wrong # args: should be "switch ?-option ...? string {?pattern body ...? ?default body?}"}
282 test switch-9.5 {unpaired pattern} -body {
283 switch x a {} b
284 } -returnCodes error -result {extra switch pattern with no body}
285 test switch-9.6 {unpaired pattern} -body {
286 switch x {a {} b}
287 } -returnCodes error -result {extra switch pattern with no body}
288 test switch-9.7 {unpaired pattern} -body {
289 switch x a {} # comment b
290 } -returnCodes error -result {extra switch pattern with no body}
291 test switch-9.8 {unpaired pattern} -returnCodes error -body {
292 switch x {a {} # comment b}
293 } -result {extra switch pattern with no body, this may be due to a comment incorrectly placed outside of a switch body - see the "switch" documentation}
294 test switch-9.9 {unpaired pattern} -body {
295 switch x a {} x {} # comment b
296 } -returnCodes error -result {extra switch pattern with no body}
297 test switch-9.10 {unpaired pattern} -returnCodes error -body {
298 switch x {a {} x {} # comment b}
299 } -result {extra switch pattern with no body, this may be due to a comment incorrectly placed outside of a switch body - see the "switch" documentation}
300
301 test switch-10.1 {compiled -exact switch} {
302 if 1 {switch -exact -- a {a {subst 1} b {subst 2}}}
303 } 1
304 test switch-10.1a {compiled -exact switch} {
305 if 1 {switch -exact a {a {subst 1} b {subst 2}}}
306 } 1
307 test switch-10.2 {compiled -exact switch} {
308 if 1 {switch -exact -- b {a {subst 1} b {subst 2}}}
309 } 2
310 test switch-10.2a {compiled -exact switch} {
311 if 1 {switch -exact b {a {subst 1} b {subst 2}}}
312 } 2
313 test switch-10.3 {compiled -exact switch} {
314 if 1 {switch -exact -- c {a {subst 1} b {subst 2}}}
315 } {}
316 test switch-10.3a {compiled -exact switch} {
317 if 1 {switch -exact c {a {subst 1} b {subst 2}}}
318 } {}
319 test switch-10.4 {compiled -exact switch} {
320 if 1 {
321 set x 0
322 switch -exact -- c {a {subst 1} b {subst 2}}
323 }
324 } {}
325 test switch-10.5 {compiled -exact switch} {
326 if 1 {switch -exact -- a {a - aa {subst 1} b {subst 2}}}
327 } 1
328 test switch-10.6 {compiled -exact switch} {
329 if 1 {switch -exact -- b {a {
330 set x 1;set x 1;set x 1;set x 1;set x 1;set x 1;set x 1;set x 1
331 set x 1;set x 1;set x 1;set x 1;set x 1;set x 1;set x 1;set x 1
332 set x 1;set x 1;set x 1;set x 1;set x 1;set x 1;set x 1;set x 1
333 set x 1;set x 1;set x 1;set x 1;set x 1;set x 1;set x 1;set x 1
334 set x 1;set x 1;set x 1;set x 1;set x 1;set x 1;set x 1;set x 1
335 set x 1;set x 1;set x 1;set x 1;set x 1;set x 1;set x 1;set x 1
336 set x 1;set x 1;set x 1;set x 1;set x 1;set x 1;set x 1;set x 1
337 set x 1;set x 1;set x 1;set x 1;set x 1;set x 1;set x 1;set x 1
338 } b {subst 2}}}
339 } 2
340
341 # Command variants are:
342 # c* are compiled switches, i* are interpreted
343 # *-glob use glob matching, *-exact use exact matching
344 # *2* include a default clause (different results too.)
345 proc cswtest-glob s {
346 set x 0; set y 0
347 foreach c [split $s {}] {
348 switch -glob $c {
349 a {incr x}
350 b {incr y}
351 }
352 }
353 set x [expr {$x*100}]; set y [expr {$y*100}]
354 foreach c [split $s {}] {
355 switch -glob -- $c a {incr x} b {incr y}
356 }
357 return $x,$y
358 }
359 proc iswtest-glob s {
360 set x 0; set y 0; set switch switch
361 foreach c [split $s {}] {
362 $switch -glob $c {
363 a {incr x}
364 b {incr y}
365 }
366 }
367 set x [expr {$x*100}]; set y [expr {$y*100}]
368 foreach c [split $s {}] {
369 $switch -glob -- $c a {incr x} b {incr y}
370 }
371 return $x,$y
372 }
373 proc cswtest-exact s {
374 set x 0; set y 0
375 foreach c [split $s {}] {
376 switch -exact $c {
377 a {incr x}
378 b {incr y}
379 }
380 }
381 set x [expr {$x*100}]; set y [expr {$y*100}]
382 foreach c [split $s {}] {
383 switch -exact -- $c a {incr x} b {incr y}
384 }
385 return $x,$y
386 }
387 proc iswtest-exact s {
388 set x 0; set y 0; set switch switch
389 foreach c [split $s {}] {
390 $switch -exact $c {
391 a {incr x}
392 b {incr y}
393 }
394 }
395 set x [expr {$x*100}]; set y [expr {$y*100}]
396 foreach c [split $s {}] {
397 $switch -exact -- $c a {incr x} b {incr y}
398 }
399 return $x,$y
400 }
401 proc cswtest2-glob s {
402 set x 0; set y 0; set z 0
403 foreach c [split $s {}] {
404 switch -glob $c {
405 a {incr x}
406 b {incr y}
407 default {incr z}
408 }
409 }
410 set x [expr {$x*100}]; set y [expr {$y*100}]; set z [expr {$z*100}]
411 foreach c [split $s {}] {
412 switch -glob -- $c a {incr x} b {incr y} default {incr z}
413 }
414 return $x,$y,$z
415 }
416 proc iswtest2-glob s {
417 set x 0; set y 0; set z 0; set switch switch
418 foreach c [split $s {}] {
419 $switch -glob $c {
420 a {incr x}
421 b {incr y}
422 default {incr z}
423 }
424 }
425 set x [expr {$x*100}]; set y [expr {$y*100}]; set z [expr {$z*100}]
426 foreach c [split $s {}] {
427 $switch -glob -- $c a {incr x} b {incr y} default {incr z}
428 }
429 return $x,$y,$z
430 }
431 proc cswtest2-exact s {
432 set x 0; set y 0; set z 0
433 foreach c [split $s {}] {
434 switch -exact $c {
435 a {incr x}
436 b {incr y}
437 default {incr z}
438 }
439 }
440 set x [expr {$x*100}]; set y [expr {$y*100}]; set z [expr {$z*100}]
441 foreach c [split $s {}] {
442 switch -exact -- $c a {incr x} b {incr y} default {incr z}
443 }
444 return $x,$y,$z
445 }
446 proc iswtest2-exact s {
447 set x 0; set y 0; set z 0; set switch switch
448 foreach c [split $s {}] {
449 $switch -exact $c {
450 a {incr x}
451 b {incr y}
452 default {incr z}
453 }
454 }
455 set x [expr {$x*100}]; set y [expr {$y*100}]; set z [expr {$z*100}]
456 foreach c [split $s {}] {
457 $switch -exact -- $c a {incr x} b {incr y} default {incr z}
458 }
459 return $x,$y,$z
460 }
461
462 test switch-10.7 {comparison of compiled and interpreted behaviour of switch, exact matching} {
463 cswtest-exact abcb
464 } [iswtest-exact abcb]
465 test switch-10.8 {comparison of compiled and interpreted behaviour of switch, glob matching} {
466 cswtest-glob abcb
467 } [iswtest-glob abcb]
468 test switch-10.9 {comparison of compiled and interpreted behaviour of switch, exact matching with default} {
469 cswtest2-exact abcb
470 } [iswtest2-exact abcb]
471 test switch-10.10 {comparison of compiled and interpreted behaviour of switch, glob matching with default} {
472 cswtest2-glob abcb
473 } [iswtest2-glob abcb]
474 proc cswtest-default-exact {x} {
475 switch -- $x {
476 a* {return b}
477 aa {return c}
478 default {return d}
479 }
480 }
481 test switch-10.11 {default to exact matching when compiled} {
482 cswtest-default-exact a
483 } d
484 test switch-10.12 {default to exact matching when compiled} {
485 cswtest-default-exact aa
486 } c
487 test switch-10.13 {default to exact matching when compiled} {
488 cswtest-default-exact a*
489 } b
490 test switch-10.14 {default to exact matching when compiled} {
491 cswtest-default-exact a**
492 } d
493 rename cswtest-default-exact {}
494 rename cswtest-glob {}
495 rename iswtest-glob {}
496 rename cswtest2-glob {}
497 rename iswtest2-glob {}
498 rename cswtest-exact {}
499 rename iswtest-exact {}
500 rename cswtest2-exact {}
501 rename iswtest2-exact {}
502 # Bug 1891827
503 test switch-10.15 {(not) compiled exact nocase regression} {
504 apply {{} {
505 switch -nocase -- A { a {return yes} default {return no} }
506 }}
507 } yes
508
509 # Added due to TIP#75
510 test switch-11.1 {regexp matching with -matchvar} {
511 switch -regexp -matchvar x -- abc {.(.). {set x}}
512 } {abc b}
513 test switch-11.2 {regexp matching with -matchvar} {
514 set x GOOD
515 switch -regexp -matchvar x -- abc {.(.).. {list $x z}}
516 set x
517 } GOOD
518 test switch-11.3 {regexp matching with -matchvar} {
519 switch -regexp -matchvar x -- "a b c" {.(.). {set x}}
520 } {{a b} { }}
521 test switch-11.4 {regexp matching with -matchvar} {
522 set x BAD
523 switch -regexp -matchvar x -- "a b c" {
524 bc {list $x YES}
525 default {list $x NO}
526 }
527 } {{} NO}
528 test switch-11.5 {-matchvar without -regexp} {
529 set x {}
530 list [catch {switch -glob -matchvar x -- abc . {set x}} msg] $x $msg
531 } {1 {} {-matchvar option requires -regexp option}}
532 test switch-11.6 {-matchvar unwritable} {
533 set x {}
534 list [catch {switch -regexp -matchvar x(x) -- abc . {set x}} msg] $x $msg
535 } {1 {} {can't set "x(x)": variable isn't array}}
536
537 test switch-12.1 {regexp matching with -indexvar} {
538 switch -regexp -indexvar x -- abc {.(.). {set x}}
539 } {{0 2} {1 1}}
540 test switch-12.2 {regexp matching with -indexvar} {
541 set x GOOD
542 switch -regexp -indexvar x -- abc {.(.).. {list $x z}}
543 set x
544 } GOOD
545 test switch-12.3 {regexp matching with -indexvar} {
546 switch -regexp -indexvar x -- "a b c" {.(.). {set x}}
547 } {{0 2} {1 1}}
548 test switch-12.4 {regexp matching with -indexvar} {
549 set x BAD
550 switch -regexp -indexvar x -- "a b c" {
551 bc {list $x YES}
552 default {list $x NO}
553 }
554 } {{} NO}
555 test switch-12.5 {-indexvar without -regexp} {
556 set x {}
557 list [catch {switch -glob -indexvar x -- abc . {set x}} msg] $x $msg
558 } {1 {} {-indexvar option requires -regexp option}}
559 test switch-12.6 {-indexvar unwritable} {
560 set x {}
561 list [catch {switch -regexp -indexvar x(x) -- abc . {set x}} msg] $x $msg
562 } {1 {} {can't set "x(x)": variable isn't array}}
563 test switch-12.7 {[Bug 3106532] -indexvar should be directly usable with [string range]} {
564 set str abcdef
565 switch -regexp -indexvar x -- $str ^... {string range $str {*}[lindex $x 0]}
566 } abc
567 test switch-12.8 {-indexvar and matched empty strings} {
568 switch -regexp -indexvar x -- abcdef ^...(x?) {return $x}
569 } {{0 2} {3 2}}
570 test switch-12.9 {-indexvar and unmatched strings} {
571 switch -regexp -indexvar x -- abcdef ^...(x)? {return $x}
572 } {{0 2} {-1 -1}}
573
574 test switch-13.1 {-indexvar -matchvar combinations} {
575 switch -regexp -indexvar x -matchvar y abc {
576 . {list $x $y}
577 }
578 } {{{0 0}} a}
579 test switch-13.2 {-indexvar -matchvar combinations} {
580 switch -regexp -indexvar x -matchvar y abc {
581 .$ {list $x $y}
582 }
583 } {{{2 2}} c}
584 test switch-13.3 {-indexvar -matchvar combinations} {
585 switch -regexp -indexvar x -matchvar y abc {
586 (.)(.)(.) {list $x $y}
587 }
588 } {{{0 2} {0 0} {1 1} {2 2}} {abc a b c}}
589 test switch-13.4 {-indexvar -matchvar combinations} {
590 set x -
591 set y -
592 switch -regexp -indexvar x -matchvar y abc {
593 (.)(.)(.). -
594 default {list $x $y}
595 }
596 } {{} {}}
597 test switch-13.5 {-indexvar -matchvar combinations} {
598 set x -
599 set y -
600 list [catch {
601 switch -regexp -indexvar x(x) -matchvar y abc {. {list $x $y}}
602 } msg] $x $y $msg
603 } {1 - - {can't set "x(x)": variable isn't array}}
604 test switch-13.6 {-indexvar -matchvar combinations} {
605 set x -
606 set y -
607 list [catch {
608 switch -regexp -indexvar x -matchvar y(y) abc {. {list $x $y}}
609 } msg] $x $y $msg
610 } {1 {{0 0}} - {can't set "y(y)": variable isn't array}}
611
612 test switch-14.1 {-regexp -- compilation [Bug 1854399]} {
613 switch -regexp -- 0 {
614 {[0-9]+} {return yes}
615 default {return no}
616 }
617 foo
618 } yes
619 test switch-14.2 {-regexp -- compilation [Bug 1854399]} {
620 proc foo {} {
621 switch -regexp -- 0 {
622 {[0-9]+} {return yes}
623 default {return no}
624 }
625 }
626 foo
627 } yes
628 test switch-14.3 {-regexp -- compilation [Bug 1854399]} {
629 proc foo {} {
630 switch -regexp -- 0 {
631 {\d+} {return yes}
632 default {return no}
633 }
634 }
635 foo
636 } yes
637 test switch-14.4 {-regexp -- compilation [Bug 1854399]} {
638 proc foo {} {
639 switch -regexp -- 0 {
640 {0} {return yes}
641 default {return no}
642 }
643 }
644 foo
645 } yes
646 test switch-14.5 {switch -regexp compilation} {
647 apply {{} {
648 switch -regexp -- 0 {
649 {0|1|2} {return yes}
650 default {return no}
651 }
652 }}
653 } yes
654 test switch-14.6 {switch -regexp compilation} {
655 apply {{} {
656 switch -regexp -- 0 {
657 {0|11|222} {return yes}
658 default {return no}
659 }
660 }}
661 } yes
662 test switch-14.7 {switch -regexp compilation} {
663 apply {{} {
664 switch -regexp -- 0 {
665 {[012]} {return yes}
666 default {return no}
667 }
668 }}
669 } yes
670 test switch-14.8 {switch -regexp compilation} {
671 apply {{} {
672 switch -regexp -- x {
673 {0|1|2} {return yes}
674 default {return no}
675 }
676 }}
677 } no
678 test switch-14.9 {switch -regexp compilation} {
679 apply {{} {
680 switch -regexp -- x {
681 {0|11|222} {return yes}
682 default {return no}
683 }
684 }}
685 } no
686 test switch-14.10 {switch -regexp compilation} {
687 apply {{} {
688 switch -regexp -- x {
689 {[012]} {return yes}
690 default {return no}
691 }
692 }}
693 } no
694 test switch-14.11 {switch -regexp compilation} {
695 apply {{} {
696 switch -regexp -- x {
697 {0|1|2} {return yes}
698 .+ {return yes2}
699 default {return no}
700 }
701 }}
702 } yes2
703 test switch-14.12 {switch -regexp compilation} {
704 apply {{} {
705 switch -regexp -- x {
706 {0|11|222} {return yes}
707 .+ {return yes2}
708 default {return no}
709 }
710 }}
711 } yes2
712 test switch-14.13 {switch -regexp compilation} {
713 apply {{} {
714 switch -regexp -- x {
715 {[012]} {return yes}
716 .+ {return yes2}
717 default {return no}
718 }
719 }}
720 } yes2
721 test switch-14.14 {switch -regexp compilation} {
722 apply {{} {
723 switch -regexp -- {} {
724 {0|1|2} {return yes}
725 .+ {return yes2}
726 default {return no}
727 }
728 }}
729 } no
730 test switch-14.15 {switch -regexp compilation} {
731 apply {{} {
732 switch -regexp -- {} {
733 {0|11|222} {return yes}
734 .+ {return yes2}
735 default {return no}
736 }
737 }}
738 } no
739 test switch-14.16 {switch -regexp compilation} {
740 apply {{} {
741 switch -regexp -- {} {
742 {[012]} {return yes}
743 .+ {return yes2}
744 default {return no}
745 }
746 }}
747 } no
748 test switch-14.17 {switch -regexp bug [c0bc269178]} {
749 set result {}
750 switch -regexp -matchvar m -indexvar i ac {
751 {(a)(b)?(c)} {set result $m}
752 }
753 set result
754 } {ac a {} c}
755
756 test switch-15.1 {coroutine safety of non-bytecoded switch} {*}{
757 -body {
758 proc coro {} {
759 switch -glob a {
760 a {yield ok1}
761 }
762 return ok2
763 }
764 list [coroutine c coro] [c]
765 }
766 -result {ok1 ok2}
767 -cleanup {
768 rename coro {}
769 }
770 }
771
772 # cleanup
773 catch {rename foo {}}
774 ::tcltest::cleanupTests
775 return
776
777 # Local Variables:
778 # mode: tcl
779 # End: