compexpr.test
来自「tcl是工具命令语言」· TEST 代码 · 共 330 行 · 第 1/2 页
TEST
330 行
} {1 {syntax error in expression "1+": premature end of expression}}test compExpr-2.38 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, error in special operator} { list [catch {expr {5+[expr 1+]}} msg] $msg} {1 {syntax error in expression "1+": premature end of expression}}test compExpr-2.39 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, special operator} { expr {-2}} -2test compExpr-2.40 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, special operator} { expr {4-2}} 2test compExpr-2.41 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, special operator} { catch {unset a} set a true expr {0||$a}} 1test compExpr-2.42 {CompileSubExpr procedure, error in TCL_TOKEN_SUB_EXPR parse token} { catch {unset a} set a 15 list [catch {expr {27 || "$a[expr 1+]00"}} msg] $msg} {1 {syntax error in expression "1+": premature end of expression}}test compExpr-2.43 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, special operator} { catch {unset a} set a false expr {3&&$a}} 0test compExpr-2.44 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, special operator} { catch {unset a} set a false expr {$a||1? 1 : 0}} 1test compExpr-2.45 {CompileSubExpr procedure, error in TCL_TOKEN_SUB_EXPR parse token} { catch {unset a} set a 15 list [catch {expr {1? 54 : "$a[expr 1+]00"}} msg] $msg} {1 {syntax error in expression "1+": premature end of expression}}test compExpr-3.1 {CompileLandOrLorExpr procedure, numeric 1st operand} { catch {unset a} set a 2 expr {[set a]||0}} 1test compExpr-3.2 {CompileLandOrLorExpr procedure, nonnumeric 1st operand} { catch {unset a} set a no expr {$a&&1}} 0test compExpr-3.3 {CompileSubExpr procedure, error in 1st operand} { list [catch {expr {[expr *2]||0}} msg] $msg} {1 {syntax error in expression "*2": unexpected operator *}}test compExpr-3.4 {CompileLandOrLorExpr procedure, result is 1 or 0} { catch {unset a} catch {unset b} set a no set b true expr {$a || $b}} 1test compExpr-3.5 {CompileLandOrLorExpr procedure, short-circuit semantics} { catch {unset a} set a yes expr {$a || [exit]}} 1test compExpr-3.6 {CompileLandOrLorExpr procedure, short-circuit semantics} { catch {unset a} set a no expr {$a && [exit]}} 0test compExpr-3.7 {CompileLandOrLorExpr procedure, numeric 2nd operand} { catch {unset a} set a 2 expr {0||[set a]}} 1test compExpr-3.8 {CompileLandOrLorExpr procedure, nonnumeric 2nd operand} { catch {unset a} set a no expr {1&&$a}} 0test compExpr-3.9 {CompileLandOrLorExpr procedure, error in 2nd operand} { list [catch {expr {0||[expr %2]}} msg] $msg} {1 {syntax error in expression "%2": unexpected operator %}}test compExpr-3.10 {CompileLandOrLorExpr procedure, long lor/land arm} { set a "abcdefghijkl" set i 7 expr {[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]] || [string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]] || [string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]] || [string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]&&[string compare [format %c $i] [string index $a $i]]}} 1test compExpr-4.1 {CompileCondExpr procedure, simple test} { catch {unset a} set a 2 expr {($a > 1)? "ok" : "nope"}} oktest compExpr-4.2 {CompileCondExpr procedure, complex test, convert to numeric} { catch {unset a} set a no expr {[set a]? 27 : -54}} -54test compExpr-4.3 {CompileCondExpr procedure, error in test} { list [catch {expr {[expr *2]? +1 : -1}} msg] $msg} {1 {syntax error in expression "*2": unexpected operator *}}test compExpr-4.4 {CompileCondExpr procedure, simple "true" clause} { catch {unset a} set a no expr {1? (27-2) : -54}} 25test compExpr-4.5 {CompileCondExpr procedure, convert "true" clause to numeric} { catch {unset a} set a no expr {1? $a : -54}} notest compExpr-4.6 {CompileCondExpr procedure, error in "true" clause} { list [catch {expr {1? [expr *2] : -127}} msg] $msg} {1 {syntax error in expression "*2": unexpected operator *}}test compExpr-4.7 {CompileCondExpr procedure, simple "false" clause} { catch {unset a} set a no expr {(2-2)? -3.14159 : "nope"}} nopetest compExpr-4.8 {CompileCondExpr procedure, convert "false" clause to numeric} { catch {unset a} set a 00123 expr {0? 42 : $a}} 83test compExpr-4.9 {CompileCondExpr procedure, error in "false" clause} { list [catch {expr {1? 15 : [expr *2]}} msg] $msg} {1 {syntax error in expression "*2": unexpected operator *}}test compExpr-5.1 {CompileMathFuncCall procedure, math function found} { format %.6g [expr atan2(1.0, 2.0)]} 0.463648test compExpr-5.2 {CompileMathFuncCall procedure, math function not found} { list [catch {expr {do_it()}} msg] $msg} {1 {unknown math function "do_it"}}if $gotT1 { test compExpr-5.3 {CompileMathFuncCall: call registered math function} { expr 3*T1()-1 } 368 test compExpr-5.4 {CompileMathFuncCall: call registered math function} { expr T2()*3 } 1035}test compExpr-5.5 {CompileMathFuncCall procedure, too few arguments} { list [catch {expr {atan2(1.0)}} msg] $msg} {1 {too few arguments for math function}}test compExpr-5.6 {CompileMathFuncCall procedure, complex argument} { format %.6g [expr pow(2.1, 27.5-(24.4*(5%2)))]} 9.97424test compExpr-5.7 {CompileMathFuncCall procedure, error in argument} { list [catch {expr {sinh(2.*)}} msg] $msg} {1 {syntax error in expression "sinh(2.*)": unexpected close parenthesis}}test compExpr-5.8 {CompileMathFuncCall procedure, too many arguments} { list [catch {expr {sinh(2.0, 3.0)}} msg] $msg} {1 {too many arguments for math function}}test compExpr-5.9 {CompileMathFuncCall procedure, too many arguments} { list [catch {expr {0 <= rand(5.2)}} msg] $msg} {1 {too many arguments for math function}}test compExpr-6.1 {LogSyntaxError procedure, error in expr longer than 60 chars} { list [catch {expr {(+0123456)*(+0123456)*(+0123456)*(+0123456)*(+0123456)*(+0123456)*(+0123456)/} -1 foo 3} msg] $msg} {1 {syntax error in expression "(+0123456)*(+0123456)*(+0123456)*(+0123456)*(+0123456)*(+012...": extra tokens at end of expression}}# cleanupcatch {unset a}catch {unset b}::tcltest::cleanupTestsreturn
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?