diff options
Diffstat (limited to 'tests/msgcat.test')
-rw-r--r-- | tests/msgcat.test | 150 |
1 files changed, 110 insertions, 40 deletions
diff --git a/tests/msgcat.test b/tests/msgcat.test index 3440106..050b592 100644 --- a/tests/msgcat.test +++ b/tests/msgcat.test @@ -12,13 +12,13 @@ # Note that after running these tests, entries will be left behind in the # message catalogs for locales foo, foo_BAR, and foo_BAR_baz. -package require Tcl 8.2 +package require Tcl 8.5 if {[catch {package require tcltest 2}]} { puts stderr "Skipping tests in [info script]. tcltest 2 required." return } -if {[catch {package require msgcat 1.3.5}]} { - puts stderr "Skipping tests in [info script]. No msgcat 1.3.5 found to test." +if {[catch {package require msgcat 1.5}]} { + puts stderr "Skipping tests in [info script]. No msgcat 1.5 found to test." return } @@ -49,13 +49,14 @@ namespace eval ::msgcat::test { variable body variable result variable setVars - foreach setVars [PowerSet $envVars] { + foreach setVars [PowerSet $envVars] { set result [string tolower [lindex $setVars 0]] if {[string length $result] == 0} { if {[info exists ::tcl::mac::locale]} { - set result [string tolower $::tcl::mac::locale] + set result [string tolower \ + [msgcat::ConvertLocale $::tcl::mac::locale]] } else { - if {([info sharedlibextension] == ".dll") + if {([info sharedlibextension] eq ".dll") && ![catch {package require registry}]} { # Windows and Cygwin have other ways to determine the # locale when the environment variables are missing @@ -71,7 +72,7 @@ namespace eval ::msgcat::test { variable var foreach var $envVars { catch {variable $var $::env($var)} - catch {unset ::env($var)} + unset -nocomplain ::env($var) } foreach var $setVars { set ::env($var) $var @@ -83,14 +84,14 @@ namespace eval ::msgcat::test { } -cleanup { interp delete [namespace current]::i foreach var $envVars { - catch {unset ::env($var)} + unset -nocomplain ::env($var) catch {set ::env($var) [set [namespace current]::$var]} } } -body {i eval msgcat::mclocale} -result $result incr count } - catch {unset result} - + unset -nocomplain result + # Could add tests of initialization from Windows registry here. # Use a fake registry package. @@ -120,7 +121,7 @@ namespace eval ::msgcat::test { mclocale $locale } -body { mcpreferences - } -result en + } -result {en {}} test msgcat-1.6 {mclocale set, two elements} -setup { variable locale [mclocale] @@ -146,7 +147,7 @@ namespace eval ::msgcat::test { mclocale $locale } -body { mcpreferences - } -result {en_us en} + } -result {en_us en {}} test msgcat-1.9 {mclocale set, three elements} -setup { variable locale [mclocale] @@ -172,7 +173,7 @@ namespace eval ::msgcat::test { mclocale $locale } -body { mcpreferences - } -result {en_us_funky en_us en} + } -result {en_us_funky en_us en {}} test msgcat-1.12 {mclocale set, reject evil input} -setup { variable locale [mclocale] @@ -271,12 +272,13 @@ namespace eval ::msgcat::test { # (e.g. en_UK) will search less specific locales # (e.g. en) for translation strings. # - # Do this for the 12 permutations of + # Do this for the 15 permutations of # locales: {foo foo_BAR foo_BAR_baz} - # strings: {ov1 ov2 ov3 ov4} - # locale foo defines ov1, ov2, ov3 - # locale foo_BAR defines ov2, ov3 - # locale foo_BAR_BAZ defines ov3 + # strings: {ov0 ov1 ov2 ov3 ov4} + # locale ROOT defines ov0, ov1, ov2, ov3 + # locale foo defines ov1, ov2, ov3 + # locale foo_BAR defines ov2, ov3 + # locale foo_BAR_BAZ defines ov3 # (ov4 is defined in none) # So, # ov3 should be resolved in foo, foo_BAR, foo_BAR_baz @@ -289,16 +291,23 @@ namespace eval ::msgcat::test { variable count 2 variable result array set result { - foo,ov1 ov1_foo foo,ov2 ov2_foo foo,ov3 ov3_foo foo,ov4 ov4 - foo_BAR,ov1 ov1_foo foo_BAR,ov2 ov2_foo_BAR foo_BAR,ov3 ov3_foo_BAR - foo_BAR,ov4 ov4 foo_BAR_baz,ov1 ov1_foo foo_BAR_baz,ov2 ov2_foo_BAR + foo,ov0 ov0_ROOT foo,ov1 ov1_foo foo,ov2 ov2_foo + foo,ov3 ov3_foo foo,ov4 ov4 + foo_BAR,ov0 ov0_ROOT foo_BAR,ov1 ov1_foo foo_BAR,ov2 ov2_foo_BAR + foo_BAR,ov3 ov3_foo_BAR foo_BAR,ov4 ov4 + foo_BAR_baz,ov0 ov0_ROOT foo_BAR_baz,ov1 ov1_foo + foo_BAR_baz,ov2 ov2_foo_BAR foo_BAR_baz,ov3 ov3_foo_BAR_baz foo_BAR_baz,ov4 ov4 } variable loc variable string foreach loc {foo foo_BAR foo_BAR_baz} { - foreach string {ov1 ov2 ov3 ov4} { + foreach string {ov0 ov1 ov2 ov3 ov4} { test msgcat-3.$count {mcset, overlap} -setup { + mcset {} ov0 ov0_ROOT + mcset {} ov1 ov1_ROOT + mcset {} ov2 ov2_ROOT + mcset {} ov3 ov3_ROOT mcset foo ov1 ov1_foo mcset foo ov2 ov2_foo mcset foo ov3 ov3_foo @@ -315,7 +324,7 @@ namespace eval ::msgcat::test { incr count } } - catch {unset result} + unset -nocomplain result # Tests msgcat-4.*: [mcunknown] @@ -389,11 +398,15 @@ namespace eval ::msgcat::test { # Tests msgcat-5.*: [mcload] - variable locales {foo foo_BAR foo_BAR_baz} - makeDirectory msgdir + variable locales {{} foo foo_BAR foo_BAR_baz} + set msgdir [makeDirectory msgdir] foreach loc $locales { - makeFile "::msgcat::mcset $loc abc abc-$loc" \ - [string tolower [file join msgdir $loc.msg]] + if { $loc eq {} } { + set msg ROOT + } else { + set msg [string tolower $loc] + } + makeFile [list ::msgcat::mcset $loc abc abc-$loc] $msg.msg $msgdir } variable count 1 foreach loc {foo foo_BAR foo_BAR_baz} { @@ -403,21 +416,21 @@ namespace eval ::msgcat::test { } -cleanup { mclocale $locale } -body { - mcload [file join [temporaryDirectory] msgdir] - } -result $count + mcload $msgdir + } -result [expr { $count+1 }] incr count } # Even though foo_BAR_notexist does not exist, - # foo_BAR and foo should be loaded. + # foo_BAR, foo and the root should be loaded. test msgcat-5.4 {mcload} -setup { variable locale [mclocale] mclocale foo_BAR_notexist } -cleanup { mclocale $locale } -body { - mcload [file join [temporaryDirectory] msgdir] - } -result 2 + mcload $msgdir + } -result 3 test msgcat-5.5 {mcload} -setup { variable locale [mclocale] @@ -425,12 +438,13 @@ namespace eval ::msgcat::test { } -cleanup { mclocale $locale } -body { - mcload [file join [temporaryDirectory] msgdir] - } -result 0 + mcload $msgdir + } -result 1 test msgcat-5.6 {mcload} -setup { variable locale [mclocale] mclocale foo + mcload $msgdir } -cleanup { mclocale $locale } -body { @@ -440,6 +454,7 @@ namespace eval ::msgcat::test { test msgcat-5.7 {mcload} -setup { variable locale [mclocale] mclocale foo_BAR + mcload $msgdir } -cleanup { mclocale $locale } -body { @@ -449,6 +464,7 @@ namespace eval ::msgcat::test { test msgcat-5.8 {mcload} -setup { variable locale [mclocale] mclocale foo_BAR_baz + mcload $msgdir } -cleanup { mclocale $locale } -body { @@ -456,30 +472,45 @@ namespace eval ::msgcat::test { } -result abc-foo_BAR_baz test msgcat-5.9 {mcload} -setup { + variable locale [mclocale] + mclocale no_FI_notexist + mcload $msgdir + } -cleanup { + mclocale $locale + } -body { + mc abc + } -result abc- + + test msgcat-5.10 {mcload} -setup { rename ::msgcat::mcunknown SavedMcunknown proc ::msgcat::mcunknown {dom s} { return unknown:$dom:$s } variable locale [mclocale] mclocale no_FI_notexist + mcload $msgdir } -cleanup { mclocale $locale rename ::msgcat::mcunknown {} rename SavedMcunknown ::msgcat::mcunknown } -body { - mc abc - } -result unknown:no_fi_notexist:abc - + mc def + } -result unknown:no_fi_notexist:def foreach loc $locales { - removeFile [string tolower [file join msgdir $loc.msg]] + if { $loc eq {} } { + set msg ROOT + } else { + set msg [string tolower $loc] + } + removeFile $msg.msg $msgdir } removeDirectory msgdir # Tests msgcat-6.*: [mcset], [mc] namespace inheritance # # Test mcset and mc, ensuring that resolution for messages -# proceeds from the current ns to its parent and so on to the +# proceeds from the current ns to its parent and so on to the # global ns. # # Do this for the 12 permutations of @@ -523,7 +554,7 @@ namespace eval ::msgcat::test { ::msgcat::mcset foo ov3 "ov3_foo_bar_baz" } } - + } variable locale [mclocale] mclocale foo @@ -587,6 +618,45 @@ namespace eval ::msgcat::test { mc "this is a %s" "good test" } -result "this is a good test" + # Tests msgcat-8.*: [mcflset] + + set msgdir1 [makeDirectory msgdir1] + makeFile {::msgcat::mcflset k1 v1} l1.msg $msgdir1 + + test msgcat-8.1 {mcflset} -setup { + variable locale [mclocale] + mclocale l1 + mcload $msgdir1 + } -cleanup { + mclocale $locale + } -body { + mc k1 + } -result v1 + + removeFile l1.msg $msgdir1 + removeDirectory msgdir1 + + set msgdir2 [makeDirectory msgdir2] + set msgdir3 [makeDirectory msgdir3] + makeFile "::msgcat::mcflset k2 v2 ; ::msgcat::mcload [list $msgdir3]"\ + l2.msg $msgdir2 + makeFile {::msgcat::mcflset k3 v3} l2.msg $msgdir3 + + # chained mcload + test msgcat-8.2 {mcflset} -setup { + variable locale [mclocale] + mclocale l2 + mcload $msgdir2 + } -cleanup { + mclocale $locale + } -body { + return [mc k2][mc k3] + } -result v2v3 + + removeFile l2.msg $msgdir2 + removeDirectory msgdir2 + removeDirectory msgdir3 + cleanupTests } namespace delete ::msgcat::test |