diff options
author | dgp <dgp@users.sourceforge.net> | 2005-05-25 16:13:16 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2005-05-25 16:13:16 (GMT) |
commit | 17da6ea9da2761c0e93da57cbbd779ec138e7a39 (patch) | |
tree | 5f85fe1c5270262b37c3b75c16728b3c5cc54428 /tests | |
parent | f4ce59d358e3993aa45141bf6f1c37c1166ae2ec (diff) | |
download | tcl-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')
-rw-r--r-- | tests/expr.test | 67 | ||||
-rw-r--r-- | tests/info.test | 6 |
2 files changed, 68 insertions, 5 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 diff --git a/tests/info.test b/tests/info.test index b3e777e..3441a3b 100644 --- a/tests/info.test +++ b/tests/info.test @@ -11,7 +11,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: info.test,v 1.29 2004/11/24 19:28:42 dgp Exp $ +# RCS: @(#) $Id: info.test,v 1.30 2005/05/25 16:13:17 dgp Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest @@ -613,9 +613,9 @@ test info-19.6 {info vars: Bug 1072654} -setup { # Check whether the extra testing functions are defined... if {([catch {expr T1()} msg] == 1) && ($msg == {unknown math function "T1"})} { - set functions {abs acos asin atan atan2 ceil cos cosh double exp floor fmod hypot int log log10 pow rand round sin sinh sqrt srand tan tanh wide} + set functions {abs acos asin atan atan2 bool ceil cos cosh double exp floor fmod hypot int log log10 pow rand round sin sinh sqrt srand tan tanh wide} } else { - set functions {T1 T2 T3 abs acos asin atan atan2 ceil cos cosh double exp floor fmod hypot int log log10 pow rand round sin sinh sqrt srand tan tanh wide} + set functions {T1 T2 T3 abs acos asin atan atan2 bool ceil cos cosh double exp floor fmod hypot int log log10 pow rand round sin sinh sqrt srand tan tanh wide} } test info-20.1 {info functions option} {info functions sin} sin test info-20.2 {info functions option} {lsort [info functions]} $functions |