os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/stringComp.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
# Commands covered:  string
sl@0
     2
#
sl@0
     3
# This file contains a collection of tests for one or more of the Tcl
sl@0
     4
# built-in commands.  Sourcing this file into Tcl runs the tests and
sl@0
     5
# generates output for errors.  No output means no errors were found.
sl@0
     6
#
sl@0
     7
# This differs from the original string tests in that the tests call
sl@0
     8
# things in procs, which uses the compiled string code instead of
sl@0
     9
# the runtime parse string code.  The tests of import should match
sl@0
    10
# their equivalent number in string.test.
sl@0
    11
#
sl@0
    12
# Copyright (c) 2001 by ActiveState Corporation.
sl@0
    13
# Copyright (c) 2001 by Kevin B. Kenny.  All rights reserved.
sl@0
    14
#
sl@0
    15
# See the file "license.terms" for information on usage and redistribution
sl@0
    16
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
sl@0
    17
#
sl@0
    18
# RCS: @(#) $Id: stringComp.test,v 1.6.2.1 2004/10/28 00:01:12 dgp Exp $
sl@0
    19
sl@0
    20
if {[lsearch [namespace children] ::tcltest] == -1} {
sl@0
    21
    package require tcltest
sl@0
    22
    namespace import -force ::tcltest::*
sl@0
    23
}
sl@0
    24
sl@0
    25
# Some tests require the testobj command
sl@0
    26
sl@0
    27
set ::tcltest::testConstraints(testobj) \
sl@0
    28
	[expr {[info commands testobj] != {}}]
sl@0
    29
sl@0
    30
test stringComp-1.1 {error conditions} {
sl@0
    31
    proc foo {} {string gorp a b}
sl@0
    32
    list [catch {foo} msg] $msg
sl@0
    33
} {1 {bad option "gorp": must be bytelength, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, tolower, toupper, totitle, trim, trimleft, trimright, wordend, or wordstart}}
sl@0
    34
