diff options
Diffstat (limited to 'tests/msgcat.test')
| -rw-r--r-- | tests/msgcat.test | 149 | 
1 files changed, 112 insertions, 37 deletions
| diff --git a/tests/msgcat.test b/tests/msgcat.test index b291a09..050b592 100644 --- a/tests/msgcat.test +++ b/tests/msgcat.test @@ -11,16 +11,14 @@  #  # Note that after running these tests, entries will be left behind in the  # message catalogs for locales foo, foo_BAR, and foo_BAR_baz. -# -# RCS: @(#) $Id: msgcat.test,v 1.11.2.4 2006/09/11 16:15:12 andreas_kupries Exp $ -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.4}]} { -    puts stderr "Skipping tests in [info script].  No msgcat 1.3.4 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  } @@ -55,8 +53,16 @@ namespace eval ::msgcat::test {  	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] eq ".dll") +			&& ![catch {package require registry}]} { +		    # Windows and Cygwin have other ways to determine the +		    # locale when the environment variables are missing +		    # and the registry package is present +		    continue +		}  		set result c  	    }  	} @@ -66,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 @@ -78,13 +84,13 @@ 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. @@ -115,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] @@ -141,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] @@ -167,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] @@ -266,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 @@ -284,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 @@ -310,7 +324,7 @@ namespace eval ::msgcat::test {  	    incr count  	}      } -    catch {unset result} +    unset -nocomplain result      # Tests msgcat-4.*: [mcunknown] @@ -384,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} { @@ -398,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] @@ -420,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 { @@ -435,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 { @@ -444,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 { @@ -451,23 +472,38 @@ 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 @@ -582,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 | 
