aboutsummaryrefslogtreecommitdiff
path: root/tests/expr.test
AgeCommit message (Collapse)AuthorFilesLines
2021-03-09expr: TIP 526, only support a single argSteve Bennett1-1/+1
Avoid unexpected issues by concatenating multiple arguments. This does create an incompatibility with early versions, but it is generally trivial to convert existing code to one of two forms: 1. expr {$a + $b} -- usually correct 2. expr "$a + $b" -- usually incorrect Signed-off-by: Steve Bennett <steveb@workware.net.au>
2021-01-03core: fix parsing of booleansSteve Bennett1-0/+5
When boolean parsing was combined in commit 982ec4f524bc81a240cb729cf09bd3c677aea485 it broken parsing of boolean values in expressions that weren't standalone. e.g. expr {true} was fine, but expr {true ? 4 : 5} was not. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2020-09-27core: make unary "!" work with non-int booleansD. Bohdan1-0/+8
2017-05-23expr: Replace expression engineSteve Bennett1-0/+8
Rework the expression engine to use recursive descent evaluation rather than a shunting yard algorithm. Among other things, it is easier to make lazy operators and the ternary operator work correctly. In particular, the following expression no longer crashes: $(99?9,99?9:*9:999)?9) And the code is now smaller. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2016-08-17expr: fix adjacent terms in function callsSteve Bennett1-13/+12
Previously two adjacent terms were incorrectly accepted, such as in pow(2 3) Correctly generate an error in this case and improve the error message when an expression fails to parse correctly. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-11-22Overhaul unit test frameworkSteve Bennett1-7/+5
Much closer to tcltest now, including constraints. Try to get all appropriate tests running under both Jim and Tcl. Signed-off-by: Steve Bennett <steveb@workware.net.au>
2010-10-15Simplify and speed up exprSteve Bennett1-0/+7
*: Reuse the ParseTokenList/ScriptToken machinery for 'expr' *: This is simpler than managing separate opcode/obj arrays *: expr opcodes are now in the same namespace as token types *: expr identifies int and double during parsing *: Move the 'while' common expr optimisations into Jim_EvalExpression *: Add a special trueObj and falseObj to help with these boolean optimisations *: Add lazy versions as the byte code is created instead of at the end *: Avoid repeated conversion attempts to int *: Once an object fails conversion to int and succeeds conversion to double, invalidate the string rep so the int conversion attempt no longer happens *: Also, avoid converting non-ints to int in expression optimisation *: No need for a string token for SEP and EOL tokens *: Fix shimmering of int -> double *: When an int shimmers to a double during an expression, remember that the value was originally an int (via a new type, coerced double)
2010-10-15New features, docsSteve Bennett1-8/+37
Implement lsearch in C with options *: lsearch -exact, -glob, -regexp, -not, -bool, -all, -inline Add tests for lsearch and expand expr operators: in and ni (Tcl 8.6)
2010-10-15Fix many problem with expr evaluationSteve Bennett1-1/+43
*: Import Tcl expr tests (expr-old.test) and fix things: *: !double should be boolean (int) *: double&&double and double||double should be boolean (int) *: 2.34e+1 and 2.0e2 are an acceptable double values *: precedence of && and || is not equal *: precedence of ? and : is not equal *: expression "2:3" is invalid *: lazy evaluation involving multiple && and || was quite wrong *: Fix unary minus wrt subexpressions. e.g. -(-1.5) *: Also add support for functions: int, double, abs, round *: Fix lazy evaluation of ternary operator *: Error on missing ?, missing : *: Fix double unary minus *: Add unary plus *: Fix parsing of double with no '.' before 'e'. Also support 'E'. *: Right-to-left associativity of ternary operator is *almost* correct *: Import div/mod of -ve integers from Tcl *: Rotate (<<< and >>>) failed because of wrong arity *: Don't use auto-converted double values *: When an expression fails, show the expression *: Bump version to 0.62
2010-10-15Improve expression supportSteve Bennett1-0/+45
Especially ternary operator and unary minus Still evaluates both sides of the ternary operator :-( Fix unary minus And add const in more places to avoid this mistake in future
2010-10-15Bugs, features and testsSteve Bennett1-0/+17
source fails with zero length file unknown can't be called recursively *: This can be useful when using unknown to dynamically load code, which may in turn want to dynamically load code *: Limit it to 50 recursions though Allow string greater/less comparison *: Comparing two strings for order did not work Implement file join *: It's not to hard and is handy when working with the current dir, "" Don't omit [unknown] completely from stack trace *: Since we lose valuable informtion, just omit the name Fix return from case Turn regexp patterns into real objects *: Thus caching the compiled regexps Allow error to rethrow an error Replace bcopy() with more standard memcpy() Fixes to parray, improve errorInfo *: errorInfo takes an optional stack trace Add tests for rethrowing errors via errorInfo Fix ndelay *: Was looking at wrong param *: Also fix usage/help for aio.socket Package should be able to call exit *: Currently any return from a package is changed to JIM_ERR Line counting is incorrect for backlash newline