summaryrefslogtreecommitdiffstats
path: root/tests/expr.test
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2005-05-25 16:13:16 (GMT)
committerdgp <dgp@users.sourceforge.net>2005-05-25 16:13:16 (GMT)
commit17da6ea9da2761c0e93da57cbbd779ec138e7a39 (patch)
tree5f85fe1c5270262b37c3b75c16728b3c5cc54428 /tests/expr.test
parentf4ce59d358e3993aa45141bf6f1c37c1166ae2ec (diff)
downloadtcl-17da6ea9da2761c0e93da57cbbd779ec138e7a39.zip
tcl-17da6ea9da2761c0e93da57cbbd779ec138e7a39.tar.gz
tcl-17da6ea9da2761c0e93da57cbbd779ec138e7a39.tar.bz2
TIP#182 IMPLEMENTATION [Patch 1165062]
* doc/mathfunc.n: New built-in math function bool(). * generic/tclBasic.c: * tests/expr.test: * tests/info.test:
Diffstat (limited to 'tests/expr.test')
-rw-r--r--tests/expr.test67
1 files changed, 65 insertions, 2 deletions
diff --git a/tests/expr.test b/tests/expr.test
index 5992421..067ad20 100644
--- a/tests/expr.test
+++ b/tests/expr.test
@@ -10,10 +10,10 @@
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
-# RCS: @(#) $Id: expr.test,v 1.32 2005/05/10 18:35:19 kennykb Exp $
+# RCS: @(#) $Id: expr.test,v 1.33 2005/05/25 16:13:17 dgp Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
- package require tcltest
+ package require tcltest 2.1
namespace import -force ::tcltest::*
}
@@ -5181,6 +5181,69 @@ test expr-30.4 {silent overflow on input conversion} {ieeeFloatingPoint} {
list [scan -1.7976931348623159e+308 %f v] $v
} {1 -Inf}
+# bool() tests (TIP #182)
+set i 0
+foreach s {yes true on} {
+ test expr-31.$i.0 {boolean conversion} {expr bool($s)} 1
+ test expr-31.$i.1 {boolean conversion} {expr bool(!$s)} 0
+ test expr-31.$i.2 {boolean conversion} {expr bool("$s")} 1
+ test expr-31.$i.3 {boolean conversion} {expr bool(!"$s")} 0
+ set j 1
+ while {$j < [string length $s]-1} {
+ test expr-31.$i.4.$j {boolean conversion} {
+ expr bool([string range $s 0 $j])
+ } 1
+ test expr-31.$i.5.$j {boolean conversion} {
+ expr bool("[string range $s 0 $j]")
+ } 1
+ incr j
+ }
+ incr i
+}
+test expr-31.0.4.0 {boolean conversion} {expr bool(y)} 1
+test expr-31.0.5.0 {boolean conversion} {expr bool("y")} 1
+test expr-31.1.4.0 {boolean conversion} {expr bool(t)} 1
+test expr-31.1.5.0 {boolean conversion} {expr bool("t")} 1
+test expr-31.2.4.0 {boolean conversion} -body {
+ expr bool(o)
+} -returnCodes error -match glob -result *
+test expr-31.2.5.0 {boolean conversion} -body {
+ expr bool("o")
+} -returnCodes error -match glob -result *
+foreach s {no false off} {
+ test expr-31.$i.0 {boolean conversion} {expr bool($s)} 0
+ test expr-31.$i.1 {boolean conversion} {expr bool(!$s)} 1
+ test expr-31.$i.2 {boolean conversion} {expr bool("$s")} 0
+ test expr-31.$i.3 {boolean conversion} {expr bool(!"$s")} 1
+ set j 1
+ while {$j < [string length $s]-1} {
+ test expr-31.$i.4.$j {boolean conversion} {
+ expr bool([string range $s 0 $j])
+ } 0
+ test expr-31.$i.5.$j {boolean conversion} {
+ expr bool("[string range $s 0 $j]")
+ } 0
+ incr j
+ }
+ incr i
+}
+test expr-31.3.4.0 {boolean conversion} {expr bool(n)} 0
+test expr-31.3.5.0 {boolean conversion} {expr bool("n")} 0
+test expr-31.4.4.0 {boolean conversion} {expr bool(f)} 0
+test expr-31.4.5.0 {boolean conversion} {expr bool("f")} 0
+test expr-31.6 {boolean conversion} {expr bool(-1 + 1)} 0
+test expr-31.7 {boolean conversion} {expr bool(0 + 1)} 1
+test expr-31.8 {boolean conversion} {expr bool(0.0)} 0
+test expr-31.9 {boolean conversion} {expr bool(0x0)} 0
+test expr-31.10 {boolean conversion} {expr bool(wide(0))} 0
+test expr-31.11 {boolean conversion} {expr bool(5.0)} 1
+test expr-31.12 {boolean conversion} {expr bool(5)} 1
+test expr-31.13 {boolean conversion} {expr bool(0x5)} 1
+test expr-31.14 {boolean conversion} {expr bool(wide(5))} 1
+test expr-31.15 {boolean conversion} -body {
+ expr bool("fred")
+} -returnCodes error -match glob -result *
+
# cleanup
if {[info exists a]} {
unset a