os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/msgcat.test
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
# This file contains a collection of tests for the msgcat package.
sl@0
     2
# Sourcing this file into Tcl runs the tests and
sl@0
     3
# generates output for errors.  No output means no errors were found.
sl@0
     4
#
sl@0
     5
# Copyright (c) 1998 Mark Harrison.
sl@0
     6
# Copyright (c) 1998-1999 by Scriptics Corporation.
sl@0
     7
# Contributions from Don Porter, NIST, 2002.  (not subject to US copyright)
sl@0
     8
#
sl@0
     9
# See the file "license.terms" for information on usage and redistribution
sl@0
    10
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
sl@0
    11
#
sl@0
    12
# Note that after running these tests, entries will be left behind in the
sl@0
    13
# message catalogs for locales foo, foo_BAR, and foo_BAR_baz.
sl@0
    14
#
sl@0
    15
# RCS: @(#) $Id: msgcat.test,v 1.11.2.4 2006/09/11 16:15:12 andreas_kupries Exp $
sl@0
    16
sl@0
    17
package require Tcl 8.2
sl@0
    18
if {[catch {package require tcltest 2}]} {
sl@0
    19
    puts stderr "Skipping tests in [info script].  tcltest 2 required."
sl@0
    20
    return
sl@0
    21
}
sl@0
    22
if {[catch {package require msgcat 1.3.4}]} {
sl@0
    23
    puts stderr "Skipping tests in [info script].  No msgcat 1.3.4 found to test."
sl@0
    24
    return
sl@0
    25
}
sl@0
    26
sl@0
    27
