Skip to content

Commit 7cb9f9d

Browse files
committed
Tests for [switch -integer]
1 parent 7f32da5 commit 7cb9f9d

File tree

1 file changed

+98
-1
lines changed

1 file changed

+98
-1
lines changed

tests/switch.test

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ test switch-3.5 {-exact vs. -glob vs. -regexp} {
9999
} exact
100100
test switch-3.6 {-exact vs. -glob vs. -regexp} -body {
101101
switch -foo a b c
102-
} -returnCodes error -result {bad option "-foo": must be -exact, -glob, -indexvar, -matchvar, -nocase, -regexp, or --}
102+
} -returnCodes error -result {bad option "-foo": must be -exact, -glob, -indexvar, -integer, -matchvar, -nocase, -regexp, or --}
103103
test switch-3.7 {-exact vs. -glob vs. -regexp with -nocase} {
104104
switch -exact -nocase aaaab {
105105
^a*b$ {subst regexp}
@@ -157,6 +157,15 @@ test switch-3.17 {-exact vs. -glob vs. -regexp} -body {
157157
test switch-3.18 {-exact vs. -glob vs. -regexp} -body {
158158
switch -regexp -glob Foo Foo {set result OK}
159159
} -returnCodes error -result {bad option "-glob": -regexp option already found}
160+
test switch-3.19 {-exact vs. -glob vs. -regexp} -body {
161+
switch -glob -integer Foo Foo {set result OK}
162+
} -returnCodes error -result {bad option "-integer": -glob option already found}
163+
test switch-3.20 {-exact vs. -glob vs. -regexp} -body {
164+
switch -integer -glob Foo Foo {set result OK}
165+
} -returnCodes error -result {bad option "-glob": -integer option already found}
166+
test switch-3.21 {-exact vs. -glob vs. -regexp} -body {
167+
switch -integer -nocase Foo Foo {set result OK}
168+
} -returnCodes error -result {-nocase option cannot be used with -integer option}
160169

161170
test switch-4.1 {error in executed command} {
162171
list [catch {switch a a {error "Just a test"} default {subst 1}} msg] \
@@ -768,6 +777,94 @@ test switch-15.1 {coroutine safety of non-bytecoded switch} {*}{
768777
rename coro {}
769778
}
770779
}
780+
781+
test switch-16.1 {switch -integer: interp, polyarg} {
782+
switch -integer 0x1 01 {string cat ok}
783+
} ok
784+
test switch-16.2 {switch -integer: interp, polyarg} {
785+
switch -integer 0x1 0 {error early} 01 {string cat ok}
786+
} ok
787+
test switch-16.3 {switch -integer: interp, polyarg} {
788+
switch -integer 0x1 0 {error early} 01 {string cat ok} default {error late}
789+
} ok
790+
test switch-16.4 {switch -integer: interp, polyarg} {
791+
switch -integer 0x1 0 {error early} default {string cat ok}
792+
} ok
793+
test switch-16.5 {switch -integer: interp, polyarg} {
794+
switch -integer 0x1 0 {error body}
795+
} {}
796+
test switch-16.6 {switch -integer: interp, polyarg} -returnCodes error -body {
797+
switch -integer 0x1 gorp {error body}
798+
} -result {expected integer but got "gorp"}
799+
test switch-16.7 {switch -integer: interp, polyarg} -returnCodes error -body {
800+
switch -integer gorp 0 {error body}
801+
} -result {expected integer but got "gorp"}
802+
803+
test switch-17.1 {switch -integer: interp, splitlist} {
804+
switch -integer 0x1 {01 {string cat ok}}
805+
} ok
806+
test switch-17.2 {switch -integer: interp, splitlist} {
807+
switch -integer 0x1 {0 {error early} 01 {string cat ok}}
808+
} ok
809+
test switch-17.3 {switch -integer: interp, splitlist} {
810+
switch -integer 0x1 {0 {error early} 01 {string cat ok} default {error late}}
811+
} ok
812+
test switch-17.4 {switch -integer: interp, splitlist} {
813+
switch -integer 0x1 {0 {error early} default {string cat ok}}
814+
} ok
815+
test switch-17.5 {switch -integer: interp, splitlist} {
816+
switch -integer 0x1 {0 {error body}}
817+
} {}
818+
test switch-17.6 {switch -integer: interp, splitlist} -returnCodes error -body {
819+
switch -integer 0x1 {gorp {error body}}
820+
} -result {expected integer but got "gorp"}
821+
test switch-17.7 {switch -integer: interp, splitlist} -returnCodes error -body {
822+
switch -integer gorp {0 {error body}}
823+
} -result {expected integer but got "gorp"}
824+
825+
test switch-18.1 {switch -integer: compiled, polyarg} {
826+
switch -integer -- 0x1 01 {string cat ok}
827+
} ok
828+
test switch-18.2 {switch -integer: compiled, polyarg} {
829+
switch -integer -- 0x1 0 {error early} 01 {string cat ok}
830+
} ok
831+
test switch-18.3 {switch -integer: compiled, polyarg} {
832+
switch -integer -- 0x1 0 {error early} 01 {string cat ok} default {error late}
833+
} ok
834+
test switch-18.4 {switch -integer: compiled, polyarg} {
835+
switch -integer -- 0x1 0 {error early} default {string cat ok}
836+
} ok
837+
test switch-18.5 {switch -integer: compiled, polyarg} {
838+
switch -integer -- 0x1 0 {error body}
839+
} {}
840+
test switch-18.6 {switch -integer: compiled, polyarg} -returnCodes error -body {
841+
switch -integer -- 0x1 gorp {error body}
842+
} -result {expected integer but got "gorp"}
843+
test switch-18.7 {switch -integer: compiled, polyarg} -returnCodes error -body {
844+
switch -integer -- gorp 0 {error body}
845+
} -result {expected integer but got "gorp"}
846+
847+
test switch-19.1 {switch -integer: compiled, splitlist} {
848+
switch -integer -- 0x1 {01 {string cat ok}}
849+
} ok
850+
test switch-19.2 {switch -integer: compiled, splitlist} {
851+
switch -integer -- 0x1 {0 {error early} 01 {string cat ok}}
852+
} ok
853+
test switch-19.3 {switch -integer: compiled, splitlist} {
854+
switch -integer -- 0x1 {0 {error early} 01 {string cat ok} default {error late}}
855+
} ok
856+
test switch-19.4 {switch -integer: compiled, splitlist} {
857+
switch -integer -- 0x1 {0 {error early} default {string cat ok}}
858+
} ok
859+
test switch-19.5 {switch -integer: compiled, splitlist} {
860+
switch -integer -- 0x1 {0 {error body}}
861+
} {}
862+
test switch-19.6 {switch -integer: compiled, splitlist} -returnCodes error -body {
863+
switch -integer -- 0x1 {gorp {error body}}
864+
} -result {expected integer but got "gorp"}
865+
test switch-19.7 {switch -integer: compiled, splitlist} -returnCodes error -body {
866+
switch -integer -- gorp {0 {error body}}
867+
} -result {expected integer but got "gorp"}
771868

772869
# cleanup
773870
catch {rename foo {}}

0 commit comments

Comments
 (0)