sl@0
|
1 |
# Commands covered: expr
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# This file contains the original set of tests for the compilation (and
|
sl@0
|
4 |
# indirectly execution) of Tcl's expr command. A new set of tests covering
|
sl@0
|
5 |
# the new implementation are in the files "parseExpr.test" and
|
sl@0
|
6 |
# "compExpr.test". Sourcing this file into Tcl runs the tests and generates
|
sl@0
|
7 |
# output for errors. No output means no errors were found.
|
sl@0
|
8 |
#
|
sl@0
|
9 |
# Copyright (c) 1996-1997 Sun Microsystems, Inc.
|
sl@0
|
10 |
# Copyright (c) 1998-1999 by Scriptics Corporation.
|
sl@0
|
11 |
#
|
sl@0
|
12 |
# See the file "license.terms" for information on usage and redistribution
|
sl@0
|
13 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
sl@0
|
14 |
#
|
sl@0
|
15 |
# RCS: @(#) $Id: compExpr-old.test,v 1.7 2001/12/06 10:59:17 dkf Exp $
|
sl@0
|
16 |
|
sl@0
|
17 |
if {[lsearch [namespace children] ::tcltest] == -1} {
|
sl@0
|
18 |
package require tcltest
|
sl@0
|
19 |
namespace import -force ::tcltest::*
|
sl@0
|
20 |
}
|
sl@0
|
21 |
|
sl@0
|
22 |
if {([catch {expr T1()} msg] == 1) && ($msg == {unknown math function "T1"})} {
|
sl@0
|
23 |
set gotT1 0
|
sl@0
|
24 |
puts "This application hasn't been compiled with the \"T1\" and"
|
sl@0
|
25 |
puts "\"T2\" math functions, so I'll skip some of the expr tests."
|
sl@0
|
26 |
} else {
|
sl@0
|
27 |
set gotT1 1
|
sl@0
|
28 |
}
|
sl@0
|
29 |
|
sl@0
|
30 |
# procedures used below
|
sl@0
|
31 |
|
sl@0
|
32 |
proc put_hello_char {c} {
|
sl@0
|
33 |
global a
|
sl@0
|
34 |
append a [format %c $c]
|
sl@0
|
35 |
return $c
|
sl@0
|
36 |
}
|
sl@0
|
37 |
proc hello_world {} {
|
sl@0
|
38 |
global a
|
sl@0
|
39 |
set a ""
|
sl@0
|
40 |
set L1 [set l0 [set h_1 [set q 0]]]
|
sl@0
|
41 |
for {put_hello_char [expr [put_hello_char [expr [set h 7]*10+2]]+29]} {$l0?[put_hello_char $l0]
|
sl@0
|
42 |
:!$h_1} {put_hello_char $ll;expr {$L1==2?[set ll [expr 32+0-0+[set bar 0]]]:0}} {expr {[incr L1]==[expr 1+([string length "abc"]-[string length "abc"])]
|
sl@0
|
43 |
?[set ll [set l0 [expr 54<<1]]]:$ll==108&&$L1<3?
|
sl@0
|
44 |
[incr ll [expr 1|1<<1]; set ll $ll; set ll $ll; set ll $ll; set ll $ll; set l0 [expr ([string length "abc"]-[string length "abc"])+([string length "abc"]-[string length "abc"])-([string length "abc"]-[string length "abc"])+([string length "abc"]-[string length "abc"])]; set l0; set l0 $l0; set l0; set l0]:$L1==4&&$ll==32?[set ll [expr 19+$h1+([string length "abc"]-[string length "abc"])-([string length "abc"]-[string length "abc"])+([string length "abc"]-[string length "abc"])-([string length "abc"]-[string length "abc"])+[set foo [expr ([string length "abc"]-[string length "abc"])+([string length "abc"]-[string length "abc"])+([string length "abc"]-[string length "abc"])]]]]
|
sl@0
|
45 |
:[set q [expr $q-$h1+([string length "abc"]-[string length "abc"])-([string length "abc"]-[string length "abc"])]]};expr {$L1==5?[incr ll -8; set ll $ll; set ll]:$q&&$h1&&1};expr {$L1==4+2
|
sl@0
|
46 |
?[incr ll 3]:[expr ([string length "abc"]-[string length "abc"])+1]};expr {$ll==($h<<4)+2+0&&$L1!=6?[incr ll -6]:[set h1 [expr 100+([string length "abc"]-[string length "abc"])-([string length "abc"]-[string length "abc"])]]}
|
sl@0
|
47 |
expr {$L1!=1<<3?[incr q [expr ([string length "abc"]-[string length "abc"])-1]]:[set h_1 [set ll $h1]]}
|
sl@0
|
48 |
}
|
sl@0
|
49 |
set a
|
sl@0
|
50 |
}
|
sl@0
|
51 |
|
sl@0
|
52 |
proc 12days {a b c} {
|
sl@0
|
53 |
global xxx
|
sl@0
|
54 |
expr {1<$a?[expr {$a<3?[12days -79 -13 [string range $c [12days -87 \
|
sl@0
|
55 |
[expr 1-$b] [string range $c [12days -86 0 [string range $c 1 end]] \
|
sl@0
|
56 |
end]] end]]:1};expr {$a<$b?[12days [expr $a+1] $b $c]:3};expr {[12days \
|
sl@0
|
57 |
-94 [expr $a-27] $c]&&$a==2?$b<13?[12days 2 [expr $b+1] "%s %d %d\n"]:9
|
sl@0
|
58 |
:16}]:$a<0?$a<-72?[12days $b $a "@n'+,#'/*\{\}w+/w#cdnr/+,\{\}r/*de\}+,/*\{*+,/w\{%+,/w#q#n+,/#\{l+,/n\{n+,/+#n+,/#;#q#n+,/+k#;*+,/'r :'d*'3,\}\{w+K w'K:'+\}e#';dq#'l q#'+d'K#!/+k#;q#'r\}eKK#\}w'r\}eKK\{nl\]'/#;#q#n')\{)#\}w')\{)\{nl\]'/+#n';d\}rw' i;# )\{nl\]!/n\{n#'; r\{#w'r nc\{nl\]'/#\{l,+'K \{rw' iK\{;\[\{nl\]'/w#q#n'wk nw' iwk\{KK\{nl\]!/w\{%'l##w#' i; :\{nl\]'/*\{q#'ld;r'\}\{nlwb!/*de\}'c ;;\{nl'-\{\}rw\]'/+,\}##'*\}#nc,',#nw\]'/+kd'+e\}+;#'rdq#w! nr'/ ') \}+\}\{rl#'\{n' ')# \}'+\}##(!!/"]
|
sl@0
|
59 |
:$a<-50?[string compare [format %c $b] [string index $c 0]]==0?[append \
|
sl@0
|
60 |
xxx [string index $c 31];scan [string index $c 31] %c x;set x]
|
sl@0
|
61 |
:[12days -65 $b [string range $c 1 end]]:[12days [expr ([string compare \
|
sl@0
|
62 |
[string index $c 0] "/"]==0)+$a] $b [string range $c 1 end]]:0<$a
|
sl@0
|
63 |
?[12days 2 2 "%s"]:[string compare [string index $c 0] "/"]==0||
|
sl@0
|
64 |
[12days 0 [12days -61 [scan [string index $c 0] %c x; set x] \
|
sl@0
|
65 |
"!ek;dc i@bK'(q)-\[w\]*%n+r3#l,\{\}:\nuwloca-O;m .vpbks,fxntdCeghiry"] \
|
sl@0
|
66 |
[string range $c 1 end]]}
|
sl@0
|
67 |
}
|
sl@0
|
68 |
proc do_twelve_days {} {
|
sl@0
|
69 |
global xxx
|
sl@0
|
70 |
set xxx ""
|
sl@0
|
71 |
12days 1 1 1
|
sl@0
|
72 |
string length $xxx
|
sl@0
|
73 |
}
|
sl@0
|
74 |
|
sl@0
|
75 |
# start of tests
|
sl@0
|
76 |
|
sl@0
|
77 |
catch {unset a b i x}
|
sl@0
|
78 |
|
sl@0
|
79 |
test compExpr-old-1.1 {TclCompileExprCmd: no expression} {
|
sl@0
|
80 |
list [catch {expr } msg] $msg
|
sl@0
|
81 |
} {1 {wrong # args: should be "expr arg ?arg ...?"}}
|
sl@0
|
82 |
test compExpr-old-1.2 {TclCompileExprCmd: one expression word} {
|
sl@0
|
83 |
expr -25
|
sl@0
|
84 |
} -25
|
sl@0
|
85 |
test compExpr-old-1.3 {TclCompileExprCmd: two expression words} {
|
sl@0
|
86 |
expr -8.2 -6
|
sl@0
|
87 |
} -14.2
|
sl@0
|
88 |
test compExpr-old-1.4 {TclCompileExprCmd: five expression words} {
|
sl@0
|
89 |
expr 20 - 5 +10 -7
|
sl@0
|
90 |
} 18
|
sl@0
|
91 |
test compExpr-old-1.5 {TclCompileExprCmd: quoted expression word} {
|
sl@0
|
92 |
expr "0005"
|
sl@0
|
93 |
} 5
|
sl@0
|
94 |
test compExpr-old-1.6 {TclCompileExprCmd: quoted expression word} {
|
sl@0
|
95 |
catch {expr "0005"zxy} msg
|
sl@0
|
96 |
set msg
|
sl@0
|
97 |
} {extra characters after close-quote}
|
sl@0
|
98 |
test compExpr-old-1.7 {TclCompileExprCmd: expression word in braces} {
|
sl@0
|
99 |
expr {-0005}
|
sl@0
|
100 |
} -5
|
sl@0
|
101 |
test compExpr-old-1.8 {TclCompileExprCmd: expression word in braces} {
|
sl@0
|
102 |
expr {{-0x1234}}
|
sl@0
|
103 |
} -4660
|
sl@0
|
104 |
test compExpr-old-1.9 {TclCompileExprCmd: expression word in braces} {
|
sl@0
|
105 |
catch {expr {-0005}foo} msg
|
sl@0
|
106 |
set msg
|
sl@0
|
107 |
} {extra characters after close-brace}
|
sl@0
|
108 |
test compExpr-old-1.10 {TclCompileExprCmd: other expression word in braces} {
|
sl@0
|
109 |
expr 4*[llength "6 2"]
|
sl@0
|
110 |
} 8
|
sl@0
|
111 |
test compExpr-old-1.11 {TclCompileExprCmd: expression word terminated by ;} {
|
sl@0
|
112 |
expr 4*[llength "6 2"];
|
sl@0
|
113 |
} 8
|
sl@0
|
114 |
test compExpr-old-1.12 {TclCompileExprCmd: inlined expr (in "catch") inside other catch} {
|
sl@0
|
115 |
set a xxx
|
sl@0
|
116 |
catch {
|
sl@0
|
117 |
# Might not be a number
|
sl@0
|
118 |
set a [expr 10*$a]
|
sl@0
|
119 |
}
|
sl@0
|
120 |
} 1
|
sl@0
|
121 |
test compExpr-old-1.13 {TclCompileExprCmd: second level of substitutions in expr not in braces with single var reference} {
|
sl@0
|
122 |
set a xxx
|
sl@0
|
123 |
set x 27; set bool {$x}; if $bool {set a foo}
|
sl@0
|
124 |
set a
|
sl@0
|
125 |
} foo
|
sl@0
|
126 |
test compExpr-old-1.14 {TclCompileExprCmd: second level of substitutions in expr with comparison as top-level operator} {
|
sl@0
|
127 |
set a xxx
|
sl@0
|
128 |
set x 2; set b {$x}; set a [expr $b == 2]
|
sl@0
|
129 |
set a
|
sl@0
|
130 |
} 1
|
sl@0
|
131 |
|
sl@0
|
132 |
test compExpr-old-2.1 {TclCompileExpr: are builtin functions registered?} {
|
sl@0
|
133 |
expr double(5*[llength "6 2"])
|
sl@0
|
134 |
} 10.0
|
sl@0
|
135 |
test compExpr-old-2.2 {TclCompileExpr: error in expr} {
|
sl@0
|
136 |
catch {expr 2**3} msg
|
sl@0
|
137 |
set msg
|
sl@0
|
138 |
} {syntax error in expression "2**3": unexpected operator *}
|
sl@0
|
139 |
test compExpr-old-2.3 {TclCompileExpr: junk after legal expr} {
|
sl@0
|
140 |
catch {expr 7*[llength "a b"]foo} msg
|
sl@0
|
141 |
set msg
|
sl@0
|
142 |
} {syntax error in expression "7*2foo": extra tokens at end of expression}
|
sl@0
|
143 |
test compExpr-old-2.4 {TclCompileExpr: numeric expr string rep == formatted int rep} {
|
sl@0
|
144 |
expr {0001}
|
sl@0
|
145 |
} 1
|
sl@0
|
146 |
|
sl@0
|
147 |
test compExpr-old-3.1 {CompileCondExpr: just lor expr} {expr 3||0} 1
|
sl@0
|
148 |
test compExpr-old-3.2 {CompileCondExpr: error in lor expr} {
|
sl@0
|
149 |
catch {expr x||3} msg
|
sl@0
|
150 |
set msg
|
sl@0
|
151 |
} {syntax error in expression "x||3": variable references require preceding $}
|
sl@0
|
152 |
test compExpr-old-3.3 {CompileCondExpr: test true arm} {expr 3>2?44:66} 44
|
sl@0
|
153 |
test compExpr-old-3.4 {CompileCondExpr: error compiling true arm} {
|
sl@0
|
154 |
catch {expr 3>2?2**3:66} msg
|
sl@0
|
155 |
set msg
|
sl@0
|
156 |
} {syntax error in expression "3>2?2**3:66": unexpected operator *}
|
sl@0
|
157 |
test compExpr-old-3.5 {CompileCondExpr: test false arm} {expr 2>3?44:66} 66
|
sl@0
|
158 |
test compExpr-old-3.6 {CompileCondExpr: error compiling false arm} {
|
sl@0
|
159 |
catch {expr 2>3?44:2**3} msg
|
sl@0
|
160 |
set msg
|
sl@0
|
161 |
} {syntax error in expression "2>3?44:2**3": unexpected operator *}
|
sl@0
|
162 |
test compExpr-old-3.7 {CompileCondExpr: long arms & nested cond exprs} {nonPortable} {
|
sl@0
|
163 |
puts "Note: doing test compExpr-old-3.7 which can take several minutes to run"
|
sl@0
|
164 |
hello_world
|
sl@0
|
165 |
} {Hello world}
|
sl@0
|
166 |
catch {unset xxx}
|
sl@0
|
167 |
test compExpr-old-3.8 {CompileCondExpr: long arms & nested cond exprs} {nonPortable} {
|
sl@0
|
168 |
puts "Note: doing test compExpr-old-3.8 which can take several minutes to run"
|
sl@0
|
169 |
do_twelve_days
|
sl@0
|
170 |
} 2358
|
sl@0
|
171 |
catch {unset xxx}
|
sl@0
|
172 |
|
sl@0
|
173 |
test compExpr-old-4.1 {CompileLorExpr: just land expr} {expr 1.3&&3.3} 1
|
sl@0
|
174 |
test compExpr-old-4.2 {CompileLorExpr: error in land expr} {
|
sl@0
|
175 |
catch {expr x&&3} msg
|
sl@0
|
176 |
set msg
|
sl@0
|
177 |
} {syntax error in expression "x&&3": variable references require preceding $}
|
sl@0
|
178 |
test compExpr-old-4.3 {CompileLorExpr: simple lor exprs} {expr 0||1.0} 1
|
sl@0
|
179 |
test compExpr-old-4.4 {CompileLorExpr: simple lor exprs} {expr 3.0||0.0} 1
|
sl@0
|
180 |
test compExpr-old-4.5 {CompileLorExpr: simple lor exprs} {expr 0||0||1} 1
|
sl@0
|
181 |
test compExpr-old-4.6 {CompileLorExpr: error compiling lor arm} {
|
sl@0
|
182 |
catch {expr 2**3||4.0} msg
|
sl@0
|
183 |
set msg
|
sl@0
|
184 |
} {syntax error in expression "2**3||4.0": unexpected operator *}
|
sl@0
|
185 |
test compExpr-old-4.7 {CompileLorExpr: error compiling lor arm} {
|
sl@0
|
186 |
catch {expr 1.3||2**3} msg
|
sl@0
|
187 |
set msg
|
sl@0
|
188 |
} {syntax error in expression "1.3||2**3": unexpected operator *}
|
sl@0
|
189 |
test compExpr-old-4.8 {CompileLorExpr: error compiling lor arms} {
|
sl@0
|
190 |
list [catch {expr {"a"||"b"}} msg] $msg
|
sl@0
|
191 |
} {1 {expected boolean value but got "a"}}
|
sl@0
|
192 |
test compExpr-old-4.9 {CompileLorExpr: long lor arm} {
|
sl@0
|
193 |
set a "abcdefghijkl"
|
sl@0
|
194 |
set i 7
|
sl@0
|
195 |
expr {[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]] || [string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]] || [string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]] || [string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]}
|
sl@0
|
196 |
} 1
|
sl@0
|
197 |
|
sl@0
|
198 |
test compExpr-old-5.1 {CompileLandExpr: just bitor expr} {expr 7|0x13} 23
|
sl@0
|
199 |
test compExpr-old-5.2 {CompileLandExpr: error in bitor expr} {
|
sl@0
|
200 |
catch {expr x|3} msg
|
sl@0
|
201 |
set msg
|
sl@0
|
202 |
} {syntax error in expression "x|3": variable references require preceding $}
|
sl@0
|
203 |
test compExpr-old-5.3 {CompileLandExpr: simple land exprs} {expr 0&&1.0} 0
|
sl@0
|
204 |
test compExpr-old-5.4 {CompileLandExpr: simple land exprs} {expr 0&&0} 0
|
sl@0
|
205 |
test compExpr-old-5.5 {CompileLandExpr: simple land exprs} {expr 3.0&&1.2} 1
|
sl@0
|
206 |
test compExpr-old-5.6 {CompileLandExpr: simple land exprs} {expr 1&&1&&2} 1
|
sl@0
|
207 |
test compExpr-old-5.7 {CompileLandExpr: error compiling land arm} {
|
sl@0
|
208 |
catch {expr 2**3&&4.0} msg
|
sl@0
|
209 |
set msg
|
sl@0
|
210 |
} {syntax error in expression "2**3&&4.0": unexpected operator *}
|
sl@0
|
211 |
test compExpr-old-5.8 {CompileLandExpr: error compiling land arm} {
|
sl@0
|
212 |
catch {expr 1.3&&2**3} msg
|
sl@0
|
213 |
set msg
|
sl@0
|
214 |
} {syntax error in expression "1.3&&2**3": unexpected operator *}
|
sl@0
|
215 |
test compExpr-old-5.9 {CompileLandExpr: error compiling land arm} {
|
sl@0
|
216 |
list [catch {expr {"a"&&"b"}} msg] $msg
|
sl@0
|
217 |
} {1 {expected boolean value but got "a"}}
|
sl@0
|
218 |
test compExpr-old-5.10 {CompileLandExpr: long land arms} {
|
sl@0
|
219 |
set a "abcdefghijkl"
|
sl@0
|
220 |
set i 7
|
sl@0
|
221 |
expr {[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]] && [string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]] && [string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]] && [string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]^[string compare [format %c 103] [string index $a $i]]^[string compare [format %c 105] [string index $a $i]]}
|
sl@0
|
222 |
} 1
|
sl@0
|
223 |
|
sl@0
|
224 |
test compExpr-old-6.1 {CompileBitXorExpr: just bitand expr} {expr 7&0x13} 3
|
sl@0
|
225 |
test compExpr-old-6.2 {CompileBitXorExpr: error in bitand expr} {
|
sl@0
|
226 |
catch {expr x|3} msg
|
sl@0
|
227 |
set msg
|
sl@0
|
228 |
} {syntax error in expression "x|3": variable references require preceding $}
|
sl@0
|
229 |
test compExpr-old-6.3 {CompileBitXorExpr: simple bitxor exprs} {expr 7^0x13} 20
|
sl@0
|
230 |
test compExpr-old-6.4 {CompileBitXorExpr: simple bitxor exprs} {expr 3^0x10} 19
|
sl@0
|
231 |
test compExpr-old-6.5 {CompileBitXorExpr: simple bitxor exprs} {expr 0^7} 7
|
sl@0
|
232 |
test compExpr-old-6.6 {CompileBitXorExpr: simple bitxor exprs} {expr -1^7} -8
|
sl@0
|
233 |
test compExpr-old-6.7 {CompileBitXorExpr: error compiling bitxor arm} {
|
sl@0
|
234 |
catch {expr 2**3|6} msg
|
sl@0
|
235 |
set msg
|
sl@0
|
236 |
} {syntax error in expression "2**3|6": unexpected operator *}
|
sl@0
|
237 |
test compExpr-old-6.8 {CompileBitXorExpr: error compiling bitxor arm} {
|
sl@0
|
238 |
catch {expr 2^x} msg
|
sl@0
|
239 |
set msg
|
sl@0
|
240 |
} {syntax error in expression "2^x": variable references require preceding $}
|
sl@0
|
241 |
test compExpr-old-6.9 {CompileBitXorExpr: runtime error in bitxor arm} {
|
sl@0
|
242 |
list [catch {expr {24.0^3}} msg] $msg
|
sl@0
|
243 |
} {1 {can't use floating-point value as operand of "^"}}
|
sl@0
|
244 |
test compExpr-old-6.10 {CompileBitXorExpr: runtime error in bitxor arm} {
|
sl@0
|
245 |
list [catch {expr {"a"^"b"}} msg] $msg
|
sl@0
|
246 |
} {1 {can't use non-numeric string as operand of "^"}}
|
sl@0
|
247 |
|
sl@0
|
248 |
test compExpr-old-7.1 {CompileBitAndExpr: just equality expr} {expr 3==2} 0
|
sl@0
|
249 |
test compExpr-old-7.2 {CompileBitAndExpr: just equality expr} {expr 2.0==2} 1
|
sl@0
|
250 |
test compExpr-old-7.3 {CompileBitAndExpr: just equality expr} {expr 3.2!=2.2} 1
|
sl@0
|
251 |
test compExpr-old-7.4 {CompileBitAndExpr: just equality expr} {expr {"abc" == "abd"}} 0
|
sl@0
|
252 |
test compExpr-old-7.5 {CompileBitAndExpr: error in equality expr} {
|
sl@0
|
253 |
catch {expr x==3} msg
|
sl@0
|
254 |
set msg
|
sl@0
|
255 |
} {syntax error in expression "x==3": variable references require preceding $}
|
sl@0
|
256 |
test compExpr-old-7.6 {CompileBitAndExpr: simple bitand exprs} {expr 7&0x13} 3
|
sl@0
|
257 |
test compExpr-old-7.7 {CompileBitAndExpr: simple bitand exprs} {expr 0xf2&0x53} 82
|
sl@0
|
258 |
test compExpr-old-7.8 {CompileBitAndExpr: simple bitand exprs} {expr 3&6} 2
|
sl@0
|
259 |
test compExpr-old-7.9 {CompileBitAndExpr: simple bitand exprs} {expr -1&-7} -7
|
sl@0
|
260 |
test compExpr-old-7.10 {CompileBitAndExpr: error compiling bitand arm} {
|
sl@0
|
261 |
catch {expr 2**3&6} msg
|
sl@0
|
262 |
set msg
|
sl@0
|
263 |
} {syntax error in expression "2**3&6": unexpected operator *}
|
sl@0
|
264 |
test compExpr-old-7.11 {CompileBitAndExpr: error compiling bitand arm} {
|
sl@0
|
265 |
catch {expr 2&x} msg
|
sl@0
|
266 |
set msg
|
sl@0
|
267 |
} {syntax error in expression "2&x": variable references require preceding $}
|
sl@0
|
268 |
test compExpr-old-7.12 {CompileBitAndExpr: runtime error in bitand arm} {
|
sl@0
|
269 |
list [catch {expr {24.0&3}} msg] $msg
|
sl@0
|
270 |
} {1 {can't use floating-point value as operand of "&"}}
|
sl@0
|
271 |
test compExpr-old-7.13 {CompileBitAndExpr: runtime error in bitand arm} {
|
sl@0
|
272 |
list [catch {expr {"a"&"b"}} msg] $msg
|
sl@0
|
273 |
} {1 {can't use non-numeric string as operand of "&"}}
|
sl@0
|
274 |
|
sl@0
|
275 |
test compExpr-old-8.1 {CompileEqualityExpr: just relational expr} {expr 3>=2} 1
|
sl@0
|
276 |
test compExpr-old-8.2 {CompileEqualityExpr: just relational expr} {expr 2<=2.1} 1
|
sl@0
|
277 |
test compExpr-old-8.3 {CompileEqualityExpr: just relational expr} {expr 3.2>"2.2"} 1
|
sl@0
|
278 |
test compExpr-old-8.4 {CompileEqualityExpr: just relational expr} {expr {"0y"<"0x12"}} 0
|
sl@0
|
279 |
test compExpr-old-8.5 {CompileEqualityExpr: error in relational expr} {
|
sl@0
|
280 |
catch {expr x>3} msg
|
sl@0
|
281 |
set msg
|
sl@0
|
282 |
} {syntax error in expression "x>3": variable references require preceding $}
|
sl@0
|
283 |
test compExpr-old-8.6 {CompileEqualityExpr: simple equality exprs} {expr 7==0x13} 0
|
sl@0
|
284 |
test compExpr-old-8.7 {CompileEqualityExpr: simple equality exprs} {expr -0xf2!=0x53} 1
|
sl@0
|
285 |
test compExpr-old-8.8 {CompileEqualityExpr: simple equality exprs} {expr {"12398712938788234-1298379" != ""}} 1
|
sl@0
|
286 |
test compExpr-old-8.9 {CompileEqualityExpr: simple equality exprs} {expr -1!="abc"} 1
|
sl@0
|
287 |
test compExpr-old-8.10 {CompileEqualityExpr: error compiling equality arm} {
|
sl@0
|
288 |
catch {expr 2**3==6} msg
|
sl@0
|
289 |
set msg
|
sl@0
|
290 |
} {syntax error in expression "2**3==6": unexpected operator *}
|
sl@0
|
291 |
test compExpr-old-8.11 {CompileEqualityExpr: error compiling equality arm} {
|
sl@0
|
292 |
catch {expr 2!=x} msg
|
sl@0
|
293 |
set msg
|
sl@0
|
294 |
} {syntax error in expression "2!=x": variable references require preceding $}
|
sl@0
|
295 |
|
sl@0
|
296 |
|
sl@0
|
297 |
test compExpr-old-9.1 {CompileRelationalExpr: just shift expr} {expr 3<<2} 12
|
sl@0
|
298 |
test compExpr-old-9.2 {CompileRelationalExpr: just shift expr} {expr 0xff>>2} 63
|
sl@0
|
299 |
test compExpr-old-9.3 {CompileRelationalExpr: just shift expr} {expr -1>>2} -1
|
sl@0
|
300 |
test compExpr-old-9.4 {CompileRelationalExpr: just shift expr} {expr {1<<3}} 8
|
sl@0
|
301 |
|
sl@0
|
302 |
# The following test is different for 32-bit versus 64-bit
|
sl@0
|
303 |
# architectures because LONG_MIN is different
|
sl@0
|
304 |
|
sl@0
|
305 |
if {0x80000000 > 0} {
|
sl@0
|
306 |
test compExpr-old-9.5 {CompileRelationalExpr: shift expr producing LONG_MIN} {nonPortable} {
|
sl@0
|
307 |
expr {1<<63}
|
sl@0
|
308 |
} -9223372036854775808
|
sl@0
|
309 |
} else {
|
sl@0
|
310 |
test compExpr-old-9.5 {CompileRelationalExpr: shift expr producing LONG_MIN} {nonPortable} {
|
sl@0
|
311 |
expr {1<<31}
|
sl@0
|
312 |
} -2147483648
|
sl@0
|
313 |
}
|
sl@0
|
314 |
test compExpr-old-9.6 {CompileRelationalExpr: error in shift expr} {
|
sl@0
|
315 |
catch {expr x>>3} msg
|
sl@0
|
316 |
set msg
|
sl@0
|
317 |
} {syntax error in expression "x>>3": variable references require preceding $}
|
sl@0
|
318 |
test compExpr-old-9.7 {CompileRelationalExpr: simple relational exprs} {expr 0xff>=+0x3} 1
|
sl@0
|
319 |
test compExpr-old-9.8 {CompileRelationalExpr: simple relational exprs} {expr -0xf2<0x3} 1
|
sl@0
|
320 |
test compExpr-old-9.9 {CompileRelationalExpr: error compiling relational arm} {
|
sl@0
|
321 |
catch {expr 2**3>6} msg
|
sl@0
|
322 |
set msg
|
sl@0
|
323 |
} {syntax error in expression "2**3>6": unexpected operator *}
|
sl@0
|
324 |
test compExpr-old-9.10 {CompileRelationalExpr: error compiling relational arm} {
|
sl@0
|
325 |
catch {expr 2<x} msg
|
sl@0
|
326 |
set msg
|
sl@0
|
327 |
} {syntax error in expression "2<x": variable references require preceding $}
|
sl@0
|
328 |
|
sl@0
|
329 |
test compExpr-old-10.1 {CompileShiftExpr: just add expr} {expr 4+-2} 2
|
sl@0
|
330 |
test compExpr-old-10.2 {CompileShiftExpr: just add expr} {expr 0xff-2} 253
|
sl@0
|
331 |
test compExpr-old-10.3 {CompileShiftExpr: just add expr} {expr -1--2} 1
|
sl@0
|
332 |
test compExpr-old-10.4 {CompileShiftExpr: just add expr} {expr 1-0123} -82
|
sl@0
|
333 |
test compExpr-old-10.5 {CompileShiftExpr: error in add expr} {
|
sl@0
|
334 |
catch {expr x+3} msg
|
sl@0
|
335 |
set msg
|
sl@0
|
336 |
} {syntax error in expression "x+3": variable references require preceding $}
|
sl@0
|
337 |
test compExpr-old-10.6 {CompileShiftExpr: simple shift exprs} {expr 0xff>>0x3} 31
|
sl@0
|
338 |
test compExpr-old-10.7 {CompileShiftExpr: simple shift exprs} {expr -0xf2<<0x3} -1936
|
sl@0
|
339 |
test compExpr-old-10.8 {CompileShiftExpr: error compiling shift arm} {
|
sl@0
|
340 |
catch {expr 2**3>>6} msg
|
sl@0
|
341 |
set msg
|
sl@0
|
342 |
} {syntax error in expression "2**3>>6": unexpected operator *}
|
sl@0
|
343 |
test compExpr-old-10.9 {CompileShiftExpr: error compiling shift arm} {
|
sl@0
|
344 |
catch {expr 2<<x} msg
|
sl@0
|
345 |
set msg
|
sl@0
|
346 |
} {syntax error in expression "2<<x": variable references require preceding $}
|
sl@0
|
347 |
test compExpr-old-10.10 {CompileShiftExpr: runtime error} {
|
sl@0
|
348 |
list [catch {expr {24.0>>43}} msg] $msg
|
sl@0
|
349 |
} {1 {can't use floating-point value as operand of ">>"}}
|
sl@0
|
350 |
test compExpr-old-10.11 {CompileShiftExpr: runtime error} {
|
sl@0
|
351 |
list [catch {expr {"a"<<"b"}} msg] $msg
|
sl@0
|
352 |
} {1 {can't use non-numeric string as operand of "<<"}}
|
sl@0
|
353 |
|
sl@0
|
354 |
test compExpr-old-11.1 {CompileAddExpr: just multiply expr} {expr 4*-2} -8
|
sl@0
|
355 |
test compExpr-old-11.2 {CompileAddExpr: just multiply expr} {expr 0xff%2} 1
|
sl@0
|
356 |
test compExpr-old-11.3 {CompileAddExpr: just multiply expr} {expr -1/2} -1
|
sl@0
|
357 |
test compExpr-old-11.4 {CompileAddExpr: just multiply expr} {expr 7891%0123} 6
|
sl@0
|
358 |
test compExpr-old-11.5 {CompileAddExpr: error in multiply expr} {
|
sl@0
|
359 |
catch {expr x*3} msg
|
sl@0
|
360 |
set msg
|
sl@0
|
361 |
} {syntax error in expression "x*3": variable references require preceding $}
|
sl@0
|
362 |
test compExpr-old-11.6 {CompileAddExpr: simple add exprs} {expr 0xff++0x3} 258
|
sl@0
|
363 |
test compExpr-old-11.7 {CompileAddExpr: simple add exprs} {expr -0xf2--0x3} -239
|
sl@0
|
364 |
test compExpr-old-11.8 {CompileAddExpr: error compiling add arm} {
|
sl@0
|
365 |
catch {expr 2**3+6} msg
|
sl@0
|
366 |
set msg
|
sl@0
|
367 |
} {syntax error in expression "2**3+6": unexpected operator *}
|
sl@0
|
368 |
test compExpr-old-11.9 {CompileAddExpr: error compiling add arm} {
|
sl@0
|
369 |
catch {expr 2-x} msg
|
sl@0
|
370 |
set msg
|
sl@0
|
371 |
} {syntax error in expression "2-x": variable references require preceding $}
|
sl@0
|
372 |
test compExpr-old-11.10 {CompileAddExpr: runtime error} {
|
sl@0
|
373 |
list [catch {expr {24.0+"xx"}} msg] $msg
|
sl@0
|
374 |
} {1 {can't use non-numeric string as operand of "+"}}
|
sl@0
|
375 |
test compExpr-old-11.11 {CompileAddExpr: runtime error} {
|
sl@0
|
376 |
list [catch {expr {"a"-"b"}} msg] $msg
|
sl@0
|
377 |
} {1 {can't use non-numeric string as operand of "-"}}
|
sl@0
|
378 |
test compExpr-old-11.12 {CompileAddExpr: runtime error} {
|
sl@0
|
379 |
list [catch {expr {3/0}} msg] $msg
|
sl@0
|
380 |
} {1 {divide by zero}}
|
sl@0
|
381 |
test compExpr-old-11.13 {CompileAddExpr: runtime error} {
|
sl@0
|
382 |
list [catch {expr {2.3/0.0}} msg] $msg
|
sl@0
|
383 |
} {1 {divide by zero}}
|
sl@0
|
384 |
|
sl@0
|
385 |
test compExpr-old-12.1 {CompileMultiplyExpr: just unary expr} {expr ~4} -5
|
sl@0
|
386 |
test compExpr-old-12.2 {CompileMultiplyExpr: just unary expr} {expr --5} 5
|
sl@0
|
387 |
test compExpr-old-12.3 {CompileMultiplyExpr: just unary expr} {expr !27} 0
|
sl@0
|
388 |
test compExpr-old-12.4 {CompileMultiplyExpr: just unary expr} {expr ~0xff00ff} -16711936
|
sl@0
|
389 |
test compExpr-old-12.5 {CompileMultiplyExpr: error in unary expr} {
|
sl@0
|
390 |
catch {expr ~x} msg
|
sl@0
|
391 |
set msg
|
sl@0
|
392 |
} {syntax error in expression "~x": variable references require preceding $}
|
sl@0
|
393 |
test compExpr-old-12.6 {CompileMultiplyExpr: simple multiply exprs} {expr 0xff*0x3} 765
|
sl@0
|
394 |
test compExpr-old-12.7 {CompileMultiplyExpr: simple multiply exprs} {expr -0xf2%-0x3} -2
|
sl@0
|
395 |
test compExpr-old-12.8 {CompileMultiplyExpr: error compiling multiply arm} {
|
sl@0
|
396 |
catch {expr 2*3%%6} msg
|
sl@0
|
397 |
set msg
|
sl@0
|
398 |
} {syntax error in expression "2*3%%6": unexpected operator %}
|
sl@0
|
399 |
test compExpr-old-12.9 {CompileMultiplyExpr: error compiling multiply arm} {
|
sl@0
|
400 |
catch {expr 2*x} msg
|
sl@0
|
401 |
set msg
|
sl@0
|
402 |
} {syntax error in expression "2*x": variable references require preceding $}
|
sl@0
|
403 |
test compExpr-old-12.10 {CompileMultiplyExpr: runtime error} {
|
sl@0
|
404 |
list [catch {expr {24.0*"xx"}} msg] $msg
|
sl@0
|
405 |
} {1 {can't use non-numeric string as operand of "*"}}
|
sl@0
|
406 |
test compExpr-old-12.11 {CompileMultiplyExpr: runtime error} {
|
sl@0
|
407 |
list [catch {expr {"a"/"b"}} msg] $msg
|
sl@0
|
408 |
} {1 {can't use non-numeric string as operand of "/"}}
|
sl@0
|
409 |
|
sl@0
|
410 |
test compExpr-old-13.1 {CompileUnaryExpr: unary exprs} {expr -0xff} -255
|
sl@0
|
411 |
test compExpr-old-13.2 {CompileUnaryExpr: unary exprs} {expr +000123} 83
|
sl@0
|
412 |
test compExpr-old-13.3 {CompileUnaryExpr: unary exprs} {expr +--++36} 36
|
sl@0
|
413 |
test compExpr-old-13.4 {CompileUnaryExpr: unary exprs} {expr !2} 0
|
sl@0
|
414 |
test compExpr-old-13.5 {CompileUnaryExpr: unary exprs} {expr +--+-62.0} -62.0
|
sl@0
|
415 |
test compExpr-old-13.6 {CompileUnaryExpr: unary exprs} {expr !0.0} 1
|
sl@0
|
416 |
test compExpr-old-13.7 {CompileUnaryExpr: unary exprs} {expr !0xef} 0
|
sl@0
|
417 |
test compExpr-old-13.8 {CompileUnaryExpr: error compiling unary expr} {
|
sl@0
|
418 |
catch {expr ~x} msg
|
sl@0
|
419 |
set msg
|
sl@0
|
420 |
} {syntax error in expression "~x": variable references require preceding $}
|
sl@0
|
421 |
test compExpr-old-13.9 {CompileUnaryExpr: error compiling unary expr} {
|
sl@0
|
422 |
catch {expr !1.x} msg
|
sl@0
|
423 |
set msg
|
sl@0
|
424 |
} {syntax error in expression "!1.x": extra tokens at end of expression}
|
sl@0
|
425 |
test compExpr-old-13.10 {CompileUnaryExpr: runtime error} {
|
sl@0
|
426 |
list [catch {expr {~"xx"}} msg] $msg
|
sl@0
|
427 |
} {1 {can't use non-numeric string as operand of "~"}}
|
sl@0
|
428 |
test compExpr-old-13.11 {CompileUnaryExpr: runtime error} {
|
sl@0
|
429 |
list [catch {expr ~4.0} msg] $msg
|
sl@0
|
430 |
} {1 {can't use floating-point value as operand of "~"}}
|
sl@0
|
431 |
test compExpr-old-13.12 {CompileUnaryExpr: just primary expr} {expr 0x123} 291
|
sl@0
|
432 |
test compExpr-old-13.13 {CompileUnaryExpr: just primary expr} {
|
sl@0
|
433 |
set a 27
|
sl@0
|
434 |
expr $a
|
sl@0
|
435 |
} 27
|
sl@0
|
436 |
test compExpr-old-13.14 {CompileUnaryExpr: just primary expr} {
|
sl@0
|
437 |
expr double(27)
|
sl@0
|
438 |
} 27.0
|
sl@0
|
439 |
test compExpr-old-13.15 {CompileUnaryExpr: just primary expr} {expr "123"} 123
|
sl@0
|
440 |
test compExpr-old-13.16 {CompileUnaryExpr: error in primary expr} {
|
sl@0
|
441 |
catch {expr [set]} msg
|
sl@0
|
442 |
set msg
|
sl@0
|
443 |
} {wrong # args: should be "set varName ?newValue?"}
|
sl@0
|
444 |
test compExpr-old-14.1 {CompilePrimaryExpr: literal primary} {expr 1} 1
|
sl@0
|
445 |
test compExpr-old-14.2 {CompilePrimaryExpr: literal primary} {expr 123} 123
|
sl@0
|
446 |
test compExpr-old-14.3 {CompilePrimaryExpr: literal primary} {expr 0xff} 255
|
sl@0
|
447 |
test compExpr-old-14.4 {CompilePrimaryExpr: literal primary} {expr 00010} 8
|
sl@0
|
448 |
test compExpr-old-14.5 {CompilePrimaryExpr: literal primary} {expr 62.0} 62.0
|
sl@0
|
449 |
test compExpr-old-14.6 {CompilePrimaryExpr: literal primary} {
|
sl@0
|
450 |
expr 3.1400000
|
sl@0
|
451 |
} 3.14
|
sl@0
|
452 |
test compExpr-old-14.7 {CompilePrimaryExpr: literal primary} {expr {{abcde}<{abcdef}}} 1
|
sl@0
|
453 |
test compExpr-old-14.8 {CompilePrimaryExpr: literal primary} {expr {{abc\
|
sl@0
|
454 |
def} < {abcdef}}} 1
|
sl@0
|
455 |
test compExpr-old-14.9 {CompilePrimaryExpr: literal primary} {expr {{abc\tde} > {abc\tdef}}} 0
|
sl@0
|
456 |
test compExpr-old-14.10 {CompilePrimaryExpr: literal primary} {expr {{123}}} 123
|
sl@0
|
457 |
test compExpr-old-14.11 {CompilePrimaryExpr: var reference primary} {
|
sl@0
|
458 |
set i 789
|
sl@0
|
459 |
list [expr {$i}] [expr $i]
|
sl@0
|
460 |
} {789 789}
|
sl@0
|
461 |
test compExpr-old-14.12 {CompilePrimaryExpr: var reference primary} {
|
sl@0
|
462 |
set i {789} ;# test expr's aggressive conversion to numeric semantics
|
sl@0
|
463 |
list [expr {$i}] [expr $i]
|
sl@0
|
464 |
} {789 789}
|
sl@0
|
465 |
test compExpr-old-14.13 {CompilePrimaryExpr: var reference primary} {
|
sl@0
|
466 |
catch {unset a}
|
sl@0
|
467 |
set a(foo) foo
|
sl@0
|
468 |
set a(bar) bar
|
sl@0
|
469 |
set a(123) 123
|
sl@0
|
470 |
set result ""
|
sl@0
|
471 |
lappend result [expr $a(123)] [expr {$a(bar)<$a(foo)}]
|
sl@0
|
472 |
catch {unset a}
|
sl@0
|
473 |
set result
|
sl@0
|
474 |
} {123 1}
|
sl@0
|
475 |
test compExpr-old-14.14 {CompilePrimaryExpr: var reference primary} {
|
sl@0
|
476 |
set i 123 ;# test "$var.0" floating point conversion hack
|
sl@0
|
477 |
list [expr $i] [expr $i.0] [expr $i.0/12.0]
|
sl@0
|
478 |
} {123 123.0 10.25}
|
sl@0
|
479 |
test compExpr-old-14.15 {CompilePrimaryExpr: var reference primary} {
|
sl@0
|
480 |
set i 123
|
sl@0
|
481 |
catch {expr $i.2} msg
|
sl@0
|
482 |
set msg
|
sl@0
|
483 |
} 123.2
|
sl@0
|
484 |
test compExpr-old-14.16 {CompilePrimaryExpr: error compiling var reference primary} {
|
sl@0
|
485 |
catch {expr {$a(foo}} msg
|
sl@0
|
486 |
set errorInfo
|
sl@0
|
487 |
} {missing )
|
sl@0
|
488 |
while compiling
|
sl@0
|
489 |
"expr {$a(foo}"}
|
sl@0
|
490 |
test compExpr-old-14.17 {CompilePrimaryExpr: string primary that looks like var ref} {
|
sl@0
|
491 |
expr $
|
sl@0
|
492 |
} $
|
sl@0
|
493 |
test compExpr-old-14.18 {CompilePrimaryExpr: quoted string primary} {
|
sl@0
|
494 |
expr "21"
|
sl@0
|
495 |
} 21
|
sl@0
|
496 |
test compExpr-old-14.19 {CompilePrimaryExpr: quoted string primary} {
|
sl@0
|
497 |
set i 123
|
sl@0
|
498 |
set x 456
|
sl@0
|
499 |
expr "$i+$x"
|
sl@0
|
500 |
} 579
|
sl@0
|
501 |
test compExpr-old-14.20 {CompilePrimaryExpr: quoted string primary} {
|
sl@0
|
502 |
set i 3
|
sl@0
|
503 |
set x 6
|
sl@0
|
504 |
expr 2+"$i.$x"
|
sl@0
|
505 |
} 5.6
|
sl@0
|
506 |
test compExpr-old-14.21 {CompilePrimaryExpr: error in quoted string primary} {
|
sl@0
|
507 |
catch {expr "[set]"} msg
|
sl@0
|
508 |
set msg
|
sl@0
|
509 |
} {wrong # args: should be "set varName ?newValue?"}
|
sl@0
|
510 |
test compExpr-old-14.22 {CompilePrimaryExpr: subcommand primary} {
|
sl@0
|
511 |
expr {[set i 123; set i]}
|
sl@0
|
512 |
} 123
|
sl@0
|
513 |
test compExpr-old-14.23 {CompilePrimaryExpr: error in subcommand primary} {
|
sl@0
|
514 |
catch {expr {[set]}} msg
|
sl@0
|
515 |
set errorInfo
|
sl@0
|
516 |
} {wrong # args: should be "set varName ?newValue?"
|
sl@0
|
517 |
while compiling
|
sl@0
|
518 |
"set"
|
sl@0
|
519 |
while compiling
|
sl@0
|
520 |
"expr {[set]}"}
|
sl@0
|
521 |
test compExpr-old-14.24 {CompilePrimaryExpr: error in subcommand primary} {
|
sl@0
|
522 |
catch {expr {[set i}} msg
|
sl@0
|
523 |
set errorInfo
|
sl@0
|
524 |
} {missing close-bracket
|
sl@0
|
525 |
while compiling
|
sl@0
|
526 |
"expr {[set i}"}
|
sl@0
|
527 |
test compExpr-old-14.25 {CompilePrimaryExpr: math function primary} {
|
sl@0
|
528 |
format %.6g [expr exp(1.0)]
|
sl@0
|
529 |
} 2.71828
|
sl@0
|
530 |
test compExpr-old-14.26 {CompilePrimaryExpr: math function primary} {
|
sl@0
|
531 |
format %.6g [expr pow(2.0+0.1,3.0+0.1)]
|
sl@0
|
532 |
} 9.97424
|
sl@0
|
533 |
test compExpr-old-14.27 {CompilePrimaryExpr: error in math function primary} {
|
sl@0
|
534 |
catch {expr sinh::(2.0)} msg
|
sl@0
|
535 |
set errorInfo
|
sl@0
|
536 |
} {syntax error in expression "sinh::(2.0)": expected parenthesis enclosing function arguments
|
sl@0
|
537 |
while compiling
|
sl@0
|
538 |
"expr sinh::(2.0)"}
|
sl@0
|
539 |
test compExpr-old-14.28 {CompilePrimaryExpr: subexpression primary} {
|
sl@0
|
540 |
expr 2+(3*4)
|
sl@0
|
541 |
} 14
|
sl@0
|
542 |
test compExpr-old-14.29 {CompilePrimaryExpr: error in subexpression primary} {
|
sl@0
|
543 |
catch {expr 2+(3*[set])} msg
|
sl@0
|
544 |
set errorInfo
|
sl@0
|
545 |
} {wrong # args: should be "set varName ?newValue?"
|
sl@0
|
546 |
while compiling
|
sl@0
|
547 |
"set"
|
sl@0
|
548 |
while compiling
|
sl@0
|
549 |
"expr 2+(3*[set])"}
|
sl@0
|
550 |
test compExpr-old-14.30 {CompilePrimaryExpr: missing paren in subexpression primary} {
|
sl@0
|
551 |
catch {expr 2+(3*(4+5)} msg
|
sl@0
|
552 |
set errorInfo
|
sl@0
|
553 |
} {syntax error in expression "2+(3*(4+5)": looking for close parenthesis
|
sl@0
|
554 |
while compiling
|
sl@0
|
555 |
"expr 2+(3*(4+5)"}
|
sl@0
|
556 |
test compExpr-old-14.31 {CompilePrimaryExpr: just var ref in subexpression primary} {
|
sl@0
|
557 |
set i "5+10"
|
sl@0
|
558 |
list "[expr $i] == 15" "[expr ($i)] == 15" "[eval expr ($i)] == 15"
|
sl@0
|
559 |
} {{15 == 15} {15 == 15} {15 == 15}}
|
sl@0
|
560 |
test compExpr-old-14.32 {CompilePrimaryExpr: unexpected token} {
|
sl@0
|
561 |
catch {expr @} msg
|
sl@0
|
562 |
set errorInfo
|
sl@0
|
563 |
} {syntax error in expression "@": character not legal in expressions
|
sl@0
|
564 |
while compiling
|
sl@0
|
565 |
"expr @"}
|
sl@0
|
566 |
|
sl@0
|
567 |
test compExpr-old-15.1 {CompileMathFuncCall: missing parenthesis} {
|
sl@0
|
568 |
catch {expr sinh2.0)} msg
|
sl@0
|
569 |
set errorInfo
|
sl@0
|
570 |
} {syntax error in expression "sinh2.0)": variable references require preceding $
|
sl@0
|
571 |
while compiling
|
sl@0
|
572 |
"expr sinh2.0)"}
|
sl@0
|
573 |
test compExpr-old-15.2 {CompileMathFuncCall: unknown math function} {
|
sl@0
|
574 |
catch {expr whazzathuh(1)} msg
|
sl@0
|
575 |
set errorInfo
|
sl@0
|
576 |
} {unknown math function "whazzathuh"
|
sl@0
|
577 |
while compiling
|
sl@0
|
578 |
"expr whazzathuh(1)"}
|
sl@0
|
579 |
test compExpr-old-15.3 {CompileMathFuncCall: too many arguments} {
|
sl@0
|
580 |
catch {expr sin(1,2,3)} msg
|
sl@0
|
581 |
set errorInfo
|
sl@0
|
582 |
} {too many arguments for math function
|
sl@0
|
583 |
while compiling
|
sl@0
|
584 |
"expr sin(1,2,3)"}
|
sl@0
|
585 |
test compExpr-old-15.4 {CompileMathFuncCall: ')' found before last required arg} {
|
sl@0
|
586 |
catch {expr sin()} msg
|
sl@0
|
587 |
set errorInfo
|
sl@0
|
588 |
} {too few arguments for math function
|
sl@0
|
589 |
while compiling
|
sl@0
|
590 |
"expr sin()"}
|
sl@0
|
591 |
test compExpr-old-15.5 {CompileMathFuncCall: too few arguments} {
|
sl@0
|
592 |
catch {expr pow(1)} msg
|
sl@0
|
593 |
set errorInfo
|
sl@0
|
594 |
} {too few arguments for math function
|
sl@0
|
595 |
while compiling
|
sl@0
|
596 |
"expr pow(1)"}
|
sl@0
|
597 |
test compExpr-old-15.6 {CompileMathFuncCall: missing ')'} {
|
sl@0
|
598 |
catch {expr sin(1} msg
|
sl@0
|
599 |
set errorInfo
|
sl@0
|
600 |
} {syntax error in expression "sin(1": missing close parenthesis at end of function call
|
sl@0
|
601 |
while compiling
|
sl@0
|
602 |
"expr sin(1"}
|
sl@0
|
603 |
if $gotT1 {
|
sl@0
|
604 |
test compExpr-old-15.7 {CompileMathFuncCall: call registered math function} {
|
sl@0
|
605 |
expr 2*T1()
|
sl@0
|
606 |
} 246
|
sl@0
|
607 |
test compExpr-old-15.8 {CompileMathFuncCall: call registered math function} {
|
sl@0
|
608 |
expr T2()*3
|
sl@0
|
609 |
} 1035
|
sl@0
|
610 |
|
sl@0
|
611 |
test compExpr-old-15.9 {CompileMathFuncCall: call registered math function} {
|
sl@0
|
612 |
expr T3(21, 37)
|
sl@0
|
613 |
} 37
|
sl@0
|
614 |
test compExpr-old-15.10 {CompileMathFuncCall: call registered math function} {
|
sl@0
|
615 |
expr T3(21.2, 37)
|
sl@0
|
616 |
} 37.0
|
sl@0
|
617 |
test compExpr-old-15.11 {CompileMathFuncCall: call registered math function} {
|
sl@0
|
618 |
expr T3(-21.2, -17.5)
|
sl@0
|
619 |
} -17.5
|
sl@0
|
620 |
}
|
sl@0
|
621 |
|
sl@0
|
622 |
test compExpr-old-16.1 {GetToken: checks whether integer token starting with "0x" (e.g., "0x$") is invalid} {
|
sl@0
|
623 |
catch {unset a}
|
sl@0
|
624 |
set a(VALUE) ff15
|
sl@0
|
625 |
set i 123
|
sl@0
|
626 |
if {[expr 0x$a(VALUE)] & 16} {
|
sl@0
|
627 |
set i {}
|
sl@0
|
628 |
}
|
sl@0
|
629 |
set i
|
sl@0
|
630 |
} {}
|
sl@0
|
631 |
test compExpr-old-16.2 {GetToken: check for string literal in braces} {
|
sl@0
|
632 |
expr {{1}}
|
sl@0
|
633 |
} {1}
|
sl@0
|
634 |
|
sl@0
|
635 |
# Check "expr" and computed command names.
|
sl@0
|
636 |
|
sl@0
|
637 |
test compExpr-old-17.1 {expr and computed command names} {
|
sl@0
|
638 |
set i 0
|
sl@0
|
639 |
set z expr
|
sl@0
|
640 |
$z 1+2
|
sl@0
|
641 |
} 3
|
sl@0
|
642 |
|
sl@0
|
643 |
# Check correct conversion of operands to numbers: If the string looks like
|
sl@0
|
644 |
# an integer, convert to integer. Otherwise, if the string looks like a
|
sl@0
|
645 |
# double, convert to double.
|
sl@0
|
646 |
|
sl@0
|
647 |
test compExpr-old-18.1 {expr and conversion of operands to numbers} {
|
sl@0
|
648 |
set x [lindex 11 0]
|
sl@0
|
649 |
catch {expr int($x)}
|
sl@0
|
650 |
expr {$x}
|
sl@0
|
651 |
} 11
|
sl@0
|
652 |
|
sl@0
|
653 |
# Check "expr" and interpreter result object resetting before appending
|
sl@0
|
654 |
# an error msg during evaluation of exprs not in {}s
|
sl@0
|
655 |
|
sl@0
|
656 |
test compExpr-old-19.1 {expr and interpreter result object resetting} {
|
sl@0
|
657 |
proc p {} {
|
sl@0
|
658 |
set t 10.0
|
sl@0
|
659 |
set x 2.0
|
sl@0
|
660 |
set dx 0.2
|
sl@0
|
661 |
set f {$dx-$x/10}
|
sl@0
|
662 |
set g {-$x/5}
|
sl@0
|
663 |
set center 1.0
|
sl@0
|
664 |
set x [expr $x-$center]
|
sl@0
|
665 |
set dx [expr $dx+$g]
|
sl@0
|
666 |
set x [expr $x+$f+$center]
|
sl@0
|
667 |
set x [expr $x+$f+$center]
|
sl@0
|
668 |
set y [expr round($x)]
|
sl@0
|
669 |
}
|
sl@0
|
670 |
p
|
sl@0
|
671 |
} 3
|
sl@0
|
672 |
|
sl@0
|
673 |
# cleanup
|
sl@0
|
674 |
if {[info exists a]} {
|
sl@0
|
675 |
unset a
|
sl@0
|
676 |
}
|
sl@0
|
677 |
::tcltest::cleanupTests
|
sl@0
|
678 |
return
|