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