os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/expr-old.test
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
# Commands covered: expr
sl@0
     2
#
sl@0
     3
# This file contains the original set of tests for Tcl's expr command.
sl@0
     4
# Since the expr command is now compiled, a new set of tests covering
sl@0
     5
# the new implementation are in the files "parseExpr.test" and
sl@0
     6
# "compExpr.test". Sourcing this file into Tcl runs the tests and generates
sl@0
     7
# output for errors. No output means no errors were found.
sl@0
     8
#
sl@0
     9
# Copyright (c) 1991-1994 The Regents of the University of California.
sl@0
    10
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
sl@0
    11
# Copyright (c) 1998-2000 by Scriptics Corporation.
sl@0
    12
#
sl@0
    13
# See the file "license.terms" for information on usage and redistribution
sl@0
    14
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
sl@0
    15
#
sl@0
    16
# RCS: @(#) $Id: expr-old.test,v 1.16.2.5 2006/05/04 12:34:39 dgp Exp $
sl@0
    17
sl@0
    18
if {[lsearch [namespace children] ::tcltest] == -1} {
sl@0
    19
    package require tcltest 2.1
sl@0
    20
    namespace import -force ::tcltest::*
sl@0
    21
}
sl@0
    22
sl@0
    23
if {([catch {expr T1()} msg] == 1) && ($msg == {unknown math function "T1"})} {
sl@0
    24
    set gotT1 0
sl@0
    25
    puts "This application hasn't been compiled with the \"T1\" and"
sl@0
    26
    puts "\"T2\" math functions, so I'll skip some of the expr tests."
sl@0
    27
} else {
sl@0
    28
    set gotT1 1
sl@0
    29
}
sl@0
    30
sl@0
    31
# First, test all of the integer operators individually.
sl@0
    32
sl@0
    33
test expr-old-1.1 {integer operators} {expr -4} -4
sl@0
    34
test expr-old-1.2 {integer operators} {expr -(1+4)} -5
sl@0
    35
test expr-old-1.3 {integer operators} {expr ~3} -4
sl@0
    36
test expr-old-1.4 {integer operators} {expr !2} 0
sl@0
    37
test expr-old-1.5 {integer operators} {expr !0} 1
sl@0
    38
test expr-old-1.6 {integer operators} {expr 4*6} 24
sl@0
    39
test expr-old-1.7 {integer operators} {expr 36/12} 3
sl@0
    40
test expr-old-1.8 {integer operators} {expr 27/4} 6
sl@0
    41
test expr-old-1.9 {integer operators} {expr 27%4} 3
sl@0
    42
test expr-old-1.10 {integer operators} {expr 2+2} 4
sl@0
    43
test expr-old-1.11 {integer operators} {expr 2-6} -4
sl@0
    44
test expr-old-1.12 {integer operators} {expr 1<<3} 8
sl@0
    45
test expr-old-1.13 {integer operators} {expr 0xff>>2} 63
sl@0
    46
test expr-old-1.14 {integer operators} {expr -1>>2} -1
sl@0
    47
test expr-old-1.15 {integer operators} {expr 3>2} 1
sl@0
    48
test expr-old-1.16 {integer operators} {expr 2>2} 0
sl@0
    49
test expr-old-1.17 {integer operators} {expr 1>2} 0
sl@0
    50
test expr-old-1.18 {integer operators} {expr 3<2} 0
sl@0
    51
test expr-old-1.19 {integer operators} {expr 2<2} 0
sl@0
    52
test expr-old-1.20 {integer operators} {expr 1<2} 1
sl@0
    53
test expr-old-1.21 {integer operators} {expr 3>=2} 1
sl@0
    54
test expr-old-1.22 {integer operators} {expr 2>=2} 1
sl@0
    55
test expr-old-1.23 {integer operators} {expr 1>=2} 0
sl@0
    56
test expr-old-1.24 {integer operators} {expr 3<=2} 0
sl@0
    57
test expr-old-1.25 {integer operators} {expr 2<=2} 1
sl@0
    58
test expr-old-1.26 {integer operators} {expr 1<=2} 1
sl@0
    59
test expr-old-1.27 {integer operators} {expr 3==2} 0
sl@0
    60
test expr-old-1.28 {integer operators} {expr 2==2} 1
sl@0
    61
test expr-old-1.29 {integer operators} {expr 3!=2} 1
sl@0
    62
test expr-old-1.30 {integer operators} {expr 2!=2} 0
sl@0
    63
test expr-old-1.31 {integer operators} {expr 7&0x13} 3
sl@0
    64
test expr-old-1.32 {integer operators} {expr 7^0x13} 20
sl@0
    65
test expr-old-1.33 {integer operators} {expr 7|0x13} 23
sl@0
    66
test expr-old-1.34 {integer operators} {expr 0&&1} 0
sl@0
    67
test expr-old-1.35 {integer operators} {expr 0&&0} 0
sl@0
    68
test expr-old-1.36 {integer operators} {expr 1&&3} 1
sl@0
    69
test expr-old-1.37 {integer operators} {expr 0||1} 1
sl@0
    70
test expr-old-1.38 {integer operators} {expr 3||0} 1
sl@0
    71
test expr-old-1.39 {integer operators} {expr 0||0} 0
sl@0
    72
test expr-old-1.40 {integer operators} {expr 3>2?44:66} 44
sl@0
    73
test expr-old-1.41 {integer operators} {expr 2>3?44:66} 66
sl@0
    74
test expr-old-1.42 {integer operators} {expr 36/5} 7
sl@0
    75
test expr-old-1.43 {integer operators} {expr 36%5} 1
sl@0
    76
test expr-old-1.44 {integer operators} {expr -36/5} -8
sl@0
    77
test expr-old-1.45 {integer operators} {expr -36%5} 4
sl@0
    78
test expr-old-1.46 {integer operators} {expr 36/-5} -8
sl@0
    79
test expr-old-1.47 {integer operators} {expr 36%-5} -4
sl@0
    80
test expr-old-1.48 {integer operators} {expr -36/-5} 7
sl@0
    81
test expr-old-1.49 {integer operators} {expr -36%-5} -1
sl@0
    82
test expr-old-1.50 {integer operators} {expr +36} 36
sl@0
    83
test expr-old-1.51 {integer operators} {expr +--++36} 36
sl@0
    84
test expr-old-1.52 {integer operators} {expr +36%+5} 1
sl@0
    85
test expr-old-1.53 {integer operators} {
sl@0
    86
    catch {unset x}
sl@0
    87
    set x yes
sl@0
    88
    list [expr {1 && $x}] [expr {$x && 1}] \
sl@0
    89
         [expr {0 || $x}] [expr {$x || 0}]
sl@0
    90
} {1 1 1 1}
sl@0
    91
sl@0
    92
# Check the floating-point operators individually, along with
sl@0
    93
# automatic conversion to integers where needed.
sl@0
    94
sl@0
    95
test expr-old-2.1 {floating-point operators} {expr -4.2} -4.2
sl@0
    96
test expr-old-2.2 {floating-point operators} {expr -(1.1+4.2)} -5.3
sl@0
    97
test expr-old-2.3 {floating-point operators} {expr +5.7} 5.7
sl@0
    98
test expr-old-2.4 {floating-point operators} {expr +--+-62.0} -62.0
sl@0
    99
test expr-old-2.5 {floating-point operators} {expr !2.1} 0
sl@0
   100
test expr-old-2.6 {floating-point operators} {expr !0.0} 1
sl@0
   101
test expr-old-2.7 {floating-point operators} {expr 4.2*6.3} 26.46
sl@0
   102
test expr-old-2.8 {floating-point operators} {expr 36.0/12.0} 3.0
sl@0
   103
test expr-old-2.9 {floating-point operators} {expr 27/4.0} 6.75
sl@0
   104
test expr-old-2.10 {floating-point operators} {expr 2.3+2.1} 4.4
sl@0
   105
test expr-old-2.11 {floating-point operators} {expr 2.3-6.5} -4.2
sl@0
   106
test expr-old-2.12 {floating-point operators} {expr 3.1>2.1} 1
sl@0
   107
test expr-old-2.13 {floating-point operators} {expr {2.1 > 2.1}} 0
sl@0
   108
test expr-old-2.14 {floating-point operators} {expr 1.23>2.34e+1} 0
sl@0
   109
test expr-old-2.15 {floating-point operators} {expr 3.45<2.34} 0
sl@0
   110
test expr-old-2.16 {floating-point operators} {expr 0.002e3<--200e-2} 0
sl@0
   111
test expr-old-2.17 {floating-point operators} {expr 1.1<2.1} 1
sl@0
   112
test expr-old-2.18 {floating-point operators} {expr 3.1>=2.2} 1
sl@0
   113
