︙ | | | ︙ | |
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
e.g. {append x bar} -> foobar
proc sum args {expr [join $args +]}
e.g. {sum 1 2 3} -> 6
#native sum2 {function (interp, args) {return eval(args.join("+"));}}
#e.g. {sum2 2 3 4} -> 9
e.g. {concat {a b} {c d}} -> {a b c d}
e.g. {set d [dict create a 1 b 2 c 3]} -> {a 1 b 2 c 3}
e.g. {dict exists $d c} -> 1
e.g. {dict exists $d x} -> 0
e.g. {dict get $d b} -> 2
e.g. {dict keys $d} -> {a b c}
|
>
>
>
>
>
|
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
e.g. {append x bar} -> foobar
proc sum args {expr [join $args +]}
e.g. {sum 1 2 3} -> 6
#native sum2 {function (interp, args) {return eval(args.join("+"));}}
#e.g. {sum2 2 3 4} -> 9
e.g. {catch foo msg} -> 1
e.g. {set msg} -> {invalid command name "foo"}
e.g. {catch {expr 7*6}} -> 0
e.g. {catch {expr 7*6} msg; set msg} -> 42
e.g. {concat {a b} {c d}} -> {a b c d}
e.g. {set d [dict create a 1 b 2 c 3]} -> {a 1 b 2 c 3}
e.g. {dict exists $d c} -> 1
e.g. {dict exists $d x} -> 0
e.g. {dict get $d b} -> 2
e.g. {dict keys $d} -> {a b c}
|
︙ | | | ︙ | |
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
e.g. {set x 0xFF; expr {$x+0}} -> 255
e.g. {expr 0376} -> 254
e.g. {set x 0375; expr $x} -> 253
e.g. {expr {$x}} -> 253
e.g. {expr 6 * 7} -> 42
e.g. {expr 1 == 2} -> 0
e.g. {expr 1 < 2} -> 1
e.g. {expr !0} -> 1
e.g. {expr !42} -> 0
e.g. {set x 3} -> 3
e.g. {expr $x+1} -> 4
e.g. {expr {$x+1}} -> 4
e.g. {set x a; set y b; expr {$x == $y}} -> 0
e.g. {expr {$x != $y}} -> 1
set forres ""
e.g. {for {set i 0} {$i < 5} {incr i} {append forres $i}; set forres} -> 01234
e.g. {foreach i {a b c d e} {append foreachres $i}; set foreachres} -> abcde
e.g. {format %x 255} -> ff
e.g. {format %X 254} -> FE
|
>
>
>
>
>
>
>
|
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
e.g. {set x 0xFF; expr {$x+0}} -> 255
e.g. {expr 0376} -> 254
e.g. {set x 0375; expr $x} -> 253
e.g. {expr {$x}} -> 253
e.g. {expr 6 * 7} -> 42
e.g. {expr 1 == 2} -> 0
e.g. {expr 1 < 2} -> 1
e.g. {expr 1 > 2} -> 0
e.g. {expr 1 != 2} -> 1
e.g. {expr 1 <= 2} -> 1
e.g. {expr 1 >= 2} -> 0
e.g. {expr !0} -> 1
e.g. {expr !42} -> 0
e.g. {set x 3} -> 3
e.g. {expr $x+1} -> 4
e.g. {expr {$x+1}} -> 4
e.g. {set x a; set y b; expr {$x == $y}} -> 0
e.g. {expr {$x != $y}} -> 1
e.g. {expr 43 % 5} -> 3
e.g. {set x -44; expr {-$x}} -> 44
e.g. {expr 1<<3} -> 8
set forres ""
e.g. {for {set i 0} {$i < 5} {incr i} {append forres $i}; set forres} -> 01234
e.g. {foreach i {a b c d e} {append foreachres $i}; set foreachres} -> abcde
e.g. {format %x 255} -> ff
e.g. {format %X 254} -> FE
|
︙ | | | ︙ | |
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
e.g. {llength $x} -> 4
e.g. {lindex $x 2} -> c
e.g. {lrange $x 1 2} -> {b c}
e.g. {lreverse {a b c}} -> {c b a}
e.g. {lsearch $x b} -> 1
e.g. {lsearch $x y} -> -1
e.g. {lsort {z x y}} -> {x y z}
e.g. {regexp {X[ABC]Y} XAY} -> 1
e.g. {regexp {X[ABC]Y} XDY} -> 0
e.g. {regsub {[A-C]+} uBAAD x} -> uxD
e.g. {split "a b c d"} -> {a b {} c d}
e.g. {split " a b c d"} -> {{} a b {} c d}
|
>
>
>
>
>
|
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
e.g. {llength $x} -> 4
e.g. {lindex $x 2} -> c
e.g. {lrange $x 1 2} -> {b c}
e.g. {lreverse {a b c}} -> {c b a}
e.g. {lsearch $x b} -> 1
e.g. {lsearch $x y} -> -1
e.g. {lsort {z x y}} -> {x y z}
e.g. {proc f args {expr [join $args +]}} -> ""
e.g. {f 1} -> 1
e.g. {f 1 2} -> 3
e.g. {f 1 2 3} -> 6
e.g. {regexp {X[ABC]Y} XAY} -> 1
e.g. {regexp {X[ABC]Y} XDY} -> 0
e.g. {regsub {[A-C]+} uBAAD x} -> uxD
e.g. {split "a b c d"} -> {a b {} c d}
e.g. {split " a b c d"} -> {{} a b {} c d}
|
︙ | | | ︙ | |
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
e.g. {string length ""} -> 0
e.g. {string length foo} -> 3
e.g. {string range hello 1 3} -> ell
e.g. {string tolower Tcl} -> tcl
e.g. {string toupper Tcl} -> TCL
e.g. {string trim " foo "} -> foo
#e.g. {set x a.\x62.c} -> a.b.c ;# severe malfunction, breaks test suite operation :(
puts "total $total tests, passed $passed, failed $fail"
#----------- clean up variables used in tests
foreach var [info vars] {
set pos [lsearch $vars $var] ;# expr can't substitute commands yet
set neq [string compare $var vars]
if {$var != "vars" && $pos < 0} {unset $var}
}
unset vars var pos neq
puts "vars now: [info vars]"
puts "[llength [info commands]] commands implemented"
|
|
|
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
e.g. {string length ""} -> 0
e.g. {string length foo} -> 3
e.g. {string range hello 1 3} -> ell
e.g. {string tolower Tcl} -> tcl
e.g. {string toupper Tcl} -> TCL
e.g. {string trim " foo "} -> foo
e.g. {set x a.\x62.c} -> a.b.c ;# severe malfunction, breaks test suite operation :(
puts "total $total tests, passed $passed, failed $fail"
#----------- clean up variables used in tests
foreach var [info vars] {
set pos [lsearch $vars $var] ;# expr can't substitute commands yet
set neq [string compare $var vars]
if {$var != "vars" && $pos < 0} {unset $var}
}
unset vars var pos neq
puts "vars now: [info vars]"
puts "[llength [info commands]] commands implemented"
|