From ea1b12824f360ca2f3b4838e1d88605b9b1c1a6d Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Sat, 19 Dec 2020 09:31:40 +1000 Subject: core: support integer expressions in various commands For convenience, many commands now accept integer expressions rather than only simple integers. These are: loop, range, incr, string repeat, lrepeat, pack, unpack, rand This simplifies many cases where previously expr {} or $() was required. e.g. foreach i [range 4+1 2*$b] { ... } string repeat 2**$n a Signed-off-by: Steve Bennett --- tests/binary.test | 26 +++++++++++++------------- tests/coverage.test | 4 ++-- tests/dict2.test | 4 ++-- tests/jim.test | 32 +++++++++++++++----------------- tests/pack.test | 8 ++++---- 5 files changed, 36 insertions(+), 38 deletions(-) (limited to 'tests') diff --git a/tests/binary.test b/tests/binary.test index 8eb93f9..5c6ca72 100644 --- a/tests/binary.test +++ b/tests/binary.test @@ -251,7 +251,7 @@ test binary-8.9 {Tcl_BinaryObjCmd: format} -returnCodes error -body { test binary-8.10 {Tcl_BinaryObjCmd: format} -returnCodes error -body { set a {0x50 0x51} binary format c $a -} -result "expected integer but got \"0x50 0x51\"" +} -match glob -result "expected integer *but got \"0x50 0x51\"" test binary-8.11 {Tcl_BinaryObjCmd: format} { set a {0x50 0x51} binary format c1 $a @@ -262,7 +262,7 @@ test binary-9.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body { } -result {not enough arguments for all format specifiers} test binary-9.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body { binary format s blat -} -result {expected integer but got "blat"} +} -match glob -result {expected integer *but got "blat"} test binary-9.3 {Tcl_BinaryObjCmd: format} { binary format s0 0x50 } {} @@ -290,7 +290,7 @@ test binary-9.10 {Tcl_BinaryObjCmd: format} -returnCodes error -body { test binary-9.11 {Tcl_BinaryObjCmd: format} -returnCodes error -body { set a {0x50 0x51} binary format s $a -} -result "expected integer but got \"0x50 0x51\"" +} -match glob -result "expected integer *but got \"0x50 0x51\"" test binary-9.12 {Tcl_BinaryObjCmd: format} { set a {0x50 0x51} binary format s1 $a @@ -301,7 +301,7 @@ test binary-10.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body { } -result {not enough arguments for all format specifiers} test binary-10.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body { binary format S blat -} -result {expected integer but got "blat"} +} -match glob -result {expected integer *but got "blat"} test binary-10.3 {Tcl_BinaryObjCmd: format} { binary format S0 0x50 } {} @@ -329,7 +329,7 @@ test binary-10.10 {Tcl_BinaryObjCmd: format} -returnCodes error -body { test binary-10.11 {Tcl_BinaryObjCmd: format} -returnCodes error -body { set a {0x50 0x51} binary format S $a -} -result "expected integer but got \"0x50 0x51\"" +} -match glob -result "expected integer *but got \"0x50 0x51\"" test binary-10.12 {Tcl_BinaryObjCmd: format} { set a {0x50 0x51} binary format S1 $a @@ -340,7 +340,7 @@ test binary-11.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body { } -result {not enough arguments for all format specifiers} test binary-11.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body { binary format i blat -} -result {expected integer but got "blat"} +} -match glob -result {expected integer *but got "blat"} test binary-11.3 {Tcl_BinaryObjCmd: format} { binary format i0 0x50 } {} @@ -371,7 +371,7 @@ test binary-11.11 {Tcl_BinaryObjCmd: format} -returnCodes error -body { test binary-11.12 {Tcl_BinaryObjCmd: format} -returnCodes error -body { set a {0x50 0x51} binary format i $a -} -result "expected integer but got \"0x50 0x51\"" +} -match glob -result "expected integer *but got \"0x50 0x51\"" test binary-11.13 {Tcl_BinaryObjCmd: format} { set a {0x50 0x51} binary format i1 $a @@ -382,7 +382,7 @@ test binary-12.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body { } -result {not enough arguments for all format specifiers} test binary-12.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body { binary format I blat -} -result {expected integer but got "blat"} +} -match glob -result {expected integer *but got "blat"} test binary-12.3 {Tcl_BinaryObjCmd: format} { binary format I0 0x50 } {} @@ -413,7 +413,7 @@ test binary-12.11 {Tcl_BinaryObjCmd: format} -returnCodes error -body { test binary-12.12 {Tcl_BinaryObjCmd: format} -returnCodes error -body { set a {0x50 0x51} binary format I $a -} -result "expected integer but got \"0x50 0x51\"" +} -match glob -result "expected integer *but got \"0x50 0x51\"" test binary-12.13 {Tcl_BinaryObjCmd: format} { set a {0x50 0x51} binary format I1 $a @@ -1664,7 +1664,7 @@ test binary-48.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body { } -result {not enough arguments for all format specifiers} test binary-48.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body { binary format t blat -} -result {expected integer but got "blat"} +} -match glob -result {expected integer *but got "blat"} test binary-48.3 {Tcl_BinaryObjCmd: format} { binary format S0 0x50 } {} @@ -1710,7 +1710,7 @@ test binary-48.16 {Tcl_BinaryObjCmd: format} -returnCodes error -body { test binary-48.17 {Tcl_BinaryObjCmd: format} -returnCodes error -body { set a {0x50 0x51} binary format t $a -} -result "expected integer but got \"0x50 0x51\"" +} -match glob -result "expected integer *but got \"0x50 0x51\"" test binary-48.18 {Tcl_BinaryObjCmd: format} bigEndian { set a {0x50 0x51} binary format t1 $a @@ -1726,7 +1726,7 @@ test binary-49.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body { } -result {not enough arguments for all format specifiers} test binary-49.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body { binary format n blat -} -result {expected integer but got "blat"} +} -match glob -result {expected integer *but got "blat"} test binary-49.3 {Tcl_BinaryObjCmd: format} { binary format n0 0x50 } {} @@ -1757,7 +1757,7 @@ test binary-49.11 {Tcl_BinaryObjCmd: format} -returnCodes error -body { test binary-49.12 {Tcl_BinaryObjCmd: format} -returnCodes error -body { set a {0x50 0x51} binary format n $a -} -result "expected integer but got \"0x50 0x51\"" +} -match glob -result "expected integer *but got \"0x50 0x51\"" test binary-49.13 {Tcl_BinaryObjCmd: format} littleEndian { set a {0x50 0x51} binary format n1 $a diff --git a/tests/coverage.test b/tests/coverage.test index faa1f02..a405c43 100644 --- a/tests/coverage.test +++ b/tests/coverage.test @@ -182,11 +182,11 @@ test rand-1 {rand} -constraints rand -body { test rand-2 {rand} -constraints rand -body { rand foo -} -returnCodes error -result {expected integer but got "foo"} +} -returnCodes error -match glob -result {expected integer *but got "foo"} test rand-3 {rand} -constraints rand -body { rand 2 bar -} -returnCodes error -result {expected integer but got "bar"} +} -returnCodes error -match glob -result {expected integer *but got "bar"} test rand-4 {rand} rand { string is integer [rand] diff --git a/tests/dict2.test b/tests/dict2.test index 493cf91..2a36dc1 100644 --- a/tests/dict2.test +++ b/tests/dict2.test @@ -316,14 +316,14 @@ test dict-11.9 {dict incr command} -returnCodes error -body { dict-sort $dictv } -cleanup { unset dictv -} -result {expected integer but got "dummy"} +} -match glob -result {expected integer *but got "dummy"} test dict-11.10 {dict incr command} -returnCodes error -body { set dictv {a 1} dict incr dictv a dummy dict-sort $dictv } -cleanup { unset dictv -} -result {expected integer but got "dummy"} +} -match glob -result {expected integer *but got "dummy"} test dict-11.11 {dict incr command} -setup { unset -nocomplain dictv } -body { diff --git a/tests/jim.test b/tests/jim.test index ba76879..79cbd8d 100644 --- a/tests/jim.test +++ b/tests/jim.test @@ -1269,11 +1269,10 @@ test incr-1.23 {TclCompileIncrCmd: increment given, formatted int != int} { set i 25 incr i 000012345 ;# a decimal literal } 12370 -test incr-1.24 {TclCompileIncrCmd: increment given, formatted int != int} { +test incr-1.24 {TclCompileIncrCmd: increment given, formatted int != int} -body { set i 25 - catch {incr i 1a} msg - set msg -} {expected integer but got "1a"} + incr i 1a +} -returnCodes error -match glob -result {expected integer *but got "1a"} test incr-1.25 {TclCompileIncrCmd: too many arguments} { set i 10 @@ -1282,10 +1281,10 @@ test incr-1.25 {TclCompileIncrCmd: too many arguments} { } {wrong # args: should be "incr varName ?increment?"} -test incr-1.29 {TclCompileIncrCmd: runtime error, bad variable value} { +test incr-1.29 {TclCompileIncrCmd: runtime error, bad variable value} -body { set x " - " - list [catch {incr x 1} msg] $msg -} {1 {expected integer but got " - "}} + incr x 1 +} -returnCodes error -match glob -result {expected integer *but got " - "} test incr-1.30 {TclCompileIncrCmd: array var, braced (no subs)} { catch {unset array} @@ -1488,12 +1487,11 @@ test incr-2.23 {incr command (not compiled): increment given, formatted int != i set i 25 $z i 000012345 ;# an octal literal } 12370 -test incr-2.24 {incr command (not compiled): increment given, formatted int != int} { +test incr-2.24 {incr command (not compiled): increment given, formatted int != int} -body { set z incr set i 25 - catch {$z i 1a} msg - set msg -} {expected integer but got "1a"} + $z i 1a +} -returnCodes error -match glob -result {expected integer *but got "1a"} test incr-2.25 {incr command (not compiled): too many arguments} { set z incr @@ -1502,11 +1500,11 @@ test incr-2.25 {incr command (not compiled): too many arguments} { set msg } {wrong # args: should be "incr varName ?increment?"} -test incr-2.29 {incr command (not compiled): runtime error, bad variable value} { +test incr-2.29 {incr command (not compiled): runtime error, bad variable value} -body { set z incr set x " - " - list [catch {$z x 1} msg] $msg -} {1 {expected integer but got " - "}} + $z x 1 +} -returnCodes error -match glob -result {expected integer *but got " - "} ################################################################################ # LLENGTH @@ -3433,15 +3431,15 @@ test range-6.1 {range} -body { test range-6.2 {range} -body { range foo -} -returnCodes error -result {expected integer but got "foo"} +} -returnCodes error -match glob -result {expected integer *but got "foo"} test range-6.3 {range} -body { range 2 bar -} -returnCodes error -result {expected integer but got "bar"} +} -returnCodes error -match glob -result {expected integer *but got "bar"} test range-6.4 {range} -body { range 2 4 foo -} -returnCodes error -result {expected integer but got "foo"} +} -returnCodes error -match glob -result {expected integer *but got "foo"} test range-6.5 {range} -body { range 10 0 diff --git a/tests/pack.test b/tests/pack.test index d059087..0746e44 100644 --- a/tests/pack.test +++ b/tests/pack.test @@ -12,7 +12,7 @@ test pack-1.2 {pack invalid type} -body { test pack-1.3 {pack bad width} -body { pack a 1 -intbe badint -} -returnCodes error -result {expected integer but got "badint"} +} -returnCodes error -match glob -result {expected integer *but got "badint"} test pack-1.4 {pack bad width} -body { pack a 1 -intbe -5 @@ -20,7 +20,7 @@ test pack-1.4 {pack bad width} -body { test pack-1.5 {pack bad offset} -body { pack a 1 -intbe 5 badint -} -returnCodes error -result {expected integer but got "badint"} +} -returnCodes error -match glob -result {expected integer *but got "badint"} test pack-1.6 {pack bad offset} -body { pack a 1 -intbe 5 -6 @@ -78,7 +78,7 @@ test unpack-1.2 {unpack invalid type} -body { test unpack-1.3 {unpack bad width} -body { unpack abc -intle 0 badint -} -returnCodes error -result {expected integer but got "badint"} +} -returnCodes error -match glob -result {expected integer *but got "badint"} test unpack-1.4 {unpack bad width} -body { unpack abc -intle 0 -5 @@ -86,7 +86,7 @@ test unpack-1.4 {unpack bad width} -body { test unpack-1.5 {unpack bad offset} -body { unpack abc -intle badint 8 -} -returnCodes error -result {expected integer but got "badint"} +} -returnCodes error -match glob -result {expected integer *but got "badint"} test unpack-1.6 {unpack bad offset} -body { unpack abc -intle -6 8 -- cgit v1.1