test expr-old-2.19 {floating-point operators} {expr 2.345>=2.345} 1
sl@0
   114
test expr-old-2.20 {floating-point operators} {expr 1.1>=2.2} 0
sl@0
   115
test expr-old-2.21 {floating-point operators} {expr 3.0<=2.0} 0
sl@0
   116
test expr-old-2.22 {floating-point operators} {expr 2.2<=2.2} 1
sl@0
   117
test expr-old-2.23 {floating-point operators} {expr 2.2<=2.2001} 1
sl@0
   118
test expr-old-2.24 {floating-point operators} {expr 3.2==2.2} 0
sl@0
   119
test expr-old-2.25 {floating-point operators} {expr 2.2==2.2} 1
sl@0
   120
test expr-old-2.26 {floating-point operators} {expr 3.2!=2.2} 1
sl@0
   121
test expr-old-2.27 {floating-point operators} {expr 2.2!=2.2} 0
sl@0
   122
test expr-old-2.28 {floating-point operators} {expr 0.0&&0.0} 0
sl@0
   123
test expr-old-2.29 {floating-point operators} {expr 0.0&&1.3} 0
sl@0
   124
test expr-old-2.30 {floating-point operators} {expr 1.3&&0.0} 0
sl@0
   125
test expr-old-2.31 {floating-point operators} {expr 1.3&&3.3} 1
sl@0
   126
test expr-old-2.32 {floating-point operators} {expr 0.0||0.0} 0
sl@0
   127
test expr-old-2.33 {floating-point operators} {expr 0.0||1.3} 1
sl@0
   128
test expr-old-2.34 {floating-point operators} {expr 1.3||0.0} 1
sl@0
   129
test expr-old-2.35 {floating-point operators} {expr 3.3||0.0} 1
sl@0
   130
test expr-old-2.36 {floating-point operators} {expr 3.3>2.3?44.3:66.3} 44.3
sl@0
   131
test expr-old-2.37 {floating-point operators} {expr 2.3>3.3?44.3:66.3} 66.3
sl@0
   132
test expr-old-2.38 {floating-point operators} {
sl@0
   133
    list [catch {expr 028.1 + 09.2} msg] $msg
sl@0
   134
} {0 37.3}
sl@0
   135
sl@0
   136
# Operators that aren't legal on floating-point numbers
sl@0
   137
sl@0
   138
