summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoroehhar <harald.oehlmann@elmicron.de>2015-06-26 15:16:34 (GMT)
committeroehhar <harald.oehlmann@elmicron.de>2015-06-26 15:16:34 (GMT)
commit4acadf8d7735df752772eb9708d76bb81d6cecf4 (patch)
tree6b885a5cbcd34339fa0405d4a9ed81b3d982df82
parent23f6fa6d86cce6e3841ecdaf19957d0313407f28 (diff)
downloadtcl-4acadf8d7735df752772eb9708d76bb81d6cecf4.zip
tcl-4acadf8d7735df752772eb9708d76bb81d6cecf4.tar.gz
tcl-4acadf8d7735df752772eb9708d76bb81d6cecf4.tar.bz2
Tests for mcexists and mcloadedlocales
-rwxr-xr-xlibrary/msgcat/msgcat.tcl2
-rwxr-xr-xtests/msgcat.test95
2 files changed, 96 insertions, 1 deletions
diff --git a/library/msgcat/msgcat.tcl b/library/msgcat/msgcat.tcl
index 8bef081..0991f1c 100755
--- a/library/msgcat/msgcat.tcl
+++ b/library/msgcat/msgcat.tcl
@@ -248,7 +248,7 @@ proc msgcat::mcexists {args} {
set ns [uplevel 1 [list ::namespace current]]
set loclist [PackagePreferences $ns]
- while {[llength $args] > 1} {
+ while {[llength $args] != 1} {
set args [lassign $args option]
switch -glob -- $option {
-exactnamespace { set exactnamespace 1 }
diff --git a/tests/msgcat.test b/tests/msgcat.test
index 8fd94e1..e7c84a2 100755
--- a/tests/msgcat.test
+++ b/tests/msgcat.test
@@ -32,6 +32,8 @@ namespace eval ::msgcat::test {
# Tests msgcat-0.*: locale initialization
+ # Calculate set of all permutations of a list
+ # PowerSet {1 2 3} -> {1 2 3} {2 3} {1 3} 3 {1 2} 2 1 {}
proc PowerSet {l} {
if {[llength $l] == 0} {return [list [list]]}
set element [lindex $l 0]
@@ -666,6 +668,99 @@ namespace eval ::msgcat::test {
removeDirectory msgdir2
removeDirectory msgdir3
+ # Tests msgcat-9.*: [mcexists]
+
+ test msgcat-9.1 {mcexists no parameter} -body {
+ mcexists
+ } -returnCodes 1\
+ -result {wrong # args: should be "mcexists ?-exactnamespace? ?-exactlocale? src"}
+
+ test msgcat-9.2 {mcexists unknown option} -body {
+ mcexists -unknown src
+ } -returnCodes 1\
+ -result {unknown option "-unknown"}
+
+ test msgcat-9.3 {mcexists} -setup {
+ mcforgetpackage
+ variable locale [mclocale]
+ mclocale foo
+ mcset foo k1 v1
+ } -cleanup {
+ mclocale $locale
+ } -body {
+ list [mcexists k1] [mcexists k2]
+ } -result {1 0}
+
+ test msgcat-9.4 {mcexists descendent preference} -setup {
+ mcforgetpackage
+ variable locale [mclocale]
+ mclocale foo_bar
+ mcset foo k1 v1
+ } -cleanup {
+ mclocale $locale
+ } -body {
+ list [mcexists k1] [mcexists -exactlocale k1]
+ } -result {1 0}
+
+ test msgcat-9.5 {mcexists parent namespace} -setup {
+ mcforgetpackage
+ variable locale [mclocale]
+ mclocale foo_bar
+ mcset foo k1 v1
+ } -cleanup {
+ mclocale $locale
+ } -body {
+ namespace eval ::msgcat::test::sub {
+ list [::msgcat::mcexists k1]\
+ [::msgcat::mcexists -exactnamespace k1]
+ }
+ } -result {1 0}
+
+ # Tests msgcat-10.*: [mcloadedlocales]
+
+ test msgcat-10.1 {mcloadedlocales no arg} -body {
+ mcloadedlocales
+ } -returnCodes 1\
+ -result {wrong # args: should be "mcloadedlocales subcommand"}
+
+ test msgcat-10.2 {mcloadedlocales wrong subcommand} -body {
+ mcloadedlocales junk
+ } -returnCodes 1\
+ -result {unknown subcommand "junk": must be clear, or loaded}
+
+ test msgcat-10.3 {mcloadedlocales loaded} -setup {
+ mcforgetpackage
+ variable locale [mclocale]
+ mclocale {}
+ mcloadedlocales clear
+ } -cleanup {
+ mclocale $locale
+ } -body {
+ mclocale foo_bar
+ set resultlist [mcloadedlocales loaded]
+ # The result is position independent so check length and existence
+ list [llength $resultlist] [expr {"" in $resultlist}]\
+ [expr {"foo" in $resultlist}]\
+ [expr {"foo_bar" in $resultlist}]
+ } -result {3 1 1 1}
+
+ test msgcat-10.4 {mcloadedlocales clear} -setup {
+ mcforgetpackage
+ variable locale [mclocale]
+ mclocale {}
+ mcloadedlocales clear
+ } -cleanup {
+ mclocale $locale
+ } -body {
+ mclocale foo
+ mcset foo k1 v1
+ set res [mcexists k1]
+ mclocale ""
+ mcloadedlocales clear
+ mclocale foo
+ lappend res [mcexists k1]
+ } -result {1 0}
+
cleanupTests
}
namespace delete ::msgcat::test