namespace eval ::msgcat::test {
sl@0
    28
    namespace import ::msgcat::*
sl@0
    29
    namespace import ::tcltest::test
sl@0
    30
    namespace import ::tcltest::cleanupTests
sl@0
    31
    namespace import ::tcltest::temporaryDirectory
sl@0
    32
    namespace import ::tcltest::make*
sl@0
    33
    namespace import ::tcltest::remove*
sl@0
    34
sl@0
    35
    # Tests msgcat-0.*: locale initialization
sl@0
    36
sl@0
    37
    proc PowerSet {l} {
sl@0
    38
	if {[llength $l] == 0} {return [list [list]]}
sl@0
    39
	set element [lindex $l 0]
sl@0
    40
	set rest [lrange $l 1 end]
sl@0
    41
	set result [list]
sl@0
    42
	foreach x [PowerSet $rest] {
sl@0
    43
	    lappend result [linsert $x 0 $element]
sl@0
    44
	    lappend result $x
sl@0
    45
	}
sl@0
    46
	return $result
sl@0
    47
    }
sl@0
    48
sl@0
    49
    variable envVars {LC_ALL LC_MESSAGES LANG}
sl@0
    50
    variable count 0
sl@0
    51
    variable body
sl@0
    52
    variable result
sl@0
    53
    variable setVars
sl@0
    54
    foreach setVars [PowerSet $envVars] { 
sl@0
    55
	set result [string tolower [lindex $setVars 0]]
sl@0
    56
	if {[string length $result] == 0} {
sl@0
    57
	    if {[info exists ::tcl::mac::locale]} {
sl@0
    58
		set result [string tolower $::tcl::mac::locale]
sl@0
    59
	    } else {
sl@0
    60
		set result c
sl@0
    61
	    }
sl@0
    62
	}
sl@0
    63
	test msgcat-0.$count [list \
sl@0
    64
	    locale initialization from environment variables $setVars \
sl@0
    65
	] -setup {
sl@0
    66
	    variable var
sl@0
    67
	    foreach var $envVars {
sl@0
    68
		catch {variable $var $::env($var)}
sl@0
    69
		catch {unset ::env($var)}
sl@0
    70
	    }
sl@0
    71
	    foreach var $setVars {
sl@0
    72
		set ::env($var) $var
sl@0
    73
	    }
sl@0
    74
	    interp create [namespace current]::i
sl@0
    75
	    i eval [list package ifneeded msgcat [package provide msgcat] \
sl@0
    76
		    [package ifneeded msgcat [package provide msgcat]]]
sl@0
    77
	    i eval package require msgcat
sl@0
    78
	} -cleanup {
sl@0
    79
	    interp delete [namespace current]::i
sl@0
    80
	    foreach var $envVars {
sl@0
    81
		catch {unset ::env($var)}
sl@0
    82
		catch {set ::env($var) [set [namespace current]::$var]}
sl@0
    83
	    }
sl@0
    84
	} -body {i eval msgcat::mclocale} -result $result
sl@0
    85
	incr count
sl@0
    86
    }
sl@0
    87
    catch {unset result}
sl@0
    88
    
sl@0
    89
    # Could add tests of initialization from Windows registry here.
sl@0
    90
    # Use a fake registry package.
sl@0
    91
sl@0
    92
    # Tests msgcat-1.*: [mclocale], [mcpreferences]
sl@0
    93
sl@0
    94
    test msgcat-1.3 {mclocale set, single element} -setup {
sl@0
    95
	variable locale [mclocale]
sl@0
    96
    } -cleanup {
sl@0
    97
	mclocale $locale
sl@0
    98
    } -body {
sl@0
    99
	mclocale en
sl@0
   100
    } -result en
sl@0
   101
sl@0
   102
    test msgcat-1.4 {mclocale get, single element} -setup {
sl@0
   103
	variable locale [mclocale]
sl@0
   104
	mclocale en
sl@0
   105
    } -cleanup {
sl@0
   106
	mclocale $locale
sl@0
   107
    } -body {
sl@0
   108
	mclocale
sl@0
   109
    } -result en
sl@0
   110
sl@0
   111
    test msgcat-1.5 {mcpreferences, single element} -setup {
sl@0
   112
	variable locale [mclocale]
sl@0
   113
	mclocale en
sl@0
   114
    } -cleanup {
sl@0
   115
	mclocale $locale
sl@0
   116
    } -body {
sl@0
   117
	mcpreferences
sl@0
   118
    } -result en
sl@0
   119
sl@0
   120
    test msgcat-1.6 {mclocale set, two elements} -setup {
sl@0
   121
	variable locale [mclocale]
sl@0
   122
    } -cleanup {
sl@0
   123
	mclocale $locale
sl@0
   124
    } -body {
sl@0
   125
	mclocale en_US
sl@0
   126
    } -result en_us
sl@0
   127
sl@0
   128
    test msgcat-1.7 {mclocale get, two elements} -setup {
sl@0
   129
	variable locale [mclocale]
sl@0
   130
	mclocale en_US
sl@0
   131
    } -cleanup {
sl@0
   132
	mclocale $locale
sl@0
   133
    } -body {
sl@0
   134
	mclocale
sl@0
   135
    } -result en_us
sl@0
   136
sl@0
   137
    test msgcat-1.8 {mcpreferences, two elements} -setup {
sl@0
   138
	variable locale [mclocale]
sl@0
   139
	mclocale en_US
sl@0
   140
    } -cleanup {
sl@0
   141
	mclocale $locale
sl@0
   142
    } -body {
sl@0
   143
	mcpreferences
sl@0
   144
    } -result {en_us en}
sl@0
   145
sl@0
   146
    test msgcat-1.9 {mclocale set, three elements} -setup {
sl@0
   147
	variable locale [mclocale]
sl@0
   148
    } -cleanup {
sl@0
   149
	mclocale $locale
sl@0
   150
    } -body {
sl@0
   151
	mclocale en_US_funky
sl@0
   152
    } -result en_us_funky
sl@0
   153
sl@0
   154
    test msgcat-1.10 {mclocale get, three elements} -setup {
sl@0
   155
	variable locale [mclocale]
sl@0
   156
	mclocale en_US_funky
sl@0
   157
    } -cleanup {
sl@0
   158
	mclocale $locale
sl@0
   159
    } -body {
sl@0
   160
	mclocale
sl@0
   161
    } -result en_us_funky
sl@0
   162
sl@0
   163
    test msgcat-1.11 {mcpreferences, three elements} -setup {
sl@0
   164
	variable locale [mclocale]
sl@0
   165
	mclocale en_US_funky
sl@0
   166
    } -cleanup {
sl@0
   167
	mclocale $locale
sl@0
   168
    } -body {
sl@0
   169
	mcpreferences
sl@0
   170
    } -result {en_us_funky en_us en}
sl@0
   171
sl@0
   172
    test msgcat-1.12 {mclocale set, reject evil input} -setup {
sl@0
   173
	variable locale [mclocale]
sl@0
   174
    } -cleanup {
sl@0
   175
	mclocale $locale
sl@0
   176
    } -body {
sl@0
   177
	mclocale /path/to/evil/code
sl@0
   178
    } -returnCodes error -match glob -result {invalid newLocale value *}
sl@0
   179
sl@0
   180
    test msgcat-1.13 {mclocale set, reject evil input} -setup {
sl@0
   181
	variable locale [mclocale]
sl@0
   182
    } -cleanup {
sl@0
   183
	mclocale $locale
sl@0
   184
    } -body {
sl@0
   185
	mclocale looks/ok/../../../../but/is/path/to/evil/code
sl@0
   186
    } -returnCodes error -match glob -result {invalid newLocale value *}
sl@0
   187
sl@0
   188
    # Tests msgcat-2.*: [mcset], [mcmset], namespace partitioning
sl@0
   189
sl@0
   190
    test msgcat-2.1 {mcset, global scope} {
sl@0
   191
	namespace eval :: ::msgcat::mcset  foo_BAR text1 text2
sl@0
   192
    } {text2}
sl@0
   193
sl@0
   194
    test msgcat-2.2 {mcset, global scope, default} {
sl@0
   195
	namespace eval :: ::msgcat::mcset foo_BAR text3
sl@0
   196
    } {text3}
sl@0
   197
sl@0
   198
    test msgcat-2.2.1 {mcset, namespace overlap} {
sl@0
   199
	namespace eval baz {::msgcat::mcset  foo_BAR con1 con1baz}
sl@0
   200
    } {con1baz}
sl@0
   201
sl@0
   202
    test msgcat-2.3 {mcset, namespace overlap} -setup {
sl@0
   203
	namespace eval bar {::msgcat::mcset  foo_BAR con1 con1bar}
sl@0
   204
	namespace eval baz {::msgcat::mcset  foo_BAR con1 con1baz}
sl@0
   205
	variable locale [mclocale]
sl@0
   206
	mclocale foo_BAR
sl@0
   207
    } -cleanup {
sl@0
   208
	mclocale $locale
sl@0
   209
    } -body {
sl@0
   210
	namespace eval bar {::msgcat::mc con1}
sl@0
   211
    } -result con1bar
sl@0
   212
sl@0
   213
    test msgcat-2.4 {mcset, namespace overlap} -setup {
sl@0
   214
	namespace eval bar {::msgcat::mcset  foo_BAR con1 con1bar}
sl@0
   215
	namespace eval baz {::msgcat::mcset  foo_BAR con1 con1baz}
sl@0
   216
	variable locale [mclocale]
sl@0
   217
	mclocale foo_BAR
sl@0
   218
    } -cleanup {
sl@0
   219
	mclocale $locale
sl@0
   220
    } -body {
sl@0
   221
	namespace eval baz {::msgcat::mc con1}
sl@0
   222
    } -result con1baz
sl@0
   223
sl@0
   224
    test msgcat-2.5 {mcmset, global scope} -setup {
sl@0
   225
	namespace eval :: {
sl@0
   226
	    ::msgcat::mcmset  foo_BAR {
sl@0
   227
	        src1 trans1
sl@0
   228
	        src2 trans2
sl@0
   229
	    }
sl@0
   230
	}
sl@0
   231
	variable locale [mclocale]
sl@0
   232
	mclocale foo_BAR
sl@0
   233
    } -cleanup {
sl@0
   234
	mclocale $locale
sl@0
   235
    } -body {
sl@0
   236
	namespace eval :: {
sl@0
   237
	    ::msgcat::mc src1
sl@0
   238
	}
sl@0
   239
    } -result trans1
sl@0
   240
sl@0
   241
    test msgcat-2.6 {mcmset, namespace overlap} -setup {
sl@0
   242
	namespace eval bar {::msgcat::mcmset  foo_BAR {con2 con2bar}}
sl@0
   243
	namespace eval baz {::msgcat::mcmset  foo_BAR {con2 con2baz}}
sl@0
   244
	variable locale [mclocale]
sl@0
   245
	mclocale foo_BAR
sl@0
   246
    } -cleanup {
sl@0
   247
	mclocale $locale
sl@0
   248
    } -body {
sl@0
   249
	namespace eval bar {::msgcat::mc con2}
sl@0
   250
    } -result con2bar
sl@0
   251
sl@0
   252
    test msgcat-2.7 {mcmset, namespace overlap} -setup {
sl@0
   253
	namespace eval bar {::msgcat::mcmset  foo_BAR {con2 con2bar}}
sl@0
   254
	namespace eval baz {::msgcat::mcmset  foo_BAR {con2 con2baz}}
sl@0
   255
	variable locale [mclocale]
sl@0
   256
	mclocale foo_BAR
sl@0
   257
    } -cleanup {
sl@0
   258
	mclocale $locale
sl@0
   259
    } -body {
sl@0
   260
	namespace eval baz {::msgcat::mc con2}
sl@0
   261
    } -result con2baz
sl@0
   262
sl@0
   263
    # Tests msgcat-3.*: [mcset], [mc], catalog "inheritance"
sl@0
   264
    #
sl@0
   265
    # Test mcset and mc, ensuring that more specific locales
sl@0
   266
    # (e.g. en_UK) will search less specific locales
sl@0
   267
    # (e.g. en) for translation strings.
sl@0
   268
    #
sl@0
   269
    # Do this for the 12 permutations of
sl@0
   270
    #     locales: {foo foo_BAR foo_BAR_baz}
sl@0
   271
    #     strings: {ov1 ov2 ov3 ov4}
sl@0
   272
    #     locale foo         defines ov1, ov2, ov3
sl@0
   273
    #     locale foo_BAR     defines      ov2, ov3
sl@0
   274
    #     locale foo_BAR_BAZ defines           ov3
sl@0
   275
    #     (ov4 is defined in none)
sl@0
   276
    # So,
sl@0
   277
    #     ov3 should be resolved in foo, foo_BAR, foo_BAR_baz
sl@0
   278
    #     ov2 should be resolved in foo, foo_BAR
sl@0
   279
    #     ov2 should resolve to foo_BAR in foo_BAR_baz
sl@0
   280
    #     ov1 should be resolved in foo
sl@0
   281
    #     ov1 should resolve to foo in foo_BAR, foo_BAR_baz
sl@0
   282
    #     ov4 should be resolved in none, and call mcunknown
sl@0
   283
    #
sl@0
   284
    variable count 2
sl@0
   285
    variable result
sl@0
   286
    array set result {
sl@0
   287
	foo,ov1 ov1_foo foo,ov2 ov2_foo foo,ov3 ov3_foo foo,ov4 ov4
sl@0
   288
	foo_BAR,ov1 ov1_foo foo_BAR,ov2 ov2_foo_BAR foo_BAR,ov3 ov3_foo_BAR
sl@0
   289
	foo_BAR,ov4 ov4 foo_BAR_baz,ov1 ov1_foo foo_BAR_baz,ov2 ov2_foo_BAR
sl@0
   290
	foo_BAR_baz,ov3 ov3_foo_BAR_baz foo_BAR_baz,ov4 ov4
sl@0
   291
    }
sl@0
   292
    variable loc
sl@0
   293
    variable string
sl@0
   294
    foreach loc {foo foo_BAR foo_BAR_baz} {
sl@0
   295
	foreach string {ov1 ov2 ov3 ov4} {
sl@0
   296
	    test msgcat-3.$count {mcset, overlap} -setup {
sl@0
   297
		mcset foo ov1 ov1_foo
sl@0
   298
		mcset foo ov2 ov2_foo
sl@0
   299
		mcset foo ov3 ov3_foo
sl@0
   300
		mcset foo_BAR ov2 ov2_foo_BAR
sl@0
   301
		mcset foo_BAR ov3 ov3_foo_BAR
sl@0
   302
		mcset foo_BAR_baz ov3 ov3_foo_BAR_baz
sl@0
   303
		variable locale [mclocale]
sl@0
   304
		mclocale $loc
sl@0
   305
	    } -cleanup {
sl@0
   306
		mclocale $locale
sl@0
   307
	    } -body {
sl@0
   308
		mc $string
sl@0
   309
	    } -result $result($loc,$string)
sl@0
   310
	    incr count
sl@0
   311
	}
sl@0
   312
    }
sl@0
   313
    catch {unset result}
sl@0
   314
sl@0
   315
    # Tests msgcat-4.*: [mcunknown]
sl@0
   316
sl@0
   317
    test msgcat-4.2 {mcunknown, default} -setup {
sl@0
   318
	mcset foo unk1 "unknown 1"
sl@0
   319
	variable locale [mclocale]
sl@0
   320
	mclocale foo
sl@0
   321
    } -cleanup {
sl@0
   322
	mclocale $locale
sl@0
   323
    } -body {
sl@0
   324
	mc unk1
sl@0
   325
    } -result {unknown 1}
sl@0
   326
sl@0
   327
    test msgcat-4.3 {mcunknown, default} -setup {
sl@0
   328
	mcset foo unk1 "unknown 1"
sl@0
   329
	variable locale [mclocale]
sl@0
   330
	mclocale foo
sl@0
   331
    } -cleanup {
sl@0
   332
	mclocale $locale
sl@0
   333
    } -body {
sl@0
   334
	mc unk2
sl@0
   335
    } -result unk2
sl@0
   336
sl@0
   337
    test msgcat-4.4 {mcunknown, overridden} -setup {
sl@0
   338
	rename ::msgcat::mcunknown SavedMcunknown
sl@0
   339
	proc ::msgcat::mcunknown {dom s} {
sl@0
   340
            return unknown:$dom:$s
sl@0
   341
	}
sl@0
   342
	mcset foo unk1 "unknown 1"
sl@0
   343
	variable locale [mclocale]
sl@0
   344
	mclocale foo
sl@0
   345
    } -cleanup {
sl@0
   346
	mclocale $locale
sl@0
   347
	rename ::msgcat::mcunknown {}
sl@0
   348
	rename SavedMcunknown ::msgcat::mcunknown
sl@0
   349
    } -body {
sl@0
   350
	mc unk1
sl@0
   351
    } -result {unknown 1}
sl@0
   352
sl@0
   353
    test msgcat-4.5 {mcunknown, overridden} -setup {
sl@0
   354
	rename ::msgcat::mcunknown SavedMcunknown
sl@0
   355
	proc ::msgcat::mcunknown {dom s} {
sl@0
   356
            return unknown:$dom:$s
sl@0
   357
	}
sl@0
   358
	mcset foo unk1 "unknown 1"
sl@0
   359
	variable locale [mclocale]
sl@0
   360
	mclocale foo
sl@0
   361
    } -cleanup {
sl@0
   362
	mclocale $locale
sl@0
   363
	rename ::msgcat::mcunknown {}
sl@0
   364
	rename SavedMcunknown ::msgcat::mcunknown
sl@0
   365
    } -body {
sl@0
   366
	mc unk2
sl@0
   367
    } -result {unknown:foo:unk2}
sl@0
   368
sl@0
   369
    test msgcat-4.6 {mcunknown, uplevel context} -setup {
sl@0
   370
	rename ::msgcat::mcunknown SavedMcunknown
sl@0
   371
	proc ::msgcat::mcunknown {dom s} {
sl@0
   372
            return "unknown:$dom:$s:[expr {[info level] - 1}]"
sl@0
   373
	}
sl@0
   374
	mcset foo unk1 "unknown 1"
sl@0
   375
	variable locale [mclocale]
sl@0
   376
	mclocale foo
sl@0
   377
    } -cleanup {
sl@0
   378
	mclocale $locale
sl@0
   379
	rename ::msgcat::mcunknown {}
sl@0
   380
	rename SavedMcunknown ::msgcat::mcunknown
sl@0
   381
    } -body {
sl@0
   382
	mc unk2
sl@0
   383
    } -result unknown:foo:unk2:[info level]
sl@0
   384
sl@0
   385
    # Tests msgcat-5.*: [mcload]
sl@0
   386
sl@0
   387
    variable locales {foo foo_BAR foo_BAR_baz}
sl@0
   388
    makeDirectory msgdir
sl@0
   389
    foreach loc $locales {
sl@0
   390
	makeFile "::msgcat::mcset $loc abc abc-$loc" \
sl@0
   391
		[string tolower [file join msgdir $loc.msg]]
sl@0
   392
    }
sl@0
   393
    variable count 1
sl@0
   394
    foreach loc {foo foo_BAR foo_BAR_baz} {
sl@0
   395
	test msgcat-5.$count {mcload} -setup {
sl@0
   396
	    variable locale [mclocale]
sl@0
   397
	    mclocale $loc
sl@0
   398
	} -cleanup {
sl@0
   399
	    mclocale $locale
sl@0
   400
	} -body {
sl@0
   401
	    mcload [file join [temporaryDirectory] msgdir]
sl@0
   402
	} -result $count
sl@0
   403
	incr count
sl@0
   404
    }
sl@0
   405
sl@0
   406
    # Even though foo_BAR_notexist does not exist,
sl@0
   407
    # foo_BAR and foo should be loaded.
sl@0
   408
	test msgcat-5.4 {mcload} -setup {
sl@0
   409
	    variable locale [mclocale]
sl@0
   410
	    mclocale foo_BAR_notexist
sl@0
   411
	} -cleanup {
sl@0
   412
	    mclocale $locale
sl@0
   413
	} -body {
sl@0
   414
	    mcload [file join [temporaryDirectory] msgdir]
sl@0
   415
	} -result 2
sl@0
   416
sl@0
   417
	test msgcat-5.5 {mcload} -setup {
sl@0
   418
	    variable locale [mclocale]
sl@0
   419
	    mclocale no_FI_notexist
sl@0
   420
	} -cleanup {
sl@0
   421
	    mclocale $locale
sl@0
   422
	} -body {
sl@0
   423
	    mcload [file join [temporaryDirectory] msgdir]
sl@0
   424
	} -result 0
sl@0
   425
sl@0
   426
	test msgcat-5.6 {mcload} -setup {
sl@0
   427
	    variable locale [mclocale]
sl@0
   428
	    mclocale foo
sl@0
   429
	} -cleanup {
sl@0
   430
	    mclocale $locale
sl@0
   431
	} -body {
sl@0
   432
	    mc abc
sl@0
   433
	} -result abc-foo
sl@0
   434
sl@0
   435
	test msgcat-5.7 {mcload} -setup {
sl@0
   436
	    variable locale [mclocale]
sl@0
   437
	    mclocale foo_BAR
sl@0
   438
	} -cleanup {
sl@0
   439
	    mclocale $locale
sl@0
   440
	} -body {
sl@0
   441
	    mc abc
sl@0
   442
	} -result abc-foo_BAR
sl@0
   443
sl@0
   444
	test msgcat-5.8 {mcload} -setup {
sl@0
   445
	    variable locale [mclocale]
sl@0
   446
	    mclocale foo_BAR_baz
sl@0
   447
	} -cleanup {
sl@0
   448
	    mclocale $locale
sl@0
   449
	} -body {
sl@0
   450
	    mc abc
sl@0
   451
	} -result abc-foo_BAR_baz
sl@0
   452
sl@0
   453
	test msgcat-5.9 {mcload} -setup {
sl@0
   454
	    rename ::msgcat::mcunknown SavedMcunknown
sl@0
   455
	    proc ::msgcat::mcunknown {dom s} {
sl@0
   456
		return unknown:$dom:$s
sl@0
   457
	    }
sl@0
   458
	    variable locale [mclocale]
sl@0
   459
	    mclocale no_FI_notexist
sl@0
   460
	} -cleanup {
sl@0
   461
	    mclocale $locale
sl@0
   462
	    rename ::msgcat::mcunknown {}
sl@0
   463
	    rename SavedMcunknown ::msgcat::mcunknown
sl@0
   464
	} -body {
sl@0
   465
	    mc abc
sl@0
   466
	} -result unknown:no_fi_notexist:abc
sl@0
   467
sl@0
   468
sl@0
   469
    foreach loc $locales {
sl@0
   470
	removeFile [string tolower [file join msgdir $loc.msg]]
sl@0
   471
    }
sl@0
   472
    removeDirectory msgdir
sl@0
   473
sl@0
   474
    # Tests msgcat-6.*: [mcset], [mc] namespace inheritance
sl@0
   475
#
sl@0
   476
# Test mcset and mc, ensuring that resolution for messages
sl@0
   477
# proceeds from the current ns to its parent and so on to the 
sl@0
   478
# global ns.
sl@0
   479
#
sl@0
   480
# Do this for the 12 permutations of
sl@0
   481
#     locales: foo
sl@0
   482
#     namespaces: foo foo::bar foo::bar::baz
sl@0
   483
#     strings: {ov1 ov2 ov3 ov4}
sl@0
   484
#     namespace ::foo            defines ov1, ov2, ov3
sl@0
   485
#     namespace ::foo::bar       defines      ov2, ov3
sl@0
   486
#     namespace ::foo::bar::baz  defines           ov3
sl@0
   487
#
sl@0
   488
#     ov4 is not defined in any namespace.
sl@0
   489
#
sl@0
   490
# So,
sl@0
   491
#     ov3 should be resolved in ::foo::bar::baz, ::foo::bar, ::foo;
sl@0
   492
#     ov2 should be resolved in ::foo, ::foo::bar
sl@0
   493
#     ov1 should be resolved in ::foo
sl@0
   494
#     ov4 should be resolved in none, and call mcunknown
sl@0
   495
#
sl@0
   496
sl@0
   497
    variable result
sl@0
   498
    array set result {
sl@0
   499
	foo,ov1 ov1_foo foo,ov2 ov2_foo foo,ov3 ov3_foo foo,ov4 ov4
sl@0
   500
	foo::bar,ov1 ov1_foo foo::bar,ov2 ov2_foo_bar
sl@0
   501
	foo::bar,ov3 ov3_foo_bar foo::bar,ov4 ov4 foo::bar::baz,ov1 ov1_foo
sl@0
   502
	foo::bar::baz,ov2 ov2_foo_bar foo::bar::baz,ov3 ov3_foo_bar_baz
sl@0
   503
	foo::bar::baz,ov4 ov4
sl@0
   504
    }
sl@0
   505
    variable count 1
sl@0
   506
    variable ns
sl@0
   507
    foreach ns {foo foo::bar foo::bar::baz} {
sl@0
   508
	foreach string {ov1 ov2 ov3 ov4} {
sl@0
   509
	    test msgcat-6.$count {mcset, overlap} -setup {
sl@0
   510
		namespace eval foo {
sl@0
   511
		    ::msgcat::mcset foo ov1 ov1_foo
sl@0
   512
		    ::msgcat::mcset foo ov2 ov2_foo
sl@0
   513
		    ::msgcat::mcset foo ov3 ov3_foo
sl@0
   514
		    namespace eval bar {
sl@0
   515
			::msgcat::mcset foo ov2 ov2_foo_bar
sl@0
   516
			::msgcat::mcset foo ov3 ov3_foo_bar
sl@0
   517
			namespace eval baz {
sl@0
   518
			    ::msgcat::mcset foo ov3 "ov3_foo_bar_baz"
sl@0
   519
			}
sl@0
   520
		    }
sl@0
   521
		    
sl@0
   522
		}
sl@0
   523
		variable locale [mclocale]
sl@0
   524
		mclocale foo
sl@0
   525
	    } -cleanup {
sl@0
   526
		mclocale $locale
sl@0
   527
		namespace delete foo
sl@0
   528
	    } -body {
sl@0
   529
		namespace eval $ns [list ::msgcat::mc $string]
sl@0
   530
	    } -result $result($ns,$string)
sl@0
   531
	    incr count
sl@0
   532
	}
sl@0
   533
    }
sl@0
   534
sl@0
   535
    # Tests msgcat-7.*: [mc] extra args processed by [format]
sl@0
   536
sl@0
   537
    test msgcat-7.1 {mc extra args go through to format} -setup {
sl@0
   538
	mcset foo format1 "this is a test"
sl@0
   539
	mcset foo format2 "this is a %s"
sl@0
   540
	mcset foo format3 "this is a %s %s"
sl@0
   541
	variable locale [mclocale]
sl@0
   542
	mclocale foo
sl@0
   543
    } -cleanup {
sl@0
   544
	mclocale $locale
sl@0
   545
    } -body {
sl@0
   546
	mc format1 "good test"
sl@0
   547
    } -result "this is a test"
sl@0
   548
sl@0
   549
    test msgcat-7.2 {mc extra args go through to format} -setup {
sl@0
   550
	mcset foo format1 "this is a test"
sl@0
   551
	mcset foo format2 "this is a %s"
sl@0
   552
	mcset foo format3 "this is a %s %s"
sl@0
   553
	variable locale [mclocale]
sl@0
   554
	mclocale foo
sl@0
   555
    } -cleanup {
sl@0
   556
	mclocale $locale
sl@0
   557
    } -body {
sl@0
   558
	mc format2 "good test"
sl@0
   559
    } -result "this is a good test"
sl@0
   560
sl@0
   561
    test msgcat-7.3 {mc errors from format are propagated} -setup {
sl@0
   562
	mcset foo format1 "this is a test"
sl@0
   563
	mcset foo format2 "this is a %s"
sl@0
   564
	mcset foo format3 "this is a %s %s"
sl@0
   565
	variable locale [mclocale]
sl@0
   566
	mclocale foo
sl@0
   567
    } -cleanup {
sl@0
   568
	mclocale $locale
sl@0
   569
    } -body {
sl@0
   570
	catch {mc format3 "good test"}
sl@0
   571
    } -result 1
sl@0
   572
sl@0
   573
    test msgcat-7.4 {mc, extra args are given to unknown} -setup {
sl@0
   574
	mcset foo format1 "this is a test"
sl@0
   575
	mcset foo format2 "this is a %s"
sl@0
   576
	mcset foo format3 "this is a %s %s"
sl@0
   577
	variable locale [mclocale]
sl@0
   578
	mclocale foo
sl@0
   579
    } -cleanup {
sl@0
   580
	mclocale $locale
sl@0
   581
    } -body {
sl@0
   582
	mc "this is a %s" "good test"
sl@0
   583
    } -result "this is a good test"
sl@0
   584
sl@0
   585
    cleanupTests
sl@0
   586
}
sl@0
   587
namespace delete ::msgcat::test
sl@0
   588
return
sl@0
   589