test stringComp-1.2 {error conditions} {
sl@0
    35
    proc foo {} {string}
sl@0
    36
    list [catch {foo} msg] $msg
sl@0
    37
} {1 {wrong # args: should be "string option arg ?arg ...?"}}
sl@0
    38
test stringComp-1.3 {error condition - undefined method during compile} {
sl@0
    39
    # We don't want this to complain about 'never' because it may never
sl@0
    40
    # be called, or string may get redefined.  This must compile OK.
sl@0
    41
    proc foo {str i} {
sl@0
    42
        if {"yes" == "no"} { string never called but complains here }
sl@0
    43
        string index $str $i
sl@0
    44
    }
sl@0
    45
    foo abc 0
sl@0
    46
} a
sl@0
    47
sl@0
    48
test stringComp-2.1 {string compare, too few args} {
sl@0
    49
    proc foo {} {string compare a}
sl@0
    50
    list [catch {foo} msg] $msg
sl@0
    51
} {1 {wrong # args: should be "string compare ?-nocase? ?-length int? string1 string2"}}
sl@0
    52
test stringComp-2.2 {string compare, bad args} {
sl@0
    53
    proc foo {} {string compare a b c}
sl@0
    54
    list [catch {foo} msg] $msg
sl@0
    55
} {1 {bad option "a": must be -nocase or -length}}
sl@0
    56
test stringComp-2.3 {string compare, bad args} {
sl@0
    57
    list [catch {string compare -length -nocase str1 str2} msg] $msg
sl@0
    58
} {1 {expected integer but got "-nocase"}}
sl@0
    59
test stringComp-2.4 {string compare, too many args} {
sl@0
    60
    list [catch {string compare -length 10 -nocase str1 str2 str3} msg] $msg
sl@0
    61
} {1 {wrong # args: should be "string compare ?-nocase? ?-length int? string1 string2"}}
sl@0
    62
test stringComp-2.5 {string compare with length unspecified} {
sl@0
    63
    list [catch {string compare -length 10 10} msg] $msg
sl@0
    64
} {1 {wrong # args: should be "string compare ?-nocase? ?-length int? string1 string2"}}
sl@0
    65
test stringComp-2.6 {string compare} {
sl@0
    66
    proc foo {} {string compare abcde abdef}
sl@0
    67
    foo
sl@0
    68
} -1
sl@0
    69
test stringComp-2.7 {string compare, shortest method name} {
sl@0
    70
    proc foo {} {string c abcde ABCDE}
sl@0
    71
    foo
sl@0
    72
} 1
sl@0
    73
test stringComp-2.8 {string compare} {
sl@0
    74
    proc foo {} {string compare abcde abcde}
sl@0
    75
    foo
sl@0
    76
} 0
sl@0
    77
test stringComp-2.9 {string compare with length} {
sl@0
    78
    proc foo {} {string compare -length 2 abcde abxyz}
sl@0
    79
    foo
sl@0
    80
} 0
sl@0
    81
test stringComp-2.10 {string compare with special index} {
sl@0
    82
    proc foo {} {string compare -length end-3 abcde abxyz}
sl@0
    83
    list [catch {foo} msg] $msg
sl@0
    84
} {1 {expected integer but got "end-3"}}
sl@0
    85
test stringComp-2.11 {string compare, unicode} {
sl@0
    86
    proc foo {} {string compare ab\u7266 ab\u7267}
sl@0
    87
    foo
sl@0
    88
} -1
sl@0
    89
test stringComp-2.12 {string compare, high bit} {
sl@0
    90
    # This test will fail if the underlying comparaison
sl@0
    91
    # is using signed chars instead of unsigned chars.
sl@0
    92
    # (like SunOS's default memcmp thus the compat/memcmp.c)
sl@0
    93
    proc foo {} {string compare "\x80" "@"}
sl@0
    94
    foo
sl@0
    95
    # Nb this tests works also in utf8 space because \x80 is
sl@0
    96
    # translated into a 2 or more bytelength but whose first byte has
sl@0
    97
    # the high bit set.
sl@0
    98
} 1
sl@0
    99
test stringComp-2.13 {string compare -nocase} {
sl@0
   100
    proc foo {} {string compare -nocase abcde abdef}
sl@0
   101
    foo
sl@0
   102
} -1
sl@0
   103
test stringComp-2.14 {string compare -nocase} {
sl@0
   104
    proc foo {} {string c -nocase abcde ABCDE}
sl@0
   105
    foo
sl@0
   106
} 0
sl@0
   107
test stringComp-2.15 {string compare -nocase} {
sl@0
   108
    proc foo {} {string compare -nocase abcde abcde}
sl@0
   109
    foo
sl@0
   110
} 0
sl@0
   111
test stringComp-2.16 {string compare -nocase with length} {
sl@0
   112
    proc foo {} {string compare -length 2 -nocase abcde Abxyz}
sl@0
   113
    foo
sl@0
   114
} 0
sl@0
   115
test stringComp-2.17 {string compare -nocase with length} {
sl@0
   116
    proc foo {} {string compare -nocase -length 3 abcde Abxyz}
sl@0
   117
    foo
sl@0
   118
} -1
sl@0
   119
test stringComp-2.18 {string compare -nocase with length <= 0} {
sl@0
   120
    proc foo {} {string compare -nocase -length -1 abcde AbCdEf}
sl@0
   121
    foo
sl@0
   122
} -1
sl@0
   123
test stringComp-2.19 {string compare -nocase with excessive length} {
sl@0
   124
    proc foo {} {string compare -nocase -length 50 AbCdEf abcde}
sl@0
   125
    foo
sl@0
   126
} 1
sl@0
   127
test stringComp-2.20 {string compare -len unicode} {
sl@0
   128
    # These are strings that are 6 BYTELENGTH long, but the length
sl@0
   129
    # shouldn't make a different because there are actually 3 CHARS long
sl@0
   130
    proc foo {} {string compare -len 5 \334\334\334 \334\334\374}
sl@0
   131
    foo
sl@0
   132
} -1
sl@0
   133
test stringComp-2.21 {string compare -nocase with special index} {
sl@0
   134
    proc foo {} {string compare -nocase -length end-3 Abcde abxyz}
sl@0
   135
    list [catch {foo} msg] $msg
sl@0
   136
} {1 {expected integer but got "end-3"}}
sl@0
   137
test stringComp-2.22 {string compare, null strings} {
sl@0
   138
    proc foo {} {string compare "" ""}
sl@0
   139
    foo
sl@0
   140
} 0
sl@0
   141
test stringComp-2.23 {string compare, null strings} {
sl@0
   142
    proc foo {} {string compare "" foo}
sl@0
   143
    foo
sl@0
   144
} -1
sl@0
   145
test stringComp-2.24 {string compare, null strings} {
sl@0
   146
    proc foo {} {string compare foo ""}
sl@0
   147
    foo
sl@0
   148
} 1
sl@0
   149
test stringComp-2.25 {string compare -nocase, null strings} {
sl@0
   150
    proc foo {} {string compare -nocase "" ""}
sl@0
   151
    foo
sl@0
   152
} 0
sl@0
   153
test stringComp-2.26 {string compare -nocase, null strings} {
sl@0
   154
    proc foo {} {string compare -nocase "" foo}
sl@0
   155
    foo
sl@0
   156
} -1
sl@0
   157
test stringComp-2.27 {string compare -nocase, null strings} {
sl@0
   158
    proc foo {} {string compare -nocase foo ""}
sl@0
   159
    foo
sl@0
   160
} 1
sl@0
   161
test stringComp-2.28 {string compare with length, unequal strings} {
sl@0
   162
    proc foo {} {string compare -length 2 abc abde}
sl@0
   163
    foo
sl@0
   164
} 0
sl@0
   165
test stringComp-2.29 {string compare with length, unequal strings} {
sl@0
   166
    proc foo {} {string compare -length 2 ab abde}
sl@0
   167
    foo
sl@0
   168
} 0
sl@0
   169
test stringComp-2.30 {string compare with NUL character vs. other ASCII} {
sl@0
   170
    # Be careful here, since UTF-8 rep comparison with memcmp() of
sl@0
   171
    # these puts chars in the wrong order
sl@0
   172
    proc foo {} {string compare \x00 \x01}
sl@0
   173
    foo
sl@0
   174
} -1
sl@0
   175
test stringComp-2.31 {string compare, high bit} {
sl@0
   176
    proc foo {} {string compare "a\x80" "a@"}
sl@0
   177
    foo
sl@0
   178
} 1
sl@0
   179
test stringComp-2.32 {string compare, high bit} {
sl@0
   180
    proc foo {} {string compare "a\x00" "a\x01"}
sl@0
   181
    foo
sl@0
   182
} -1
sl@0
   183
test stringComp-2.33 {string compare, high bit} {
sl@0
   184
    proc foo {} {string compare "\x00\x00" "\x00\x01"}
sl@0
   185
    foo
sl@0
   186
} -1
sl@0
   187
sl@0
   188
# only need a few tests on equal, since it uses the same code as
sl@0
   189
# string compare, but just modifies the return output
sl@0
   190
test stringComp-3.1 {string equal} {
sl@0
   191
    proc foo {} {string equal abcde abdef}
sl@0
   192
    foo
sl@0
   193
} 0
sl@0
   194
test stringComp-3.2 {string equal} {
sl@0
   195
    proc foo {} {string eq abcde ABCDE}
sl@0
   196
    foo
sl@0
   197
} 0
sl@0
   198
test stringComp-3.3 {string equal} {
sl@0
   199
    proc foo {} {string equal abcde abcde}
sl@0
   200
    foo
sl@0
   201
} 1
sl@0
   202
test stringComp-3.4 {string equal -nocase} {
sl@0
   203
    proc foo {} {string equal -nocase \334\334\334\334\374\374\374\374 \334\334\334\334\334\334\334\334}
sl@0
   204
    foo
sl@0
   205
} 1
sl@0
   206
test stringComp-3.5 {string equal -nocase} {
sl@0
   207
    proc foo {} {string equal -nocase abcde abdef}
sl@0
   208
    foo
sl@0
   209
} 0
sl@0
   210
test stringComp-3.6 {string equal -nocase} {
sl@0
   211
    proc foo {} {string eq -nocase abcde ABCDE}
sl@0
   212
    foo
sl@0
   213
} 1
sl@0
   214
test stringComp-3.7 {string equal -nocase} {
sl@0
   215
    proc foo {} {string equal -nocase abcde abcde}
sl@0
   216
    foo
sl@0
   217
} 1
sl@0
   218
test stringComp-3.8 {string equal with length, unequal strings} {
sl@0
   219
    proc foo {} {string equal -length 2 abc abde}
sl@0
   220
    foo
sl@0
   221
} 1
sl@0
   222
sl@0
   223
test stringComp-4.1 {string first, too few args} {
sl@0
   224
    proc foo {} {string first a}
sl@0
   225
    list [catch {foo} msg] $msg
sl@0
   226
} {1 {wrong # args: should be "string first subString string ?startIndex?"}}
sl@0
   227
test stringComp-4.2 {string first, bad args} {
sl@0
   228
    proc foo {} {string first a b c}
sl@0
   229
    list [catch {foo} msg] $msg
sl@0
   230
} {1 {bad index "c": must be integer or end?-integer?}}
sl@0
   231
test stringComp-4.3 {string first, too many args} {
sl@0
   232
    proc foo {} {string first a b 5 d}
sl@0
   233
    list [catch {foo} msg] $msg
sl@0
   234
} {1 {wrong # args: should be "string first subString string ?startIndex?"}}
sl@0
   235
test stringComp-4.4 {string first} {
sl@0
   236
    proc foo {} {string first bq abcdefgbcefgbqrs}
sl@0
   237
    foo
sl@0
   238
} 12
sl@0
   239
test stringComp-4.5 {string first} {
sl@0
   240
    proc foo {} {string fir bcd abcdefgbcefgbqrs}
sl@0
   241
    foo
sl@0
   242
} 1
sl@0
   243
test stringComp-4.6 {string first} {
sl@0
   244
    proc foo {} {string f b abcdefgbcefgbqrs}
sl@0
   245
    foo
sl@0
   246
} 1
sl@0
   247
test stringComp-4.7 {string first} {
sl@0
   248
    proc foo {} {string first xxx x123xx345xxx789xxx012}
sl@0
   249
    foo
sl@0
   250
} 9
sl@0
   251
test stringComp-4.8 {string first} {
sl@0
   252
    proc foo {} {string first "" x123xx345xxx789xxx012}
sl@0
   253
    foo
sl@0
   254
} -1
sl@0
   255
test stringComp-4.9 {string first, unicode} {
sl@0
   256
    proc foo {} {string first x abc\u7266x}
sl@0
   257
    foo
sl@0
   258
} 4
sl@0
   259
test stringComp-4.10 {string first, unicode} {
sl@0
   260
    proc foo {} {string first \u7266 abc\u7266x}
sl@0
   261
    foo
sl@0
   262
} 3
sl@0
   263
test stringComp-4.11 {string first, start index} {
sl@0
   264
    proc foo {} {string first \u7266 abc\u7266x 3}
sl@0
   265
    foo
sl@0
   266
} 3
sl@0
   267
test stringComp-4.12 {string first, start index} {
sl@0
   268
    proc foo {} {string first \u7266 abc\u7266x 4}
sl@0
   269
    foo
sl@0
   270
} -1
sl@0
   271
test stringComp-4.13 {string first, start index} {
sl@0
   272
    proc foo {} {string first \u7266 abc\u7266x end-2}
sl@0
   273
    foo
sl@0
   274
} 3
sl@0
   275
test stringComp-4.14 {string first, negative start index} {
sl@0
   276
    proc foo {} {string first b abc -1}
sl@0
   277
    foo
sl@0
   278
} 1
sl@0
   279
sl@0
   280
test stringComp-5.1 {string index} {
sl@0
   281
    proc foo {} {string index}
sl@0
   282
    list [catch {foo} msg] $msg
sl@0
   283
} {1 {wrong # args: should be "string index string charIndex"}}
sl@0
   284
test stringComp-5.2 {string index} {
sl@0
   285
    proc foo {} {string index a b c}
sl@0
   286
    list [catch {foo} msg] $msg
sl@0
   287
} {1 {wrong # args: should be "string index string charIndex"}}
sl@0
   288
test stringComp-5.3 {string index} {
sl@0
   289
    proc foo {} {string index abcde 0}
sl@0
   290
    foo
sl@0
   291
} a
sl@0
   292
test stringComp-5.4 {string index} {
sl@0
   293
    proc foo {} {string in abcde 4}
sl@0
   294
    foo
sl@0
   295
} e
sl@0
   296
test stringComp-5.5 {string index} {
sl@0
   297
    proc foo {} {string index abcde 5}
sl@0
   298
    foo
sl@0
   299
} {}
sl@0
   300
test stringComp-5.6 {string index} {
sl@0
   301
    proc foo {} {string index abcde -10}
sl@0
   302
    list [catch {foo} msg] $msg
sl@0
   303
} {0 {}}
sl@0
   304
test stringComp-5.7 {string index} {
sl@0
   305
    proc foo {} {string index a xyz}
sl@0
   306
    list [catch {foo} msg] $msg
sl@0
   307
} {1 {bad index "xyz": must be integer or end?-integer?}}
sl@0
   308
test stringComp-5.8 {string index} {
sl@0
   309
    proc foo {} {string index abc end}
sl@0
   310
    foo
sl@0
   311
} c
sl@0
   312
test stringComp-5.9 {string index} {
sl@0
   313
    proc foo {} {string index abc end-1}
sl@0
   314
    foo
sl@0
   315
} b
sl@0
   316
test stringComp-5.10 {string index, unicode} {
sl@0
   317
    proc foo {} {string index abc\u7266d 4}
sl@0
   318
    foo
sl@0
   319
} d
sl@0
   320
test stringComp-5.11 {string index, unicode} {
sl@0
   321
    proc foo {} {string index abc\u7266d 3}
sl@0
   322
    foo
sl@0
   323
} \u7266
sl@0
   324
test stringComp-5.12 {string index, unicode over char length, under byte length} {
sl@0
   325
    proc foo {} {string index \334\374\334\374 6}
sl@0
   326
    foo
sl@0
   327
} {}
sl@0
   328
test stringComp-5.13 {string index, bytearray object} {
sl@0
   329
    proc foo {} {string index [binary format a5 fuz] 0}
sl@0
   330
    foo
sl@0
   331
} f
sl@0
   332
test stringComp-5.14 {string index, bytearray object} {
sl@0
   333
    proc foo {} {string index [binary format I* {0x50515253 0x52}] 3}
sl@0
   334
    foo
sl@0
   335
} S
sl@0
   336
test stringComp-5.15 {string index, bytearray object} {
sl@0
   337
    proc foo {} {
sl@0
   338
	set b [binary format I* {0x50515253 0x52}]
sl@0
   339
	set i1 [string index $b end-6]
sl@0
   340
	set i2 [string index $b 1]
sl@0
   341
	string compare $i1 $i2
sl@0
   342
    }
sl@0
   343
    foo
sl@0
   344
} 0
sl@0
   345
test stringComp-5.16 {string index, bytearray object with string obj shimmering} {
sl@0
   346
    proc foo {} {
sl@0
   347
	set str "0123456789\x00 abcdedfghi"
sl@0
   348
	binary scan $str H* dump
sl@0
   349
	string compare [string index $str 10] \x00
sl@0
   350
    }
sl@0
   351
    foo
sl@0
   352
} 0
sl@0
   353
test stringComp-5.17 {string index, bad integer} {
sl@0
   354
    proc foo {} {string index "abc" 08}
sl@0
   355
    list [catch {foo} msg] $msg
sl@0
   356
} {1 {bad index "08": must be integer or end?-integer? (looks like invalid octal number)}}
sl@0
   357
test stringComp-5.18 {string index, bad integer} {
sl@0
   358
    proc foo {} {string index "abc" end-00289}
sl@0
   359
    list [catch {foo} msg] $msg
sl@0
   360
} {1 {bad index "end-00289": must be integer or end?-integer? (looks like invalid octal number)}}
sl@0
   361
test stringComp-5.19 {string index, bytearray object out of bounds} {
sl@0
   362
    proc foo {} {string index [binary format I* {0x50515253 0x52}] -1}
sl@0
   363
    foo
sl@0
   364
} {}
sl@0
   365
test stringComp-5.20 {string index, bytearray object out of bounds} {
sl@0
   366
    proc foo {} {string index [binary format I* {0x50515253 0x52}] 20}
sl@0
   367
    foo
sl@0
   368
} {}
sl@0
   369
sl@0
   370
sl@0
   371
proc largest_int {} {
sl@0
   372
    # This will give us what the largest valid int on this machine is,
sl@0
   373
    # so we can test for overflow properly below on >32 bit systems
sl@0
   374
    set int 1
sl@0
   375
    set exp 7; # assume we get at least 8 bits
sl@0
   376
    while {$int > 0} { set int [expr {1 << [incr exp]}] }
sl@0
   377
    return [expr {$int-1}]
sl@0
   378
}
sl@0
   379
sl@0
   380
## string is
sl@0
   381
## not yet bc
sl@0
   382
sl@0
   383
catch {rename largest_int {}}
sl@0
   384
sl@0
   385
## string last
sl@0
   386
## not yet bc
sl@0
   387
sl@0
   388
## string length
sl@0
   389
## not yet bc
sl@0
   390
test stringComp-8.1 {string bytelength} {
sl@0
   391
    proc foo {} {string bytelength}
sl@0
   392
    list [catch {foo} msg] $msg
sl@0
   393
} {1 {wrong # args: should be "string bytelength string"}}
sl@0
   394
test stringComp-8.2 {string bytelength} {
sl@0
   395
    proc foo {} {string bytelength a b}
sl@0
   396
    list [catch {foo} msg] $msg
sl@0
   397
} {1 {wrong # args: should be "string bytelength string"}}
sl@0
   398
test stringComp-8.3 {string bytelength} {
sl@0
   399
    proc foo {} {string bytelength "\u00c7"}
sl@0
   400
    foo
sl@0
   401
} 2
sl@0
   402
test stringComp-8.4 {string bytelength} {
sl@0
   403
    proc foo {} {string b ""}
sl@0
   404
    foo
sl@0
   405
} 0
sl@0
   406
sl@0
   407
## string length
sl@0
   408
##
sl@0
   409
test stringComp-9.1 {string length} {
sl@0
   410
    proc foo {} {string length}
sl@0
   411
    list [catch {foo} msg] $msg
sl@0
   412
} {1 {wrong # args: should be "string length string"}}
sl@0
   413
test stringComp-9.2 {string length} {
sl@0
   414
    proc foo {} {string length a b}
sl@0
   415
    list [catch {foo} msg] $msg
sl@0
   416
} {1 {wrong # args: should be "string length string"}}
sl@0
   417
test stringComp-9.3 {string length} {
sl@0
   418
    proc foo {} {string length "a little string"}
sl@0
   419
    foo
sl@0
   420
} 15
sl@0
   421
test stringComp-9.4 {string length} {
sl@0
   422
    proc foo {} {string le ""}
sl@0
   423
    foo
sl@0
   424
} 0
sl@0
   425
test stringComp-9.5 {string length, unicode} {
sl@0
   426
    proc foo {} {string le "abcd\u7266"}
sl@0
   427
    foo
sl@0
   428
} 5
sl@0
   429
test stringComp-9.6 {string length, bytearray object} {
sl@0
   430
    proc foo {} {string length [binary format a5 foo]}
sl@0
   431
    foo
sl@0
   432
} 5
sl@0
   433
test stringComp-9.7 {string length, bytearray object} {
sl@0
   434
    proc foo {} {string length [binary format I* {0x50515253 0x52}]}
sl@0
   435
    foo
sl@0
   436
} 8
sl@0
   437
sl@0
   438
## string map
sl@0
   439
## not yet bc
sl@0
   440
sl@0
   441
## string match
sl@0
   442
##
sl@0
   443
test stringComp-11.1 {string match, too few args} {
sl@0
   444
    proc foo {} {string match a}
sl@0
   445
    list [catch {foo} msg] $msg
sl@0
   446
} {1 {wrong # args: should be "string match ?-nocase? pattern string"}}
sl@0
   447
test stringComp-11.2 {string match, too many args} {
sl@0
   448
    proc foo {} {string match a b c d}
sl@0
   449
    list [catch {foo} msg] $msg
sl@0
   450
} {1 {wrong # args: should be "string match ?-nocase? pattern string"}}
sl@0
   451
test stringComp-11.3 {string match} {
sl@0
   452
    proc foo {} {string match abc abc}
sl@0
   453
    foo
sl@0
   454
} 1
sl@0
   455
test stringComp-11.4 {string match} {
sl@0
   456
    proc foo {} {string mat abc abd}
sl@0
   457
    foo
sl@0
   458
} 0
sl@0
   459
test stringComp-11.5 {string match} {
sl@0
   460
    proc foo {} {string match ab*c abc}
sl@0
   461
    foo
sl@0
   462
} 1
sl@0
   463
test stringComp-11.6 {string match} {
sl@0
   464
    proc foo {} {string match ab**c abc}
sl@0
   465
    foo
sl@0
   466
} 1
sl@0
   467
test stringComp-11.7 {string match} {
sl@0
   468
    proc foo {} {string match ab* abcdef}
sl@0
   469
    foo
sl@0
   470
} 1
sl@0
   471
test stringComp-11.8 {string match} {
sl@0
   472
    proc foo {} {string match *c abc}
sl@0
   473
    foo
sl@0
   474
} 1
sl@0
   475
test stringComp-11.9 {string match} {
sl@0
   476
    proc foo {} {string match *3*6*9 0123456789}
sl@0
   477
    foo
sl@0
   478
} 1
sl@0
   479
test stringComp-11.10 {string match} {
sl@0
   480
    proc foo {} {string match *3*6*9 01234567890}
sl@0
   481
    foo
sl@0
   482
} 0
sl@0
   483
test stringComp-11.11 {string match} {
sl@0
   484
    proc foo {} {string match a?c abc}
sl@0
   485
    foo
sl@0
   486
} 1
sl@0
   487
test stringComp-11.12 {string match} {
sl@0
   488
    proc foo {} {string match a??c abc}
sl@0
   489
    foo
sl@0
   490
} 0
sl@0
   491
test stringComp-11.13 {string match} {
sl@0
   492
    proc foo {} {string match ?1??4???8? 0123456789}
sl@0
   493
    foo
sl@0
   494
} 1
sl@0
   495
test stringComp-11.14 {string match} {
sl@0
   496
    proc foo {} {string match {[abc]bc} abc}
sl@0
   497
    foo
sl@0
   498
} 1
sl@0
   499
test stringComp-11.15 {string match} {
sl@0
   500
    proc foo {} {string match {a[abc]c} abc}
sl@0
   501
    foo
sl@0
   502
} 1
sl@0
   503
test stringComp-11.16 {string match} {
sl@0
   504
    proc foo {} {string match {a[xyz]c} abc}
sl@0
   505
    foo
sl@0
   506
} 0
sl@0
   507
test stringComp-11.17 {string match} {
sl@0
   508
    proc foo {} {string match {12[2-7]45} 12345}
sl@0
   509
    foo
sl@0
   510
} 1
sl@0
   511
test stringComp-11.18 {string match} {
sl@0
   512
    proc foo {} {string match {12[ab2-4cd]45} 12345}
sl@0
   513
    foo
sl@0
   514
} 1
sl@0
   515
test stringComp-11.19 {string match} {
sl@0
   516
    proc foo {} {string match {12[ab2-4cd]45} 12b45}
sl@0
   517
    foo
sl@0
   518
} 1
sl@0
   519
test stringComp-11.20 {string match} {
sl@0
   520
    proc foo {} {string match {12[ab2-4cd]45} 12d45}
sl@0
   521
    foo
sl@0
   522
} 1
sl@0
   523
test stringComp-11.21 {string match} {
sl@0
   524
    proc foo {} {string match {12[ab2-4cd]45} 12145}
sl@0
   525
    foo
sl@0
   526
} 0
sl@0
   527
test stringComp-11.22 {string match} {
sl@0
   528
    proc foo {} {string match {12[ab2-4cd]45} 12545}
sl@0
   529
    foo
sl@0
   530
} 0
sl@0
   531
test stringComp-11.23 {string match} {
sl@0
   532
    proc foo {} {string match {a\*b} a*b}
sl@0
   533
    foo
sl@0
   534
} 1
sl@0
   535
test stringComp-11.24 {string match} {
sl@0
   536
    proc foo {} {string match {a\*b} ab}
sl@0
   537
    foo
sl@0
   538
} 0
sl@0
   539
test stringComp-11.25 {string match} {
sl@0
   540
    proc foo {} {string match {a\*\?\[\]\\\x} "a*?\[\]\\x"}
sl@0
   541
    foo
sl@0
   542
} 1
sl@0
   543
test stringComp-11.26 {string match} {
sl@0
   544
    proc foo {} {string match ** ""}
sl@0
   545
    foo
sl@0
   546
} 1
sl@0
   547
test stringComp-11.27 {string match} {
sl@0
   548
    proc foo {} {string match *. ""}
sl@0
   549
    foo
sl@0
   550
} 0
sl@0
   551
test stringComp-11.28 {string match} {
sl@0
   552
    proc foo {} {string match "" ""}
sl@0
   553
    foo
sl@0
   554
} 1
sl@0
   555
test stringComp-11.29 {string match} {
sl@0
   556
    proc foo {} {string match \[a a}
sl@0
   557
    foo
sl@0
   558
} 1
sl@0
   559
test stringComp-11.30 {string match, bad args} {
sl@0
   560
    proc foo {} {string match - b c}
sl@0
   561
    list [catch {foo} msg] $msg
sl@0
   562
} {1 {bad option "-": must be -nocase}}
sl@0
   563
test stringComp-11.31 {string match case} {
sl@0
   564
    proc foo {} {string match a A}
sl@0
   565
    foo
sl@0
   566
} 0
sl@0
   567
test stringComp-11.32 {string match nocase} {
sl@0
   568
    proc foo {} {string match -n a A}
sl@0
   569
    foo
sl@0
   570
} 1
sl@0
   571
test stringComp-11.33 {string match nocase} {
sl@0
   572
    proc foo {} {string match -nocase a\334 A\374}
sl@0
   573
    foo
sl@0
   574
} 1
sl@0
   575
test stringComp-11.34 {string match nocase} {
sl@0
   576
    proc foo {} {string match -nocase a*f ABCDEf}
sl@0
   577
    foo
sl@0
   578
} 1
sl@0
   579
test stringComp-11.35 {string match case, false hope} {
sl@0
   580
    # This is true because '_' lies between the A-Z and a-z ranges
sl@0
   581
    proc foo {} {string match {[A-z]} _}
sl@0
   582
    foo
sl@0
   583
} 1
sl@0
   584
test stringComp-11.36 {string match nocase range} {
sl@0
   585
    # This is false because although '_' lies between the A-Z and a-z ranges,
sl@0
   586
    # we lower case the end points before checking the ranges.
sl@0
   587
    proc foo {} {string match -nocase {[A-z]} _}
sl@0
   588
    foo
sl@0
   589
} 0
sl@0
   590
test stringComp-11.37 {string match nocase} {
sl@0
   591
    proc foo {} {string match -nocase {[A-fh-Z]} g}
sl@0
   592
    foo
sl@0
   593
} 0
sl@0
   594
test stringComp-11.38 {string match case, reverse range} {
sl@0
   595
    proc foo {} {string match {[A-fh-Z]} g}
sl@0
   596
    foo
sl@0
   597
} 1
sl@0
   598
test stringComp-11.39 {string match, *\ case} {
sl@0
   599
    proc foo {} {string match {*\abc} abc}
sl@0
   600
    foo
sl@0
   601
} 1
sl@0
   602
test stringComp-11.40 {string match, *special case} {
sl@0
   603
    proc foo {} {string match {*[ab]} abc}
sl@0
   604
    foo
sl@0
   605
} 0
sl@0
   606
test stringComp-11.41 {string match, *special case} {
sl@0
   607
    proc foo {} {string match {*[ab]*} abc}
sl@0
   608
    foo
sl@0
   609
} 1
sl@0
   610
test stringComp-11.42 {string match, *special case} {
sl@0
   611
    proc foo {} {string match "*\\" "\\"}
sl@0
   612
    foo
sl@0
   613
} 0
sl@0
   614
test stringComp-11.43 {string match, *special case} {
sl@0
   615
    proc foo {} {string match "*\\\\" "\\"}
sl@0
   616
    foo
sl@0
   617
} 1
sl@0
   618
test stringComp-11.44 {string match, *special case} {
sl@0
   619
    proc foo {} {string match "*???" "12345"}
sl@0
   620
    foo
sl@0
   621
} 1
sl@0
   622
test stringComp-11.45 {string match, *special case} {
sl@0
   623
    proc foo {} {string match "*???" "12"}
sl@0
   624
    foo
sl@0
   625
} 0
sl@0
   626
test stringComp-11.46 {string match, *special case} {
sl@0
   627
    proc foo {} {string match "*\\*" "abc*"}
sl@0
   628
    foo
sl@0
   629
} 1
sl@0
   630
test stringComp-11.47 {string match, *special case} {
sl@0
   631
    proc foo {} {string match "*\\*" "*"}
sl@0
   632
    foo
sl@0
   633
} 1
sl@0
   634
test stringComp-11.48 {string match, *special case} {
sl@0
   635
    proc foo {} {string match "*\\*" "*abc"}
sl@0
   636
    foo
sl@0
   637
} 0
sl@0
   638
test stringComp-11.49 {string match, *special case} {
sl@0
   639
    proc foo {} {string match "?\\*" "a*"}
sl@0
   640
    foo
sl@0
   641
} 1
sl@0
   642
test stringComp-11.50 {string match, *special case} {
sl@0
   643
    proc foo {} {string match "\\" "\\"}
sl@0
   644
    foo
sl@0
   645
} 0
sl@0
   646
test stringComp-11.51 {string match; *, -nocase and UTF-8} {
sl@0
   647
    proc foo {} {string match -nocase [binary format I 717316707] \
sl@0
   648
	    [binary format I 2028036707]}
sl@0
   649
    foo
sl@0
   650
} 1
sl@0
   651
test stringComp-11.52 {string match, null char in string} {
sl@0
   652
    proc foo {} {
sl@0
   653
	set ptn "*abc*"
sl@0
   654
	foreach elem [list "\u0000@abc" "@abc" "\u0000@abc\u0000" "blahabcblah"] {
sl@0
   655
	    lappend out [string match $ptn $elem]
sl@0
   656
	}
sl@0
   657
	set out
sl@0
   658
    }
sl@0
   659
    foo
sl@0
   660
} {1 1 1 1}
sl@0
   661
test stringComp-11.53 {string match, null char in pattern} {
sl@0
   662
    proc foo {} {
sl@0
   663
	set out ""
sl@0
   664
	foreach {ptn elem} [list \
sl@0
   665
		"*\u0000abc\u0000"  "\u0000abc\u0000" \
sl@0
   666
		"*\u0000abc\u0000"  "\u0000abc\u0000ef" \
sl@0
   667
		"*\u0000abc\u0000*" "\u0000abc\u0000ef" \
sl@0
   668
		"*\u0000abc\u0000"  "@\u0000abc\u0000ef" \
sl@0
   669
		"*\u0000abc\u0000*"  "@\u0000abc\u0000ef" \
sl@0
   670
		] {
sl@0
   671
	    lappend out [string match $ptn $elem]
sl@0
   672
	}
sl@0
   673
	set out
sl@0
   674
    }
sl@0
   675
    foo
sl@0
   676
} {1 0 1 0 1}
sl@0
   677
test stringComp-11.54 {string match, failure} {
sl@0
   678
    proc foo {} {
sl@0
   679
	set longString ""
sl@0
   680
	for {set i 0} {$i < 10} {incr i} {
sl@0
   681
	    append longString "abcdefghijklmnopqrstuvwxy\u0000z01234567890123"
sl@0
   682
	}
sl@0
   683
	list [string match *cba* $longString] \
sl@0
   684
		[string match *a*l*\u0000* $longString] \
sl@0
   685
		[string match *a*l*\u0000*123 $longString] \
sl@0
   686
		[string match *a*l*\u0000*123* $longString] \
sl@0
   687
		[string match *a*l*\u0000*cba* $longString] \
sl@0
   688
		[string match *===* $longString]
sl@0
   689
    }
sl@0
   690
    foo
sl@0
   691
} {0 1 1 1 0 0}
sl@0
   692
sl@0
   693
## string range
sl@0
   694
## not yet bc
sl@0
   695
sl@0
   696
## string repeat
sl@0
   697
## not yet bc
sl@0
   698
sl@0
   699
## string replace
sl@0
   700
## not yet bc
sl@0
   701
sl@0
   702
## string tolower
sl@0
   703
## not yet bc
sl@0
   704
sl@0
   705
## string toupper
sl@0
   706
## not yet bc
sl@0
   707
sl@0
   708
## string totitle
sl@0
   709
## not yet bc
sl@0
   710
sl@0
   711
## string trim*
sl@0
   712
## not yet bc
sl@0
   713
sl@0
   714
## string word*
sl@0
   715
## not yet bc
sl@0
   716
sl@0
   717
# cleanup
sl@0
   718
::tcltest::cleanupTests
sl@0
   719
return