test expr-old-3.1 {illegal floating-point operations} {
sl@0
   139
    list [catch {expr ~4.0} msg] $msg
sl@0
   140
} {1 {can't use floating-point value as operand of "~"}}
sl@0
   141
test expr-old-3.2 {illegal floating-point operations} {
sl@0
   142
    list [catch {expr 27%4.0} msg] $msg
sl@0
   143
} {1 {can't use floating-point value as operand of "%"}}
sl@0
   144
test expr-old-3.3 {illegal floating-point operations} {
sl@0
   145
    list [catch {expr 27.0%4} msg] $msg
sl@0
   146
} {1 {can't use floating-point value as operand of "%"}}
sl@0
   147
test expr-old-3.4 {illegal floating-point operations} {
sl@0
   148
    list [catch {expr 1.0<<3} msg] $msg
sl@0
   149
} {1 {can't use floating-point value as operand of "<<"}}
sl@0
   150
test expr-old-3.5 {illegal floating-point operations} {
sl@0
   151
    list [catch {expr 3<<1.0} msg] $msg
sl@0
   152
} {1 {can't use floating-point value as operand of "<<"}}
sl@0
   153
test expr-old-3.6 {illegal floating-point operations} {
sl@0
   154
    list [catch {expr 24.0>>3} msg] $msg
sl@0
   155
} {1 {can't use floating-point value as operand of ">>"}}
sl@0
   156
test expr-old-3.7 {illegal floating-point operations} {
sl@0
   157
    list [catch {expr 24>>3.0} msg] $msg
sl@0
   158
} {1 {can't use floating-point value as operand of ">>"}}
sl@0
   159
test expr-old-3.8 {illegal floating-point operations} {
sl@0
   160
    list [catch {expr 24&3.0} msg] $msg
sl@0
   161
} {1 {can't use floating-point value as operand of "&"}}
sl@0
   162
test expr-old-3.9 {illegal floating-point operations} {
sl@0
   163
    list [catch {expr 24.0|3} msg] $msg
sl@0
   164
} {1 {can't use floating-point value as operand of "|"}}
sl@0
   165
test expr-old-3.10 {illegal floating-point operations} {
sl@0
   166
    list [catch {expr 24.0^3} msg] $msg
sl@0
   167
} {1 {can't use floating-point value as operand of "^"}}
sl@0
   168
sl@0
   169
# Check the string operators individually.
sl@0
   170
sl@0
   171
test expr-old-4.1 {string operators} {expr {"abc" > "def"}} 0
sl@0
   172
test expr-old-4.2 {string operators} {expr {"def" > "def"}} 0
sl@0
   173
test expr-old-4.3 {string operators} {expr {"g" > "def"}} 1
sl@0
   174
test expr-old-4.4 {string operators} {expr {"abc" < "abd"}} 1
sl@0
   175
test expr-old-4.5 {string operators} {expr {"abd" < "abd"}} 0
sl@0
   176
test expr-old-4.6 {string operators} {expr {"abe" < "abd"}} 0
sl@0
   177
test expr-old-4.7 {string operators} {expr {"abc" >= "def"}} 0
sl@0
   178
test expr-old-4.8 {string operators} {expr {"def" >= "def"}} 1
sl@0
   179
test expr-old-4.9 {string operators} {expr {"g" >= "def"}} 1
sl@0
   180
test expr-old-4.10 {string operators} {expr {"abc" <= "abd"}} 1
sl@0
   181
test expr-old-4.11 {string operators} {expr {"abd" <= "abd"}} 1
sl@0
   182
test expr-old-4.12 {string operators} {expr {"abe" <= "abd"}} 0
sl@0
   183
test expr-old-4.13 {string operators} {expr {"abc" == "abd"}} 0
sl@0
   184
test expr-old-4.14 {string operators} {expr {"abd" == "abd"}} 1
sl@0
   185
test expr-old-4.15 {string operators} {expr {"abc" != "abd"}} 1
sl@0
   186
test expr-old-4.16 {string operators} {expr {"abd" != "abd"}} 0
sl@0
   187
test expr-old-4.17 {string operators} {expr {"0y" < "0x12"}} 0
sl@0
   188
test expr-old-4.18 {string operators} {expr {"." < " "}} 0
sl@0
   189
test expr-old-4.19 {string operators} {expr {"abc" eq "abd"}} 0
sl@0
   190
test expr-old-4.20 {string operators} {expr {"abd" eq "abd"}} 1
sl@0
   191
test expr-old-4.21 {string operators} {expr {"abc" ne "abd"}} 1
sl@0
   192
test expr-old-4.22 {string operators} {expr {"abd" ne "abd"}} 0
sl@0
   193
test expr-old-4.23 {string operators} {expr {"" eq "abd"}} 0
sl@0
   194
test expr-old-4.24 {string operators} {expr {"" eq ""}} 1
sl@0
   195
test expr-old-4.25 {string operators} {expr {"abd" ne ""}} 1
sl@0
   196
test expr-old-4.26 {string operators} {expr {"" ne ""}} 0
sl@0
   197
test expr-old-4.27 {string operators} {expr {"longerstring" eq "shorter"}} 0
sl@0
   198
test expr-old-4.28 {string operators} {expr {"longerstring" ne "shorter"}} 1
sl@0
   199
sl@0
   200
# The following tests are non-portable because on some systems "+"
sl@0
   201
# and "-" can be parsed as numbers.
sl@0
   202
sl@0
   203
test expr-old-4.29 {string operators} {nonPortable} {expr {"0" == "+"}} 0
sl@0
   204
test expr-old-4.30 {string operators} {nonPortable} {expr {"0" == "-"}} 0
sl@0
   205
test expr-old-4.31 {string operators} {expr {1?"foo":"bar"}} foo
sl@0
   206
test expr-old-4.32 {string operators} {expr {0?"foo":"bar"}} bar
sl@0
   207
sl@0
   208
# Operators that aren't legal on string operands.
sl@0
   209
sl@0
   210
test expr-old-5.1 {illegal string operations} {
sl@0
   211
    list [catch {expr {-"a"}} msg] $msg
sl@0
   212
} {1 {can't use non-numeric string as operand of "-"}}
sl@0
   213
test expr-old-5.2 {illegal string operations} {
sl@0
   214
    list [catch {expr {+"a"}} msg] $msg
sl@0
   215
} {1 {can't use non-numeric string as operand of "+"}}
sl@0
   216
test expr-old-5.3 {illegal string operations} {
sl@0
   217
    list [catch {expr {~"a"}} msg] $msg
sl@0
   218
} {1 {can't use non-numeric string as operand of "~"}}
sl@0
   219
test expr-old-5.4 {illegal string operations} {
sl@0
   220
    list [catch {expr {!"a"}} msg] $msg
sl@0
   221
} {1 {can't use non-numeric string as operand of "!"}}
sl@0
   222
test expr-old-5.5 {illegal string operations} {
sl@0
   223
    list [catch {expr {"a"*"b"}} msg] $msg
sl@0
   224
} {1 {can't use non-numeric string as operand of "*"}}
sl@0
   225
test expr-old-5.6 {illegal string operations} {
sl@0
   226
    list [catch {expr {"a"/"b"}} msg] $msg
sl@0
   227
} {1 {can't use non-numeric string as operand of "/"}}
sl@0
   228
test expr-old-5.7 {illegal string operations} {
sl@0
   229
    list [catch {expr {"a"%"b"}} msg] $msg
sl@0
   230
} {1 {can't use non-numeric string as operand of "%"}}
sl@0
   231
test expr-old-5.8 {illegal string operations} {
sl@0
   232
    list [catch {expr {"a"+"b"}} msg] $msg
sl@0
   233
} {1 {can't use non-numeric string as operand of "+"}}
sl@0
   234
test expr-old-5.9 {illegal string operations} {
sl@0
   235
    list [catch {expr {"a"-"b"}} msg] $msg
sl@0
   236
} {1 {can't use non-numeric string as operand of "-"}}
sl@0
   237
test expr-old-5.10 {illegal string operations} {
sl@0
   238
    list [catch {expr {"a"<<"b"}} msg] $msg
sl@0
   239
} {1 {can't use non-numeric string as operand of "<<"}}
sl@0
   240
test expr-old-5.11 {illegal string operations} {
sl@0
   241
    list [catch {expr {"a">>"b"}} msg] $msg
sl@0
   242
} {1 {can't use non-numeric string as operand of ">>"}}
sl@0
   243
test expr-old-5.12 {illegal string operations} {
sl@0
   244
    list [catch {expr {"a"&"b"}} msg] $msg
sl@0
   245
} {1 {can't use non-numeric string as operand of "&"}}
sl@0
   246
test expr-old-5.13 {illegal string operations} {
sl@0
   247
    list [catch {expr {"a"^"b"}} msg] $msg
sl@0
   248
} {1 {can't use non-numeric string as operand of "^"}}
sl@0
   249
test expr-old-5.14 {illegal string operations} {
sl@0
   250
    list [catch {expr {"a"|"b"}} msg] $msg
sl@0
   251
} {1 {can't use non-numeric string as operand of "|"}}
sl@0
   252
test expr-old-5.15 {illegal string operations} {
sl@0
   253
    list [catch {expr {"a"&&"b"}} msg] $msg
sl@0
   254
} {1 {expected boolean value but got "a"}}
sl@0
   255
test expr-old-5.16 {illegal string operations} {
sl@0
   256
    list [catch {expr {"a"||"b"}} msg] $msg
sl@0
   257
} {1 {expected boolean value but got "a"}}
sl@0
   258
test expr-old-5.17 {illegal string operations} {
sl@0
   259
    list [catch {expr {"a"?4:2}} msg] $msg
sl@0
   260
} {1 {expected boolean value but got "a"}}
sl@0
   261
sl@0
   262
# Check precedence pairwise.
sl@0
   263
sl@0
   264
test expr-old-6.1 {precedence checks} {expr -~3} 4
sl@0
   265
test expr-old-6.2 {precedence checks} {expr -!3} 0
sl@0
   266
test expr-old-6.3 {precedence checks} {expr -~0} 1
sl@0
   267
sl@0
   268
test expr-old-7.1 {precedence checks} {expr 2*4/6} 1
sl@0
   269
test expr-old-7.2 {precedence checks} {expr 24/6*3} 12
sl@0
   270
test expr-old-7.3 {precedence checks} {expr 24/6/2} 2
sl@0
   271
sl@0
   272
test expr-old-8.1 {precedence checks} {expr -2+4} 2
sl@0
   273
test expr-old-8.2 {precedence checks} {expr -2-4} -6
sl@0
   274
test expr-old-8.3 {precedence checks} {expr +2-4} -2
sl@0
   275
sl@0
   276
test expr-old-9.1 {precedence checks} {expr 2*3+4} 10
sl@0
   277
test expr-old-9.2 {precedence checks} {expr 8/2+4} 8
sl@0
   278
test expr-old-9.3 {precedence checks} {expr 8%3+4} 6
sl@0
   279
test expr-old-9.4 {precedence checks} {expr 2*3-1} 5
sl@0
   280
test expr-old-9.5 {precedence checks} {expr 8/2-1} 3
sl@0
   281
test expr-old-9.6 {precedence checks} {expr 8%3-1} 1
sl@0
   282
sl@0
   283
test expr-old-10.1 {precedence checks} {expr 6-3-2} 1
sl@0
   284
sl@0
   285
test expr-old-11.1 {precedence checks} {expr 7+1>>2} 2
sl@0
   286
test expr-old-11.2 {precedence checks} {expr 7+1<<2} 32
sl@0
   287
test expr-old-11.3 {precedence checks} {expr 7>>3-2} 3
sl@0
   288
test expr-old-11.4 {precedence checks} {expr 7<<3-2} 14
sl@0
   289
sl@0
   290
test expr-old-12.1 {precedence checks} {expr 6>>1>4} 0
sl@0
   291
test expr-old-12.2 {precedence checks} {expr 6>>1<2} 0
sl@0
   292
test expr-old-12.3 {precedence checks} {expr 6>>1>=3} 1
sl@0
   293
test expr-old-12.4 {precedence checks} {expr 6>>1<=2} 0
sl@0
   294
test expr-old-12.5 {precedence checks} {expr 6<<1>5} 1
sl@0
   295
test expr-old-12.6 {precedence checks} {expr 6<<1<5} 0
sl@0
   296
test expr-old-12.7 {precedence checks} {expr 5<=6<<1} 1
sl@0
   297
test expr-old-12.8 {precedence checks} {expr 5>=6<<1} 0
sl@0
   298
sl@0
   299
test expr-old-13.1 {precedence checks} {expr 2<3<4} 1
sl@0
   300
test expr-old-13.2 {precedence checks} {expr 0<4>2} 0
sl@0
   301
test expr-old-13.3 {precedence checks} {expr 4>2<1} 0
sl@0
   302
test expr-old-13.4 {precedence checks} {expr 4>3>2} 0
sl@0
   303
test expr-old-13.5 {precedence checks} {expr 4>3>=2} 0
sl@0
   304
test expr-old-13.6 {precedence checks} {expr 4>=3>2} 0
sl@0
   305
test expr-old-13.7 {precedence checks} {expr 4>=3>=2} 0
sl@0
   306
test expr-old-13.8 {precedence checks} {expr 0<=4>=2} 0
sl@0
   307
test expr-old-13.9 {precedence checks} {expr 4>=2<=0} 0
sl@0
   308
test expr-old-13.10 {precedence checks} {expr 2<=3<=4} 1
sl@0
   309
sl@0
   310
test expr-old-14.1 {precedence checks} {expr 1==4>3} 1
sl@0
   311
test expr-old-14.2 {precedence checks} {expr 0!=4>3} 1
sl@0
   312
test expr-old-14.3 {precedence checks} {expr 1==3<4} 1
sl@0
   313
test expr-old-14.4 {precedence checks} {expr 0!=3<4} 1
sl@0
   314
test expr-old-14.5 {precedence checks} {expr 1==4>=3} 1
sl@0
   315
test expr-old-14.6 {precedence checks} {expr 0!=4>=3} 1
sl@0
   316
test expr-old-14.7 {precedence checks} {expr 1==3<=4} 1
sl@0
   317
test expr-old-14.8 {precedence checks} {expr 0!=3<=4} 1
sl@0
   318
test expr-old-14.9 {precedence checks} {expr 1eq4>3} 1
sl@0
   319
test expr-old-14.10 {precedence checks} {expr 0ne4>3} 1
sl@0
   320
test expr-old-14.11 {precedence checks} {expr 1eq3<4} 1
sl@0
   321
test expr-old-14.12 {precedence checks} {expr 0ne3<4} 1
sl@0
   322
test expr-old-14.13 {precedence checks} {expr 1eq4>=3} 1
sl@0
   323
test expr-old-14.14 {precedence checks} {expr 0ne4>=3} 1
sl@0
   324
test expr-old-14.15 {precedence checks} {expr 1eq3<=4} 1
sl@0
   325
test expr-old-14.16 {precedence checks} {expr 0ne3<=4} 1
sl@0
   326
sl@0
   327
test expr-old-15.1 {precedence checks} {expr 1==3==3} 0
sl@0
   328
test expr-old-15.2 {precedence checks} {expr 3==3!=2} 1
sl@0
   329
test expr-old-15.3 {precedence checks} {expr 2!=3==3} 0
sl@0
   330
test expr-old-15.4 {precedence checks} {expr 2!=1!=1} 0
sl@0
   331
test expr-old-15.5 {precedence checks} {expr 1eq3eq3} 0
sl@0
   332
test expr-old-15.6 {precedence checks} {expr 3eq3ne2} 1
sl@0
   333
test expr-old-15.7 {precedence checks} {expr 2ne3eq3} 0
sl@0
   334
test expr-old-15.8 {precedence checks} {expr 2ne1ne1} 0
sl@0
   335
sl@0
   336
test expr-old-16.1 {precedence checks} {expr 2&3eq2} 0
sl@0
   337
test expr-old-16.2 {precedence checks} {expr 1&3ne3} 0
sl@0
   338
test expr-old-16.3 {precedence checks} {expr 2&3eq2} 0
sl@0
   339
test expr-old-16.4 {precedence checks} {expr 1&3ne3} 0
sl@0
   340
sl@0
   341
test expr-old-17.1 {precedence checks} {expr 7&3^0x10} 19
sl@0
   342
test expr-old-17.2 {precedence checks} {expr 7^0x10&3} 7
sl@0
   343
sl@0
   344
test expr-old-18.1 {precedence checks} {expr 7^0x10|3} 23
sl@0
   345
test expr-old-18.2 {precedence checks} {expr 7|0x10^3} 23
sl@0
   346
sl@0
   347
test expr-old-19.1 {precedence checks} {expr 7|3&&1} 1
sl@0
   348
test expr-old-19.2 {precedence checks} {expr 1&&3|7} 1
sl@0
   349
test expr-old-19.3 {precedence checks} {expr 0&&1||1} 1
sl@0
   350
test expr-old-19.4 {precedence checks} {expr 1||1&&0} 1
sl@0
   351
sl@0
   352
test expr-old-20.1 {precedence checks} {expr 1||0?3:4} 3
sl@0
   353
test expr-old-20.2 {precedence checks} {expr 1?0:4||1} 0
sl@0
   354
test expr-old-20.3 {precedence checks} {expr 1?2:0?3:4} 2
sl@0
   355
test expr-old-20.4 {precedence checks} {expr 0?2:0?3:4} 4
sl@0
   356
test expr-old-20.5 {precedence checks} {expr 1?2?3:4:0} 3
sl@0
   357
test expr-old-20.6 {precedence checks} {expr 0?2?3:4:0} 0
sl@0
   358
sl@0
   359
# Parentheses.
sl@0
   360
sl@0
   361
test expr-old-21.1 {parenthesization} {expr (2+4)*6} 36
sl@0
   362
test expr-old-21.2 {parenthesization} {expr (1?0:4)||1} 1
sl@0
   363
test expr-old-21.3 {parenthesization} {expr +(3-4)} -1
sl@0
   364
sl@0
   365
# Embedded commands and variable names.
sl@0
   366
sl@0
   367
set a 16 
sl@0
   368
test expr-old-22.1 {embedded variables} {expr {2*$a}} 32 
sl@0
   369
test expr-old-22.2 {embedded variables} {
sl@0
   370
    set x -5
sl@0
   371
    set y 10
sl@0
   372
    expr {$x + $y}
sl@0
   373
} {5} 
sl@0
   374
test expr-old-22.3 {embedded variables} {
sl@0
   375
    set x "  -5"
sl@0
   376
    set y "  +10"
sl@0
   377
    expr {$x + $y}
sl@0
   378
} {5}
sl@0
   379
test expr-old-22.4 {embedded commands and variables} {expr {[set a] - 14}} 2
sl@0
   380
test expr-old-22.5 {embedded commands and variables} {
sl@0
   381
    list [catch {expr {12 - [bad_command_name]}} msg] $msg
sl@0
   382
} {1 {invalid command name "bad_command_name"}}
sl@0
   383
sl@0
   384
# Double-quotes and things inside them.
sl@0
   385
sl@0
   386
test expr-old-23.1 {double quotes} {expr {"abc"}} abc
sl@0
   387
test expr-old-23.2 {double quotes} {
sl@0
   388
    set a 189
sl@0
   389
    expr {"$a.bc"}
sl@0
   390
} 189.bc
sl@0
   391
test expr-old-23.3 {double quotes} {
sl@0
   392
    set b2 xyx
sl@0
   393
    expr {"$b2$b2$b2.[set b2].[set b2]"}
sl@0
   394
} xyxxyxxyx.xyx.xyx
sl@0
   395
test expr-old-23.4 {double quotes} {expr {"11\}\}22"}} 11}}22
sl@0
   396
test expr-old-23.5 {double quotes} {expr {"\*bc"}} {*bc}
sl@0
   397
test expr-old-23.6 {double quotes} {
sl@0
   398
    catch {unset bogus__}
sl@0
   399
    list [catch {expr {"$bogus__"}} msg] $msg
sl@0
   400
} {1 {can't read "bogus__": no such variable}}
sl@0
   401
test expr-old-23.7 {double quotes} {
sl@0
   402
    list [catch {expr {"a[error Testing]bc"}} msg] $msg
sl@0
   403
} {1 Testing}
sl@0
   404
test expr-old-23.8 {double quotes} {
sl@0
   405
    list [catch {expr {"12398712938788234-1298379" != ""}} msg] $msg
sl@0
   406
} {0 1}
sl@0
   407
sl@0
   408
# Numbers in various bases.
sl@0
   409
sl@0
   410
test expr-old-24.1 {numbers in different bases} {expr 0x20} 32
sl@0
   411
test expr-old-24.2 {numbers in different bases} {expr 015} 13
sl@0
   412
sl@0
   413
# Conversions between various data types.
sl@0
   414
sl@0
   415
test expr-old-25.1 {type conversions} {expr 2+2.5} 4.5
sl@0
   416
test expr-old-25.2 {type conversions} {expr 2.5+2} 4.5
sl@0
   417
test expr-old-25.3 {type conversions} {expr 2-2.5} -0.5
sl@0
   418
test expr-old-25.4 {type conversions} {expr 2/2.5} 0.8
sl@0
   419
test expr-old-25.5 {type conversions} {expr 2>2.5} 0
sl@0
   420
test expr-old-25.6 {type conversions} {expr 2.5>2} 1
sl@0
   421
test expr-old-25.7 {type conversions} {expr 2<2.5} 1
sl@0
   422
test expr-old-25.8 {type conversions} {expr 2>=2.5} 0
sl@0
   423
test expr-old-25.9 {type conversions} {expr 2<=2.5} 1
sl@0
   424
test expr-old-25.10 {type conversions} {expr 2==2.5} 0
sl@0
   425
test expr-old-25.11 {type conversions} {expr 2!=2.5} 1
sl@0
   426
test expr-old-25.12 {type conversions} {expr 2>"ab"} 0
sl@0
   427
test expr-old-25.13 {type conversions} {expr {2>" "}} 1
sl@0
   428
test expr-old-25.14 {type conversions} {expr {"24.1a" > 24.1}} 1
sl@0
   429
test expr-old-25.15 {type conversions} {expr {24.1 > "24.1a"}} 0
sl@0
   430
test expr-old-25.16 {type conversions} {expr 2+2.5} 4.5
sl@0
   431
test expr-old-25.17 {type conversions} {expr 2+2.5} 4.5
sl@0
   432
test expr-old-25.18 {type conversions} {expr 2.0e2} 200.0
sl@0
   433
test expr-old-25.19 {type conversions} {eformat} {expr 2.0e15} 2e+15
sl@0
   434
test expr-old-25.20 {type conversions} {expr 10.0} 10.0
sl@0
   435
sl@0
   436
# Various error conditions.
sl@0
   437
sl@0
   438
test expr-old-26.1 {error conditions} {
sl@0
   439
    list [catch {expr 2+"a"} msg] $msg
sl@0
   440
} {1 {can't use non-numeric string as operand of "+"}}
sl@0
   441
test expr-old-26.2 {error conditions} {
sl@0
   442
    list [catch {expr 2+4*} msg] $msg
sl@0
   443
} {1 {syntax error in expression "2+4*": premature end of expression}}
sl@0
   444
test expr-old-26.3 {error conditions} {
sl@0
   445
    list [catch {expr 2+4*(} msg] $msg
sl@0
   446
} {1 {syntax error in expression "2+4*(": premature end of expression}}
sl@0
   447
catch {unset _non_existent_}
sl@0
   448
test expr-old-26.4 {error conditions} {
sl@0
   449
    list [catch {expr 2+$_non_existent_} msg] $msg
sl@0
   450
} {1 {can't read "_non_existent_": no such variable}}
sl@0
   451
set a xx
sl@0
   452
test expr-old-26.5 {error conditions} {
sl@0
   453
    list [catch {expr {2+$a}} msg] $msg
sl@0
   454
} {1 {can't use non-numeric string as operand of "+"}}
sl@0
   455
test expr-old-26.6 {error conditions} {
sl@0
   456
    list [catch {expr {2+[set a]}} msg] $msg
sl@0
   457
} {1 {can't use non-numeric string as operand of "+"}}
sl@0
   458
test expr-old-26.7 {error conditions} {
sl@0
   459
    list [catch {expr {2+(4}} msg] $msg
sl@0
   460
} {1 {syntax error in expression "2+(4": looking for close parenthesis}}
sl@0
   461
test expr-old-26.8 {error conditions} {
sl@0
   462
    list [catch {expr 2/0} msg] $msg $errorCode
sl@0
   463
} {1 {divide by zero} {ARITH DIVZERO {divide by zero}}}
sl@0
   464
test expr-old-26.9 {error conditions} {
sl@0
   465
    list [catch {expr 2%0} msg] $msg $errorCode
sl@0
   466
} {1 {divide by zero} {ARITH DIVZERO {divide by zero}}}
sl@0
   467
test expr-old-26.10 {error conditions} {
sl@0
   468
    list [catch {expr 2.0/0.0} msg] $msg $errorCode
sl@0
   469
} {1 {divide by zero} {ARITH DIVZERO {divide by zero}}}
sl@0
   470
test expr-old-26.11 {error conditions} {
sl@0
   471
    list [catch {expr 2#} msg] $msg
sl@0
   472
} {1 {syntax error in expression "2#": extra tokens at end of expression}}
sl@0
   473
test expr-old-26.12 {error conditions} {
sl@0
   474
    list [catch {expr a.b} msg] $msg
sl@0
   475
} {1 {syntax error in expression "a.b": variable references require preceding $}}
sl@0
   476
test expr-old-26.13 {error conditions} {
sl@0
   477
    list [catch {expr {"a"/"b"}} msg] $msg
sl@0
   478
} {1 {can't use non-numeric string as operand of "/"}}
sl@0
   479
test expr-old-26.14 {error conditions} {
sl@0
   480
    list [catch {expr 2:3} msg] $msg
sl@0
   481
} {1 {syntax error in expression "2:3": extra tokens at end of expression}}
sl@0
   482
test expr-old-26.15 {error conditions} {
sl@0
   483
    list [catch {expr a@b} msg] $msg
sl@0
   484
} {1 {syntax error in expression "a@b": variable references require preceding $}}
sl@0
   485
test expr-old-26.16 {error conditions} {
sl@0
   486
    list [catch {expr a[b} msg] $msg
sl@0
   487
} {1 {missing close-bracket}}
sl@0
   488
test expr-old-26.17 {error conditions} {
sl@0
   489
    list [catch {expr a`b} msg] $msg
sl@0
   490
} {1 {syntax error in expression "a`b": variable references require preceding $}}
sl@0
   491
test expr-old-26.18 {error conditions} {
sl@0
   492
    list [catch {expr \"a\"\{b} msg] $msg
sl@0
   493
} {1 syntax\ error\ in\ expression\ \"\"a\"\{b\":\ extra\ tokens\ at\ end\ of\ expression}
sl@0
   494
test expr-old-26.19 {error conditions} {
sl@0
   495
    list [catch {expr a} msg] $msg
sl@0
   496
} {1 {syntax error in expression "a": variable references require preceding $}}
sl@0
   497
test expr-old-26.20 {error conditions} {
sl@0
   498
    list [catch expr msg] $msg
sl@0
   499
} {1 {wrong # args: should be "expr arg ?arg ...?"}}
sl@0
   500
sl@0
   501
# Cancelled evaluation.
sl@0
   502
sl@0
   503
test expr-old-27.1 {cancelled evaluation} {
sl@0
   504
    set a 1
sl@0
   505
    expr {0&&[set a 2]}
sl@0
   506
    set a
sl@0
   507
} 1
sl@0
   508
test expr-old-27.2 {cancelled evaluation} {
sl@0
   509
    set a 1
sl@0
   510
    expr {1||[set a 2]}
sl@0
   511
    set a
sl@0
   512
} 1
sl@0
   513
test expr-old-27.3 {cancelled evaluation} {
sl@0
   514
    set a 1
sl@0
   515
    expr {0?[set a 2]:1}
sl@0
   516
    set a
sl@0
   517
} 1
sl@0
   518
test expr-old-27.4 {cancelled evaluation} {
sl@0
   519
    set a 1
sl@0
   520
    expr {1?2:[set a 2]}
sl@0
   521
    set a
sl@0
   522
} 1
sl@0
   523
catch {unset x}
sl@0
   524
test expr-old-27.5 {cancelled evaluation} {
sl@0
   525
    list [catch {expr {[info exists x] && $x}} msg] $msg
sl@0
   526
} {0 0}
sl@0
   527
test expr-old-27.6 {cancelled evaluation} {
sl@0
   528
    list [catch {expr {0 && [concat $x]}} msg] $msg
sl@0
   529
} {0 0}
sl@0
   530
test expr-old-27.7 {cancelled evaluation} {
sl@0
   531
    set one 1
sl@0
   532
    list [catch {expr {1 || 1/$one}} msg] $msg
sl@0
   533
} {0 1}
sl@0
   534
test expr-old-27.8 {cancelled evaluation} {
sl@0
   535
    list [catch {expr {1 || -"string"}} msg] $msg
sl@0
   536
} {0 1}
sl@0
   537
test expr-old-27.9 {cancelled evaluation} {
sl@0
   538
    list [catch {expr {1 || ("string" * ("x" && "y"))}} msg] $msg
sl@0
   539
} {0 1}
sl@0
   540
test expr-old-27.10 {cancelled evaluation} {
sl@0
   541
    set x -1.0
sl@0
   542
    list [catch {expr {($x > 0) ? round(log($x)) : 0}} msg] $msg
sl@0
   543
} {0 0}
sl@0
   544
test expr-old-27.11 {cancelled evaluation} {
sl@0
   545
    list [catch {expr {0 && foo}} msg] $msg
sl@0
   546
} {1 {syntax error in expression "0 && foo": variable references require preceding $}}
sl@0
   547
test expr-old-27.12 {cancelled evaluation} {
sl@0
   548
    list [catch {expr {0 ? 1 : foo}} msg] $msg
sl@0
   549
} {1 {syntax error in expression "0 ? 1 : foo": variable references require preceding $}}
sl@0
   550
sl@0
   551
# Tcl_ExprBool as used in "if" statements
sl@0
   552
sl@0
   553
test expr-old-28.1 {Tcl_ExprBoolean usage} {
sl@0
   554
    set a 1
sl@0
   555
    if {2} {set a 2}
sl@0
   556
    set a
sl@0
   557
} 2
sl@0
   558
test expr-old-28.2 {Tcl_ExprBoolean usage} {
sl@0
   559
    set a 1
sl@0
   560
    if {0} {set a 2}
sl@0
   561
    set a
sl@0
   562
} 1
sl@0
   563
test expr-old-28.3 {Tcl_ExprBoolean usage} {
sl@0
   564
    set a 1
sl@0
   565
    if {1.2} {set a 2}
sl@0
   566
    set a
sl@0
   567
} 2
sl@0
   568
test expr-old-28.4 {Tcl_ExprBoolean usage} {
sl@0
   569
    set a 1
sl@0
   570
    if {-1.1} {set a 2}
sl@0
   571
    set a
sl@0
   572
} 2
sl@0
   573
test expr-old-28.5 {Tcl_ExprBoolean usage} {
sl@0
   574
    set a 1
sl@0
   575
    if {0.0} {set a 2}
sl@0
   576
    set a
sl@0
   577
} 1
sl@0
   578
test expr-old-28.6 {Tcl_ExprBoolean usage} {
sl@0
   579
    set a 1
sl@0
   580
    if {"YES"} {set a 2}
sl@0
   581
    set a
sl@0
   582
} 2
sl@0
   583
test expr-old-28.7 {Tcl_ExprBoolean usage} {
sl@0
   584
    set a 1
sl@0
   585
    if {"no"} {set a 2}
sl@0
   586
    set a
sl@0
   587
} 1
sl@0
   588
test expr-old-28.8 {Tcl_ExprBoolean usage} {
sl@0
   589
    set a 1
sl@0
   590
    if {"true"} {set a 2}
sl@0
   591
    set a
sl@0
   592
} 2
sl@0
   593
test expr-old-28.9 {Tcl_ExprBoolean usage} {
sl@0
   594
    set a 1
sl@0
   595
    if {"fAlse"} {set a 2}
sl@0
   596
    set a
sl@0
   597
} 1
sl@0
   598
test expr-old-28.10 {Tcl_ExprBoolean usage} {
sl@0
   599
    set a 1
sl@0
   600
    if {"on"} {set a 2}
sl@0
   601
    set a
sl@0
   602
} 2
sl@0
   603
test expr-old-28.11 {Tcl_ExprBoolean usage} {
sl@0
   604
    set a 1
sl@0
   605
    if {"Off"} {set a 2}
sl@0
   606
    set a
sl@0
   607
} 1
sl@0
   608
test expr-old-28.12 {Tcl_ExprBool usage} {
sl@0
   609
    list [catch {if {"abc"} {}} msg] $msg
sl@0
   610
} {1 {expected boolean value but got "abc"}}
sl@0
   611
test expr-old-28.13 {Tcl_ExprBool usage} {
sl@0
   612
    list [catch {if {"ogle"} {}} msg] $msg
sl@0
   613
} {1 {expected boolean value but got "ogle"}}
sl@0
   614
test expr-old-28.14 {Tcl_ExprBool usage} {
sl@0
   615
    list [catch {if {"o"} {}} msg] $msg
sl@0
   616
} {1 {expected boolean value but got "o"}}
sl@0
   617
sl@0
   618
# Operands enclosed in braces
sl@0
   619
sl@0
   620
test expr-old-29.1 {braces} {expr {{abc}}} abc
sl@0
   621
test expr-old-29.2 {braces} {expr {{00010}}} 8
sl@0
   622
test expr-old-29.3 {braces} {expr {{3.1200000}}} 3.12
sl@0
   623
test expr-old-29.4 {braces} {expr {{a{b}{1 {2 3}}c}}} "a{b}{1 {2 3}}c"
sl@0
   624
test expr-old-29.5 {braces} {
sl@0
   625
    list [catch {expr "\{abc"} msg] $msg
sl@0
   626
} {1 {missing close-brace}}
sl@0
   627
sl@0
   628
# Very long values
sl@0
   629
sl@0
   630
test expr-old-30.1 {long values} {
sl@0
   631
    set a "0000 1111 2222 3333 4444"
sl@0
   632
    set a "$a | $a | $a | $a | $a"
sl@0
   633
    set a "$a || $a || $a || $a || $a"
sl@0
   634
    expr {$a}
sl@0
   635
} {0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 || 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 || 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 || 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 || 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444 | 0000 1111 2222 3333 4444}
sl@0
   636
test expr-old-30.2 {long values} {
sl@0
   637
    set a "000000000000000000000000000000"
sl@0
   638
    set a "$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a${a}5"
sl@0
   639
    expr $a
sl@0
   640
} 5
sl@0
   641
sl@0
   642
# Expressions spanning multiple arguments
sl@0
   643
sl@0
   644
test expr-old-31.1 {multiple arguments to expr command} {
sl@0
   645
    expr 4 + ( 6 *12) -3
sl@0
   646
} 73
sl@0
   647
test expr-old-31.2 {multiple arguments to expr command} {
sl@0
   648
    list [catch {expr 2 + (3 + 4} msg] $msg
sl@0
   649
} {1 {syntax error in expression "2 + (3 + 4": looking for close parenthesis}}
sl@0
   650
test expr-old-31.3 {multiple arguments to expr command} {
sl@0
   651
    list [catch {expr 2 + 3 +} msg] $msg
sl@0
   652
} {1 {syntax error in expression "2 + 3 +": premature end of expression}}
sl@0
   653
test expr-old-31.4 {multiple arguments to expr command} {
sl@0
   654
    list [catch {expr 2 + 3 )} msg] $msg
sl@0
   655
} {1 {syntax error in expression "2 + 3 )": extra tokens at end of expression}}
sl@0
   656
sl@0
   657
# Math functions
sl@0
   658
sl@0
   659
test expr-old-32.1 {math functions in expressions} {
sl@0
   660
    format %.6g [expr acos(0.5)]
sl@0
   661
} {1.0472}
sl@0
   662
test expr-old-32.2 {math functions in expressions} {
sl@0
   663
    format %.6g [expr asin(0.5)]
sl@0
   664
} {0.523599}
sl@0
   665
test expr-old-32.3 {math functions in expressions} {
sl@0
   666
    format %.6g [expr atan(1.0)]
sl@0
   667
} {0.785398}
sl@0
   668
test expr-old-32.4 {math functions in expressions} {
sl@0
   669
    format %.6g [expr atan2(2.0, 2.0)]
sl@0
   670
} {0.785398}
sl@0
   671
test expr-old-32.5 {math functions in expressions} {
sl@0
   672
    format %.6g [expr ceil(1.999)]
sl@0
   673
} {2}
sl@0
   674
test expr-old-32.6 {math functions in expressions} {
sl@0
   675
    format %.6g [expr cos(.1)]
sl@0
   676
} {0.995004}
sl@0
   677
test expr-old-32.7 {math functions in expressions} {
sl@0
   678
    format %.6g [expr cosh(.1)]
sl@0
   679
} {1.005}
sl@0
   680
test expr-old-32.8 {math functions in expressions} {
sl@0
   681
    format %.6g [expr exp(1.0)]
sl@0
   682
} {2.71828}
sl@0
   683
test expr-old-32.9 {math functions in expressions} {
sl@0
   684
    format %.6g [expr floor(2.000)]
sl@0
   685
} {2}
sl@0
   686
test expr-old-32.10 {math functions in expressions} {
sl@0
   687
    format %.6g [expr floor(2.001)]
sl@0
   688
} {2}
sl@0
   689
test expr-old-32.11 {math functions in expressions} {
sl@0
   690
    format %.6g [expr fmod(7.3, 3.2)]
sl@0
   691
} {0.9}
sl@0
   692
test expr-old-32.12 {math functions in expressions} {
sl@0
   693
    format %.6g [expr hypot(3.0, 4.0)]
sl@0
   694
} {5}
sl@0
   695
test expr-old-32.13 {math functions in expressions} {
sl@0
   696
    format %.6g [expr log(2.8)]
sl@0
   697
} {1.02962}
sl@0
   698
test expr-old-32.14 {math functions in expressions} {
sl@0
   699
    format %.6g [expr log10(2.8)]
sl@0
   700
} {0.447158}
sl@0
   701
test expr-old-32.15 {math functions in expressions} {
sl@0
   702
    format %.6g [expr pow(2.1, 3.1)]
sl@0
   703
} {9.97424}
sl@0
   704
test expr-old-32.16 {math functions in expressions} {
sl@0
   705
    format %.6g [expr sin(.1)]
sl@0
   706
} {0.0998334}
sl@0
   707
test expr-old-32.17 {math functions in expressions} {
sl@0
   708
    format %.6g [expr sinh(.1)]
sl@0
   709
} {0.100167}
sl@0
   710
test expr-old-32.18 {math functions in expressions} {
sl@0
   711
    format %.6g [expr sqrt(2.0)]
sl@0
   712
} {1.41421}
sl@0
   713
test expr-old-32.19 {math functions in expressions} {
sl@0
   714
    format %.6g [expr tan(0.8)]
sl@0
   715
} {1.02964}
sl@0
   716
test expr-old-32.20 {math functions in expressions} {
sl@0
   717
    format %.6g [expr tanh(0.8)]
sl@0
   718
} {0.664037}
sl@0
   719
test expr-old-32.21 {math functions in expressions} {
sl@0
   720
    format %.6g [expr abs(-1.8)]
sl@0
   721
} {1.8}
sl@0
   722
test expr-old-32.22 {math functions in expressions} {
sl@0
   723
    expr abs(10.0)
sl@0
   724
} {10.0}
sl@0
   725
test expr-old-32.23 {math functions in expressions} {
sl@0
   726
    format %.6g [expr abs(-4)]
sl@0
   727
} {4}
sl@0
   728
test expr-old-32.24 {math functions in expressions} {
sl@0
   729
    format %.6g [expr abs(66)]
sl@0
   730
} {66}
sl@0
   731
sl@0
   732
# The following test is different for 32-bit versus 64-bit architectures.
sl@0
   733
sl@0
   734
if {0x80000000 > 0} {
sl@0
   735
    test expr-old-32.25 {math functions in expressions} {nonPortable} {
sl@0
   736
	list [catch {expr abs(0x8000000000000000)} msg] $msg
sl@0
   737
    } {1 {integer value too large to represent}}
sl@0
   738
} else {
sl@0
   739
    test expr-old-32.25 {math functions in expressions} {nonPortable} {
sl@0
   740
	list [catch {expr abs(0x80000000)} msg] $msg
sl@0
   741
    } {1 {integer value too large to represent}}
sl@0
   742
}
sl@0
   743
sl@0
   744
test expr-old-32.26 {math functions in expressions} {
sl@0
   745
    expr double(1)
sl@0
   746
} {1.0}
sl@0
   747
test expr-old-32.27 {math functions in expressions} {
sl@0
   748
    expr double(1.1)
sl@0
   749
} {1.1}
sl@0
   750
test expr-old-32.28 {math functions in expressions} {
sl@0
   751
    expr int(1)
sl@0
   752
} {1}
sl@0
   753
test expr-old-32.29 {math functions in expressions} {
sl@0
   754
    expr int(1.4)
sl@0
   755
} {1}
sl@0
   756
test expr-old-32.30 {math functions in expressions} {
sl@0
   757
    expr int(1.6)
sl@0
   758
} {1}
sl@0
   759
test expr-old-32.31 {math functions in expressions} {
sl@0
   760
    expr int(-1.4)
sl@0
   761
} {-1}
sl@0
   762
test expr-old-32.32 {math functions in expressions} {
sl@0
   763
    expr int(-1.6)
sl@0
   764
} {-1}
sl@0
   765
test expr-old-32.33 {math functions in expressions} {
sl@0
   766
    list [catch {expr int(1e60)} msg] $msg
sl@0
   767
} {1 {integer value too large to represent}}
sl@0
   768
test expr-old-32.34 {math functions in expressions} {
sl@0
   769
    list [catch {expr int(-1e60)} msg] $msg
sl@0
   770
} {1 {integer value too large to represent}}
sl@0
   771
test expr-old-32.35 {math functions in expressions} {
sl@0
   772
    expr round(1.49)
sl@0
   773
} {1}
sl@0
   774
test expr-old-32.36 {math functions in expressions} {
sl@0
   775
    expr round(1.51)
sl@0
   776
} {2}
sl@0
   777
test expr-old-32.37 {math functions in expressions} {
sl@0
   778
    expr round(-1.49)
sl@0
   779
} {-1}
sl@0
   780
test expr-old-32.38 {math functions in expressions} {
sl@0
   781
    expr round(-1.51)
sl@0
   782
} {-2}
sl@0
   783
test expr-old-32.39 {math functions in expressions} {
sl@0
   784
    list [catch {expr round(1e60)} msg] $msg
sl@0
   785
} {1 {integer value too large to represent}}
sl@0
   786
test expr-old-32.40 {math functions in expressions} {
sl@0
   787
    list [catch {expr round(-1e60)} msg] $msg
sl@0
   788
} {1 {integer value too large to represent}}
sl@0
   789
test expr-old-32.41 {math functions in expressions} {
sl@0
   790
    list [catch {expr pow(1.0 + 3.0 - 2, .8 * 5)} msg] $msg
sl@0
   791
} {0 16.0}
sl@0
   792
test expr-old-32.42 {math functions in expressions} {
sl@0
   793
    list [catch {expr hypot(5*.8,3)} msg] $msg
sl@0
   794
} {0 5.0}
sl@0
   795
if $gotT1 {
sl@0
   796
    test expr-old-32.43 {math functions in expressions} {
sl@0
   797
	expr 2*T1()
sl@0
   798
    } 246
sl@0
   799
    test expr-old-32.44 {math functions in expressions} {
sl@0
   800
	expr T2()*3
sl@0
   801
    } 1035
sl@0
   802
}
sl@0
   803
test expr-old-32.45 {math functions in expressions} {
sl@0
   804
    expr (0 <= rand()) && (rand() < 1)
sl@0
   805
} {1}
sl@0
   806
test expr-old-32.46 {math functions in expressions} {
sl@0
   807
    list [catch {expr rand(24)} msg] $msg
sl@0
   808
} {1 {too many arguments for math function}}
sl@0
   809
test expr-old-32.47 {math functions in expressions} {
sl@0
   810
    list [catch {expr srand()} msg] $msg
sl@0
   811
} {1 {too few arguments for math function}}
sl@0
   812
test expr-old-32.48 {math functions in expressions} {
sl@0
   813
    list [catch {expr srand(3.79)} msg] $msg
sl@0
   814
} {1 {expected integer but got "3.79"}}
sl@0
   815
test expr-old-32.49 {math functions in expressions} {
sl@0
   816
    list [catch {expr srand("")} msg] $msg
sl@0
   817
} {1 {argument to math function didn't have numeric value}}
sl@0
   818
test expr-old-32.50 {math functions in expressions} {
sl@0
   819
    set result [expr round(srand(12345) * 1000)]
sl@0
   820
    for {set i 0} {$i < 10} {incr i} {
sl@0
   821
	lappend result [expr round(rand() * 1000)]
sl@0
   822
    }
sl@0
   823
    set result
sl@0
   824
} {97 834 948 36 12 51 766 585 914 784 333}
sl@0
   825
test expr-old-32.51 {math functions in expressions} {
sl@0
   826
    list [catch {expr {srand([lindex "6ty" 0])}} msg] $msg
sl@0
   827
} {1 {argument to math function didn't have numeric value}}
sl@0
   828
test expr-old-32.52 {math functions in expressions} {
sl@0
   829
    expr {srand(int(1<<37)) < 1}
sl@0
   830
} {1}
sl@0
   831
test expr-old-32.53 {math functions in expressions} {
sl@0
   832
    expr {srand((1<<31) - 1) > 0}
sl@0
   833
} {1}
sl@0
   834
sl@0
   835
test expr-old-33.1 {conversions and fancy args to math functions} {
sl@0
   836
    expr hypot ( 3 , 4 )
sl@0
   837
} 5.0
sl@0
   838
test expr-old-33.2 {conversions and fancy args to math functions} {
sl@0
   839
    expr hypot ( (2.0+1.0) , 4 )
sl@0
   840
} 5.0
sl@0
   841
test expr-old-33.3 {conversions and fancy args to math functions} {
sl@0
   842
    expr hypot ( 3 , (3.0 + 1.0) )
sl@0
   843
} 5.0
sl@0
   844
test expr-old-33.4 {conversions and fancy args to math functions} {
sl@0
   845
    format %.6g [expr cos(acos(0.1))]
sl@0
   846
} 0.1
sl@0
   847
sl@0
   848
test expr-old-34.1 {errors in math functions} {
sl@0
   849
    list [catch {expr func_2(1.0)} msg] $msg
sl@0
   850
} {1 {unknown math function "func_2"}}
sl@0
   851
test expr-old-34.2 {errors in math functions} {
sl@0
   852
    list [catch {expr func|(1.0)} msg] $msg
sl@0
   853
} {1 {syntax error in expression "func|(1.0)": variable references require preceding $}}
sl@0
   854
test expr-old-34.3 {errors in math functions} {
sl@0
   855
    list [catch {expr {hypot("a b", 2.0)}} msg] $msg
sl@0
   856
} {1 {argument to math function didn't have numeric value}}
sl@0
   857
test expr-old-34.4 {errors in math functions} {
sl@0
   858
    list [catch {expr hypot(1.0 2.0)} msg] $msg
sl@0
   859
} {1 {syntax error in expression "hypot(1.0 2.0)": missing close parenthesis at end of function call}}
sl@0
   860
test expr-old-34.5 {errors in math functions} {
sl@0
   861
    list [catch {expr hypot(1.0, 2.0} msg] $msg
sl@0
   862
} {1 {syntax error in expression "hypot(1.0, 2.0": missing close parenthesis at end of function call}}
sl@0
   863
test expr-old-34.6 {errors in math functions} {
sl@0
   864
    list [catch {expr hypot(1.0 ,} msg] $msg
sl@0
   865
} {1 {syntax error in expression "hypot(1.0 ,": premature end of expression}}
sl@0
   866
test expr-old-34.7 {errors in math functions} {
sl@0
   867
    list [catch {expr hypot(1.0)} msg] $msg
sl@0
   868
} {1 {too few arguments for math function}}
sl@0
   869
test expr-old-34.8 {errors in math functions} {
sl@0
   870
    list [catch {expr hypot(1.0, 2.0, 3.0)} msg] $msg
sl@0
   871
} {1 {too many arguments for math function}}
sl@0
   872
test expr-old-34.9 {errors in math functions} {
sl@0
   873
    list [catch {expr acos(-2.0)} msg] $msg $errorCode
sl@0
   874
} {1 {domain error: argument not in valid range} {ARITH DOMAIN {domain error: argument not in valid range}}}
sl@0
   875
test expr-old-34.10 {errors in math functions} {nonPortable} {
sl@0
   876
    list [catch {expr pow(-3, 1000001)} msg] $msg $errorCode
sl@0
   877
} {1 {floating-point value too large to represent} {ARITH OVERFLOW {floating-point value too large to represent}}}
sl@0
   878
test expr-old-34.11 {errors in math functions} {
sl@0
   879
    list [catch {expr pow(3, 1000001)} msg] $msg $errorCode
sl@0
   880
} {1 {floating-point value too large to represent} {ARITH OVERFLOW {floating-point value too large to represent}}}
sl@0
   881
test expr-old-34.12 {errors in math functions} {
sl@0
   882
    list [catch {expr -14.0*exp(100000)} msg] $msg $errorCode
sl@0
   883
} {1 {floating-point value too large to represent} {ARITH OVERFLOW {floating-point value too large to represent}}}
sl@0
   884
test expr-old-34.13 {errors in math functions} {
sl@0
   885
    list [catch {expr int(1.0e30)} msg] $msg $errorCode
sl@0
   886
} {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}}
sl@0
   887
test expr-old-34.14 {errors in math functions} {
sl@0
   888
    list [catch {expr int(-1.0e30)} msg] $msg $errorCode
sl@0
   889
} {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}}
sl@0
   890
test expr-old-34.15 {errors in math functions} {
sl@0
   891
    list [catch {expr round(1.0e30)} msg] $msg $errorCode
sl@0
   892
} {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}}
sl@0
   893
test expr-old-34.16 {errors in math functions} {
sl@0
   894
    list [catch {expr round(-1.0e30)} msg] $msg $errorCode
sl@0
   895
} {1 {integer value too large to represent} {ARITH IOVERFLOW {integer value too large to represent}}}
sl@0
   896
if $gotT1 {
sl@0
   897
    test expr-old-34.17 {errors in math functions} {
sl@0
   898
	list [catch {expr T1(4)} msg] $msg
sl@0
   899
    } {1 {too many arguments for math function}}
sl@0
   900
}
sl@0
   901
sl@0
   902
test expr-old-36.1 {ExprLooksLikeInt procedure} -body {
sl@0
   903
    expr 0289
sl@0
   904
} -returnCodes error -match glob -result {*invalid octal number*}
sl@0
   905
test expr-old-36.2 {ExprLooksLikeInt procedure} {
sl@0
   906
    set x 0289
sl@0
   907
    list [catch {expr {$x+1}} msg] $msg
sl@0
   908
} {1 {can't use invalid octal number as operand of "+"}}
sl@0
   909
test expr-old-36.3 {ExprLooksLikeInt procedure} {
sl@0
   910
    list [catch {expr 0289.1} msg] $msg
sl@0
   911
} {0 289.1}
sl@0
   912
test expr-old-36.4 {ExprLooksLikeInt procedure} {
sl@0
   913
    set x 0289.1
sl@0
   914
    list [catch {expr {$x+1}} msg] $msg
sl@0
   915
} {0 290.1}
sl@0
   916
test expr-old-36.5 {ExprLooksLikeInt procedure} {
sl@0
   917
    set x {  +22}
sl@0
   918
    list [catch {expr {$x+1}} msg] $msg
sl@0
   919
} {0 23}
sl@0
   920
test expr-old-36.6 {ExprLooksLikeInt procedure} {
sl@0
   921
    set x {	-22}
sl@0
   922
    list [catch {expr {$x+1}} msg] $msg
sl@0
   923
} {0 -21}
sl@0
   924
test expr-old-36.7 {ExprLooksLikeInt procedure} {nonPortable unixOnly} {
sl@0
   925
    list [catch {expr nan} msg] $msg
sl@0
   926
} {1 {domain error: argument not in valid range}}
sl@0
   927
test expr-old-36.8 {ExprLooksLikeInt procedure} {
sl@0
   928
    list [catch {expr 78e1} msg] $msg
sl@0
   929
} {0 780.0}
sl@0
   930
test expr-old-36.9 {ExprLooksLikeInt procedure} {
sl@0
   931
    list [catch {expr 24E1} msg] $msg
sl@0
   932
} {0 240.0}
sl@0
   933
test expr-old-36.10 {ExprLooksLikeInt procedure} {nonPortable unixOnly} {
sl@0
   934
    list [catch {expr 78e} msg] $msg
sl@0
   935
} {1 {syntax error in expression "78e"}}
sl@0
   936
sl@0
   937
# test for [Bug #542588]
sl@0
   938
test expr-old-36.11 {ExprLooksLikeInt procedure} {
sl@0
   939
    # define a "too large integer"; this one works also for 64bit arith
sl@0
   940
    set x 665802003400000000000000
sl@0
   941
    list [catch {expr {$x+1}} msg] $msg
sl@0
   942
} {1 {can't use integer value too large to represent as operand of "+"}}
sl@0
   943
sl@0
   944
# tests for [Bug #587140]
sl@0
   945
test expr-old-36.12 {ExprLooksLikeInt procedure} {
sl@0
   946
    set x "10;"
sl@0
   947
    list [catch {expr {$x+1}} msg] $msg
sl@0
   948
} {1 {can't use non-numeric string as operand of "+"}}
sl@0
   949
test expr-old-36.13 {ExprLooksLikeInt procedure} {
sl@0
   950
    set x " +"
sl@0
   951
    list [catch {expr {$x+1}} msg] $msg
sl@0
   952
} {1 {can't use non-numeric string as operand of "+"}}
sl@0
   953
test expr-old-36.14 {ExprLooksLikeInt procedure} {
sl@0
   954
    set x "123456789012345678901234567890 "
sl@0
   955
    list [catch {expr {$x+1}} msg] $msg
sl@0
   956
} {1 {can't use integer value too large to represent as operand of "+"}}
sl@0
   957
test expr-old-36.15 {ExprLooksLikeInt procedure} {
sl@0
   958
    set x "099 "
sl@0
   959
    list [catch {expr {$x+1}} msg] $msg
sl@0
   960
} {1 {can't use invalid octal number as operand of "+"}}
sl@0
   961
test expr-old-36.16 {ExprLooksLikeInt procedure} {
sl@0
   962
    set x " 0xffffffffffffffffffffffffffffffffffffff  "
sl@0
   963
    list [catch {expr {$x+1}} msg] $msg
sl@0
   964
} {1 {can't use integer value too large to represent as operand of "+"}}
sl@0
   965
sl@0
   966
if {[info commands testexprlong] == {}} {
sl@0
   967
    puts "This application hasn't been compiled with the \"testexprlong\""
sl@0
   968
    puts "command, so I can't test Tcl_ExprLong etc."
sl@0
   969
} else {
sl@0
   970
test expr-old-37.1 {Check that Tcl_ExprLong doesn't modify interpreter result if no error} {
sl@0
   971
    testexprlong
sl@0
   972
} {This is a result: 5}
sl@0
   973
}
sl@0
   974
sl@0
   975
if {[info commands testexprstring] == {}} {
sl@0
   976
    puts "This application hasn't been compiled with the \"testexprstring\""
sl@0
   977
    puts "command, so I can't test Tcl_ExprString etc."
sl@0
   978
} else {
sl@0
   979
test expr-old-38.1 {Verify Tcl_ExprString's basic operation} {
sl@0
   980
    list [testexprstring "1+4"] [testexprstring "2*3+4.2"] \
sl@0
   981
        [catch {testexprstring "1+"} msg] $msg
sl@0
   982
} {5 10.2 1 {syntax error in expression "1+": premature end of expression}}
sl@0
   983
}
sl@0
   984
sl@0
   985
#
sl@0
   986
# Test for bug #908375: rounding numbers that do not fit in a
sl@0
   987
# long but do fit in a wide
sl@0
   988
#
sl@0
   989
sl@0
   990
test expr-old-39.1 {Rounding with wide result} {
sl@0
   991
    set x 1.0e10
sl@0
   992
    set y [expr $x + 0.1]
sl@0
   993
    catch {
sl@0
   994
	set x [list [expr {$x == round($y)}] [expr $x == -round(-$y)]]
sl@0
   995
    }
sl@0
   996
    set x
sl@0
   997
} {1 1}
sl@0
   998
unset -nocomplain x y
sl@0
   999
sl@0
  1000
# Special test for Pentium arithmetic bug of 1994:
sl@0
  1001
sl@0
  1002
if {(4195835.0 - (4195835.0/3145727.0)*3145727.0) == 256.0} {
sl@0
  1003
    puts "Warning: this machine contains a defective Pentium processor"
sl@0
  1004
    puts "that performs arithmetic incorrectly.  I recommend that you"
sl@0
  1005
    puts "call Intel customer service immediately at 1-800-628-8686"
sl@0
  1006
    puts "to request a replacement processor."
sl@0
  1007
}
sl@0
  1008
sl@0
  1009
# cleanup
sl@0
  1010
::tcltest::cleanupTests
sl@0
  1011
return