expr.test

来自「tcl是工具命令语言」· TEST 代码 · 共 301 行 · 第 1/2 页

TEST
301
字号
# Commands covered: expr## This file contains a collection of tests for one or more of the Tcl# built-in commands. Sourcing this file into Tcl runs the tests and# generates output for errors.  No output means no errors were found.## Copyright (c) 1996-1997 Sun Microsystems, Inc.# Copyright (c) 1998-2000 by Scriptics Corporation.## See the file "license.terms" for information on usage and redistribution# of this file, and for a DISCLAIMER OF ALL WARRANTIES.## RCS: @(#) $Id: expr.test,v 1.17 2002/07/31 09:33:45 dkf Exp $if {[lsearch [namespace children] ::tcltest] == -1} {    package require tcltest    namespace import -force ::tcltest::*}testConstraint registeredMathFuncs [expr {    ([catch {expr T1()} msg] != 1) || ($msg ne {unknown math function "T1"})}]# procedures used belowproc put_hello_char {c} {    global a    append a [format %c $c]    return $c}proc hello_world {} {    global a    set a ""    set L1 [set l0 [set h_1 [set q 0]]]    for {put_hello_char [expr [put_hello_char [expr [set h 7]*10+2]]+29]} {$l0?[put_hello_char $l0]        :!$h_1} {put_hello_char $ll;expr {$L1==2?[set ll [expr 32+0-0+[set bar 0]]]:0}} {expr {[incr L1]==[expr 1+([string length "abc"]-[string length "abc"])]        ?[set ll [set l0 [expr 54<<1]]]:$ll==108&&$L1<3?        [incr ll [expr 1|1<<1]; set ll $ll; set ll $ll; set ll $ll; set ll $ll; set l0 [expr ([string length "abc"]-[string length "abc"])+([string length "abc"]-[string length "abc"])-([string length "abc"]-[string length "abc"])+([string length "abc"]-[string length "abc"])]; set l0; set l0 $l0; set l0; set l0]:$L1==4&&$ll==32?[set ll [expr 19+$h1+([string length "abc"]-[string length "abc"])-([string length "abc"]-[string length "abc"])+([string length "abc"]-[string length "abc"])-([string length "abc"]-[string length "abc"])+[set foo [expr ([string length "abc"]-[string length "abc"])+([string length "abc"]-[string length "abc"])+([string length "abc"]-[string length "abc"])]]]]        :[set q [expr $q-$h1+([string length "abc"]-[string length "abc"])-([string length "abc"]-[string length "abc"])]]};expr {$L1==5?[incr ll -8; set ll $ll; set ll]:$q&&$h1&&1};expr {$L1==4+2        ?[incr ll 3]:[expr ([string length "abc"]-[string length "abc"])+1]};expr {$ll==($h<<4)+2+0&&$L1!=6?[incr ll -6]:[set h1 [expr 100+([string length "abc"]-[string length "abc"])-([string length "abc"]-[string length "abc"])]]}        expr {$L1!=1<<3?[incr q [expr ([string length "abc"]-[string length "abc"])-1]]:[set h_1 [set ll $h1]]}    }    set a}proc 12days {a b c} {    global xxx    expr {1<$a?[expr {$a<3?[12days -79 -13 [string range $c [12days -87 \	[expr 1-$b] [string range $c [12days -86 0 [string range $c 1 end]] \	end]] end]]:1};expr {$a<$b?[12days [expr $a+1] $b $c]:3};expr {[12days \	-94 [expr $a-27] $c]&&$a==2?$b<13?[12days 2 [expr $b+1] "%s %d %d\n"]:9	:16}]:$a<0?$a<-72?[12days $b $a "@n'+,#'/*\{\}w+/w#cdnr/+,\{\}r/*de\}+,/*\{*+,/w\{%+,/w#q#n+,/#\{l+,/n\{n+,/+#n+,/#;#q#n+,/+k#;*+,/'r :'d*'3,\}\{w+K w'K:'+\}e#';dq#'l q#'+d'K#!/+k#;q#'r\}eKK#\}w'r\}eKK\{nl\]'/#;#q#n')\{)#\}w')\{)\{nl\]'/+#n';d\}rw' i;# )\{nl\]!/n\{n#'; r\{#w'r nc\{nl\]'/#\{l,+'K \{rw' iK\{;\[\{nl\]'/w#q#n'wk nw' iwk\{KK\{nl\]!/w\{%'l##w#' i; :\{nl\]'/*\{q#'ld;r'\}\{nlwb!/*de\}'c ;;\{nl'-\{\}rw\]'/+,\}##'*\}#nc,',#nw\]'/+kd'+e\}+;#'rdq#w! nr'/ ') \}+\}\{rl#'\{n' ')# \}'+\}##(!!/"]	:$a<-50?[string compare [format %c $b] [string index $c 0]]==0?[append \	xxx [string index $c 31];scan [string index $c 31] %c x;set x]	:[12days -65 $b [string range $c 1 end]]:[12days [expr ([string compare \	[string index $c 0] "/"]==0)+$a] $b [string range $c 1 end]]:0<$a	?[12days 2 2 "%s"]:[string compare [string index $c 0] "/"]==0||	[12days 0 [12days -61 [scan [string index $c 0] %c x; set x] \	"!ek;dc i@bK'(q)-\[w\]*%n+r3#l,\{\}:\nuwloca-O;m .vpbks,fxntdCeghiry"] \	[string range $c 1 end]]}}proc do_twelve_days {} {    global xxx    set xxx ""    12days 1 1 1    string length $xxx}# start of testscatch {unset a b i x}test expr-1.1 {TclCompileExprCmd: no expression} {    list [catch {expr  } msg] $msg} {1 {wrong # args: should be "expr arg ?arg ...?"}}test expr-1.2 {TclCompileExprCmd: one expression word} {    expr -25} -25test expr-1.3 {TclCompileExprCmd: two expression words} {    expr -8.2   -6} -14.2test expr-1.4 {TclCompileExprCmd: five expression words} {    expr 20 - 5 +10 -7} 18test expr-1.5 {TclCompileExprCmd: quoted expression word} {    expr "0005"} 5test expr-1.6 {TclCompileExprCmd: quoted expression word} {    catch {expr "0005"zxy} msg    set msg} {extra characters after close-quote}test expr-1.7 {TclCompileExprCmd: expression word in braces} {    expr {-0005}} -5test expr-1.8 {TclCompileExprCmd: expression word in braces} {    expr {{-0x1234}}} -4660test expr-1.9 {TclCompileExprCmd: expression word in braces} {    catch {expr {-0005}foo} msg    set msg} {extra characters after close-brace}test expr-1.10 {TclCompileExprCmd: other expression word in braces} {    expr 4*[llength "6 2"]} 8test expr-1.11 {TclCompileExprCmd: expression word terminated by ;} {    expr 4*[llength "6 2"];} 8test expr-1.12 {TclCompileExprCmd: inlined expr (in "catch") inside other catch} {    set a xxx    catch {	# Might not be a number	set a [expr 10*$a]    }} 1test expr-1.13 {TclCompileExprCmd: second level of substitutions in expr not in braces with single var reference} {    set a xxx    set x 27;  set bool {$x};  if $bool {set a foo}    set a} footest expr-1.14 {TclCompileExprCmd: second level of substitutions in expr with comparison as top-level operator} {    set a xxx    set x 2;  set b {$x};  set a [expr $b == 2]    set a} 1test expr-1.15 {TclCompileExprCmd: second level of substitutions in expr with comparison as top-level operator} {    set a xxx    set x 2;  set b {$x};  set a [expr $b eq 2]    set a} 1test expr-2.1 {TclCompileExpr: are builtin functions registered?} {    expr double(5*[llength "6 2"])} 10.0test expr-2.2 {TclCompileExpr: error in expr} {    catch {expr 2**3} msg    set msg} {syntax error in expression "2**3": unexpected operator *}test expr-2.3 {TclCompileExpr: junk after legal expr} {    catch {expr 7*[llength "a b"]foo} msg    set msg} {syntax error in expression "7*2foo": extra tokens at end of expression}test expr-2.4 {TclCompileExpr: numeric expr string rep == formatted int rep} {    expr {0001}} 1test expr-3.1 {CompileCondExpr: just lor expr} {expr 3||0} 1test expr-3.2 {CompileCondExpr: error in lor expr} {    catch {expr x||3} msg    set msg} {syntax error in expression "x||3": variable references require preceding $}test expr-3.3 {CompileCondExpr: test true arm} {expr 3>2?44:66} 44

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?