📄 expr-old.test
字号:
test expr-old-16.2 {precedence checks} {expr 1&3!=3} 0test expr-old-17.1 {precedence checks} {expr 7&3^0x10} 19test expr-old-17.2 {precedence checks} {expr 7^0x10&3} 7test expr-old-18.1 {precedence checks} {expr 7^0x10|3} 23test expr-old-18.2 {precedence checks} {expr 7|0x10^3} 23test expr-old-19.1 {precedence checks} {expr 7|3&&1} 1test expr-old-19.2 {precedence checks} {expr 1&&3|7} 1test expr-old-19.3 {precedence checks} {expr 0&&1||1} 1test expr-old-19.4 {precedence checks} {expr 1||1&&0} 1test expr-old-20.1 {precedence checks} {expr 1||0?3:4} 3test expr-old-20.2 {precedence checks} {expr 1?0:4||1} 0test expr-old-20.3 {precedence checks} {expr 1?2:0?3:4} 2test expr-old-20.4 {precedence checks} {expr 0?2:0?3:4} 4test expr-old-20.5 {precedence checks} {expr 1?2?3:4:0} 3test expr-old-20.6 {precedence checks} {expr 0?2?3:4:0} 0# Parentheses.test expr-old-21.1 {parenthesization} {expr (2+4)*6} 36test expr-old-21.2 {parenthesization} {expr (1?0:4)||1} 1test expr-old-21.3 {parenthesization} {expr +(3-4)} -1# Embedded commands and variable names.set a 16 test expr-old-22.1 {embedded variables} {expr {2*$a}} 32 test expr-old-22.2 {embedded variables} { set x -5 set y 10 expr {$x + $y}} {5} test expr-old-22.3 {embedded variables} { set x " -5" set y " +10" expr {$x + $y}} {5}test expr-old-22.4 {embedded commands and variables} {expr {[set a] - 14}} 2test expr-old-22.5 {embedded commands and variables} { list [catch {expr {12 - [bad_command_name]}} msg] $msg} {1 {invalid command name "bad_command_name"}}# Double-quotes and things inside them.test expr-old-23.1 {double quotes} {expr {"abc"}} abctest expr-old-23.2 {double quotes} { set a 189 expr {"$a.bc"}} 189.bctest expr-old-23.3 {double quotes} { set b2 xyx expr {"$b2$b2$b2.[set b2].[set b2]"}} xyxxyxxyx.xyx.xyxtest expr-old-23.4 {double quotes} {expr {"11\}\}22"}} 11}}22test expr-old-23.5 {double quotes} {expr {"\*bc"}} {*bc}test expr-old-23.6 {double quotes} { catch {unset bogus__} list [catch {expr {"$bogus__"}} msg] $msg} {1 {can't read "bogus__": no such variable}}test expr-old-23.7 {double quotes} { list [catch {expr {"a[error Testing]bc"}} msg] $msg} {1 Testing}test expr-old-23.8 {double quotes} { list [catch {expr {"12398712938788234-1298379" != ""}} msg] $msg} {0 1}# Numbers in various bases.test expr-old-24.1 {numbers in different bases} {expr 0x20} 32test expr-old-24.2 {numbers in different bases} {expr 015} 13# Conversions between various data types.test expr-old-25.1 {type conversions} {expr 2+2.5} 4.5test expr-old-25.2 {type conversions} {expr 2.5+2} 4.5test expr-old-25.3 {type conversions} {expr 2-2.5} -0.5test expr-old-25.4 {type conversions} {expr 2/2.5} 0.8test expr-old-25.5 {type conversions} {expr 2>2.5} 0test expr-old-25.6 {type conversions} {expr 2.5>2} 1test expr-old-25.7 {type conversions} {expr 2<2.5} 1test expr-old-25.8 {type conversions} {expr 2>=2.5} 0test expr-old-25.9 {type conversions} {expr 2<=2.5} 1test expr-old-25.10 {type conversions} {expr 2==2.5} 0test expr-old-25.11 {type conversions} {expr 2!=2.5} 1test expr-old-25.12 {type conversions} {expr 2>"ab"} 0test expr-old-25.13 {type conversions} {expr {2>" "}} 1test expr-old-25.14 {type conversions} {expr {"24.1a" > 24.1}} 1test expr-old-25.15 {type conversions} {expr {24.1 > "24.1a"}} 0test expr-old-25.16 {type conversions} {expr 2+2.5} 4.5test expr-old-25.17 {type conversions} {expr 2+2.5} 4.5test expr-old-25.18 {type conversions} {expr 2.0e2} 200.0test expr-old-25.19 {type conversions} {expr 2.0e15} 2e+15test expr-old-25.20 {type conversions} {expr 10.0} 10.0# Various error conditions.test expr-old-26.1 {error conditions} { list [catch {expr 2+"a"} msg] $msg} {1 {can't use non-numeric string as operand of "+"}}test expr-old-26.2 {error conditions} { list [catch {expr 2+4*} msg] $msg} {1 {syntax error in expression "2+4*"}}test expr-old-26.3 {error conditions} { list [catch {expr 2+4*(} msg] $msg} {1 {syntax error in expression "2+4*("}}catch {unset _non_existent_}test expr-old-26.4 {error conditions} { list [catch {expr 2+$_non_existent_} msg] $msg} {1 {can't read "_non_existent_": no such variable}}set a xxtest expr-old-26.5 {error conditions} { list [catch {expr {2+$a}} msg] $msg} {1 {can't use non-numeric string as operand of "+"}}test expr-old-26.6 {error conditions} { list [catch {expr {2+[set a]}} msg] $msg} {1 {can't use non-numeric string as operand of "+"}}test expr-old-26.7 {error conditions} { list [catch {expr {2+(4}} msg] $msg} {1 {syntax error in expression "2+(4"}}test expr-old-26.8 {error conditions} { list [catch {expr 2/0} msg] $msg $errorCode} {1 {divide by zero} {ARITH DIVZERO {divide by zero}}}test expr-old-26.9 {error conditions} { list [catch {expr 2%0} msg] $msg $errorCode} {1 {divide by zero} {ARITH DIVZERO {divide by zero}}}test expr-old-26.10 {error conditions} { list [catch {expr 2.0/0.0} msg] $msg $errorCode} {1 {divide by zero} {ARITH DIVZERO {divide by zero}}}test expr-old-26.11 {error conditions} { list [catch {expr 2#} msg] $msg} {1 {syntax error in expression "2#"}}test expr-old-26.12 {error conditions} { list [catch {expr a.b} msg] $msg} {1 {syntax error in expression "a.b"}}test expr-old-26.13 {error conditions} { list [catch {expr {"a"/"b"}} msg] $msg} {1 {can't use non-numeric string as operand of "/"}}test expr-old-26.14 {error conditions} { list [catch {expr 2:3} msg] $msg} {1 {syntax error in expression "2:3"}}test expr-old-26.15 {error conditions} { list [catch {expr a@b} msg] $msg} {1 {syntax error in expression "a@b"}}test expr-old-26.16 {error conditions} { list [catch {expr a[b} msg] $msg} {1 {missing close-bracket or close-brace}}test expr-old-26.17 {error conditions} { list [catch {expr a`b} msg] $msg} {1 {syntax error in expression "a`b"}}test expr-old-26.18 {error conditions} { list [catch {expr \"a\"\{b} msg] $msg} {1 {missing close-brace}}test expr-old-26.19 {error conditions} { list [catch {expr a} msg] $msg} {1 {syntax error in expression "a"}}test expr-old-26.20 {error conditions} { list [catch expr msg] $msg} {1 {wrong # args: should be "expr arg ?arg ...?"}}# Cancelled evaluation.test expr-old-27.1 {cancelled evaluation} { set a 1 expr {0&&[set a 2]} set a} 1test expr-old-27.2 {cancelled evaluation} { set a 1 expr {1||[set a 2]} set a} 1test expr-old-27.3 {cancelled evaluation} { set a 1 expr {0?[set a 2]:1} set a} 1test expr-old-27.4 {cancelled evaluation} { set a 1 expr {1?2:[set a 2]} set a} 1catch {unset x}test expr-old-27.5 {cancelled evaluation} { list [catch {expr {[info exists x] && $x}} msg] $msg} {0 0}test expr-old-27.6 {cancelled evaluation} { list [catch {expr {0 && [concat $x]}} msg] $msg} {0 0}test expr-old-27.7 {cancelled evaluation} { set one 1 list [catch {expr {1 || 1/$one}} msg] $msg} {0 1}test expr-old-27.8 {cancelled evaluation} { list [catch {expr {1 || -"string"}} msg] $msg} {0 1}test expr-old-27.9 {cancelled evaluation} { list [catch {expr {1 || ("string" * ("x" && "y"))}} msg] $msg} {0 1}test expr-old-27.10 {cancelled evaluation} { set x -1.0 list [catch {expr {($x > 0) ? round(log($x)) : 0}} msg] $msg} {0 0}test expr-old-27.11 {cancelled evaluation} { list [catch {expr {0 && foo}} msg] $msg} {1 {syntax error in expression "0 && foo"}}test expr-old-27.12 {cancelled evaluation} { list [catch {expr {0 ? 1 : foo}} msg] $msg} {1 {syntax error in expression "0 ? 1 : foo"}}# Tcl_ExprBool as used in "if" statementstest expr-old-28.1 {Tcl_ExprBoolean usage} { set a 1 if {2} {set a 2} set a} 2test expr-old-28.2 {Tcl_ExprBoolean usage} { set a 1 if {0} {set a 2} set a} 1test expr-old-28.3 {Tcl_ExprBoolean usage} { set a 1 if {1.2} {set a 2} set a} 2test expr-old-28.4 {Tcl_ExprBoolean usage} { set a 1 if {-1.1} {set a 2} set a} 2test expr-old-28.5 {Tcl_ExprBoolean usage} { set a 1 if {0.0} {set a 2} set a} 1test expr-old-28.6 {Tcl_ExprBoolean usage} { set a 1 if {"YES"} {set a 2} set a} 2test expr-old-28.7 {Tcl_ExprBoolean usage} { set a 1 if {"no"} {set a 2} set a} 1test expr-old-28.8 {Tcl_ExprBoolean usage} { set a 1 if {"true"} {set a 2} set a} 2test expr-old-28.9 {Tcl_ExprBoolean usage} { set a 1 if {"fAlse"} {set a 2} set a} 1test expr-old-28.10 {Tcl_ExprBoolean usage} { set a 1 if {"on"} {set a 2} set a} 2test expr-old-28.11 {Tcl_ExprBoolean usage} { set a 1 if {"Off"} {set a 2} set a} 1test expr-old-28.12 {Tcl_ExprBool usage} { list [catch {if {"abc"} {}} msg] $msg} {1 {expected boolean value but got "abc"}}test expr-old-28.13 {Tcl_ExprBool usage} { list [catch {if {"ogle"} {}} msg] $msg} {1 {expected boolean value but got "ogle"}}test expr-old-28.14 {Tcl_ExprBool usage} { list [catch {if {"o"} {}} msg] $msg} {1 {expected boolean value but got "o"}}# Operands enclosed in bracestest expr-old-29.1 {braces} {expr {{abc}}} abctest expr-old-29.2 {braces} {expr {{00010}}} 8test expr-old-29.3 {braces} {expr {{3.1200000}}} 3.12test expr-old-29.4 {braces} {expr {{a{b}{1 {2 3}}c}}} "a{b}{1 {2 3}}c"test expr-old-29.5 {braces} { list [catch {expr "\{abc"} msg] $msg} {1 {missing close-brace}}# Very long valuestest expr-old-30.1 {long values} { set a "0000 1111 2222 3333 4444" set a "$a | $a | $a | $a | $a" set a "$a || $a || $a || $a || $a" expr {$a}} {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}test expr-old-30.2 {long values} { set a "000000000000000000000000000000" set a "$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a${a}5" expr $a} 5# Expressions spanning multiple argumentstest expr-old-31.1 {multiple arguments to expr command} { expr 4 + ( 6 *12) -3} 73test expr-old-31.2 {multiple arguments to expr command} { list [catch {expr 2 + (3 + 4} msg] $msg
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -