diff options
author | oehhar <harald.oehlmann@elmicron.de> | 2018-01-13 15:23:38 (GMT) |
---|---|---|
committer | oehhar <harald.oehlmann@elmicron.de> | 2018-01-13 15:23:38 (GMT) |
commit | ecaec63f48c02c5bb7c0e7585ebc1d746b77ffd9 (patch) | |
tree | 1ddfc8af501ec8aa9e30ef20967955c2f5323200 | |
parent | e1ffd3f0057b68e75bce64f9c514b9993fb8a79c (diff) | |
download | tcl-ecaec63f48c02c5bb7c0e7585ebc1d746b77ffd9.zip tcl-ecaec63f48c02c5bb7c0e7585ebc1d746b77ffd9.tar.gz tcl-ecaec63f48c02c5bb7c0e7585ebc1d746b77ffd9.tar.bz2 |
Extended command msgcat::mcexists by switch "-namespace ns" to explicitly specify namespace
-rw-r--r-- | library/msgcat/msgcat.tcl | 22 | ||||
-rw-r--r-- | tests/msgcat.test | 120 |
2 files changed, 109 insertions, 33 deletions
diff --git a/library/msgcat/msgcat.tcl b/library/msgcat/msgcat.tcl index 29ccf0a..e57802b 100644 --- a/library/msgcat/msgcat.tcl +++ b/library/msgcat/msgcat.tcl @@ -265,23 +265,31 @@ proc msgcat::mcexists {args} { variable Loclist variable PackageConfig - set ns [PackageNamespaceGet] - set loclist [PackagePreferences $ns] - while {[llength $args] != 1} { set args [lassign $args option] switch -glob -- $option { - -exactnamespace { set exactnamespace 1 } - -exactlocale { set loclist [lrange $loclist 0 0] } + -exactnamespace - -exactlocale { set $option 1 } + -namespace { + if {[llength $args] < 2} { + return -code error\ + "Argument missing for switch \"-namespace\"" + } + set args [lassign $args ns] + } -* { return -code error "unknown option \"$option\"" } default { return -code error "wrong # args: should be\ \"[lindex [info level 0] 0] ?-exactnamespace?\ - ?-exactlocale? src\"" + ?-exactlocale? ?-namespace ns? src\"" } } } set src [lindex $args 0] + + if {![info exists ns]} { set ns [PackageNamespaceGet] } + + set loclist [PackagePreferences $ns] + if {[info exists -exactlocale]} { set loclist [lrange $loclist 0 0] } while {$ns ne ""} { foreach loc $loclist { @@ -289,7 +297,7 @@ proc msgcat::mcexists {args} { return 1 } } - if {[info exists exactnamespace]} {return 0} + if {[info exists -exactnamespace]} {return 0} set ns [namespace parent $ns] } return 0 diff --git a/tests/msgcat.test b/tests/msgcat.test index c8f325b..a99086d 100644 --- a/tests/msgcat.test +++ b/tests/msgcat.test @@ -688,7 +688,7 @@ namespace eval ::msgcat::test { test msgcat-9.1 {mcexists no parameter} -body { mcexists } -returnCodes 1\ - -result {wrong # args: should be "mcexists ?-exactnamespace? ?-exactlocale? src"} + -result {wrong # args: should be "mcexists ?-exactnamespace? ?-exactlocale? ?-namespace ns? src"} test msgcat-9.2 {mcexists unknown option} -body { mcexists -unknown src @@ -724,12 +724,34 @@ namespace eval ::msgcat::test { mcset foo k1 v1 } -cleanup { mclocale $locale + namespace delete ::foo } -body { - namespace eval ::msgcat::test::sub { + namespace eval ::foo { list [::msgcat::mcexists k1]\ - [::msgcat::mcexists -exactnamespace k1] + [::msgcat::mcexists -namespace ::msgcat::test k1] } - } -result {1 0} + } -result {0 1} + + test msgcat-9.6 {mcexists -namespace - ns argument missing} -setup { + mcforgetpackage + variable locale [mclocale] + mclocale foo_bar + mcset foo k1 v1 + } -cleanup { + mclocale $locale + namespace delete ::foo + } -body { + namespace eval ::foo { + list [::msgcat::mcexists k1]\ + [::msgcat::mcexists -namespace ::msgcat::test k1] + } + } -result {0 1} + + test msgcat-9.1 {mcexists -namespace with no parameter} -body { + mcexists -namespace src + } -returnCodes 1\ + -result {Argument missing for switch "-namespace"} + # Tests msgcat-10.*: [mcloadedlocales] @@ -1080,26 +1102,29 @@ namespace eval ::msgcat::test { # - namespace defined, class defined oo, classless test msgcat-15.1 {mc in class} -setup { - namespace eval ::bar { + # full namespace is ::msgcat::test:bar + namespace eval bar { ::msgcat::mcset foo_BAR con2 con2bar oo::class create ClassCur oo::define ClassCur method method1 {} {::msgcat::mc con2} } - namespace eval ::baz { - set ObjCur [::bar::ClassCur new] + # full namespace is ::msgcat::test:baz + namespace eval baz { + set ObjCur [::msgcat::test::bar::ClassCur new] } variable locale [mclocale] mclocale foo_BAR } -cleanup { mclocale $locale - namespace eval ::bar {::msgcat::mcforgetpackage} - namespace delete ::bar ::baz + namespace eval bar {::msgcat::mcforgetpackage} + namespace delete bar baz } -body { - $::baz::ObjCur method1 + $baz::ObjCur method1 } -result con2bar test msgcat-15.2 {mc in classless object} -setup { - namespace eval ::bar { + # full namespace is ::msgcat::test:bar + namespace eval bar { ::msgcat::mcset foo_BAR con2 con2bar oo::object create ObjCur oo::objdefine ObjCur method method1 {} {::msgcat::mc con2} @@ -1108,42 +1133,85 @@ namespace eval ::msgcat::test { mclocale foo_BAR } -cleanup { mclocale $locale - namespace eval ::bar {::msgcat::mcforgetpackage} - namespace delete ::bar + namespace eval bar {::msgcat::mcforgetpackage} + namespace delete bar } -body { - ::bar::ObjCur method1 + bar::ObjCur method1 } -result con2bar + test msgcat-15.3 {mc in classless object with explicite namespace eval}\ + -setup { + # full namespace is ::msgcat::test:bar + namespace eval bar { + ::msgcat::mcset foo_BAR con2 con2bar + oo::object create ObjCur + oo::objdefine ObjCur method method1 {} { + namespace eval ::msgcat::test::baz { + ::msgcat::mc con2 + } + } + } + namespace eval baz { + ::msgcat::mcset foo_BAR con2 con2baz + } + variable locale [mclocale] + mclocale foo_BAR + } -cleanup { + mclocale $locale + namespace eval bar {::msgcat::mcforgetpackage} + namespace eval baz {::msgcat::mcforgetpackage} + namespace delete bar baz + } -body { + bar::ObjCur method1 + } -result con2baz + # Test msgcat-16.*: command mcpackagenamespaceget test msgcat-16.1 {mcpackagenamespaceget in namespace procedure} -body { - namespace eval ::baz {msgcat::mcpackagenamespaceget} - } -result ::baz + namespace eval baz {msgcat::mcpackagenamespaceget} + } -result ::msgcat::test::baz test msgcat-16.2 {mcpackagenamespaceget in class} -setup { - namespace eval ::bar { + namespace eval bar { oo::class create ClassCur oo::define ClassCur method method1 {} {msgcat::mcpackagenamespaceget} } - namespace eval ::baz { - set ObjCur [::bar::ClassCur new] + namespace eval baz { + set ObjCur [::msgcat::test::bar::ClassCur new] } } -cleanup { - namespace delete ::bar ::baz + namespace delete bar baz } -body { - $::baz::ObjCur method1 - } -result ::bar + $baz::ObjCur method1 + } -result ::msgcat::test::bar test msgcat-16.3 {mcpackagenamespaceget in classless object} -setup { - namespace eval ::bar { + namespace eval bar { oo::object create ObjCur oo::objdefine ObjCur method method1 {} {msgcat::mcpackagenamespaceget} } } -cleanup { - namespace delete ::bar + namespace delete bar + } -body { + bar::ObjCur method1 + } -result ::msgcat::test::bar + + test msgcat-16.4\ + {mcpackagenamespaceget in classless object with explicite namespace eval}\ + -setup { + namespace eval bar { + oo::object create ObjCur + oo::objdefine ObjCur method method1 {} { + namespace eval ::msgcat::test::baz { + msgcat::mcpackagenamespaceget + } + } + } + } -cleanup { + namespace delete bar baz } -body { - ::bar::ObjCur method1 - } -result ::bar + bar::ObjCur method1 + } -result ::msgcat::test::baz # Test msgcat-17.*: mcn command |