aboutsummaryrefslogtreecommitdiff
path: root/tests/case.test
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2010-01-24 10:53:36 +1000
committerSteve Bennett <steveb@workware.net.au>2010-10-15 11:02:39 +1000
commit6ef810ae664dccd457fe1ed750f7d509b6f60878 (patch)
tree13f3ab69416d1fc7f5d10db06c1bf83aa0153e4f /tests/case.test
parenta0017cc44c22a83df8f92600317ad8ccd635e2a1 (diff)
downloadjimtcl-6ef810ae664dccd457fe1ed750f7d509b6f60878.zip
jimtcl-6ef810ae664dccd457fe1ed750f7d509b6f60878.tar.gz
jimtcl-6ef810ae664dccd457fe1ed750f7d509b6f60878.tar.bz2
Bugs, features and tests
source fails with zero length file unknown can't be called recursively *: This can be useful when using unknown to dynamically load code, which may in turn want to dynamically load code *: Limit it to 50 recursions though Allow string greater/less comparison *: Comparing two strings for order did not work Implement file join *: It's not to hard and is handy when working with the current dir, "" Don't omit [unknown] completely from stack trace *: Since we lose valuable informtion, just omit the name Fix return from case Turn regexp patterns into real objects *: Thus caching the compiled regexps Allow error to rethrow an error Replace bcopy() with more standard memcpy() Fixes to parray, improve errorInfo *: errorInfo takes an optional stack trace Add tests for rethrowing errors via errorInfo Fix ndelay *: Was looking at wrong param *: Also fix usage/help for aio.socket Package should be able to call exit *: Currently any return from a package is changed to JIM_ERR Line counting is incorrect for backlash newline
Diffstat (limited to 'tests/case.test')
-rw-r--r--tests/case.test80
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/case.test b/tests/case.test
new file mode 100644
index 0000000..1973477
--- /dev/null
+++ b/tests/case.test
@@ -0,0 +1,80 @@
+source testing.tcl
+
+# Test that control structures can be implemented in a proc
+
+proc control {cond code} {
+ set iscond [uplevel 1 expr $cond]
+ #puts "$cond -> $iscond"
+ if {$iscond} {
+ set rc [catch [list uplevel 1 $code] error]
+ #puts "$code -> rc=$rc, error=$error"
+ return -code $rc $error
+ }
+}
+
+test control-1.1 "False case" {
+ control 0 bogus
+} {}
+
+test control-1.2 "Simple case" {
+ control 1 {return result}
+} {result}
+
+test control-1.3 "Break from proc" {
+ set result {}
+ foreach i {1 2 3 4 5} {
+ control {$i == 4} {break}
+ lappend result $i
+ }
+ set result
+} {1 2 3}
+
+test control-1.4 "Return from proc" {
+ foreach i {1 2 3 4 5} {
+ control {$i == 3} {return $i}
+ }
+} {3}
+
+test control-1.5 "Continue from proc" {
+ set result {}
+ foreach i {1 2 3 4 5} {
+ control {$i == 2} {continue}
+ lappend result $i
+ }
+ set result
+} {1 3 4 5}
+
+# case is a proc, but it should be able
+# to cause a return in do_case
+proc do_case {var} {
+ case $var in {
+ 1 {
+ return one
+ }
+ 2 {
+ return two
+ }
+ 3 {
+ return 33
+ }
+ 4 {
+ continue
+ }
+ 5 {
+ break
+ }
+ 6 {
+ return six
+ }
+ }
+ return zero
+}
+
+test control-2.1 "Return from case" {
+ set result {}
+ foreach i {0 1 2 3 4 5 6} {
+ lappend result [do_case $i]
+ }
+ set result
+} {zero one two 33}
+