compexpr.test

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

TEST
330
字号
# This file contains a collection of tests for the procedures in the# file tclCompExpr.c.  Sourcing this file into Tcl runs the tests and# generates output for errors.  No output means no errors were found.## Copyright (c) 1997 Sun Microsystems, Inc.# Copyright (c) 1998-1999 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: compExpr.test,v 1.6 2001/12/06 10:59:17 dkf Exp $if {[lsearch [namespace children] ::tcltest] == -1} {    package require tcltest    namespace import -force ::tcltest::*}if {([catch {expr T1()} msg] == 1) && ($msg == {unknown math function "T1"})} {    set gotT1 0    puts "This application hasn't been compiled with the \"T1\" and"    puts "\"T2\" math functions, so I'll skip some of the expr tests."} else {    set gotT1 1}catch {unset a}test compExpr-1.1 {TclCompileExpr procedure, successful expr parse and compile} {    expr 1+2} 3test compExpr-1.2 {TclCompileExpr procedure, error parsing expr} {    list [catch {expr 1+2+} msg] $msg} {1 {syntax error in expression "1+2+": premature end of expression}}test compExpr-1.3 {TclCompileExpr procedure, error compiling expr} {    list [catch {expr "foo(123)"} msg] $msg} {1 {unknown math function "foo"}}test compExpr-1.4 {TclCompileExpr procedure, expr has no operators} {    set a {000123}    expr {$a}} 83test compExpr-2.1 {CompileSubExpr procedure, TCL_TOKEN_WORD parse token} {    catch {unset a}    set a 27    expr {"foo$a" < "bar"}} 0test compExpr-2.2 {CompileSubExpr procedure, error compiling TCL_TOKEN_WORD parse token} {    list [catch {expr {"00[expr 1+]" + 17}} msg] $msg} {1 {syntax error in expression "1+": premature end of expression}}test compExpr-2.3 {CompileSubExpr procedure, TCL_TOKEN_TEXT parse token} {    expr {{12345}}} 12345test compExpr-2.4 {CompileSubExpr procedure, empty TCL_TOKEN_TEXT parse token} {    expr {{}}} {}test compExpr-2.5 {CompileSubExpr procedure, TCL_TOKEN_BS parse token} {    expr "\{  \\ +123 \}"} 123test compExpr-2.6 {CompileSubExpr procedure, TCL_TOKEN_COMMAND parse token} {    expr {[info tclversion] != ""}} 1test compExpr-2.7 {CompileSubExpr procedure, TCL_TOKEN_COMMAND parse token} {    expr {[]}} {}test compExpr-2.8 {CompileSubExpr procedure, error in TCL_TOKEN_COMMAND parse token} {    list [catch {expr {[foo "bar"xxx] + 17}} msg] $msg} {1 {extra characters after close-quote}}test compExpr-2.9 {CompileSubExpr procedure, TCL_TOKEN_VARIABLE parse token} {    catch {unset a}    set a 123    expr {$a*2}} 246test compExpr-2.10 {CompileSubExpr procedure, TCL_TOKEN_VARIABLE parse token} {    catch {unset a}    catch {unset b}    set a(george) martha    set b geo    expr {$a(${b}rge)}} marthatest compExpr-2.11 {CompileSubExpr procedure, error in TCL_TOKEN_VARIABLE parse token} {    catch {unset a}    list [catch {expr {$a + 17}} msg] $msg} {1 {can't read "a": no such variable}}test compExpr-2.12 {CompileSubExpr procedure, TCL_TOKEN_SUB_EXPR parse token} {    expr {27||3? 3<<(1+4) : 4&&9}} 96test compExpr-2.13 {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.14 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, op found} {    expr {5*6}} 30test compExpr-2.15 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, math function found} {    format %.6g [expr {sin(2.0)}]} 0.909297test compExpr-2.16 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, math function not found} {    list [catch {expr {fred(2.0)}} msg] $msg} {1 {unknown math function "fred"}}test compExpr-2.17 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {    expr {4*2}} 8test compExpr-2.18 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {    expr {4/2}} 2test compExpr-2.19 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {    expr {4%2}} 0test compExpr-2.20 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {    expr {4<<2}} 16test compExpr-2.21 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {    expr {4>>2}} 1test compExpr-2.22 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {    expr {4<2}} 0test compExpr-2.23 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {    expr {4>2}} 1test compExpr-2.24 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {    expr {4<=2}} 0test compExpr-2.25 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {    expr {4>=2}} 1test compExpr-2.26 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {    expr {4==2}} 0test compExpr-2.27 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {    expr {4!=2}} 1test compExpr-2.28 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {    expr {4&2}} 0test compExpr-2.29 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {    expr {4^2}} 6test compExpr-2.30 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator} {    expr {4|2}} 6test compExpr-2.31 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator, 1 operand} {    expr {!4}} 0test compExpr-2.32 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator, 1 operand} {    expr {~4}} -5test compExpr-2.33 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, normal operator, comparison} {    catch {unset a}    set a 15    expr {$a==15}  ;# compiled out-of-line to runtime call on Tcl_ExprObjCmd} 1test compExpr-2.34 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, special operator} {    expr {+2}} 2test compExpr-2.35 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, error in special operator} {    list [catch {expr {+[expr 1+]}} msg] $msg} {1 {syntax error in expression "1+": premature end of expression}}test compExpr-2.36 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, special operator} {    expr {4+2}} 6test compExpr-2.37 {CompileSubExpr procedure, TCL_TOKEN_OPERATOR token, error in special operator} {    list [catch {expr {[expr 1+]+5}} msg] $msg

⌨️ 快捷键说明

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