summaryrefslogtreecommitdiffstats
path: root/tests/range.test
diff options
context:
space:
mode:
authorgriffin <briang42@easystreet.net>2022-07-22 19:15:12 (GMT)
committergriffin <briang42@easystreet.net>2022-07-22 19:15:12 (GMT)
commit91d2dee1010be253cb830d0e45bb10cdc17ac523 (patch)
treecb37c3284cf8431d9394d889669f97901445b9b4 /tests/range.test
parent59814de67b021d7f37ac7dd71c6943e223cab441 (diff)
downloadtcl-91d2dee1010be253cb830d0e45bb10cdc17ac523.zip
tcl-91d2dee1010be253cb830d0e45bb10cdc17ac523.tar.gz
tcl-91d2dee1010be253cb830d0e45bb10cdc17ac523.tar.bz2
Rewrite argument processing code. All correct and error conditions are handled. Add some new tests and disable some tests that should maybe work.
Diffstat (limited to 'tests/range.test')
-rw-r--r--tests/range.test81
1 files changed, 75 insertions, 6 deletions
diff --git a/tests/range.test b/tests/range.test
index 9ac0a7a..c68a8f9 100644
--- a/tests/range.test
+++ b/tests/range.test
@@ -16,13 +16,14 @@ if {"::tcltest" ni [namespace children]} {
testConstraint arithSeriesDouble 0
testConstraint arithSeriesShimmer 1
+testConstraint arithSeriesShimmerOk 0
## Arg errors
test range-1.1 {error cases} -body {
range
} \
-returnCodes 1 \
- -result {wrong # args: should be "range start op end ?by step?"}
+ -result {wrong # args: should be "range n ??op? n ??by? n??"}
test range-1.2 {step magnitude} {
@@ -100,6 +101,18 @@ test range-1.16 {large numbers} {
-result {1000000 1100000 1200000 1300000 1400000 1500000 1600000 1700000 1800000 1900000 2000000}
}
+test range-1.17 {too many arguments} -body {
+ range 12 to 24 by 2 with feeling
+} -returnCodes 1 -result {wrong # args: should be "range n ??op? n ??by? n??"}
+
+test range-1.18 {too many arguments extra valid keyword} -body {
+ range 12 to 24 by 2 count
+} -returnCodes 1 -result {wrong # args: should be "range n ??op? n ??by? n??"}
+
+test range-1.19 {too many arguments extra numeric value} -body {
+ range 12 to 24 by 2 7
+} -returnCodes 1 -result {wrong # args: should be "range n ??op? n ??by? n??"}
+
#
# Short-hand use cases
#
@@ -192,23 +205,23 @@ test range-3.1 {experiement} {
test range-3.2 {error case} -body {
range foo
-} -returnCodes 1 -result {bad start value: "foo"}
+} -returnCodes 1 -result {bad operation "foo": must be .., to, count, or by}
test range-3.3 {error case} -body {
range 10 foo
-} -returnCodes 1 -result {bad end value: "foo"}
+} -returnCodes 1 -result {bad operation "foo": must be .., to, count, or by}
test range-3.4 {error case} -body {
range 25 or 6
-} -returnCodes 1 -result {bad range operation "or": must be .., to, count, or by}
+} -returnCodes 1 -result {bad operation "or": must be .., to, count, or by}
test range-3.5 {simple count and step arguments} {
range 25 by 6
-} {0 6 12 18 24}
+} {0 6 12 18 24 30 36 42 48 54 60 66 72 78 84 90 96 102 108 114 120 126 132 138 144 150}
test range-3.6 {error case} -body {
range 1 7 or 3
-} -returnCodes 1 -result {bad step keyword "or": must be by}
+} -returnCodes 1 -result {bad operation "or": must be .., to, count, or by}
test range-3.7 {lmap range} {
lmap x [range 5] { expr {$x * $x} }
@@ -245,6 +258,60 @@ test range-3.11 {lreverse range} {
arithseries
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15}
+test range-3.12 {in operator} {
+ set r [range 9]
+ set i [expr {7 in $r}]
+ set j [expr {10 ni $r}]
+ set k [expr {-1 in $r}]
+ set l [expr {4 ni $r}]
+ list $i $j $k $l [lindex [tcl::unsupported::representation $r] 3]
+} {1 1 0 0 arithseries}
+
+test range-3.13 {lmap range shimmer} arithSeriesShimmer {
+ set r [range 15]
+ set rep-before [lindex [tcl::unsupported::representation $r] 3]
+ set m [lmap i $r { expr {$i * 7} }]
+ set rep-after [lindex [tcl::unsupported::representation $r] 3]
+ set rep-m [lindex [tcl::unsupported::representation $m] 3]
+ list $r ${rep-before} ${rep-after} ${rep-m} $m
+} {{0 1 2 3 4 5 6 7 8 9 10 11 12 13 14} arithseries arithseries list {0 7 14 21 28 35 42 49 56 63 70 77 84 91 98}}
+
+test range-3.14 {array for shimmer} arithSeriesShimmerOk {
+ array set testarray {a Test for This great Function}
+ set vars [range 2]
+ set vars-rep [lindex [tcl::unsupported::representation $vars] 3]
+ array for $vars testarray {
+ lappend keys $0
+ lappend vals $1
+ }
+ # Since hash order is not guaranteed, have to validate content ignoring order
+ set valk [lmap k $keys {expr {$k in {a for great}}}]
+ set valv [lmap v $vals {expr {$v in {Test This Function}}}]
+ set vars-after [lindex [tcl::unsupported::representation $vars] 3]
+ list ${vars-rep} $valk $valv ${vars-after}
+} {arithseries {1 1 1} {1 1 1} arithseries}
+
+test range-3.15 {join for shimmer} arithSeriesShimmerOk {
+ set r [range 3]
+ set rep-before [lindex [tcl::unsupported::representation $r] 3]
+ set str [join $r :]
+ set rep-after [lindex [tcl::unsupported::representation $r] 3]
+ list ${rep-before} $str ${rep-after}
+} {arithseries 0:1:2 arithseries}
+
+test range-3.16 {error case} -body {
+ range 16 to
+} -returnCodes 1 -result {missing "to" value.}
+
+test range-3.17 {error case} -body {
+ range 17 to 13 by
+} -returnCodes 1 -result {missing "by" value.}
+
+test range-3.18 {error case} -body {
+ range 18 count
+} -returnCodes 1 -result {missing "count" value.}
+
+
# Test lmap
# Test "in" expression operator
# Test llength
@@ -253,6 +320,8 @@ arithseries
# Test start,end,step expressions
# Test lreverse
# Test lsearch
+# Test array for
+# Test join for shimmer.
test range-4.1 {end expressions} {
set start 7