os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/parseExpr.test
First public contribution.
1 # This file contains a collection of tests for the procedures in the
2 # file tclParseExpr.c. Sourcing this file into Tcl runs the tests and
3 # generates output for errors. No output means no errors were found.
5 # Copyright (c) 1997 Sun Microsystems, Inc.
6 # Copyright (c) 1998-1999 by Scriptics Corporation.
8 # See the file "license.terms" for information on usage and redistribution
9 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 # RCS: @(#) $Id: parseExpr.test,v 1.10.2.1 2003/10/06 13:55:39 dgp Exp $
13 if {[lsearch [namespace children] ::tcltest] == -1} {
14 package require tcltest 2
15 namespace import -force ::tcltest::*
18 # Note that the Tcl expression parser (tclParseExpr.c) does not check
19 # the semantic validity of the expressions it parses. It does not check,
20 # for example, that a math function actually exists, or that the operands
21 # of "<<" are integers.
23 if {[info commands testexprparser] == {}} {
24 puts "This application hasn't been compiled with the \"testexprparser\""
25 puts "command, so I can't test the Tcl expression parser."
26 ::tcltest::cleanupTests
30 # Some tests only work if wide integers (>32bit) are not found to be
32 set ::tcltest::testConstraints(wideIntegerUnparsed) \
33 [expr {-1 == 0xffffffff}]
35 test parseExpr-1.1 {Tcl_ParseExpr procedure, computing string length} {
36 testexprparser [bytestring "1+2\0 +3"] -1
37 } {- {} 0 subexpr 1+2 5 operator + 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 {}}
38 test parseExpr-1.2 {Tcl_ParseExpr procedure, computing string length} {
39 testexprparser "1 + 2" -1
40 } {- {} 0 subexpr {1 + 2} 5 operator + 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 {}}
41 test parseExpr-1.3 {Tcl_ParseExpr procedure, error getting initial lexeme} {wideIntegerUnparsed} {
42 list [catch {testexprparser {12345678901234567890} -1} msg] $msg
43 } {1 {integer value too large to represent}}
44 test parseExpr-1.4 {Tcl_ParseExpr procedure, error in conditional expression} {
45 list [catch {testexprparser {foo+} -1} msg] $msg
46 } {1 {syntax error in expression "foo+": variable references require preceding $}}
47 test parseExpr-1.5 {Tcl_ParseExpr procedure, lexemes after the expression} {
48 list [catch {testexprparser {1+2 345} -1} msg] $msg
49 } {1 {syntax error in expression "1+2 345": extra tokens at end of expression}}
51 test parseExpr-2.1 {ParseCondExpr procedure, valid test subexpr} {
52 testexprparser {2>3? 1 : 0} -1
53 } {- {} 0 subexpr {2>3? 1 : 0} 11 operator ? 0 subexpr 2>3 5 operator > 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 subexpr 1 1 text 1 0 subexpr 0 1 text 0 0 {}}
54 test parseExpr-2.2 {ParseCondExpr procedure, error in test subexpr} {
55 list [catch {testexprparser {0 || foo} -1} msg] $msg
56 } {1 {syntax error in expression "0 || foo": variable references require preceding $}}
57 test parseExpr-2.3 {ParseCondExpr procedure, next lexeme isn't "?"} {
58 testexprparser {1+2} -1
59 } {- {} 0 subexpr 1+2 5 operator + 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 {}}
60 test parseExpr-2.4 {ParseCondExpr procedure, next lexeme is "?"} {
61 testexprparser {1+2 ? 3 : 4} -1
62 } {- {} 0 subexpr {1+2 ? 3 : 4} 11 operator ? 0 subexpr 1+2 5 operator + 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 subexpr 4 1 text 4 0 {}}
63 test parseExpr-2.5 {ParseCondExpr procedure, bad lexeme after "?"} {wideIntegerUnparsed} {
64 list [catch {testexprparser {1+2 ? 12345678901234567890} -1} msg] $msg
65 } {1 {integer value too large to represent}}
66 test parseExpr-2.6 {ParseCondExpr procedure, valid "then" subexpression} {
67 testexprparser {1? 3 : 4} -1
68 } {- {} 0 subexpr {1? 3 : 4} 7 operator ? 0 subexpr 1 1 text 1 0 subexpr 3 1 text 3 0 subexpr 4 1 text 4 0 {}}
69 test parseExpr-2.7 {ParseCondExpr procedure, error in "then" subexpression} {
70 list [catch {testexprparser {1? fred : martha} -1} msg] $msg
71 } {1 {syntax error in expression "1? fred : martha": variable references require preceding $}}
72 test parseExpr-2.8 {ParseCondExpr procedure, lexeme after "then" subexpr isn't ":"} {
73 list [catch {testexprparser {1? 2 martha 3} -1} msg] $msg
74 } {1 {syntax error in expression "1? 2 martha 3": missing colon from ternary conditional}}
75 test parseExpr-2.9 {ParseCondExpr procedure, valid "else" subexpression} {
76 testexprparser {27||3? 3 : 4&&9} -1
77 } {- {} 0 subexpr {27||3? 3 : 4&&9} 15 operator ? 0 subexpr 27||3 5 operator || 0 subexpr 27 1 text 27 0 subexpr 3 1 text 3 0 subexpr 3 1 text 3 0 subexpr 4&&9 5 operator && 0 subexpr 4 1 text 4 0 subexpr 9 1 text 9 0 {}}
78 test parseExpr-2.10 {ParseCondExpr procedure, error in "else" subexpression} {
79 list [catch {testexprparser {1? 2 : martha} -1} msg] $msg
80 } {1 {syntax error in expression "1? 2 : martha": variable references require preceding $}}
82 test parseExpr-3.1 {ParseLorExpr procedure, valid logical and subexpr} {
83 testexprparser {1&&2 || 3} -1
84 } {- {} 0 subexpr {1&&2 || 3} 9 operator || 0 subexpr 1&&2 5 operator && 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
85 test parseExpr-3.2 {ParseLorExpr procedure, error in logical and subexpr} {
86 list [catch {testexprparser {1&&foo || 3} -1} msg] $msg
87 } {1 {syntax error in expression "1&&foo || 3": variable references require preceding $}}
88 test parseExpr-3.3 {ParseLorExpr procedure, next lexeme isn't "||"} {
89 testexprparser {1&&2? 1 : 0} -1
90 } {- {} 0 subexpr {1&&2? 1 : 0} 11 operator ? 0 subexpr 1&&2 5 operator && 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 1 1 text 1 0 subexpr 0 1 text 0 0 {}}
91 test parseExpr-3.4 {ParseLorExpr procedure, next lexeme is "||"} {
92 testexprparser {1&&2 || 3} -1
93 } {- {} 0 subexpr {1&&2 || 3} 9 operator || 0 subexpr 1&&2 5 operator && 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
94 test parseExpr-3.5 {ParseLorExpr procedure, bad lexeme after "||"} {wideIntegerUnparsed} {
95 list [catch {testexprparser {1&&2 || 12345678901234567890} -1} msg] $msg
96 } {1 {integer value too large to represent}}
97 test parseExpr-3.6 {ParseLorExpr procedure, valid RHS subexpression} {
98 testexprparser {1&&2 || 3 || 4} -1
99 } {- {} 0 subexpr {1&&2 || 3 || 4} 13 operator || 0 subexpr {1&&2 || 3} 9 operator || 0 subexpr 1&&2 5 operator && 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 subexpr 4 1 text 4 0 {}}
100 test parseExpr-3.7 {ParseLorExpr procedure, error in RHS subexpression} {
101 list [catch {testexprparser {1&&2 || 3 || martha} -1} msg] $msg
102 } {1 {syntax error in expression "1&&2 || 3 || martha": variable references require preceding $}}
104 test parseExpr-4.1 {ParseLandExpr procedure, valid LHS "|" subexpr} {
105 testexprparser {1|2 && 3} -1
106 } {- {} 0 subexpr {1|2 && 3} 9 operator && 0 subexpr 1|2 5 operator | 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
107 test parseExpr-4.2 {ParseLandExpr procedure, error in LHS "|" subexpr} {
108 list [catch {testexprparser {1&&foo && 3} -1} msg] $msg
109 } {1 {syntax error in expression "1&&foo && 3": variable references require preceding $}}
110 test parseExpr-4.3 {ParseLandExpr procedure, next lexeme isn't "&&"} {
111 testexprparser {1|2? 1 : 0} -1
112 } {- {} 0 subexpr {1|2? 1 : 0} 11 operator ? 0 subexpr 1|2 5 operator | 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 1 1 text 1 0 subexpr 0 1 text 0 0 {}}
113 test parseExpr-4.4 {ParseLandExpr procedure, next lexeme is "&&"} {
114 testexprparser {1|2 && 3} -1
115 } {- {} 0 subexpr {1|2 && 3} 9 operator && 0 subexpr 1|2 5 operator | 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
116 test parseExpr-4.5 {ParseLandExpr procedure, bad lexeme after "&&"} {wideIntegerUnparsed} {
117 list [catch {testexprparser {1|2 && 12345678901234567890} -1} msg] $msg
118 } {1 {integer value too large to represent}}
119 test parseExpr-4.6 {ParseLandExpr procedure, valid RHS subexpression} {
120 testexprparser {1|2 && 3 && 4} -1
121 } {- {} 0 subexpr {1|2 && 3 && 4} 13 operator && 0 subexpr {1|2 && 3} 9 operator && 0 subexpr 1|2 5 operator | 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 subexpr 4 1 text 4 0 {}}
122 test parseExpr-4.7 {ParseLandExpr procedure, error in RHS subexpression} {
123 list [catch {testexprparser {1|2 && 3 && martha} -1} msg] $msg
124 } {1 {syntax error in expression "1|2 && 3 && martha": variable references require preceding $}}
126 test parseExpr-5.1 {ParseBitOrExpr procedure, valid LHS "^" subexpr} {
127 testexprparser {1^2 | 3} -1
128 } {- {} 0 subexpr {1^2 | 3} 9 operator | 0 subexpr 1^2 5 operator ^ 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
129 test parseExpr-5.2 {ParseBitOrExpr procedure, error in LHS "^" subexpr} {
130 list [catch {testexprparser {1|foo | 3} -1} msg] $msg
131 } {1 {syntax error in expression "1|foo | 3": variable references require preceding $}}
132 test parseExpr-5.3 {ParseBitOrExpr procedure, next lexeme isn't "|"} {
133 testexprparser {1^2? 1 : 0} -1
134 } {- {} 0 subexpr {1^2? 1 : 0} 11 operator ? 0 subexpr 1^2 5 operator ^ 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 1 1 text 1 0 subexpr 0 1 text 0 0 {}}
135 test parseExpr-5.4 {ParseBitOrExpr procedure, next lexeme is "|"} {
136 testexprparser {1^2 | 3} -1
137 } {- {} 0 subexpr {1^2 | 3} 9 operator | 0 subexpr 1^2 5 operator ^ 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
138 test parseExpr-5.5 {ParseBitOrExpr procedure, bad lexeme after "|"} {wideIntegerUnparsed} {
139 list [catch {testexprparser {1^2 | 12345678901234567890} -1} msg] $msg
140 } {1 {integer value too large to represent}}
141 test parseExpr-5.6 {ParseBitOrExpr procedure, valid RHS subexpression} {
142 testexprparser {1^2 | 3 | 4} -1
143 } {- {} 0 subexpr {1^2 | 3 | 4} 13 operator | 0 subexpr {1^2 | 3} 9 operator | 0 subexpr 1^2 5 operator ^ 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 subexpr 4 1 text 4 0 {}}
144 test parseExpr-5.7 {ParseBitOrExpr procedure, error in RHS subexpression} {
145 list [catch {testexprparser {1^2 | 3 | martha} -1} msg] $msg
146 } {1 {syntax error in expression "1^2 | 3 | martha": variable references require preceding $}}
148 test parseExpr-6.1 {ParseBitXorExpr procedure, valid LHS "&" subexpr} {
149 testexprparser {1&2 ^ 3} -1
150 } {- {} 0 subexpr {1&2 ^ 3} 9 operator ^ 0 subexpr 1&2 5 operator & 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
151 test parseExpr-6.2 {ParseBitXorExpr procedure, error in LHS "&" subexpr} {
152 list [catch {testexprparser {1^foo ^ 3} -1} msg] $msg
153 } {1 {syntax error in expression "1^foo ^ 3": variable references require preceding $}}
154 test parseExpr-6.3 {ParseBitXorExpr procedure, next lexeme isn't "^"} {
155 testexprparser {1&2? 1 : 0} -1
156 } {- {} 0 subexpr {1&2? 1 : 0} 11 operator ? 0 subexpr 1&2 5 operator & 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 1 1 text 1 0 subexpr 0 1 text 0 0 {}}
157 test parseExpr-6.4 {ParseBitXorExpr procedure, next lexeme is "^"} {
158 testexprparser {1&2 ^ 3} -1
159 } {- {} 0 subexpr {1&2 ^ 3} 9 operator ^ 0 subexpr 1&2 5 operator & 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
160 test parseExpr-6.5 {ParseBitXorExpr procedure, bad lexeme after "^"} {wideIntegerUnparsed} {
161 list [catch {testexprparser {1&2 ^ 12345678901234567890} -1} msg] $msg
162 } {1 {integer value too large to represent}}
163 test parseExpr-6.6 {ParseBitXorExpr procedure, valid RHS subexpression} {
164 testexprparser {1&2 ^ 3 ^ 4} -1
165 } {- {} 0 subexpr {1&2 ^ 3 ^ 4} 13 operator ^ 0 subexpr {1&2 ^ 3} 9 operator ^ 0 subexpr 1&2 5 operator & 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 subexpr 4 1 text 4 0 {}}
166 test parseExpr-6.7 {ParseBitXorExpr procedure, error in RHS subexpression} {
167 list [catch {testexprparser {1&2 ^ 3 ^ martha} -1} msg] $msg
168 } {1 {syntax error in expression "1&2 ^ 3 ^ martha": variable references require preceding $}}
170 test parseExpr-7.1 {ParseBitAndExpr procedure, valid LHS equality subexpr} {
171 testexprparser {1==2 & 3} -1
172 } {- {} 0 subexpr {1==2 & 3} 9 operator & 0 subexpr 1==2 5 operator == 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
173 test parseExpr-7.2 {ParseBitAndExpr procedure, error in LHS equality subexpr} {
174 list [catch {testexprparser {1!=foo & 3} -1} msg] $msg
175 } {1 {syntax error in expression "1!=foo & 3": variable references require preceding $}}
176 test parseExpr-7.3 {ParseBitAndExpr procedure, next lexeme isn't "&"} {
177 testexprparser {1==2? 1 : 0} -1
178 } {- {} 0 subexpr {1==2? 1 : 0} 11 operator ? 0 subexpr 1==2 5 operator == 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 1 1 text 1 0 subexpr 0 1 text 0 0 {}}
179 test parseExpr-7.4 {ParseBitAndExpr procedure, next lexeme is "&"} {
180 testexprparser {1>2 & 3} -1
181 } {- {} 0 subexpr {1>2 & 3} 9 operator & 0 subexpr 1>2 5 operator > 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
182 test parseExpr-7.5 {ParseBitAndExpr procedure, bad lexeme after "&"} {wideIntegerUnparsed} {
183 list [catch {testexprparser {1==2 & 12345678901234567890} -1} msg] $msg
184 } {1 {integer value too large to represent}}
185 test parseExpr-7.6 {ParseBitAndExpr procedure, valid RHS subexpression} {
186 testexprparser {1<2 & 3 & 4} -1
187 } {- {} 0 subexpr {1<2 & 3 & 4} 13 operator & 0 subexpr {1<2 & 3} 9 operator & 0 subexpr 1<2 5 operator < 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 subexpr 4 1 text 4 0 {}}
188 test parseExpr-7.7 {ParseBitAndExpr procedure, error in RHS subexpression} {
189 list [catch {testexprparser {1==2 & 3>2 & martha} -1} msg] $msg
190 } {1 {syntax error in expression "1==2 & 3>2 & martha": variable references require preceding $}}
192 test parseExpr-8.1 {ParseEqualityExpr procedure, valid LHS relational subexpr} {
193 testexprparser {1<2 == 3} -1
194 } {- {} 0 subexpr {1<2 == 3} 9 operator == 0 subexpr 1<2 5 operator < 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
195 test parseExpr-8.2 {ParseEqualityExpr procedure, error in LHS relational subexpr} {
196 list [catch {testexprparser {1>=foo == 3} -1} msg] $msg
197 } {1 {syntax error in expression "1>=foo == 3": variable references require preceding $}}
198 test parseExpr-8.3 {ParseEqualityExpr procedure, next lexeme isn't "==" or "!="} {
199 testexprparser {1<2? 1 : 0} -1
200 } {- {} 0 subexpr {1<2? 1 : 0} 11 operator ? 0 subexpr 1<2 5 operator < 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 1 1 text 1 0 subexpr 0 1 text 0 0 {}}
201 test parseExpr-8.4 {ParseEqualityExpr procedure, next lexeme is "==" or "!="} {
202 testexprparser {1<2 == 3} -1
203 } {- {} 0 subexpr {1<2 == 3} 9 operator == 0 subexpr 1<2 5 operator < 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
204 test parseExpr-8.5 {ParseEqualityExpr procedure, next lexeme is "==" or "!="} {
205 testexprparser {1<2 != 3} -1
206 } {- {} 0 subexpr {1<2 != 3} 9 operator != 0 subexpr 1<2 5 operator < 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
207 test parseExpr-8.6 {ParseEqualityExpr procedure, bad lexeme after "==" or "!="} {wideIntegerUnparsed} {
208 list [catch {testexprparser {1<2 == 12345678901234567890} -1} msg] $msg
209 } {1 {integer value too large to represent}}
210 test parseExpr-8.7 {ParseEqualityExpr procedure, valid RHS subexpression} {
211 testexprparser {1<2 == 3 == 4} -1
212 } {- {} 0 subexpr {1<2 == 3 == 4} 13 operator == 0 subexpr {1<2 == 3} 9 operator == 0 subexpr 1<2 5 operator < 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 subexpr 4 1 text 4 0 {}}
213 test parseExpr-8.8 {ParseEqualityExpr procedure, error in RHS subexpression} {
214 list [catch {testexprparser {1<2 == 3 != martha} -1} msg] $msg
215 } {1 {syntax error in expression "1<2 == 3 != martha": variable references require preceding $}}
217 test parseExpr-9.1 {ParseRelationalExpr procedure, valid LHS shift subexpr} {
218 testexprparser {1<<2 < 3} -1
219 } {- {} 0 subexpr {1<<2 < 3} 9 operator < 0 subexpr 1<<2 5 operator << 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
220 test parseExpr-9.2 {ParseRelationalExpr procedure, error in LHS shift subexpr} {
221 list [catch {testexprparser {1>=foo < 3} -1} msg] $msg
222 } {1 {syntax error in expression "1>=foo < 3": variable references require preceding $}}
223 test parseExpr-9.3 {ParseRelationalExpr procedure, next lexeme isn't relational op} {
224 testexprparser {1<<2? 1 : 0} -1
225 } {- {} 0 subexpr {1<<2? 1 : 0} 11 operator ? 0 subexpr 1<<2 5 operator << 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 1 1 text 1 0 subexpr 0 1 text 0 0 {}}
226 test parseExpr-9.4 {ParseRelationalExpr procedure, next lexeme is relational op} {
227 testexprparser {1<<2 < 3} -1
228 } {- {} 0 subexpr {1<<2 < 3} 9 operator < 0 subexpr 1<<2 5 operator << 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
229 test parseExpr-9.5 {ParseRelationalExpr procedure, next lexeme is relational op} {
230 testexprparser {1>>2 > 3} -1
231 } {- {} 0 subexpr {1>>2 > 3} 9 operator > 0 subexpr 1>>2 5 operator >> 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
232 test parseExpr-9.6 {ParseRelationalExpr procedure, next lexeme is relational op} {
233 testexprparser {1<<2 <= 3} -1
234 } {- {} 0 subexpr {1<<2 <= 3} 9 operator <= 0 subexpr 1<<2 5 operator << 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
235 test parseExpr-9.7 {ParseRelationalExpr procedure, next lexeme is relational op} {
236 testexprparser {1<<2 >= 3} -1
237 } {- {} 0 subexpr {1<<2 >= 3} 9 operator >= 0 subexpr 1<<2 5 operator << 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
238 test parseExpr-9.8 {ParseRelationalExpr procedure, bad lexeme after relational op} {wideIntegerUnparsed} {
239 list [catch {testexprparser {1<<2 < 12345678901234567890} -1} msg] $msg
240 } {1 {integer value too large to represent}}
241 test parseExpr-9.9 {ParseRelationalExpr procedure, valid RHS subexpression} {
242 testexprparser {1<<2 < 3 < 4} -1
243 } {- {} 0 subexpr {1<<2 < 3 < 4} 13 operator < 0 subexpr {1<<2 < 3} 9 operator < 0 subexpr 1<<2 5 operator << 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 subexpr 4 1 text 4 0 {}}
244 test parseExpr-9.10 {ParseRelationalExpr procedure, error in RHS subexpression} {
245 list [catch {testexprparser {1<<2 < 3 > martha} -1} msg] $msg
246 } {1 {syntax error in expression "1<<2 < 3 > martha": variable references require preceding $}}
248 test parseExpr-10.1 {ParseShiftExpr procedure, valid LHS add subexpr} {
249 testexprparser {1+2 << 3} -1
250 } {- {} 0 subexpr {1+2 << 3} 9 operator << 0 subexpr 1+2 5 operator + 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
251 test parseExpr-10.2 {ParseShiftExpr procedure, error in LHS add subexpr} {
252 list [catch {testexprparser {1-foo << 3} -1} msg] $msg
253 } {1 {syntax error in expression "1-foo << 3": variable references require preceding $}}
254 test parseExpr-10.3 {ParseShiftExpr procedure, next lexeme isn't "<<" or ">>"} {
255 testexprparser {1+2? 1 : 0} -1
256 } {- {} 0 subexpr {1+2? 1 : 0} 11 operator ? 0 subexpr 1+2 5 operator + 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 1 1 text 1 0 subexpr 0 1 text 0 0 {}}
257 test parseExpr-10.4 {ParseShiftExpr procedure, next lexeme is "<<" or ">>"} {
258 testexprparser {1+2 << 3} -1
259 } {- {} 0 subexpr {1+2 << 3} 9 operator << 0 subexpr 1+2 5 operator + 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
260 test parseExpr-10.5 {ParseShiftExpr procedure, next lexeme is "<<" or ">>"} {
261 testexprparser {1+2 >> 3} -1
262 } {- {} 0 subexpr {1+2 >> 3} 9 operator >> 0 subexpr 1+2 5 operator + 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
263 test parseExpr-10.6 {ParseShiftExpr procedure, bad lexeme after "<<" or ">>"} {wideIntegerUnparsed} {
264 list [catch {testexprparser {1+2 << 12345678901234567890} -1} msg] $msg
265 } {1 {integer value too large to represent}}
266 test parseExpr-10.7 {ParseShiftExpr procedure, valid RHS subexpression} {
267 testexprparser {1+2 << 3 << 4} -1
268 } {- {} 0 subexpr {1+2 << 3 << 4} 13 operator << 0 subexpr {1+2 << 3} 9 operator << 0 subexpr 1+2 5 operator + 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 subexpr 4 1 text 4 0 {}}
269 test parseExpr-10.8 {ParseShiftExpr procedure, error in RHS subexpression} {
270 list [catch {testexprparser {1+2 << 3 >> martha} -1} msg] $msg
271 } {1 {syntax error in expression "1+2 << 3 >> martha": variable references require preceding $}}
273 test parseExpr-11.1 {ParseAddExpr procedure, valid LHS multiply subexpr} {
274 testexprparser {1*2 + 3} -1
275 } {- {} 0 subexpr {1*2 + 3} 9 operator + 0 subexpr 1*2 5 operator * 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
276 test parseExpr-11.2 {ParseAddExpr procedure, error in LHS multiply subexpr} {
277 list [catch {testexprparser {1/foo + 3} -1} msg] $msg
278 } {1 {syntax error in expression "1/foo + 3": variable references require preceding $}}
279 test parseExpr-11.3 {ParseAddExpr procedure, next lexeme isn't "+" or "-"} {
280 testexprparser {1*2? 1 : 0} -1
281 } {- {} 0 subexpr {1*2? 1 : 0} 11 operator ? 0 subexpr 1*2 5 operator * 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 1 1 text 1 0 subexpr 0 1 text 0 0 {}}
282 test parseExpr-11.4 {ParseAddExpr procedure, next lexeme is "+" or "-"} {
283 testexprparser {1*2 + 3} -1
284 } {- {} 0 subexpr {1*2 + 3} 9 operator + 0 subexpr 1*2 5 operator * 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
285 test parseExpr-11.5 {ParseAddExpr procedure, next lexeme is "+" or "-"} {
286 testexprparser {1*2 - 3} -1
287 } {- {} 0 subexpr {1*2 - 3} 9 operator - 0 subexpr 1*2 5 operator * 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
288 test parseExpr-11.6 {ParseAddExpr procedure, bad lexeme after "+" or "-"} {wideIntegerUnparsed} {
289 list [catch {testexprparser {1*2 + 12345678901234567890} -1} msg] $msg
290 } {1 {integer value too large to represent}}
291 test parseExpr-11.7 {ParseAddExpr procedure, valid RHS subexpression} {
292 testexprparser {1*2 + 3 + 4} -1
293 } {- {} 0 subexpr {1*2 + 3 + 4} 13 operator + 0 subexpr {1*2 + 3} 9 operator + 0 subexpr 1*2 5 operator * 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 subexpr 4 1 text 4 0 {}}
294 test parseExpr-11.8 {ParseAddExpr procedure, error in RHS subexpression} {
295 list [catch {testexprparser {1*2 + 3 - martha} -1} msg] $msg
296 } {1 {syntax error in expression "1*2 + 3 - martha": variable references require preceding $}}
298 test parseExpr-12.1 {ParseAddExpr procedure, valid LHS multiply subexpr} {
299 testexprparser {1*2 + 3} -1
300 } {- {} 0 subexpr {1*2 + 3} 9 operator + 0 subexpr 1*2 5 operator * 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
301 test parseExpr-12.2 {ParseAddExpr procedure, error in LHS multiply subexpr} {
302 list [catch {testexprparser {1/foo + 3} -1} msg] $msg
303 } {1 {syntax error in expression "1/foo + 3": variable references require preceding $}}
304 test parseExpr-12.3 {ParseAddExpr procedure, next lexeme isn't "+" or "-"} {
305 testexprparser {1*2? 1 : 0} -1
306 } {- {} 0 subexpr {1*2? 1 : 0} 11 operator ? 0 subexpr 1*2 5 operator * 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 1 1 text 1 0 subexpr 0 1 text 0 0 {}}
307 test parseExpr-12.4 {ParseAddExpr procedure, next lexeme is "+" or "-"} {
308 testexprparser {1*2 + 3} -1
309 } {- {} 0 subexpr {1*2 + 3} 9 operator + 0 subexpr 1*2 5 operator * 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
310 test parseExpr-12.5 {ParseAddExpr procedure, next lexeme is "+" or "-"} {
311 testexprparser {1*2 - 3} -1
312 } {- {} 0 subexpr {1*2 - 3} 9 operator - 0 subexpr 1*2 5 operator * 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
313 test parseExpr-12.6 {ParseAddExpr procedure, bad lexeme after "+" or "-"} {wideIntegerUnparsed} {
314 list [catch {testexprparser {1*2 + 12345678901234567890} -1} msg] $msg
315 } {1 {integer value too large to represent}}
316 test parseExpr-12.7 {ParseAddExpr procedure, valid RHS subexpression} {
317 testexprparser {1*2 + 3 + 4} -1
318 } {- {} 0 subexpr {1*2 + 3 + 4} 13 operator + 0 subexpr {1*2 + 3} 9 operator + 0 subexpr 1*2 5 operator * 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 subexpr 4 1 text 4 0 {}}
319 test parseExpr-12.8 {ParseAddExpr procedure, error in RHS subexpression} {
320 list [catch {testexprparser {1*2 + 3 - martha} -1} msg] $msg
321 } {1 {syntax error in expression "1*2 + 3 - martha": variable references require preceding $}}
323 test parseExpr-13.1 {ParseMultiplyExpr procedure, valid LHS unary subexpr} {
324 testexprparser {+2 * 3} -1
325 } {- {} 0 subexpr {+2 * 3} 7 operator * 0 subexpr +2 3 operator + 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
326 test parseExpr-13.2 {ParseMultiplyExpr procedure, error in LHS unary subexpr} {wideIntegerUnparsed} {
327 list [catch {testexprparser {-12345678901234567890 * 3} -1} msg] $msg
328 } {1 {integer value too large to represent}}
329 test parseExpr-13.3 {ParseMultiplyExpr procedure, next lexeme isn't "*", "/", or "%"} {
330 testexprparser {+2? 1 : 0} -1
331 } {- {} 0 subexpr {+2? 1 : 0} 9 operator ? 0 subexpr +2 3 operator + 0 subexpr 2 1 text 2 0 subexpr 1 1 text 1 0 subexpr 0 1 text 0 0 {}}
332 test parseExpr-13.4 {ParseMultiplyExpr procedure, next lexeme is "*", "/", or "%"} {
333 testexprparser {-123 * 3} -1
334 } {- {} 0 subexpr {-123 * 3} 7 operator * 0 subexpr -123 3 operator - 0 subexpr 123 1 text 123 0 subexpr 3 1 text 3 0 {}}
335 test parseExpr-13.5 {ParseMultiplyExpr procedure, next lexeme is "*", "/", or "%"} {
336 testexprparser {+-456 / 3} -1
337 } {- {} 0 subexpr {+-456 / 3} 9 operator / 0 subexpr +-456 5 operator + 0 subexpr -456 3 operator - 0 subexpr 456 1 text 456 0 subexpr 3 1 text 3 0 {}}
338 test parseExpr-13.6 {ParseMultiplyExpr procedure, next lexeme is "*", "/", or "%"} {
339 testexprparser {+-456 % 3} -1
340 } {- {} 0 subexpr {+-456 % 3} 9 operator % 0 subexpr +-456 5 operator + 0 subexpr -456 3 operator - 0 subexpr 456 1 text 456 0 subexpr 3 1 text 3 0 {}}
341 test parseExpr-13.7 {ParseMultiplyExpr procedure, bad lexeme after "*", "/", or "%"} {wideIntegerUnparsed} {
342 list [catch {testexprparser {--++5 / 12345678901234567890} -1} msg] $msg
343 } {1 {integer value too large to represent}}
344 test parseExpr-13.8 {ParseMultiplyExpr procedure, valid RHS subexpression} {
345 testexprparser {-2 / 3 % 4} -1
346 } {- {} 0 subexpr {-2 / 3 % 4} 11 operator % 0 subexpr {-2 / 3} 7 operator / 0 subexpr -2 3 operator - 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 subexpr 4 1 text 4 0 {}}
347 test parseExpr-13.9 {ParseMultiplyExpr procedure, error in RHS subexpression} {
348 list [catch {testexprparser {++2 / 3 * martha} -1} msg] $msg
349 } {1 {syntax error in expression "++2 / 3 * martha": variable references require preceding $}}
351 test parseExpr-14.1 {ParseUnaryExpr procedure, first token is unary operator} {
352 testexprparser {+2} -1
353 } {- {} 0 subexpr +2 3 operator + 0 subexpr 2 1 text 2 0 {}}
354 test parseExpr-14.2 {ParseUnaryExpr procedure, first token is unary operator} {
355 testexprparser {-2} -1
356 } {- {} 0 subexpr -2 3 operator - 0 subexpr 2 1 text 2 0 {}}
357 test parseExpr-14.3 {ParseUnaryExpr procedure, first token is unary operator} {
358 testexprparser {~2} -1
359 } {- {} 0 subexpr ~2 3 operator ~ 0 subexpr 2 1 text 2 0 {}}
360 test parseExpr-14.4 {ParseUnaryExpr procedure, first token is unary operator} {
361 testexprparser {!2} -1
362 } {- {} 0 subexpr !2 3 operator ! 0 subexpr 2 1 text 2 0 {}}
363 test parseExpr-14.5 {ParseUnaryExpr procedure, error in lexeme after unary op} {wideIntegerUnparsed} {
364 list [catch {testexprparser {-12345678901234567890} -1} msg] $msg
365 } {1 {integer value too large to represent}}
366 test parseExpr-14.6 {ParseUnaryExpr procedure, simple unary expr after unary op} {
367 testexprparser {+"1234"} -1
368 } {- {} 0 subexpr +\"1234\" 3 operator + 0 subexpr {"1234"} 1 text 1234 0 {}}
369 test parseExpr-14.7 {ParseUnaryExpr procedure, another unary expr after unary op} {
370 testexprparser {~!{fred}} -1
371 } {- {} 0 subexpr ~!{fred} 5 operator ~ 0 subexpr !{fred} 3 operator ! 0 subexpr {{fred}} 1 text fred 0 {}}
372 test parseExpr-14.8 {ParseUnaryExpr procedure, error in unary expr after unary op} {
373 list [catch {testexprparser {+-||27} -1} msg] $msg
374 } {1 {syntax error in expression "+-||27": unexpected operator ||}}
375 test parseExpr-14.9 {ParseUnaryExpr procedure, error in unary expr after unary op} {
376 list [catch {testexprparser {+-||27} -1} msg] $msg
377 } {1 {syntax error in expression "+-||27": unexpected operator ||}}
378 test parseExpr-14.10 {ParseUnaryExpr procedure, first token is not unary op} {
379 testexprparser {123} -1
380 } {- {} 0 subexpr 123 1 text 123 0 {}}
381 test parseExpr-14.11 {ParseUnaryExpr procedure, not unary expr, complex primary expr} {
382 testexprparser {(1+2)} -1
383 } {- {} 0 subexpr 1+2 5 operator + 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 {}}
384 test parseExpr-14.12 {ParseUnaryExpr procedure, not unary expr, error in primary expr} {wideIntegerUnparsed} {
385 list [catch {testexprparser {(12345678901234567890)} -1} msg] $msg
386 } {1 {integer value too large to represent}}
388 test parseExpr-15.1 {ParsePrimaryExpr procedure, just parenthesized subexpr} {
389 testexprparser {({abc}/{def})} -1
390 } {- {} 0 subexpr {{abc}/{def}} 5 operator / 0 subexpr {{abc}} 1 text abc 0 subexpr {{def}} 1 text def 0 {}}
391 test parseExpr-15.2 {ParsePrimaryExpr procedure, bad lexeme after "("} {wideIntegerUnparsed} {
392 list [catch {testexprparser {(12345678901234567890)} -1} msg] $msg
393 } {1 {integer value too large to represent}}
394 test parseExpr-15.3 {ParsePrimaryExpr procedure, valid parenthesized subexpr} {
395 testexprparser {({abc}? 2*4 : -6)} -1
396 } {- {} 0 subexpr {{abc}? 2*4 : -6} 13 operator ? 0 subexpr {{abc}} 1 text abc 0 subexpr 2*4 5 operator * 0 subexpr 2 1 text 2 0 subexpr 4 1 text 4 0 subexpr -6 3 operator - 0 subexpr 6 1 text 6 0 {}}
397 test parseExpr-15.4 {ParsePrimaryExpr procedure, error in parenthesized subexpr} {
398 list [catch {testexprparser {(? 123 : 456)} -1} msg] $msg
399 } {1 {syntax error in expression "(? 123 : 456)": unexpected ternary 'then' separator}}
400 test parseExpr-15.5 {ParsePrimaryExpr procedure, missing ")" after in parenthesized subexpr} {
401 list [catch {testexprparser {({abc}/{def}} -1} msg] $msg
402 } {1 {syntax error in expression "({abc}/{def}": looking for close parenthesis}}
403 test parseExpr-15.6 {ParsePrimaryExpr procedure, primary is literal} {
404 testexprparser {12345} -1
405 } {- {} 0 subexpr 12345 1 text 12345 0 {}}
406 test parseExpr-15.7 {ParsePrimaryExpr procedure, primary is literal} {
407 testexprparser {12345.6789} -1
408 } {- {} 0 subexpr 12345.6789 1 text 12345.6789 0 {}}
409 test parseExpr-15.8 {ParsePrimaryExpr procedure, primary is var reference} {
410 testexprparser {$a} -1
411 } {- {} 0 subexpr {$a} 2 variable {$a} 1 text a 0 {}}
412 test parseExpr-15.9 {ParsePrimaryExpr procedure, primary is var reference} {
413 testexprparser {$a(hello$there)} -1
414 } {- {} 0 subexpr {$a(hello$there)} 5 variable {$a(hello$there)} 4 text a 0 text hello 0 variable {$there} 1 text there 0 {}}
415 test parseExpr-15.10 {ParsePrimaryExpr procedure, primary is var reference} {
416 testexprparser {$a()} -1
417 } {- {} 0 subexpr {$a()} 3 variable {$a()} 2 text a 0 text {} 0 {}}
418 test parseExpr-15.11 {ParsePrimaryExpr procedure, error in var reference} {
419 list [catch {testexprparser {$a(} -1} msg] $msg
421 test parseExpr-15.12 {ParsePrimaryExpr procedure, primary is quoted string} {
422 testexprparser {"abc $xyz def"} -1
423 } {- {} 0 subexpr {"abc $xyz def"} 5 word {"abc $xyz def"} 4 text {abc } 0 variable {$xyz} 1 text xyz 0 text { def} 0 {}}
424 test parseExpr-15.13 {ParsePrimaryExpr procedure, error in quoted string} {
425 list [catch {testexprparser {"$a(12"} -1} msg] $msg
427 test parseExpr-15.14 {ParsePrimaryExpr procedure, quoted string has multiple tokens} {
428 testexprparser {"abc [xyz] $def"} -1
429 } {- {} 0 subexpr {"abc [xyz] $def"} 6 word {"abc [xyz] $def"} 5 text {abc } 0 command {[xyz]} 0 text { } 0 variable {$def} 1 text def 0 {}}
430 test parseExpr-15.15 {ParsePrimaryExpr procedure, primary is command} {
431 testexprparser {[def]} -1
432 } {- {} 0 subexpr {[def]} 1 command {[def]} 0 {}}
433 test parseExpr-15.16 {ParsePrimaryExpr procedure, primary is multiple commands} {
434 testexprparser {[one; two; three; four;]} -1
435 } {- {} 0 subexpr {[one; two; three; four;]} 1 command {[one; two; three; four;]} 0 {}}
436 test parseExpr-15.17 {ParsePrimaryExpr procedure, primary is multiple commands} {
437 testexprparser {[one; two; three; four;]} -1
438 } {- {} 0 subexpr {[one; two; three; four;]} 1 command {[one; two; three; four;]} 0 {}}
439 test parseExpr-15.18 {ParsePrimaryExpr procedure, missing close bracket} {
440 list [catch {testexprparser {[one} -1} msg] $msg
441 } {1 {missing close-bracket}}
442 test parseExpr-15.19 {ParsePrimaryExpr procedure, primary is braced string} {
443 testexprparser {{hello world}} -1
444 } {- {} 0 subexpr {{hello world}} 1 text {hello world} 0 {}}
445 test parseExpr-15.20 {ParsePrimaryExpr procedure, error in primary, which is braced string} {
446 list [catch {testexprparser "\{abc\\\n" -1} msg] $msg
447 } {1 {missing close-brace}}
448 test parseExpr-15.21 {ParsePrimaryExpr procedure, primary is braced string with multiple tokens} {
449 testexprparser "\{ \\
451 } {- {} 0 subexpr \{\ \ \\\n\ +123\ \} 4 word \{\ \ \\\n\ +123\ \} 3 text { } 0 backslash \\\n\ 0 text {+123 } 0 {}}
452 test parseExpr-15.22 {ParsePrimaryExpr procedure, primary is function call} {
453 testexprparser {foo(123)} -1
454 } {- {} 0 subexpr foo(123) 3 operator foo 0 subexpr 123 1 text 123 0 {}}
455 test parseExpr-15.23 {ParsePrimaryExpr procedure, bad lexeme after function name} {wideIntegerUnparsed} {
456 list [catch {testexprparser {foo 12345678901234567890 123)} -1} msg] $msg
457 } {1 {integer value too large to represent}}
458 test parseExpr-15.24 {ParsePrimaryExpr procedure, lexeme after function name isn't "("} {
459 list [catch {testexprparser {foo 27.4 123)} -1} msg] $msg
460 } {1 {syntax error in expression "foo 27.4 123)": variable references require preceding $}}
461 test parseExpr-15.25 {ParsePrimaryExpr procedure, bad lexeme after "("} {wideIntegerUnparsed} {
462 list [catch {testexprparser {foo(12345678901234567890)} -1} msg] $msg
463 } {1 {integer value too large to represent}}
464 test parseExpr-15.26 {ParsePrimaryExpr procedure, function call, one arg} {
465 testexprparser {foo(27*4)} -1
466 } {- {} 0 subexpr foo(27*4) 7 operator foo 0 subexpr 27*4 5 operator * 0 subexpr 27 1 text 27 0 subexpr 4 1 text 4 0 {}}
467 test parseExpr-15.27 {ParsePrimaryExpr procedure, error in function arg} {
468 list [catch {testexprparser {foo(*1-2)} -1} msg] $msg
469 } {1 {syntax error in expression "foo(*1-2)": unexpected operator *}}
470 test parseExpr-15.28 {ParsePrimaryExpr procedure, error in function arg} {
471 list [catch {testexprparser {foo(*1-2)} -1} msg] $msg
472 } {1 {syntax error in expression "foo(*1-2)": unexpected operator *}}
473 test parseExpr-15.29 {ParsePrimaryExpr procedure, function call, comma after arg} {
474 testexprparser {foo(27-2, (-2*[foo]))} -1
475 } {- {} 0 subexpr {foo(27-2, (-2*[foo]))} 15 operator foo 0 subexpr 27-2 5 operator - 0 subexpr 27 1 text 27 0 subexpr 2 1 text 2 0 subexpr {-2*[foo]} 7 operator * 0 subexpr -2 3 operator - 0 subexpr 2 1 text 2 0 subexpr {[foo]} 1 command {[foo]} 0 {}}
476 test parseExpr-15.30 {ParsePrimaryExpr procedure, bad lexeme after comma} {wideIntegerUnparsed} {
477 list [catch {testexprparser {foo(123, 12345678901234567890)} -1} msg] $msg
478 } {1 {integer value too large to represent}}
479 test parseExpr-15.31 {ParsePrimaryExpr procedure, lexeme not "," or ")" after arg} {
480 list [catch {testexprparser {foo(123 [foo])} -1} msg] $msg
481 } {1 {syntax error in expression "foo(123 [foo])": missing close parenthesis at end of function call}}
482 test parseExpr-15.32 {ParsePrimaryExpr procedure, bad lexeme after primary} {wideIntegerUnparsed} {
483 list [catch {testexprparser {123 12345678901234567890} -1} msg] $msg
484 } {1 {integer value too large to represent}}
485 test parseExpr-15.33 {ParsePrimaryExpr procedure, comma-specific message} {
486 list [catch {testexprparser {123+,456} -1} msg] $msg
487 } {1 {syntax error in expression "123+,456": commas can only separate function arguments}}
488 test parseExpr-15.34 {ParsePrimaryExpr procedure, single equal-specific message} {
489 list [catch {testexprparser {123+=456} -1} msg] $msg
490 } {1 {syntax error in expression "123+=456": single equality character not legal in expressions}}
491 test parseExpr-15.35 {ParsePrimaryExpr procedure, error in parenthesized subexpr} {
492 list [catch {testexprparser {(: 123 : 456)} -1} msg] $msg
493 } {1 {syntax error in expression "(: 123 : 456)": unexpected ternary 'else' separator}}
494 test parseExpr-15.36 {ParsePrimaryExpr procedure, missing close-bracket} {
495 # Test for Bug 681841
496 list [catch {testexprparser {[set a [format bc]} -1} msg] $msg
497 } {1 {missing close-bracket}}
499 test parseExpr-16.1 {GetLexeme procedure, whitespace before lexeme} {
500 testexprparser { 123} -1
501 } {- {} 0 subexpr 123 1 text 123 0 {}}
502 test parseExpr-16.2 {GetLexeme procedure, whitespace before lexeme} {
505 } {- {} 0 subexpr 456 1 text 456 0 {}}
506 test parseExpr-16.3 {GetLexeme procedure, no lexeme after whitespace} {
507 testexprparser { 123 \
509 } {- {} 0 subexpr 123 1 text 123 0 {}}
510 test parseExpr-16.4 {GetLexeme procedure, integer lexeme} {
511 testexprparser {000} -1
512 } {- {} 0 subexpr 000 1 text 000 0 {}}
513 test parseExpr-16.5 {GetLexeme procedure, integer lexeme too big} {wideIntegerUnparsed} {
514 list [catch {testexprparser {12345678901234567890} -1} msg] $msg
515 } {1 {integer value too large to represent}}
517 test parseExpr-16.6 {GetLexeme procedure, bad integer lexeme} -body {
518 testexprparser {0999} -1
519 } -returnCodes error -match glob -result {*invalid octal number*}
521 test parseExpr-16.7 {GetLexeme procedure, double lexeme} {
522 testexprparser {0.999} -1
523 } {- {} 0 subexpr 0.999 1 text 0.999 0 {}}
524 test parseExpr-16.8 {GetLexeme procedure, double lexeme} {
525 testexprparser {.123} -1
526 } {- {} 0 subexpr .123 1 text .123 0 {}}
527 test parseExpr-16.9 {GetLexeme procedure, double lexeme} {nonPortable unixOnly} {
528 testexprparser {nan} -1
529 } {- {} 0 subexpr nan 1 text nan 0 {}}
530 test parseExpr-16.10 {GetLexeme procedure, double lexeme} {nonPortable unixOnly} {
531 testexprparser {NaN} -1
532 } {- {} 0 subexpr NaN 1 text NaN 0 {}}
533 test parseExpr-16.11 {GetLexeme procedure, bad double lexeme too big} {
534 list [catch {testexprparser {123.e+99999999999999} -1} msg] $msg
535 } {1 {floating-point value too large to represent}}
536 test parseExpr-16.12 {GetLexeme procedure, bad double lexeme} {
537 list [catch {testexprparser {123.4x56} -1} msg] $msg
538 } {1 {syntax error in expression "123.4x56": extra tokens at end of expression}}
539 test parseExpr-16.13 {GetLexeme procedure, lexeme is "["} {
540 testexprparser {[foo]} -1
541 } {- {} 0 subexpr {[foo]} 1 command {[foo]} 0 {}}
542 test parseExpr-16.14 {GetLexeme procedure, lexeme is open brace} {
543 testexprparser {{bar}} -1
544 } {- {} 0 subexpr {{bar}} 1 text bar 0 {}}
545 test parseExpr-16.15 {GetLexeme procedure, lexeme is "("} {
546 testexprparser {(123)} -1
547 } {- {} 0 subexpr 123 1 text 123 0 {}}
548 test parseExpr-16.16 {GetLexeme procedure, lexeme is ")"} {
549 testexprparser {(2*3)} -1
550 } {- {} 0 subexpr 2*3 5 operator * 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
551 test parseExpr-16.17 {GetLexeme procedure, lexeme is "$"} {
552 testexprparser {$wombat} -1
553 } {- {} 0 subexpr {$wombat} 2 variable {$wombat} 1 text wombat 0 {}}
554 test parseExpr-16.18 "GetLexeme procedure, lexeme is '\"'" {
555 testexprparser {"fred"} -1
556 } {- {} 0 subexpr {"fred"} 1 text fred 0 {}}
557 test parseExpr-16.19 {GetLexeme procedure, lexeme is ","} {
558 testexprparser {foo(1,2)} -1
559 } {- {} 0 subexpr foo(1,2) 5 operator foo 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 {}}
560 test parseExpr-16.20 {GetLexeme procedure, lexeme is "*"} {
561 testexprparser {$a*$b} -1
562 } {- {} 0 subexpr {$a*$b} 7 operator * 0 subexpr {$a} 2 variable {$a} 1 text a 0 subexpr {$b} 2 variable {$b} 1 text b 0 {}}
563 test parseExpr-16.21 {GetLexeme procedure, lexeme is "/"} {
564 testexprparser {5/6} -1
565 } {- {} 0 subexpr 5/6 5 operator / 0 subexpr 5 1 text 5 0 subexpr 6 1 text 6 0 {}}
566 test parseExpr-16.22 {GetLexeme procedure, lexeme is "%"} {
567 testexprparser {5%[xxx]} -1
568 } {- {} 0 subexpr {5%[xxx]} 5 operator % 0 subexpr 5 1 text 5 0 subexpr {[xxx]} 1 command {[xxx]} 0 {}}
569 test parseExpr-16.23 {GetLexeme procedure, lexeme is "+"} {
570 testexprparser {1+2} -1
571 } {- {} 0 subexpr 1+2 5 operator + 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 {}}
572 test parseExpr-16.24 {GetLexeme procedure, lexeme is "-"} {
573 testexprparser {.12-0e27} -1
574 } {- {} 0 subexpr .12-0e27 5 operator - 0 subexpr .12 1 text .12 0 subexpr 0e27 1 text 0e27 0 {}}
575 test parseExpr-16.25 {GetLexeme procedure, lexeme is "?" or ":"} {
576 testexprparser {$b? 1 : 0} -1
577 } {- {} 0 subexpr {$b? 1 : 0} 8 operator ? 0 subexpr {$b} 2 variable {$b} 1 text b 0 subexpr 1 1 text 1 0 subexpr 0 1 text 0 0 {}}
578 test parseExpr-16.26 {GetLexeme procedure, lexeme is "<"} {
579 testexprparser {2<3} -1
580 } {- {} 0 subexpr 2<3 5 operator < 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
581 test parseExpr-16.27 {GetLexeme procedure, lexeme is "<<"} {
582 testexprparser {2<<3} -1
583 } {- {} 0 subexpr 2<<3 5 operator << 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
584 test parseExpr-16.28 {GetLexeme procedure, lexeme is "<="} {
585 testexprparser {2<=3} -1
586 } {- {} 0 subexpr 2<=3 5 operator <= 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
587 test parseExpr-16.29 {GetLexeme procedure, lexeme is ">"} {
588 testexprparser {2>3} -1
589 } {- {} 0 subexpr 2>3 5 operator > 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
590 test parseExpr-16.30 {GetLexeme procedure, lexeme is ">>"} {
591 testexprparser {2>>3} -1
592 } {- {} 0 subexpr 2>>3 5 operator >> 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
593 test parseExpr-16.31 {GetLexeme procedure, lexeme is ">="} {
594 testexprparser {2>=3} -1
595 } {- {} 0 subexpr 2>=3 5 operator >= 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
596 test parseExpr-16.32 {GetLexeme procedure, lexeme is "=="} {
597 testexprparser {2==3} -1
598 } {- {} 0 subexpr 2==3 5 operator == 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
599 test parseExpr-16.33 {GetLexeme procedure, bad lexeme starting with "="} {
600 list [catch {testexprparser {2=+3} -1} msg] $msg
601 } {1 {syntax error in expression "2=+3": extra tokens at end of expression}}
602 test parseExpr-16.34 {GetLexeme procedure, lexeme is "!="} {
603 testexprparser {2!=3} -1
604 } {- {} 0 subexpr 2!=3 5 operator != 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
605 test parseExpr-16.35 {GetLexeme procedure, lexeme is "!"} {
606 testexprparser {!2} -1
607 } {- {} 0 subexpr !2 3 operator ! 0 subexpr 2 1 text 2 0 {}}
608 test parseExpr-16.36 {GetLexeme procedure, lexeme is "&&"} {
609 testexprparser {2&&3} -1
610 } {- {} 0 subexpr 2&&3 5 operator && 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
611 test parseExpr-16.37 {GetLexeme procedure, lexeme is "&"} {
612 testexprparser {1&2} -1
613 } {- {} 0 subexpr 1&2 5 operator & 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 {}}
614 test parseExpr-16.38 {GetLexeme procedure, lexeme is "^"} {
615 testexprparser {1^2} -1
616 } {- {} 0 subexpr 1^2 5 operator ^ 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 {}}
617 test parseExpr-16.39 {GetLexeme procedure, lexeme is "||"} {
618 testexprparser {2||3} -1
619 } {- {} 0 subexpr 2||3 5 operator || 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
620 test parseExpr-16.40 {GetLexeme procedure, lexeme is "|"} {
621 testexprparser {1|2} -1
622 } {- {} 0 subexpr 1|2 5 operator | 0 subexpr 1 1 text 1 0 subexpr 2 1 text 2 0 {}}
623 test parseExpr-16.41 {GetLexeme procedure, lexeme is "~"} {
624 testexprparser {~2} -1
625 } {- {} 0 subexpr ~2 3 operator ~ 0 subexpr 2 1 text 2 0 {}}
626 test parseExpr-16.42 {GetLexeme procedure, lexeme is func name} {
627 testexprparser {george()} -1
628 } {- {} 0 subexpr george() 1 operator george 0 {}}
629 test parseExpr-16.43 {GetLexeme procedure, lexeme is func name} {
630 testexprparser {harmonic_ratio(2,3)} -1
631 } {- {} 0 subexpr harmonic_ratio(2,3) 5 operator harmonic_ratio 0 subexpr 2 1 text 2 0 subexpr 3 1 text 3 0 {}}
632 test parseExpr-16.44 {GetLexeme procedure, unknown lexeme} {
633 list [catch {testexprparser {@27} -1} msg] $msg
634 } {1 {syntax error in expression "@27": character not legal in expressions}}
636 test parseExpr-17.1 {PrependSubExprTokens procedure, expand token array} {
637 testexprparser {[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]]} -1
638 } {- {} 0 subexpr {[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]]} 13 operator && 0 subexpr {[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]]} 9 operator && 0 subexpr {[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]} 5 operator && 0 subexpr {[string compare [format %c $i] [string index $a $i]]} 1 command {[string compare [format %c $i] [string index $a $i]]} 0 subexpr {[string compare [format %c $i] [string index $a $i]]} 1 command {[string compare [format %c $i] [string index $a $i]]} 0 subexpr {[string compare [format %c $i] [string index $a $i]]} 1 command {[string compare [format %c $i] [string index $a $i]]} 0 subexpr {[string compare [format %c $i] [string index $a $i]]} 1 command {[string compare [format %c $i] [string index $a $i]]} 0 {}}
640 test parseExpr-18.1 {LogSyntaxError procedure, error in expr longer than 60 chars} {
641 list [catch {testexprparser {(+0123456)*(+0123456)*(+0123456)*(+0123456)*(+0123456)*(+0123456)*(+0123456)/} -1} msg] $msg
642 } {1 {syntax error in expression "(+0123456)*(+0123456)*(+0123456)*(+0123456)*(+0123456)*(+012...": premature end of expression}}
644 test parseExpr-19.1 {TclParseInteger: [Bug 648441]} {
645 # Should see this as integer "0" followed by incomplete function "x"
646 # Thus, syntax error.
647 # If Bug 648441 is not fixed, "0x" will be seen as floating point 0.0
648 list [catch {expr 0x} result] $result
649 } [list 1 {syntax error in expression "0x": extra tokens at end of expression}]
652 ::tcltest::cleanupTests