os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/util.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/util.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,360 @@
     1.4 +# This file is a Tcl script to test the code in the file tclUtil.c.
     1.5 +# This file is organized in the standard fashion for Tcl tests.
     1.6 +#
     1.7 +# Copyright (c) 1995-1998 Sun Microsystems, Inc.
     1.8 +# Copyright (c) 1998-1999 by Scriptics Corporation.
     1.9 +#
    1.10 +# See the file "license.terms" for information on usage and redistribution
    1.11 +# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
    1.12 +#
    1.13 +# RCS: @(#) $Id: util.test,v 1.10.4.4 2005/10/28 03:26:33 mdejong Exp $
    1.14 +
    1.15 +if {[lsearch [namespace children] ::tcltest] == -1} {
    1.16 +    package require tcltest
    1.17 +    namespace import -force ::tcltest::*
    1.18 +}
    1.19 +
    1.20 +test util-1.1 {TclFindElement procedure - binary element in middle of list} {
    1.21 +    lindex {0 foo\x00help 1} 1
    1.22 +} "foo\x00help"
    1.23 +test util-1.2 {TclFindElement procedure - binary element at end of list} {
    1.24 +    lindex {0 foo\x00help} 1
    1.25 +} "foo\x00help"
    1.26 +
    1.27 +test util-2.1 {TclCopyAndCollapse procedure - normal string} {
    1.28 +    lindex {0 foo} 1
    1.29 +} {foo}
    1.30 +test util-2.2 {TclCopyAndCollapse procedure - string with backslashes} {
    1.31 +    lindex {0 foo\n\x00help 1} 1
    1.32 +} "foo\n\x00help"
    1.33 +
    1.34 +test util-3.1 {Tcl_ScanCountedElement procedure - don't leave unmatched braces} {
    1.35 +    # This test checks for a very tricky feature.  Any list element
    1.36 +    # generated with Tcl_ScanCountedElement and Tcl_ConvertElement must
    1.37 +    # have the property that it can be enclosing in curly braces to make
    1.38 +    # an embedded sub-list.  If this property doesn't hold, then
    1.39 +    # Tcl_DStringStartSublist doesn't work.
    1.40 +
    1.41 +    set x {}
    1.42 +    lappend x " \\\{ \\"
    1.43 +    concat $x [llength "{$x}"]
    1.44 +} {\ \\\{\ \\ 1}
    1.45 +
    1.46 +test util-4.1 {Tcl_ConcatObj - backslash-space at end of argument} {
    1.47 +    concat a {b\ } c
    1.48 +} {a b\  c}
    1.49 +test util-4.2 {Tcl_ConcatObj - backslash-space at end of argument} {
    1.50 +    concat a {b\   } c
    1.51 +} {a b\  c}
    1.52 +test util-4.3 {Tcl_ConcatObj - backslash-space at end of argument} {
    1.53 +    concat a {b\\   } c
    1.54 +} {a b\\  c}
    1.55 +test util-4.4 {Tcl_ConcatObj - backslash-space at end of argument} {
    1.56 +    concat a {b } c
    1.57 +} {a b c}
    1.58 +test util-4.5 {Tcl_ConcatObj - backslash-space at end of argument} {
    1.59 +    concat a { } c
    1.60 +} {a c}
    1.61 +test util-4.6 {Tcl_ConcatObj - utf-8 sequence with "whitespace" char} {
    1.62 +    # Check for Bug #227512.  If this violates C isspace, then it returns \xc3.
    1.63 +    concat \xe0
    1.64 +} \xe0
    1.65 +
    1.66 +proc Wrapper_Tcl_StringMatch {pattern string} {
    1.67 +    # Forces use of Tcl_StringMatch, not Tcl_UniCharCaseMatch
    1.68 +    switch -glob -- $string $pattern {return 1} default {return 0}
    1.69 +}
    1.70 +test util-5.1 {Tcl_StringMatch} {
    1.71 +    Wrapper_Tcl_StringMatch ab*c abc
    1.72 +} 1
    1.73 +test util-5.2 {Tcl_StringMatch} {
    1.74 +    Wrapper_Tcl_StringMatch ab**c abc
    1.75 +} 1
    1.76 +test util-5.3 {Tcl_StringMatch} {
    1.77 +    Wrapper_Tcl_StringMatch ab* abcdef
    1.78 +} 1
    1.79 +test util-5.4 {Tcl_StringMatch} {
    1.80 +    Wrapper_Tcl_StringMatch *c abc
    1.81 +} 1
    1.82 +test util-5.5 {Tcl_StringMatch} {
    1.83 +    Wrapper_Tcl_StringMatch *3*6*9 0123456789
    1.84 +} 1
    1.85 +test util-5.6 {Tcl_StringMatch} {
    1.86 +    Wrapper_Tcl_StringMatch *3*6*9 01234567890
    1.87 +} 0
    1.88 +test util-5.7 {Tcl_StringMatch: UTF-8} {
    1.89 +    Wrapper_Tcl_StringMatch *u \u4e4fu
    1.90 +} 1
    1.91 +test util-5.8 {Tcl_StringMatch} {
    1.92 +    Wrapper_Tcl_StringMatch a?c abc
    1.93 +} 1
    1.94 +test util-5.9 {Tcl_StringMatch: UTF-8} {
    1.95 +    # skip one character in string
    1.96 +
    1.97 +    Wrapper_Tcl_StringMatch a?c a\u4e4fc
    1.98 +} 1
    1.99 +test util-5.10 {Tcl_StringMatch} {
   1.100 +    Wrapper_Tcl_StringMatch a??c abc
   1.101 +} 0
   1.102 +test util-5.11 {Tcl_StringMatch} {
   1.103 +    Wrapper_Tcl_StringMatch ?1??4???8? 0123456789
   1.104 +} 1
   1.105 +test util-5.12 {Tcl_StringMatch} {
   1.106 +    Wrapper_Tcl_StringMatch {[abc]bc} abc
   1.107 +} 1
   1.108 +test util-5.13 {Tcl_StringMatch: UTF-8} {
   1.109 +    # string += Tcl_UtfToUniChar(string, &ch);
   1.110 +
   1.111 +    Wrapper_Tcl_StringMatch "\[\u4e4fxy\]bc" "\u4e4fbc"
   1.112 +} 1
   1.113 +test util-5.14 {Tcl_StringMatch} {
   1.114 +    # if ((*pattern == ']') || (*pattern == '\0'))
   1.115 +    # badly formed pattern
   1.116 +
   1.117 +    Wrapper_Tcl_StringMatch {[]} {[]}
   1.118 +} 0
   1.119 +test util-5.15 {Tcl_StringMatch} {
   1.120 +    # if ((*pattern == ']') || (*pattern == '\0'))
   1.121 +    # badly formed pattern
   1.122 +
   1.123 +    Wrapper_Tcl_StringMatch {[} {[}
   1.124 +} 0
   1.125 +test util-5.16 {Tcl_StringMatch} {
   1.126 +    Wrapper_Tcl_StringMatch {a[abc]c} abc
   1.127 +} 1
   1.128 +test util-5.17 {Tcl_StringMatch: UTF-8} {
   1.129 +    # pattern += Tcl_UtfToUniChar(pattern, &endChar);
   1.130 +    # get 1 UTF-8 character
   1.131 +
   1.132 +    Wrapper_Tcl_StringMatch "a\[a\u4e4fc]c" "a\u4e4fc"
   1.133 +} 1
   1.134 +test util-5.18 {Tcl_StringMatch: UTF-8} {
   1.135 +    # pattern += Tcl_UtfToUniChar(pattern, &endChar);
   1.136 +    # proper advance: wrong answer would match on UTF trail byte of \u4e4f
   1.137 +
   1.138 +    Wrapper_Tcl_StringMatch {a[a\u4e4fc]c} [bytestring a\u008fc]
   1.139 +} 0
   1.140 +test util-5.19 {Tcl_StringMatch: UTF-8} {
   1.141 +    # pattern += Tcl_UtfToUniChar(pattern, &endChar);
   1.142 +    # proper advance.
   1.143 +
   1.144 +    Wrapper_Tcl_StringMatch {a[a\u4e4fc]c} "acc"
   1.145 +} 1
   1.146 +test util-5.20 {Tcl_StringMatch} {
   1.147 +    Wrapper_Tcl_StringMatch {a[xyz]c} abc
   1.148 +} 0
   1.149 +test util-5.21 {Tcl_StringMatch} {
   1.150 +    Wrapper_Tcl_StringMatch {12[2-7]45} 12345
   1.151 +} 1
   1.152 +test util-5.22 {Tcl_StringMatch: UTF-8 range} {
   1.153 +    Wrapper_Tcl_StringMatch "\[\u4e00-\u4e4f]" "0"
   1.154 +} 0
   1.155 +test util-5.23 {Tcl_StringMatch: UTF-8 range} {
   1.156 +    Wrapper_Tcl_StringMatch "\[\u4e00-\u4e4f]" "\u4e33"
   1.157 +} 1
   1.158 +test util-5.24 {Tcl_StringMatch: UTF-8 range} {
   1.159 +    Wrapper_Tcl_StringMatch "\[\u4e00-\u4e4f]" "\uff08"
   1.160 +} 0
   1.161 +test util-5.25 {Tcl_StringMatch} {
   1.162 +    Wrapper_Tcl_StringMatch {12[ab2-4cd]45} 12345
   1.163 +} 1
   1.164 +test util-5.26 {Tcl_StringMatch} {
   1.165 +    Wrapper_Tcl_StringMatch {12[ab2-4cd]45} 12b45
   1.166 +} 1
   1.167 +test util-5.27 {Tcl_StringMatch} {
   1.168 +    Wrapper_Tcl_StringMatch {12[ab2-4cd]45} 12d45
   1.169 +} 1
   1.170 +test util-5.28 {Tcl_StringMatch} {
   1.171 +    Wrapper_Tcl_StringMatch {12[ab2-4cd]45} 12145
   1.172 +} 0
   1.173 +test util-5.29 {Tcl_StringMatch} {
   1.174 +    Wrapper_Tcl_StringMatch {12[ab2-4cd]45} 12545
   1.175 +} 0
   1.176 +test util-5.30 {Tcl_StringMatch: forwards range} {
   1.177 +    Wrapper_Tcl_StringMatch {[k-w]} "z"
   1.178 +} 0
   1.179 +test util-5.31 {Tcl_StringMatch: forwards range} {
   1.180 +    Wrapper_Tcl_StringMatch {[k-w]} "w"
   1.181 +} 1
   1.182 +test util-5.32 {Tcl_StringMatch: forwards range} {
   1.183 +    Wrapper_Tcl_StringMatch {[k-w]} "r"
   1.184 +} 1
   1.185 +test util-5.33 {Tcl_StringMatch: forwards range} {
   1.186 +    Wrapper_Tcl_StringMatch {[k-w]} "k"
   1.187 +} 1
   1.188 +test util-5.34 {Tcl_StringMatch: forwards range} {
   1.189 +    Wrapper_Tcl_StringMatch {[k-w]} "a"
   1.190 +} 0
   1.191 +test util-5.35 {Tcl_StringMatch: reverse range} {
   1.192 +    Wrapper_Tcl_StringMatch {[w-k]} "z"
   1.193 +} 0
   1.194 +test util-5.36 {Tcl_StringMatch: reverse range} {
   1.195 +    Wrapper_Tcl_StringMatch {[w-k]} "w"
   1.196 +} 1
   1.197 +test util-5.37 {Tcl_StringMatch: reverse range} {
   1.198 +    Wrapper_Tcl_StringMatch {[w-k]} "r"
   1.199 +} 1
   1.200 +test util-5.38 {Tcl_StringMatch: reverse range} {
   1.201 +    Wrapper_Tcl_StringMatch {[w-k]} "k"
   1.202 +} 1
   1.203 +test util-5.39 {Tcl_StringMatch: reverse range} {
   1.204 +    Wrapper_Tcl_StringMatch {[w-k]} "a"
   1.205 +} 0
   1.206 +test util-5.40 {Tcl_StringMatch: skip correct number of ']'} {
   1.207 +    Wrapper_Tcl_StringMatch {[A-]x} Ax
   1.208 +} 0
   1.209 +test util-5.41 {Tcl_StringMatch: skip correct number of ']'} {
   1.210 +    Wrapper_Tcl_StringMatch {[A-]]x} Ax
   1.211 +} 1
   1.212 +test util-5.42 {Tcl_StringMatch: skip correct number of ']'} {
   1.213 +    Wrapper_Tcl_StringMatch {[A-]]x} \ue1x
   1.214 +} 0
   1.215 +test util-5.43 {Tcl_StringMatch: skip correct number of ']'} {
   1.216 +    Wrapper_Tcl_StringMatch \[A-]\ue1]x \ue1x
   1.217 +} 1
   1.218 +test util-5.44 {Tcl_StringMatch: skip correct number of ']'} {
   1.219 +    Wrapper_Tcl_StringMatch {[A-]h]x} hx
   1.220 +} 1
   1.221 +test util-5.45 {Tcl_StringMatch} {
   1.222 +    # if (*pattern == '\0')
   1.223 +    # badly formed pattern, still treats as a set
   1.224 +
   1.225 +    Wrapper_Tcl_StringMatch {[a} a
   1.226 +} 1
   1.227 +test util-5.46 {Tcl_StringMatch} {
   1.228 +    Wrapper_Tcl_StringMatch {a\*b} a*b
   1.229 +} 1
   1.230 +test util-5.47 {Tcl_StringMatch} {
   1.231 +    Wrapper_Tcl_StringMatch {a\*b} ab
   1.232 +} 0
   1.233 +test util-5.48 {Tcl_StringMatch} {
   1.234 +    Wrapper_Tcl_StringMatch {a\*\?\[\]\\\x} "a*?\[\]\\x"
   1.235 +} 1
   1.236 +test util-5.49 {Tcl_StringMatch} {
   1.237 +    Wrapper_Tcl_StringMatch ** ""
   1.238 +} 1
   1.239 +test util-5.50 {Tcl_StringMatch} {
   1.240 +    Wrapper_Tcl_StringMatch *. ""
   1.241 +} 0
   1.242 +test util-5.51 {Tcl_StringMatch} {
   1.243 +    Wrapper_Tcl_StringMatch "" ""
   1.244 +} 1
   1.245 +
   1.246 +test util-6.1 {Tcl_PrintDouble - using tcl_precision} {
   1.247 +    concat x[expr 1.4]
   1.248 +} {x1.4}
   1.249 +test util-6.2 {Tcl_PrintDouble - using tcl_precision} {
   1.250 +    concat x[expr 1.39999999999]
   1.251 +} {x1.39999999999}
   1.252 +test util-6.3 {Tcl_PrintDouble - using tcl_precision} {
   1.253 +    concat x[expr 1.399999999999]
   1.254 +} {x1.4}
   1.255 +test util-6.4 {Tcl_PrintDouble - using tcl_precision} {
   1.256 +    set tcl_precision 5
   1.257 +    concat x[expr 1.123412341234]
   1.258 +} {x1.1234}
   1.259 +set tcl_precision 12
   1.260 +test util-6.5 {Tcl_PrintDouble - make sure there's a decimal point} {
   1.261 +    concat x[expr 2.0]
   1.262 +} {x2.0}
   1.263 +test util-6.6 {Tcl_PrintDouble - make sure there's a decimal point} {eformat} {
   1.264 +    concat x[expr 3.0e98]
   1.265 +} {x3e+98}
   1.266 +
   1.267 +test util-7.1 {TclPrecTraceProc - unset callbacks} {
   1.268 +    set tcl_precision 7
   1.269 +    set x $tcl_precision
   1.270 +    unset tcl_precision
   1.271 +    list $x $tcl_precision
   1.272 +} {7 7}
   1.273 +test util-7.2 {TclPrecTraceProc - read traces, sharing among interpreters} {
   1.274 +    set tcl_precision 12
   1.275 +    interp create child
   1.276 +    set x [child eval set tcl_precision]
   1.277 +    child eval {set tcl_precision 6}
   1.278 +    interp delete child
   1.279 +    list $x $tcl_precision
   1.280 +} {12 6}
   1.281 +test util-7.3 {TclPrecTraceProc - write traces, safe interpreters} {
   1.282 +    set tcl_precision 12
   1.283 +    interp create -safe child
   1.284 +    set x [child eval {
   1.285 +	list [catch {set tcl_precision 8} msg] $msg
   1.286 +    }]
   1.287 +    interp delete child
   1.288 +    list $x $tcl_precision
   1.289 +} {{1 {can't set "tcl_precision": can't modify precision from a safe interpreter}} 12}
   1.290 +test util-7.4 {TclPrecTraceProc - write traces, bogus values} {
   1.291 +    set tcl_precision 12
   1.292 +    list [catch {set tcl_precision abc} msg] $msg $tcl_precision
   1.293 +} {1 {can't set "tcl_precision": improper value for precision} 12}
   1.294 +
   1.295 +set tcl_precision 12
   1.296 +
   1.297 +# This test always succeeded in the C locale anyway...
   1.298 +test util-8.1 {TclNeedSpace - correct UTF8 handling} {
   1.299 +    # Bug 411825
   1.300 +    # Note that this test relies on the fact that
   1.301 +    # [interp target] calls on Tcl_AppendElement()
   1.302 +    # which calls on TclNeedSpace().  If [interp target]
   1.303 +    # is ever updated, this test will no longer test
   1.304 +    # TclNeedSpace.
   1.305 +    interp create \u5420
   1.306 +    interp create [list \u5420 foo]
   1.307 +    interp alias {} fooset [list \u5420 foo] set
   1.308 +    set result [interp target {} fooset]
   1.309 +    interp delete \u5420
   1.310 +    set result
   1.311 +} "\u5420 foo"
   1.312 +
   1.313 +tcltest::testConstraint testdstring [expr {[info commands testdstring] != {}}]
   1.314 +
   1.315 +test util-8.2 {TclNeedSpace - correct UTF8 handling} testdstring {
   1.316 +    # Bug 411825
   1.317 +    # This tests the same bug as the previous test, but
   1.318 +    # should be more future-proof, as the DString
   1.319 +    # operations will likely continue to call TclNeedSpace
   1.320 +    testdstring free
   1.321 +    testdstring append \u5420 -1
   1.322 +    testdstring element foo
   1.323 +    llength [testdstring get]
   1.324 +} 2
   1.325 +test util-8.3 {TclNeedSpace - correct UTF8 handling} testdstring {
   1.326 +    # Bug 411825 - new variant reported by Dossy Shiobara
   1.327 +    testdstring free
   1.328 +    testdstring append \u00A0 -1
   1.329 +    testdstring element foo
   1.330 +    llength [testdstring get]
   1.331 +} 2
   1.332 +test util-8.4 {TclNeedSpace - correct UTF8 handling} testdstring {
   1.333 +    # Another bug uncovered while fixing 411825
   1.334 +    testdstring free
   1.335 +    testdstring append {\ } -1
   1.336 +    testdstring append \{ -1
   1.337 +    testdstring element foo
   1.338 +    llength [testdstring get]
   1.339 +} 2
   1.340 +test util-8.5 {TclNeedSpace - correct UTF8 handling} testdstring {
   1.341 +    # Note that in this test TclNeedSpace actually gets it wrong,
   1.342 +    # claiming we need a space when we really do not.  Extra space
   1.343 +    # between list elements is harmless though, and better to have
   1.344 +    # extra space in really weird string reps of lists, than to
   1.345 +    # invest the effort required to make TclNeedSpace foolproof.
   1.346 +    testdstring free
   1.347 +    testdstring append {\\ } -1
   1.348 +    testdstring element foo
   1.349 +    list [llength [testdstring get]] [string length [testdstring get]]
   1.350 +} {2 7}
   1.351 +test util-8.6 {TclNeedSpace - correct UTF8 handling} testdstring {
   1.352 +    # Another example of TclNeedSpace harmlessly getting it wrong.
   1.353 +    testdstring free
   1.354 +    testdstring append {\\ } -1
   1.355 +    testdstring append \{ -1
   1.356 +    testdstring element foo
   1.357 +    testdstring append \} -1
   1.358 +    list [llength [testdstring get]] [string length [testdstring get]]
   1.359 +} {2 9}
   1.360 +
   1.361 +# cleanup
   1.362 +::tcltest::cleanupTests
   1.363 +return