📄 parse.test
字号:
# Commands covered: set (plus basic command syntax). Also tests# the procedures in the file tclParse.c.## 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) 1991-1993 The Regents of the University of California.# Copyright (c) 1994-1996 Sun Microsystems, Inc.## See the file "license.terms" for information on usage and redistribution# of this file, and for a DISCLAIMER OF ALL WARRANTIES.## SCCS: @(#) parse.test 1.42 97/08/04 11:05:53if {[string compare test [info procs test]] == 1} then {source defs}proc fourArgs {a b c d} { global arg1 arg2 arg3 arg4 set arg1 $a set arg2 $b set arg3 $c set arg4 $d}proc getArgs args { global argv set argv $args}# Basic argument parsing.test parse-1.1 {basic argument parsing} { set arg1 {} fourArgs a b c d list $arg1 $arg2 $arg3 $arg4} {a b c d}test parse-1.2 {basic argument parsing} { set arg1 {} eval "fourArgs 123\v4\f56\r7890" list $arg1 $arg2 $arg3 $arg4} {123 4 56 7890}# Quotes.test parse-2.1 {quotes and variable-substitution} { getArgs "a b c" d set argv} {{a b c} d}test parse-2.2 {quotes and variable-substitution} { set a 101 getArgs "a$a b c" set argv} {{a101 b c}}test parse-2.3 {quotes and variable-substitution} { set argv "xy[format xabc]" set argv} {xyxabc}test parse-2.4 {quotes and variable-substitution} { set argv "xy\t" set argv} xy\ttest parse-2.5 {quotes and variable-substitution} { set argv "a b cd e f" set argv} a\ b\tc\nd\ e\ ftest parse-2.6 {quotes and variable-substitution} { set argv a"bcd"e set argv} {a"bcd"e}# Braces.test parse-3.1 {braces} { getArgs {a b c} d set argv} "{a b c} d"test parse-3.2 {braces} { set a 101 set argv {a$a b c} set b [string index $argv 1] set b} {$}test parse-3.3 {braces} { set argv {a[format xyz] b} string length $argv} 15test parse-3.4 {braces} { set argv {a\nb\}} string length $argv} 6test parse-3.5 {braces} { set argv {{{{}}}} set argv} "{{{}}}"test parse-3.6 {braces} { set argv a{{}}b set argv} "a{{}}b"test parse-3.7 {braces} { set a [format "last]"] set a} {last]}# Command substitution.test parse-4.1 {command substitution} { set a [format xyz] set a} xyztest parse-4.2 {command substitution} { set a a[format xyz]b[format q] set a} axyzbqtest parse-4.3 {command substitution} { set a a[set b 22;format %s $b]b set a} a22btest parse-4.4 {command substitution} { set a 7.7 if [catch {expr int($a)}] {set a foo} set a} 7.7# Variable substitution.test parse-5.1 {variable substitution} { set a 123 set b $a set b} 123test parse-5.2 {variable substitution} { set a 345 set b x$a.b set b} x345.btest parse-5.3 {variable substitution} { set _123z xx set b $_123z^ set b} xx^test parse-5.4 {variable substitution} { set a 78 set b a${a}b set b} a78btest parse-5.5 {variable substitution} {catch {$_non_existent_} msg} 1test parse-5.6 {variable substitution} { catch {$_non_existent_} msg set msg} {can't read "_non_existent_": no such variable}test parse-5.7 {array variable substitution} { catch {unset a} set a(xyz) 123 set b $a(xyz)foo set b} 123footest parse-5.8 {array variable substitution} { catch {unset a} set "a(x y z)" 123 set b $a(x y z)foo set b} 123footest parse-5.9 {array variable substitution} { catch {unset a}; catch {unset qqq} set "a(x y z)" qqq set $a([format x]\ y [format z]) foo set qqq} footest parse-5.10 {array variable substitution} { catch {unset a} list [catch {set b $a(22)} msg] $msg} {1 {can't read "a(22)": no such variable}}test parse-5.11 {array variable substitution} { set b a$! set b} {a$!}test parse-5.12 {array variable substitution} { set b a$() set b} {a$()}catch {unset a}test parse-5.13 {array variable substitution} { catch {unset a} set long {This is a very long variable, long enough to cause storage \ allocation to occur in Tcl_ParseVar. If that storage isn't getting \ freed up correctly, then a core leak will occur when this test is \ run. This text is probably beginning to sound like drivel, but I've \ run out of things to say and I need more characters still.} set a($long) 777 set b $a($long) list $b [array names a]} {777 {{This is a very long variable, long enough to cause storage \ allocation to occur in Tcl_ParseVar. If that storage isn't getting \ freed up correctly, then a core leak will occur when this test is \ run. This text is probably beginning to sound like drivel, but I've \ run out of things to say and I need more characters still.}}}test parse-5.14 {array variable substitution} { catch {unset a}; catch {unset b}; catch {unset a1} set a1(22) foo set a(foo) bar set b $a($a1(22)) set b} barcatch {unset a}; catch {unset a1}# Backslash substitution.set errNum 1proc bsCheck {char num} { global errNum; test parse-6.$errNum {backslash substitution} { scan $char %c value set value } $num set errNum [expr $errNum+1]}bsCheck \b 8bsCheck \e 101bsCheck \f 12bsCheck \n 10bsCheck \r 13bsCheck \t 9bsCheck \v 11bsCheck \{ 123bsCheck \} 125bsCheck \[ 91bsCheck \] 93bsCheck \$ 36bsCheck \ 32bsCheck \; 59bsCheck \\ 92bsCheck \Ca 67bsCheck \Ma 77bsCheck \CMa 67bsCheck \8a 8bsCheck \14 12bsCheck \141 97bsCheck \340 224bsCheck b\0 98bsCheck \x 120bsCheck \xa 10bsCheck \x41 65bsCheck \x541 65test parse-6.1 {backslash substitution} { set a "\a\c\n\]\}" string length $a} 5test parse-6.2 {backslash substitution} { set a {\a\c\n\]\}} string length $a} 10test parse-6.3 {backslash substitution} { set a "abc\def" set a} {abc def}test parse-6.4 {backslash substitution} { set a {abc\def} set a} {abc def}test parse-6.5 {backslash substitution} { set msg {} set a xxx set error [catch {if {24 < \ 35} {set a 22} {set \ a 33}} msg] list $error $msg $a} {0 22 22}test parse-6.6 {backslash substitution} { eval "concat abc\\"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -