⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 set-old.test

📁 tcl是工具命令语言
💻 TEST
📖 第 1 页 / 共 2 页
字号:
# Commands covered:  set, unset, array## This file includes the original set of tests for Tcl's set command.# Since the set command is now compiled, a new set of tests covering# the new implementation is in the file "set.test". 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-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: set-old.test,v 1.16 2003/02/05 20:05:51 mdejong Exp $if {[lsearch [namespace children] ::tcltest] == -1} {    package require tcltest    namespace import -force ::tcltest::*}proc ignore args {}# Simple variable operations.catch {unset a}test set-old-1.1 {basic variable setting and unsetting} {    set a 22} 22test set-old-1.2 {basic variable setting and unsetting} {    set a 123    set a} 123test set-old-1.3 {basic variable setting and unsetting} {    set a xxx    format %s $a} xxxtest set-old-1.4 {basic variable setting and unsetting} {    set a 44    unset a    list [catch {set a} msg] $msg} {1 {can't read "a": no such variable}}# Basic array operations.catch {unset a}set a(xyz) 2set a(44) 3set {a(a long name)} testtest set-old-2.1 {basic array operations} {    lsort [array names a]} {44 {a long name} xyz}test set-old-2.2 {basic array operations} {    set a(44)} 3test set-old-2.3 {basic array operations} {    set a(xyz)} 2test set-old-2.4 {basic array operations} {    set "a(a long name)"} testtest set-old-2.5 {basic array operations} {    list [catch {set a(other)} msg] $msg} {1 {can't read "a(other)": no such element in array}}test set-old-2.6 {basic array operations} {    list [catch {set a} msg] $msg} {1 {can't read "a": variable is array}}test set-old-2.7 {basic array operations} {    format %s $a(44)} 3test set-old-2.8 {basic array operations} {    format %s $a(a long name)} testunset a(44)test set-old-2.9 {basic array operations} {    lsort [array names a]} {{a long name} xyz}test set-old-2.10 {basic array operations} {    catch {unset b}    list [catch {set b(123)} msg] $msg} {1 {can't read "b(123)": no such variable}}test set-old-2.11 {basic array operations} {    catch {unset b}    set b 44    list [catch {set b(123)} msg] $msg} {1 {can't read "b(123)": variable isn't array}}test set-old-2.12 {basic array operations} {    list [catch {set a 14} msg] $msg} {1 {can't set "a": variable is array}}unset atest set-old-2.13 {basic array operations} {    list [catch {set a(xyz)} msg] $msg} {1 {can't read "a(xyz)": no such variable}}# Test the set commands, and exercise the corner cases of the code# that parses array references into two parts.test set-old-3.1 {set command} {    list [catch {set} msg] $msg} {1 {wrong # args: should be "set varName ?newValue?"}}test set-old-3.2 {set command} {    list [catch {set x y z} msg] $msg} {1 {wrong # args: should be "set varName ?newValue?"}}test set-old-3.3 {set command} {    catch {unset a}    list [catch {set a} msg] $msg} {1 {can't read "a": no such variable}}test set-old-3.4 {set command} {    catch {unset a}    set a(14) 83    list [catch {set a 22} msg] $msg} {1 {can't set "a": variable is array}}# Test the corner-cases of parsing array names, using set and unset.test set-old-4.1 {parsing array names} {    catch {unset a}    set a(()) 44    list [catch {array names a} msg] $msg} {0 ()}test set-old-4.2 {parsing array names} {    catch {unset a a(abcd}    set a(abcd 33    info exists a(abcd} 1test set-old-4.3 {parsing array names} {    catch {unset a a(abcd}    set a(abcd 33    list [catch {array names a} msg] $msg} {0 {}}test set-old-4.4 {parsing array names} {    catch {unset a abcd)}    set abcd) 33    info exists abcd)} 1test set-old-4.5 {parsing array names} {    set a(bcd yyy    catch {unset a}    list [catch {set a(bcd} msg] $msg} {0 yyy}test set-old-4.6 {parsing array names} {    catch {unset a}    set a 44    list [catch {set a(bcd test} msg] $msg} {0 test}# Errors in reading variablestest set-old-5.1 {errors in reading variables} {    catch {unset a}    list [catch {set a} msg] $msg} {1 {can't read "a": no such variable}}test set-old-5.2 {errors in reading variables} {    catch {unset a}    set a 44    list [catch {set a(18)} msg] $msg} {1 {can't read "a(18)": variable isn't array}}test set-old-5.3 {errors in reading variables} {    catch {unset a}    set a(6) 44    list [catch {set a(18)} msg] $msg} {1 {can't read "a(18)": no such element in array}}test set-old-5.4 {errors in reading variables} {    catch {unset a}    set a(6) 44    list [catch {set a} msg] $msg} {1 {can't read "a": variable is array}}# Errors and other special cases in writing variablestest set-old-6.1 {creating array during write} {    catch {unset a}    trace var a rwu ignore    list [catch {set a(14) 186} msg] $msg [array names a]} {0 186 14}test set-old-6.2 {errors in writing variables} {    catch {unset a}    set a xxx    list [catch {set a(14) 186} msg] $msg} {1 {can't set "a(14)": variable isn't array}}test set-old-6.3 {errors in writing variables} {    catch {unset a}    set a(100) yyy    list [catch {set a 2} msg] $msg} {1 {can't set "a": variable is array}}test set-old-6.4 {expanding variable size} {    catch {unset a}    list [set a short] [set a "longer name"] [set a "even longer name"] \	    [set a "a much much truly longer name"]} {short {longer name} {even longer name} {a much much truly longer name}}# Unset command, Tcl_UnsetVar procedurestest set-old-7.1 {unset command} {    catch {unset a}; catch {unset b}; catch {unset c}; catch {unset d}    set a 44    set b 55    set c 66    set d 77    unset a b c    list [catch {set a(0) 0}] [catch {set b(0) 0}] [catch {set c(0) 0}] \	    [catch {set d(0) 0}]} {0 0 0 1}test set-old-7.2 {unset command} {    list [catch {unset} msg] $msg} {0 {}}# Used to return:#{1 {wrong # args: should be "unset ?-nocomplain? ?--? ?varName varName ...?"}}test set-old-7.3 {unset command} {    catch {unset a}    list [catch {unset a} msg] $msg} {1 {can't unset "a": no such variable}}test set-old-7.4 {unset command} {    catch {unset a}    set a 44    list [catch {unset a(14)} msg] $msg} {1 {can't unset "a(14)": variable isn't array}}test set-old-7.5 {unset command} {    catch {unset a}    set a(0) xx    list [catch {unset a(14)} msg] $msg} {1 {can't unset "a(14)": no such element in array}}test set-old-7.6 {unset command} {    catch {unset a}; catch {unset b}; catch {unset c}    set a foo    set c gorp    list [catch {unset a a a(14)} msg] $msg [info exists c]} {1 {can't unset "a": no such variable} 1}test set-old-7.7 {unsetting globals from within procedures} {    set y 0    proc p1 {} {	global y	set z [p2]	return [list $z [catch {set y} msg] $msg]    }    proc p2 {} {global y; unset y; list [catch {set y} msg] $msg}    p1} {{1 {can't read "y": no such variable}} 1 {can't read "y": no such variable}}test set-old-7.8 {unsetting globals from within procedures} {    set y 0    proc p1 {} {	global y	p2	return [list [catch {set y 44} msg] $msg]    }    proc p2 {} {global y; unset y}    concat [p1] [list [catch {set y} msg] $msg]} {0 44 0 44}test set-old-7.9 {unsetting globals from within procedures} {    set y 0    proc p1 {} {	global y	unset y	return [list [catch {set y 55} msg] $msg]    }    concat [p1] [list [catch {set y} msg] $msg]} {0 55 0 55}test set-old-7.10 {unset command} {    catch {unset a}    set a(14) 22    unset a(14)    list [catch {set a(14)} msg] $msg [catch {array names a} msg2] $msg2} {1 {can't read "a(14)": no such element in array} 0 {}}test set-old-7.11 {unset command} {    catch {unset a}    set a(14) 22    unset a    list [catch {set a(14)} msg] $msg [catch {array names a} msg2] $msg2} {1 {can't read "a(14)": no such variable} 0 {}}test set-old-7.12 {unset command, -nocomplain} {    catch {unset a}    list [info exists a] [catch {unset -nocomplain a}] [info exists a]} {0 0 0}test set-old-7.13 {unset command, -nocomplain} {    set -nocomplain abc    list [info exists -nocomplain] [catch {unset -nocomplain}] \	    [info exists -nocomplain] [catch {unset -- -nocomplain}] \	    [info exists -nocomplain]} {1 0 1 0 0}test set-old-7.14 {unset command, --} {    set -- abc    list [info exists --] [catch {unset --}] \	    [info exists --] [catch {unset -- --}] \	    [info exists --]} {1 0 1 0 0}test set-old-7.15 {unset command, -nocomplain} {    set -nocomplain abc    set -- abc    list [info exists -nocomplain] [catch {unset -- -nocomplain}] \	    [info exists -nocomplain] [info exists --] \	    [catch {unset -- -nocomplain}] [info exists --] \	    [catch {unset -- --}] [info exists --]} {1 0 0 1 1 1 0 0}test set-old-7.16 {unset command, -nocomplain} {    set -nocomplain abc    set var abc    list [info exists bogus] [catch {unset -nocomplain bogus var bogus}] \	    [info exists -nocomplain] [info exists var] \	    [catch {unset -nocomplain -nocomplain}] [info exists -nocomplain]} {0 0 1 0 0 0}test set-old-7.17 {unset command, -nocomplain (no abbreviation)} {    set -nocomp abc    list [info exists -nocomp] [catch {unset -nocomp}] [info exists -nocomp]} {1 0 0}test set-old-7.18 {unset command, -nocomplain (no abbreviation)} {    catch {unset -nocomp}    list [info exists -nocomp] [catch {unset -nocomp}]} {0 1}# Array command.test set-old-8.1 {array command} {    list [catch {array} msg] $msg} {1 {wrong # args: should be "array option arrayName ?arg ...?"}}test set-old-8.2 {array command} {    list [catch {array a} msg] $msg} {1 {wrong # args: should be "array option arrayName ?arg ...?"}}test set-old-8.3 {array command} {    catch {unset a}    list [catch {array anymore a b} msg] $msg} {1 {"a" isn't an array}}test set-old-8.4 {array command} {    catch {unset a}    set a 44    list [catch {array anymore a b} msg] $msg} {1 {"a" isn't an array}}test set-old-8.5 {array command} {    proc foo {} {	set a 44	upvar 0 a x	list [catch {array anymore x b} msg] $msg    }    foo} {1 {"x" isn't an array}}test set-old-8.6 {array command} {    catch {unset a}    set a(22) 3    list [catch {array gorp a} msg] $msg} {1 {bad option "gorp": must be anymore, donesearch, exists, get, names, nextelement, set, size, startsearch, statistics, or unset}}test set-old-8.7 {array command, anymore option} {    catch {unset a}    list [catch {array anymore a x} msg] $msg} {1 {"a" isn't an array}}test set-old-8.8 {array command, anymore option, array doesn't exist yet but has compiler-allocated procedure slot} {    proc foo {x} {        if {$x==1} {            return [array anymore a x]        }        set a(x) 123    }    list [catch {foo 1} msg] $msg} {1 {"a" isn't an array}}test set-old-8.9 {array command, donesearch option} {    catch {unset a}    list [catch {array donesearch a x} msg] $msg} {1 {"a" isn't an array}}test set-old-8.10 {array command, donesearch option, array doesn't exist yet but has compiler-allocated procedure slot} {    proc foo {x} {        if {$x==1} {            return [array donesearch a x]        }        set a(x) 123    }    list [catch {foo 1} msg] $msg} {1 {"a" isn't an array}}test set-old-8.11 {array command, exists option} {    list [catch {array exists a b} msg] $msg} {1 {wrong # args: should be "array exists arrayName"}}test set-old-8.12 {array command, exists option} {    catch {unset a}    array exists a} {0}test set-old-8.13 {array command, exists option} {    catch {unset a}    set a(0) 1    array exists a} {1}test set-old-8.14 {array command, exists option, array doesn't exist yet but has compiler-allocated procedure slot} {    proc foo {x} {        if {$x==1} {            return [array exists a]        }        set a(x) 123    }    list [catch {foo 1} msg] $msg} {0 0}test set-old-8.15 {array command, get option} {    list [catch {array get} msg] $msg} {1 {wrong # args: should be "array option arrayName ?arg ...?"}}test set-old-8.16 {array command, get option} {    list [catch {array get a b c} msg] $msg} {1 {wrong # args: should be "array get arrayName ?pattern?"}}test set-old-8.17 {array command, get option} {    catch {unset a}    array get a} {}test set-old-8.18 {array command, get option} {    catch {unset a}    set a(22) 3    set {a(long name)} {}    lsort [array get a]} {{} 22 3 {long name}}test set-old-8.19 {array command, get option (unset variable)} {    catch {unset a}    set a(x) 3    trace var a(y) w ignore    array get a} {x 3}test set-old-8.20 {array command, get option, with pattern} {    catch {unset a}    set a(x1) 3    set a(x2) 4    set a(x3) 5    set a(b1) 24    set a(b2) 25    lsort [array get a x*]} {3 4 5 x1 x2 x3}test set-old-8.21 {array command, get option, array doesn't exist yet but has compiler-allocated procedure slot} {    proc foo {x} {        if {$x==1} {            return [array get a]        }        set a(x) 123    }    list [catch {foo 1} msg] $msg} {0 {}}test set-old-8.22 {array command, names option} {    catch {unset a}    set a(22) 3    list [catch {array names a 4 5} msg] $msg} {1 {bad option "4": must be -exact, -glob, or -regexp}}test set-old-8.19 {array command, names option} {    catch {unset a}    array names a} {}test set-old-8.23 {array command, names option} {    catch {unset a}    set a(22) 3; set a(Textual_name) 44; set "a(name with spaces)" xxx    list [catch {lsort [array names a]} msg] $msg} {0 {22 Textual_name {name with spaces}}}test set-old-8.24 {array command, names option} {    catch {unset a}    set a(22) 3; set a(33) 44;    trace var a(xxx) w ignore    list [catch {lsort [array names a]} msg] $msg} {0 {22 33}}test set-old-8.25 {array command, names option} {    catch {unset a}    set a(22) 3; set a(33) 44;    trace var a(xxx) w ignore    set a(xxx) value    list [catch {lsort [array names a]} msg] $msg} {0 {22 33 xxx}}test set-old-8.26 {array command, names option} {    catch {unset a}    set a(axy) 3    set a(bxy) 44    set a(no) yes    set a(xxx) value

⌨️ 快捷键说明

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