os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/util.test
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
# This file is a Tcl script to test the code in the file tclUtil.c.
sl@0
     2
# This file is organized in the standard fashion for Tcl tests.
sl@0
     3
#
sl@0
     4
# Copyright (c) 1995-1998 Sun Microsystems, Inc.
sl@0
     5
# Copyright (c) 1998-1999 by Scriptics Corporation.
sl@0
     6
#
sl@0
     7
# See the file "license.terms" for information on usage and redistribution
sl@0
     8
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
sl@0
     9
#
sl@0
    10
# RCS: @(#) $Id: util.test,v 1.10.4.4 2005/10/28 03:26:33 mdejong Exp $
sl@0
    11
sl@0
    12
if {[lsearch [namespace children] ::tcltest] == -1} {
sl@0
    13
    package require tcltest
sl@0
    14
    namespace import -force ::tcltest::*
sl@0
    15
}
sl@0
    16
sl@0
    17
test util-1.1 {TclFindElement procedure - binary element in middle of list} {
sl@0
    18
    lindex {0 foo\x00help 1} 1
sl@0
    19
} "foo\x00help"
sl@0
    20
test util-1.2 {TclFindElement procedure - binary element at end of list} {
sl@0
    21
    lindex {0 foo\x00help} 1
sl@0
    22
} "foo\x00help"
sl@0
    23
sl@0
    24
test util-2.1 {TclCopyAndCollapse procedure - normal string} {
sl@0
    25
    lindex {0 foo} 1
sl@0
    26
} {foo}
sl@0
    27
test util-2.2 {TclCopyAndCollapse procedure - string with backslashes} {
sl@0
    28
    lindex {0 foo\n\x00help 1} 1
sl@0
    29
} "foo\n\x00help"
sl@0
    30
sl@0
    31
