📄 namespace.test
字号:
namespace children test_ns_1:::} {::test_ns_1::test_ns_2}test namespace-14.8 {TclGetNamespaceForQualName, ignore extra :s if ns} { namespace children :::test_ns_1:::::test_ns_2:::} {::test_ns_1::test_ns_2::foo}test namespace-14.9 {TclGetNamespaceForQualName, extra ::s are significant for vars} { set l {} lappend l [catch {set test_ns_1::test_ns_2::} msg] $msg namespace eval test_ns_1::test_ns_2 {variable {} 2525} lappend l [set test_ns_1::test_ns_2::]} {1 {can't read "test_ns_1::test_ns_2::": no such variable} 2525}test namespace-14.10 {TclGetNamespaceForQualName, extra ::s are significant for vars} { catch {unset test_ns_1::test_ns_2::} set l {} lappend l [catch {set test_ns_1::test_ns_2::} msg] $msg set test_ns_1::test_ns_2:: 314159 lappend l [set test_ns_1::test_ns_2::]} {1 {can't read "test_ns_1::test_ns_2::": no such variable} 314159}test namespace-14.11 {TclGetNamespaceForQualName, extra ::s are significant for commands} { catch {rename test_ns_1::test_ns_2:: {}} set l {} lappend l [catch {test_ns_1::test_ns_2:: hello} msg] $msg proc test_ns_1::test_ns_2:: {args} {return "\{\}: $args"} lappend l [test_ns_1::test_ns_2:: hello]} {1 {invalid command name "test_ns_1::test_ns_2::"} {{}: hello}}test namespace-14.12 {TclGetNamespaceForQualName, extra ::s are significant for vars} { catch {eval namespace delete [namespace children :: test_ns_*]} namespace eval test_ns_1 { variable {} set test_ns_1::(x) y } set test_ns_1::(x)} ytest namespace-14.13 {TclGetNamespaceForQualName, namespace other than global ns can't have empty name} { catch {eval namespace delete [namespace children :: test_ns_*]} list [catch {namespace eval test_ns_1 {proc {} {} {}; namespace eval {} {}; {}}} msg] $msg} {1 {can't create namespace "": only global namespace can have empty name}}test namespace-15.1 {Tcl_FindNamespace, absolute name found} { catch {eval namespace delete [namespace children :: test_ns_*]} namespace eval test_ns_delete { namespace eval test_ns_delete2 {} proc cmd {args} {namespace current} } list [namespace delete ::test_ns_delete::test_ns_delete2] \ [namespace children ::test_ns_delete]} {{} {}}test namespace-15.2 {Tcl_FindNamespace, absolute name not found} { list [catch {namespace delete ::test_ns_delete::test_ns_delete2} msg] $msg} {1 {unknown namespace "::test_ns_delete::test_ns_delete2" in namespace delete command}}test namespace-15.3 {Tcl_FindNamespace, relative name found} { namespace eval test_ns_delete { namespace eval test_ns_delete2 {} namespace eval test_ns_delete3 {} list [namespace delete test_ns_delete2] \ [namespace children [namespace current]] }} {{} ::test_ns_delete::test_ns_delete3}test namespace-15.4 {Tcl_FindNamespace, relative name not found} { namespace eval test_ns_delete2 {} namespace eval test_ns_delete { list [catch {namespace delete test_ns_delete2} msg] $msg }} {1 {unknown namespace "test_ns_delete2" in namespace delete command}}test namespace-16.1 {Tcl_FindCommand, absolute name found} { catch {eval namespace delete [namespace children :: test_ns_*]} namespace eval test_ns_1 { proc cmd {args} {return "[namespace current]::cmd: $args"} variable v "::test_ns_1::cmd" eval $v one }} {::test_ns_1::cmd: one}test namespace-16.2 {Tcl_FindCommand, absolute name found} { eval $test_ns_1::v two} {::test_ns_1::cmd: two}test namespace-16.3 {Tcl_FindCommand, absolute name not found} { namespace eval test_ns_1 { variable v2 "::test_ns_1::ladidah" list [catch {eval $v2} msg] $msg }} {1 {invalid command name "::test_ns_1::ladidah"}}# save the "unknown" proc, which is redefined by the following two testscatch {rename unknown unknown.old}proc unknown {args} { return "unknown: $args"}test namespace-16.4 {Tcl_FindCommand, absolute name and TCL_GLOBAL_ONLY} { ::test_ns_1::foobar x y z} {unknown: ::test_ns_1::foobar x y z}test namespace-16.5 {Tcl_FindCommand, absolute name and TCL_GLOBAL_ONLY} { ::foobar 1 2 3 4 5} {unknown: ::foobar 1 2 3 4 5}test namespace-16.6 {Tcl_FindCommand, relative name and TCL_GLOBAL_ONLY} { test_ns_1::foobar x y z} {unknown: test_ns_1::foobar x y z}test namespace-16.7 {Tcl_FindCommand, relative name and TCL_GLOBAL_ONLY} { foobar 1 2 3 4 5} {unknown: foobar 1 2 3 4 5}# restore the "unknown" proc saved previouslycatch {rename unknown {}}catch {rename unknown.old unknown}test namespace-16.8 {Tcl_FindCommand, relative name found} { namespace eval test_ns_1 { cmd a b c }} {::test_ns_1::cmd: a b c}test namespace-16.9 {Tcl_FindCommand, relative name found} { catch {rename cmd2 {}} proc cmd2 {args} {return "[namespace current]::cmd2: $args"} namespace eval test_ns_1 { cmd2 a b c }} {::::cmd2: a b c}test namespace-16.10 {Tcl_FindCommand, relative name found, only look in current then global ns} { namespace eval test_ns_1 { proc cmd2 {args} { return "[namespace current]::cmd2 in test_ns_1: $args" } namespace eval test_ns_12 { cmd2 a b c } }} {::::cmd2: a b c}test namespace-16.11 {Tcl_FindCommand, relative name not found} { namespace eval test_ns_1 { list [catch {cmd3 a b c} msg] $msg }} {1 {invalid command name "cmd3"}}catch {unset x}test namespace-17.1 {Tcl_FindNamespaceVar, absolute name found} { catch {eval namespace delete [namespace children :: test_ns_*]} set x 314159 namespace eval test_ns_1 { set ::x }} {314159}test namespace-17.2 {Tcl_FindNamespaceVar, absolute name found} { namespace eval test_ns_1 { variable x 777 set ::test_ns_1::x }} {777}test namespace-17.3 {Tcl_FindNamespaceVar, absolute name found} { namespace eval test_ns_1 { namespace eval test_ns_2 { variable x 1111 } set ::test_ns_1::test_ns_2::x }} {1111}test namespace-17.4 {Tcl_FindNamespaceVar, absolute name not found} { namespace eval test_ns_1 { namespace eval test_ns_2 { variable x 1111 } list [catch {set ::test_ns_1::test_ns_2::y} msg] $msg }} {1 {can't read "::test_ns_1::test_ns_2::y": no such variable}}test namespace-17.5 {Tcl_FindNamespaceVar, absolute name and TCL_GLOBAL_ONLY} { namespace eval test_ns_1 { namespace eval test_ns_3 { variable ::test_ns_1::test_ns_2::x 2222 } } set ::test_ns_1::test_ns_2::x} {2222}test namespace-17.6 {Tcl_FindNamespaceVar, relative name found} { namespace eval test_ns_1 { set x }} {777}test namespace-17.7 {Tcl_FindNamespaceVar, relative name found} { namespace eval test_ns_1 { unset x set x ;# must be global x now }} {314159}test namespace-17.8 {Tcl_FindNamespaceVar, relative name not found} { namespace eval test_ns_1 { list [catch {set wuzzat} msg] $msg }} {1 {can't read "wuzzat": no such variable}}test namespace-17.9 {Tcl_FindNamespaceVar, relative name and TCL_GLOBAL_ONLY} { namespace eval test_ns_1 { variable a hello } set test_ns_1::a} {hello}catch {unset x}catch {unset l}catch {rename foo {}}test namespace-18.1 {TclResetShadowedCmdRefs, one-level check for command shadowing} { catch {eval namespace delete [namespace children :: test_ns_*]} proc foo {} {return "global foo"} namespace eval test_ns_1 { proc trigger {} { return [foo] } } set l "" lappend l [test_ns_1::trigger] namespace eval test_ns_1 { # force invalidation of cached ref to "foo" in proc trigger proc foo {} {return "foo in test_ns_1"} } lappend l [test_ns_1::trigger] set l} {{global foo} {foo in test_ns_1}}test namespace-18.2 {TclResetShadowedCmdRefs, multilevel check for command shadowing} { namespace eval test_ns_2 { proc foo {} {return "foo in ::test_ns_2"} } namespace eval test_ns_1 { namespace eval test_ns_2 {} proc trigger {} { return [test_ns_2::foo] } } set l "" lappend l [test_ns_1::trigger] namespace eval test_ns_1 { namespace eval test_ns_2 { # force invalidation of cached ref to "foo" in proc trigger proc foo {} {return "foo in ::test_ns_1::test_ns_2"} } } lappend l [test_ns_1::trigger] set l} {{foo in ::test_ns_2} {foo in ::test_ns_1::test_ns_2}}catch {unset l}catch {rename foo {}}test namespace-19.1 {GetNamespaceFromObj, global name found} { catch {eval namespace delete [namespace children :: test_ns_*]} namespace eval test_ns_1::test_ns_2 {} namespace children ::test_ns_1} {::test_ns_1::test_ns_2}test namespace-19.2 {GetNamespaceFromObj, relative name found} { namespace eval test_ns_1 { namespace children test_ns_2 }} {}test namespace-19.3 {GetNamespaceFromObj, name not found} { namespace eval test_ns_1 { list [catch {namespace children test_ns_99} msg] $msg }} {1 {unknown namespace "test_ns_99" in namespace children command}}test namespace-19.4 {GetNamespaceFromObj, invalidation of cached ns refs} { namespace eval test_ns_1 { proc foo {} { return [namespace children test_ns_2] } list [catch {namespace children test_ns_99} msg] $msg } set l {} lappend l [test_ns_1::foo] namespace delete test_ns_1::test_ns_2 namespace eval test_ns_1::test_ns_2::test_ns_3 {} lappend l [test_ns_1::foo] set l} {{} ::test_ns_1::test_ns_2::test_ns_3}test namespace-20.1 {Tcl_NamespaceObjCmd, bad subcommand} { catch {eval namespace delete [namespace children :: test_ns_*]} list [catch {namespace} msg] $msg} {1 {wrong # args: should be "namespace subcommand ?arg ...?"}}test namespace-20.2 {Tcl_NamespaceObjCmd, bad subcommand} { list [catch {namespace wombat {}} msg] $msg} {1 {bad option "wombat": must be children, code, current, delete, eval, export, forget, import, inscope, origin, parent, qualifiers, tail, or which}}test namespace-20.3 {Tcl_NamespaceObjCmd, abbreviations are okay} { namespace ch :: test_ns_*} {}test namespace-21.1 {NamespaceChildrenCmd, no args} { catch {eval namespace delete [namespace children :: test_ns_*]} namespace eval test_ns_1::test_ns_2 {} expr {[string first ::test_ns_1 [namespace children]] != -1}} {1}test namespace-21.2 {NamespaceChildrenCmd, no args} { namespace eval test_ns_1 { namespace children }} {::test_ns_1::test_ns_2}test namespace-21.3 {NamespaceChildrenCmd, ns name given} { namespace children ::test_ns_1} {::test_ns_1::test_ns_2}test namespace-21.4 {NamespaceChildrenCmd, ns name given} { namespace eval test_ns_1 { namespace children test_ns_2 }} {}test namespace-21.5 {NamespaceChildrenCmd, too many args} { namespace eval test_ns_1 { list [catch {namespace children test_ns_2 xxx yyy} msg] $msg }} {1 {wrong # args: should be "namespace children ?name? ?pattern?"}}test namespace-21.6 {NamespaceChildrenCmd, glob-style pattern given} { namespace eval test_ns_1::test_ns_foo {} namespace children test_ns_1 *f*} {::test_ns_1::test_ns_foo}test namespace-21.7 {NamespaceChildrenCmd, glob-style pattern given} { namespace eval test_ns_1::test_ns_foo {} namespace children test_ns_1 test*} {::test_ns_1::test_ns_2 ::test_ns_1::test_ns_foo}test namespace-22.1 {NamespaceCodeCmd, bad args} { catch {eval namespace delete [namespace children :: test_ns_*]} list [catch {namespace code} msg] $msg \ [catch {namespace code xxx yyy} msg] $msg} {1 {wrong # args: should be "namespace code arg"} 1 {wrong # args: should be "namespace code arg"}}test namespace-22.2 {NamespaceCodeCmd, arg is already scoped value} { namespace eval test_ns_1 { proc cmd {} {return "test_ns_1::cmd"} } namespace code {namespace inscope ::test_ns_1 cmd}} {namespace inscope ::test_ns_1 cmd}test namespace-22.3 {NamespaceCodeCmd, arg is already scoped value} { namespace code {namespace inscope ::test_ns_1 cmd}} {namespace inscope ::test_ns_1 cmd}test namespace-22.4 {NamespaceCodeCmd, in :: namespace} { namespace code unknown} {namespace inscope :: unknown}test namespace-22.5 {NamespaceCodeCmd, in other namespace} { namespace eval test_ns_1 { namespace code cmd }} {namespace inscope ::test_ns_1 cmd}test namespace-23.1 {NamespaceCurrentCmd, bad args} { catch {eval namespace delete [namespace children :: test_ns_*]} list [catch {namespace current xxx} msg] $msg \ [catch {namespace current xxx yyy} msg] $msg} {1 {wrong # args: should be "namespace current"} 1 {wrong # args: should be "namespace current"}}test namespace-23.2 {NamespaceCurrentCmd, at global level} { namespace current} {::}test namespace-23.3 {NamespaceCurrentCmd, in nested ns} { namespace eval test_ns_1::test_ns_2 { namespace current }} {::test_ns_1::test_ns_2}test namespace-24.1 {NamespaceDeleteCmd, no args} { catch {eval namespace delete [namespace children :: test_ns_*]} namespace delete} {}test namespace-24.2 {NamespaceDeleteCmd, one arg} { namespace eval test_ns_1::test_ns_2 {} namespace delete ::test_ns_1} {}test namespace-24.3 {NamespaceDeleteCmd, two args} { namespace eval test_ns_1::test_ns_2 {} list [namespace delete ::test_ns_1::test_ns_2] [namespace delete ::test_ns_1]} {{} {}}test namespace-24.4 {NamespaceDeleteCmd, unknown ns} { list [catch {namespace delete ::test_ns_foo} msg] $msg} {1 {unknown namespace "::test_ns_foo" in namespace delete command}}test namespace-25.1 {NamespaceEvalCmd, bad args} { catch {eval namespace delete [namespace children :: test_ns_*]} list [catch {namespace eval} msg] $msg
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -