aio tempname: Fix a crash when the template is invalid
[jimtcl.git] / tests / expr.test
blobb195d4ad71ee9095fd96caeed90c56650ba32a50
1 source [file dirname [info script]]/testing.tcl
3 test expr-1.1 "Compare strings lt" {
4         expr {"V000500" < "V000405"}
5 } {0}
7 test expr-1.2 "Compare strings with embedded nulls" {
8         set s1 [format abc%cdef 0]
9         set s2 [format abc%cghi 0]
10         expr {$s1 < $s2}
11 } {1}
13 test expr-1.3 "Hex values" {
14         set mask1 [expr 0x4050 & 0x0CCC]
15 } {64}
17 test expr-1.4 "Ternary operator - true" {
18         expr {1 ? 2 : 3}
19 } {2}
21 test expr-1.5 "Ternary operator - false" {
22         expr {0 ? 2 : 3}
23 } {3}
25 test expr-1.6 "Ternary operator - double check" {
26         expr {1.0 ? 2 : 3}
27 } {2}
29 test expr-1.7 "Ternary operator - string result" {
30         expr {1 ? "two" : 3}
31 } {two}
33 test expr-1.8 "Ternary operator - don't eval false path" {
34         set a 100
35         set b 200
36         set c [expr {20 ? [incr a] : [incr b]}]
37         list $a $b $c
38 } {101 200 101}
40 test expr-1.9 "Unary minus" {
41         set a 1
42         expr {-$a}
43 } {-1}
45 test expr-1.10 "Subtraction" {
46         set a 1
47         set b 10
48         expr {$b-$a}
49 } {9}
51 test expr-1.11 "Short circuit evaluation" {
52         set a 100
53         set c [expr {0 || [incr a]}]
54         list $a $c
55 } {101 1}
57 test expr-1.12 "Short circuit evaluation" {
58         set a 100
59         set c [expr {1 || [incr a]}]
60         list $a $c
61 } {100 1}
63 test expr-1.13 "Short circuit evaluation" {
64         set a 100
65         set c [expr {1 || [incr a] && [incr a]}]
66         list $a $c
67 } {100 1}
69 test expr-1.14 "Rotate left" jim {
70         expr {1 <<< 5}
71 } {32}
73 test expr-1.15 "Rotate left" jim {
74         expr {1 <<< 65}
75 } {2}
77 test expr-1.16 "Rotate right" jim {
78         expr {1 >>> 48}
79 } {65536}
81 test expr-1.17 "Rotate left" jim {
82         expr {1 >>> 63}
83 } {2}
85 # This crashes older jim
86 test expr-2.1 "bogus unarymin" -body {
87         expr {unarymin 1}
88 } -returnCodes error -match glob -result *
90 test expr-2.2 "Ternary operator - missing colon" -body {
91         expr {1 ? 2 3}
92 } -returnCodes error -match glob -result {missing operator*}
94 test expr-2.3 "Ternary operator - missing third term" -body {
95         expr {1 ? 2}
96 } -returnCodes error -match glob -result *
98 test expr-2.4 "Ternary operator - missing question" -body {
99         expr {1 : 2}
100 } -returnCodes error -match glob -result *
102 test expr-2.5 "Ternary operator with -ve values" {
103         expr {-1?-2:-3}
104 } -2
106 test expr-2.6 "Ternary operator with -ve values" {
107         expr {0?-2:-3}
108 } -3
110 test expr-3.1 "in, ni operators" {
111         set l {a b c d}
112         set c C
113         list [expr {"a" in $l}] [expr {$c in $l}] [expr {"b" ni $l}] [expr {$c ni $l}]
114 } {1 0 0 1}
116 test expr-3.2 "if: in, ni operators" {
117         set l {a b c d}
118         set a a
119         set c C
120         set result {}
121         if {$a in $l} {
122                 lappend result 1
123         }
124         if {$c in $l} {
125                 lappend result 2
126         }
127         if {$a ni $l} {
128                 lappend result 3
129         }
130         if {$c ni $l} {
131                 lappend result 4
132         }
133         if {"d" in $l} {
134                 lappend result 5
135         }
136 } {1 4 5}
138 # Don't want a to become 2.0
139 test expr-4.1 "Shimmering" {
140         set a 2
141         expr {$a < 3.0}
142         set a
143 } {2}
145 testreport