test util-3.1 {Tcl_ScanCountedElement procedure - don't leave unmatched braces} {
sl@0
    32
    # This test checks for a very tricky feature.  Any list element
sl@0
    33
    # generated with Tcl_ScanCountedElement and Tcl_ConvertElement must
sl@0
    34
    # have the property that it can be enclosing in curly braces to make
sl@0
    35
    # an embedded sub-list.  If this property doesn't hold, then
sl@0
    36
    # Tcl_DStringStartSublist doesn't work.
sl@0
    37
sl@0
    38
    set x {}
sl@0
    39
    lappend x " \\\{ \\"
sl@0
    40
    concat $x [llength "{$x}"]
sl@0
    41
} {\ \\\{\ \\ 1}
sl@0
    42
sl@0
    43
test util-4.1 {Tcl_ConcatObj - backslash-space at end of argument} {
sl@0
    44
    concat a {b\ } c
sl@0
    45
} {a b\  c}
sl@0
    46
test util-4.2 {Tcl_ConcatObj - backslash-space at end of argument} {
sl@0
    47
    concat a {b\   } c
sl@0
    48
} {a b\  c}
sl@0
    49
test util-4.3 {Tcl_ConcatObj - backslash-space at end of argument} {
sl@0
    50
    concat a {b\\   } c
sl@0
    51
} {a b\\  c}
sl@0
    52
test util-4.4 {Tcl_ConcatObj - backslash-space at end of argument} {
sl@0
    53
    concat a {b } c
sl@0
    54
} {a b c}
sl@0
    55
test util-4.5 {Tcl_ConcatObj - backslash-space at end of argument} {
sl@0
    56
    concat a { } c
sl@0
    57
} {a c}
sl@0
    58
test util-4.6 {Tcl_ConcatObj - utf-8 sequence with "whitespace" char} {
sl@0
    59
    # Check for Bug #227512.  If this violates C isspace, then it returns \xc3.
sl@0
    60
    concat \xe0
sl@0
    61
} \xe0
sl@0
    62
sl@0
    63
proc Wrapper_Tcl_StringMatch {pattern string} {
sl@0
    64
    # Forces use of Tcl_StringMatch, not Tcl_UniCharCaseMatch
sl@0
    65
    switch -glob -- $string $pattern {return 1} default {return 0}
sl@0
    66
}
sl@0
    67
test util-5.1 {Tcl_StringMatch} {
sl@0
    68
    Wrapper_Tcl_StringMatch ab*c abc
sl@0
    69
} 1
sl@0
    70
test util-5.2 {Tcl_StringMatch} {
sl@0
    71
    Wrapper_Tcl_StringMatch ab**c abc
sl@0
    72
} 1
sl@0
    73
test util-5.3 {Tcl_StringMatch} {
sl@0
    74
    Wrapper_Tcl_StringMatch ab* abcdef
sl@0
    75
} 1
sl@0
    76
test util-5.4 {Tcl_StringMatch} {
sl@0
    77
    Wrapper_Tcl_StringMatch *c abc
sl@0
    78
} 1
sl@0
    79
test util-5.5 {Tcl_StringMatch} {
sl@0
    80
    Wrapper_Tcl_StringMatch *3*6*9 0123456789
sl@0
    81
} 1
sl@0
    82
test util-5.6 {Tcl_StringMatch} {
sl@0
    83
    Wrapper_Tcl_StringMatch *3*6*9 01234567890
sl@0
    84
} 0
sl@0
    85
test util-5.7 {Tcl_StringMatch: UTF-8} {
sl@0
    86
    Wrapper_Tcl_StringMatch *u \u4e4fu
sl@0
    87
} 1
sl@0
    88
test util-5.8 {Tcl_StringMatch} {
sl@0
    89
    Wrapper_Tcl_StringMatch a?c abc
sl@0
    90
} 1
sl@0
    91
test util-5.9 {Tcl_StringMatch: UTF-8} {
sl@0
    92
    # skip one character in string
sl@0
    93
sl@0
    94
    Wrapper_Tcl_StringMatch a?c a\u4e4fc
sl@0
    95
} 1
sl@0
    96
test util-5.10 {Tcl_StringMatch} {
sl@0
    97
    Wrapper_Tcl_StringMatch a??c abc
sl@0
    98
} 0
sl@0
    99
test util-5.11 {Tcl_StringMatch} {
sl@0
   100
    Wrapper_Tcl_StringMatch ?1??4???8? 0123456789
sl@0
   101
} 1
sl@0
   102
test util-5.12 {Tcl_StringMatch} {
sl@0
   103
    Wrapper_Tcl_StringMatch {[abc]bc} abc
sl@0
   104
} 1
sl@0
   105
test util-5.13 {Tcl_StringMatch: UTF-8} {
sl@0
   106
    # string += Tcl_UtfToUniChar(string, &ch);
sl@0
   107
sl@0
   108
    Wrapper_Tcl_StringMatch "\[\u4e4fxy\]bc" "\u4e4fbc"
sl@0
   109
} 1
sl@0
   110
test util-5.14 {Tcl_StringMatch} {
sl@0
   111
    # if ((*pattern == ']') || (*pattern == '\0'))
sl@0
   112
    # badly formed pattern
sl@0
   113
sl@0
   114
    Wrapper_Tcl_StringMatch {[]} {[]}
sl@0
   115
} 0
sl@0
   116
test util-5.15 {Tcl_StringMatch} {
sl@0
   117
    # if ((*pattern == ']') || (*pattern == '\0'))
sl@0
   118
    # badly formed pattern
sl@0
   119
sl@0
   120
    Wrapper_Tcl_StringMatch {[} {[}
sl@0
   121
} 0
sl@0
   122
test util-5.16 {Tcl_StringMatch} {
sl@0
   123
    Wrapper_Tcl_StringMatch {a[abc]c} abc
sl@0
   124
} 1
sl@0
   125
test util-5.17 {Tcl_StringMatch: UTF-8} {
sl@0
   126
    # pattern += Tcl_UtfToUniChar(pattern, &endChar);
sl@0
   127
    # get 1 UTF-8 character
sl@0
   128
sl@0
   129
    Wrapper_Tcl_StringMatch "a\[a\u4e4fc]c" "a\u4e4fc"
sl@0
   130
} 1
sl@0
   131
test util-5.18 {Tcl_StringMatch: UTF-8} {
sl@0
   132
    # pattern += Tcl_UtfToUniChar(pattern, &endChar);
sl@0
   133
    # proper advance: wrong answer would match on UTF trail byte of \u4e4f
sl@0
   134
sl@0
   135
    Wrapper_Tcl_StringMatch {a[a\u4e4fc]c} [bytestring a\u008fc]
sl@0
   136
} 0
sl@0
   137
test util-5.19 {Tcl_StringMatch: UTF-8} {
sl@0
   138
    # pattern += Tcl_UtfToUniChar(pattern, &endChar);
sl@0
   139
    # proper advance.
sl@0
   140
sl@0
   141
    Wrapper_Tcl_StringMatch {a[a\u4e4fc]c} "acc"
sl@0
   142
} 1
sl@0
   143
test util-5.20 {Tcl_StringMatch} {
sl@0
   144
    Wrapper_Tcl_StringMatch {a[xyz]c} abc
sl@0
   145
} 0
sl@0
   146
test util-5.21 {Tcl_StringMatch} {
sl@0
   147
    Wrapper_Tcl_StringMatch {12[2-7]45} 12345
sl@0
   148
} 1
sl@0
   149
test util-5.22 {Tcl_StringMatch: UTF-8 range} {
sl@0
   150
    Wrapper_Tcl_StringMatch "\[\u4e00-\u4e4f]" "0"
sl@0
   151
} 0
sl@0
   152
test util-5.23 {Tcl_StringMatch: UTF-8 range} {
sl@0
   153
    Wrapper_Tcl_StringMatch "\[\u4e00-\u4e4f]" "\u4e33"
sl@0
   154
} 1
sl@0
   155
test util-5.24 {Tcl_StringMatch: UTF-8 range} {
sl@0
   156
    Wrapper_Tcl_StringMatch "\[\u4e00-\u4e4f]" "\uff08"
sl@0
   157
} 0
sl@0
   158
test util-5.25 {Tcl_StringMatch} {
sl@0
   159
    Wrapper_Tcl_StringMatch {12[ab2-4cd]45} 12345
sl@0
   160
} 1
sl@0
   161
test util-5.26 {Tcl_StringMatch} {
sl@0
   162
    Wrapper_Tcl_StringMatch {12[ab2-4cd]45} 12b45
sl@0
   163
} 1
sl@0
   164
test util-5.27 {Tcl_StringMatch} {
sl@0
   165
    Wrapper_Tcl_StringMatch {12[ab2-4cd]45} 12d45
sl@0
   166
} 1
sl@0
   167
test util-5.28 {Tcl_StringMatch} {
sl@0
   168
    Wrapper_Tcl_StringMatch {12[ab2-4cd]45} 12145
sl@0
   169
} 0
sl@0
   170
test util-5.29 {Tcl_StringMatch} {
sl@0
   171
    Wrapper_Tcl_StringMatch {12[ab2-4cd]45} 12545
sl@0
   172
} 0
sl@0
   173
test util-5.30 {Tcl_StringMatch: forwards range} {
sl@0
   174
    Wrapper_Tcl_StringMatch {[k-w]} "z"
sl@0
   175
} 0
sl@0
   176
test util-5.31 {Tcl_StringMatch: forwards range} {
sl@0
   177
    Wrapper_Tcl_StringMatch {[k-w]} "w"
sl@0
   178
} 1
sl@0
   179
test util-5.32 {Tcl_StringMatch: forwards range} {
sl@0
   180
    Wrapper_Tcl_StringMatch {[k-w]} "r"
sl@0
   181
} 1
sl@0
   182
test util-5.33 {Tcl_StringMatch: forwards range} {
sl@0
   183
    Wrapper_Tcl_StringMatch {[k-w]} "k"
sl@0
   184
} 1
sl@0
   185
test util-5.34 {Tcl_StringMatch: forwards range} {
sl@0
   186
    Wrapper_Tcl_StringMatch {[k-w]} "a"
sl@0
   187
} 0
sl@0
   188
test util-5.35 {Tcl_StringMatch: reverse range} {
sl@0
   189
    Wrapper_Tcl_StringMatch {[w-k]} "z"
sl@0
   190
} 0
sl@0
   191
test util-5.36 {Tcl_StringMatch: reverse range} {
sl@0
   192
    Wrapper_Tcl_StringMatch {[w-k]} "w"
sl@0
   193
} 1
sl@0
   194
test util-5.37 {Tcl_StringMatch: reverse range} {
sl@0
   195
    Wrapper_Tcl_StringMatch {[w-k]} "r"
sl@0
   196
} 1
sl@0
   197
test util-5.38 {Tcl_StringMatch: reverse range} {
sl@0
   198
    Wrapper_Tcl_StringMatch {[w-k]} "k"
sl@0
   199
} 1
sl@0
   200
test util-5.39 {Tcl_StringMatch: reverse range} {
sl@0
   201
    Wrapper_Tcl_StringMatch {[w-k]} "a"
sl@0
   202
} 0
sl@0
   203
test util-5.40 {Tcl_StringMatch: skip correct number of ']'} {
sl@0
   204
    Wrapper_Tcl_StringMatch {[A-]x} Ax
sl@0
   205
} 0
sl@0
   206
test util-5.41 {Tcl_StringMatch: skip correct number of ']'} {
sl@0
   207
    Wrapper_Tcl_StringMatch {[A-]]x} Ax
sl@0
   208
} 1
sl@0
   209
test util-5.42 {Tcl_StringMatch: skip correct number of ']'} {
sl@0
   210
    Wrapper_Tcl_StringMatch {[A-]]x} \ue1x
sl@0
   211
} 0
sl@0
   212
test util-5.43 {Tcl_StringMatch: skip correct number of ']'} {
sl@0
   213
    Wrapper_Tcl_StringMatch \[A-]\ue1]x \ue1x
sl@0
   214
} 1
sl@0
   215
test util-5.44 {Tcl_StringMatch: skip correct number of ']'} {
sl@0
   216
    Wrapper_Tcl_StringMatch {[A-]h]x} hx
sl@0
   217
} 1
sl@0
   218
test util-5.45 {Tcl_StringMatch} {
sl@0
   219
    # if (*pattern == '\0')
sl@0
   220
    # badly formed pattern, still treats as a set
sl@0
   221
sl@0
   222
    Wrapper_Tcl_StringMatch {[a} a
sl@0
   223
} 1
sl@0
   224
test util-5.46 {Tcl_StringMatch} {
sl@0
   225
    Wrapper_Tcl_StringMatch {a\*b} a*b
sl@0
   226
} 1
sl@0
   227
test util-5.47 {Tcl_StringMatch} {
sl@0
   228
    Wrapper_Tcl_StringMatch {a\*b} ab
sl@0
   229
} 0
sl@0
   230
test util-5.48 {Tcl_StringMatch} {
sl@0
   231
    Wrapper_Tcl_StringMatch {a\*\?\[\]\\\x} "a*?\[\]\\x"
sl@0
   232
} 1
sl@0
   233
test util-5.49 {Tcl_StringMatch} {
sl@0
   234
    Wrapper_Tcl_StringMatch ** ""
sl@0
   235
} 1
sl@0
   236
test util-5.50 {Tcl_StringMatch} {
sl@0
   237
    Wrapper_Tcl_StringMatch *. ""
sl@0
   238
} 0
sl@0
   239
test util-5.51 {Tcl_StringMatch} {
sl@0
   240
    Wrapper_Tcl_StringMatch "" ""
sl@0
   241
} 1
sl@0
   242
sl@0
   243
test util-6.1 {Tcl_PrintDouble - using tcl_precision} {
sl@0
   244
    concat x[expr 1.4]
sl@0
   245
} {x1.4}
sl@0
   246
test util-6.2 {Tcl_PrintDouble - using tcl_precision} {
sl@0
   247
    concat x[expr 1.39999999999]
sl@0
   248
} {x1.39999999999}
sl@0
   249
test util-6.3 {Tcl_PrintDouble - using tcl_precision} {
sl@0
   250
    concat x[expr 1.399999999999]
sl@0
   251
} {x1.4}
sl@0
   252
test util-6.4 {Tcl_PrintDouble - using tcl_precision} {
sl@0
   253
    set tcl_precision 5
sl@0
   254
    concat x[expr 1.123412341234]
sl@0
   255
} {x1.1234}
sl@0
   256
set tcl_precision 12
sl@0
   257
test util-6.5 {Tcl_PrintDouble - make sure there's a decimal point} {
sl@0
   258
    concat x[expr 2.0]
sl@0
   259
} {x2.0}
sl@0
   260
test util-6.6 {Tcl_PrintDouble - make sure there's a decimal point} {eformat} {
sl@0
   261
    concat x[expr 3.0e98]
sl@0
   262
} {x3e+98}
sl@0
   263
sl@0
   264
test util-7.1 {TclPrecTraceProc - unset callbacks} {
sl@0
   265
    set tcl_precision 7
sl@0
   266
    set x $tcl_precision
sl@0
   267
    unset tcl_precision
sl@0
   268
    list $x $tcl_precision
sl@0
   269
} {7 7}
sl@0
   270
test util-7.2 {TclPrecTraceProc - read traces, sharing among interpreters} {
sl@0
   271
    set tcl_precision 12
sl@0
   272
    interp create child
sl@0
   273
    set x [child eval set tcl_precision]
sl@0
   274
    child eval {set tcl_precision 6}
sl@0
   275
    interp delete child
sl@0
   276
    list $x $tcl_precision
sl@0
   277
} {12 6}
sl@0
   278
test util-7.3 {TclPrecTraceProc - write traces, safe interpreters} {
sl@0
   279
    set tcl_precision 12
sl@0
   280
    interp create -safe child
sl@0
   281
    set x [child eval {
sl@0
   282
	list [catch {set tcl_precision 8} msg] $msg
sl@0
   283
    }]
sl@0
   284
    interp delete child
sl@0
   285
    list $x $tcl_precision
sl@0
   286
} {{1 {can't set "tcl_precision": can't modify precision from a safe interpreter}} 12}
sl@0
   287
test util-7.4 {TclPrecTraceProc - write traces, bogus values} {
sl@0
   288
    set tcl_precision 12
sl@0
   289
    list [catch {set tcl_precision abc} msg] $msg $tcl_precision
sl@0
   290
} {1 {can't set "tcl_precision": improper value for precision} 12}
sl@0
   291
sl@0
   292
set tcl_precision 12
sl@0
   293
sl@0
   294
# This test always succeeded in the C locale anyway...
sl@0
   295
test util-8.1 {TclNeedSpace - correct UTF8 handling} {
sl@0
   296
    # Bug 411825
sl@0
   297
    # Note that this test relies on the fact that
sl@0
   298
    # [interp target] calls on Tcl_AppendElement()
sl@0
   299
    # which calls on TclNeedSpace().  If [interp target]
sl@0
   300
    # is ever updated, this test will no longer test
sl@0
   301
    # TclNeedSpace.
sl@0
   302
    interp create \u5420
sl@0
   303
    interp create [list \u5420 foo]
sl@0
   304
    interp alias {} fooset [list \u5420 foo] set
sl@0
   305
    set result [interp target {} fooset]
sl@0
   306
    interp delete \u5420
sl@0
   307
    set result
sl@0
   308
} "\u5420 foo"
sl@0
   309
sl@0
   310
tcltest::testConstraint testdstring [expr {[info commands testdstring] != {}}]
sl@0
   311
sl@0
   312
test util-8.2 {TclNeedSpace - correct UTF8 handling} testdstring {
sl@0
   313
    # Bug 411825
sl@0
   314
    # This tests the same bug as the previous test, but
sl@0
   315
    # should be more future-proof, as the DString
sl@0
   316
    # operations will likely continue to call TclNeedSpace
sl@0
   317
    testdstring free
sl@0
   318
    testdstring append \u5420 -1
sl@0
   319
    testdstring element foo
sl@0
   320
    llength [testdstring get]
sl@0
   321
} 2
sl@0
   322
test util-8.3 {TclNeedSpace - correct UTF8 handling} testdstring {
sl@0
   323
    # Bug 411825 - new variant reported by Dossy Shiobara
sl@0
   324
    testdstring free
sl@0
   325
    testdstring append \u00A0 -1
sl@0
   326
    testdstring element foo
sl@0
   327
    llength [testdstring get]
sl@0
   328
} 2
sl@0
   329
test util-8.4 {TclNeedSpace - correct UTF8 handling} testdstring {
sl@0
   330
    # Another bug uncovered while fixing 411825
sl@0
   331
    testdstring free
sl@0
   332
    testdstring append {\ } -1
sl@0
   333
    testdstring append \{ -1
sl@0
   334
    testdstring element foo
sl@0
   335
    llength [testdstring get]
sl@0
   336
} 2
sl@0
   337
test util-8.5 {TclNeedSpace - correct UTF8 handling} testdstring {
sl@0
   338
    # Note that in this test TclNeedSpace actually gets it wrong,
sl@0
   339
    # claiming we need a space when we really do not.  Extra space
sl@0
   340
    # between list elements is harmless though, and better to have
sl@0
   341
    # extra space in really weird string reps of lists, than to
sl@0
   342
    # invest the effort required to make TclNeedSpace foolproof.
sl@0
   343
    testdstring free
sl@0
   344
    testdstring append {\\ } -1
sl@0
   345
    testdstring element foo
sl@0
   346
    list [llength [testdstring get]] [string length [testdstring get]]
sl@0
   347
} {2 7}
sl@0
   348
test util-8.6 {TclNeedSpace - correct UTF8 handling} testdstring {
sl@0
   349
    # Another example of TclNeedSpace harmlessly getting it wrong.
sl@0
   350
    testdstring free
sl@0
   351
    testdstring append {\\ } -1
sl@0
   352
    testdstring append \{ -1
sl@0
   353
    testdstring element foo
sl@0
   354
    testdstring append \} -1
sl@0
   355
    list [llength [testdstring get]] [string length [testdstring get]]
sl@0
   356
} {2 9}
sl@0
   357
sl@0
   358
# cleanup
sl@0
   359
::tcltest::cleanupTests
sl@0
   360
return