1 # This file is a Tcl script to test the code in the file tclUtil.c.
2 # This file is organized in the standard fashion for Tcl tests.
4 # Copyright (c) 1995-1998 Sun Microsystems, Inc.
5 # Copyright (c) 1998-1999 by Scriptics Corporation.
7 # See the file "license.terms" for information on usage and redistribution
8 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10 # RCS: @(#) $Id: util.test,v 1.7.2.1 2001/07/16 23:14:13 hobbs Exp $
12 source [file dirname [info script]]/testing.tcl
14 test stringmatch-5.1 {Tcl_StringMatch} {
17 test stringmatch-5.2 {Tcl_StringMatch} {
18 string match ab**c abc
20 test stringmatch-5.3 {Tcl_StringMatch} {
21 string match ab* abcdef
23 test stringmatch-5.4 {Tcl_StringMatch} {
26 test stringmatch-5.5 {Tcl_StringMatch} {
27 string match *3*6*9 0123456789
29 test stringmatch-5.6 {Tcl_StringMatch} {
30 string match *3*6*9 01234567890
32 test stringmatch-5.7 {Tcl_StringMatch: UTF-8} {
33 string match *u \u4e4fu
35 test stringmatch-5.8 {Tcl_StringMatch} {
38 test stringmatch-5.9 {Tcl_StringMatch: UTF-8} utf8 {
39 # skip one character in string
41 string match a?c a\u4e4fc
43 test stringmatch-5.10 {Tcl_StringMatch} {
46 test stringmatch-5.11 {Tcl_StringMatch} {
47 string match ?1??4???8? 0123456789
49 test stringmatch-5.12 {Tcl_StringMatch} {
50 string match {[abc]bc} abc
52 test stringmatch-5.13 {Tcl_StringMatch: UTF-8} utf8 {
53 # string += Tcl_UtfToUniChar(string, &ch);
55 string match "\[\u4e4fxy\]bc" "\u4e4fbc"
57 test stringmatch-5.14 {Tcl_StringMatch} {
58 # if ((*pattern == ']') || (*pattern == '\0'))
59 # badly formed pattern
61 string match {[]} {[]}
63 test stringmatch-5.15 {Tcl_StringMatch} {
64 # if ((*pattern == ']') || (*pattern == '\0'))
65 # badly formed pattern
69 test stringmatch-5.16 {Tcl_StringMatch} {
70 string match {a[abc]c} abc
72 test stringmatch-5.17 {Tcl_StringMatch: UTF-8} utf8 {
73 # pattern += Tcl_UtfToUniChar(pattern, &endChar);
74 # get 1 UTF-8 character
76 string match "a\[a\u4e4fc]c" "a\u4e4fc"
78 test stringmatch-5.18 {Tcl_StringMatch: UTF-8} {
79 # pattern += Tcl_UtfToUniChar(pattern, &endChar);
80 # proper advance: wrong answer would match on UTF trail byte of \u4e4f
82 string match {a[a\u4e4fc]c} a\u008fc
84 test stringmatch-5.19 {Tcl_StringMatch: UTF-8} {
85 # pattern += Tcl_UtfToUniChar(pattern, &endChar);
88 string match {a[a\u4e4fc]c} "acc"
90 test stringmatch-5.20 {Tcl_StringMatch} {
91 string match {a[xyz]c} abc
93 test stringmatch-5.21 {Tcl_StringMatch} {
94 string match {12[2-7]45} 12345
96 test stringmatch-5.22 {Tcl_StringMatch: UTF-8 range} {
97 string match "\[\u4e00-\u4e4f]" "0"
99 test stringmatch-5.23 {Tcl_StringMatch: UTF-8 range} utf8 {
100 string match "\[\u4e00-\u4e4f]" "\u4e33"
102 test stringmatch-5.24 {Tcl_StringMatch: UTF-8 range} utf8 {
103 string match "\[\u4e00-\u4e4f]" "\uff08"
105 test stringmatch-5.25 {Tcl_StringMatch} {
106 string match {12[ab2-4cd]45} 12345
108 test stringmatch-5.26 {Tcl_StringMatch} {
109 string match {12[ab2-4cd]45} 12b45
111 test stringmatch-5.27 {Tcl_StringMatch} {
112 string match {12[ab2-4cd]45} 12d45
114 test stringmatch-5.28 {Tcl_StringMatch} {
115 string match {12[ab2-4cd]45} 12145
117 test stringmatch-5.29 {Tcl_StringMatch} {
118 string match {12[ab2-4cd]45} 12545
120 test stringmatch-5.30 {Tcl_StringMatch: forwards range} {
121 string match {[k-w]} "z"
123 test stringmatch-5.31 {Tcl_StringMatch: forwards range} {
124 string match {[k-w]} "w"
126 test stringmatch-5.32 {Tcl_StringMatch: forwards range} {
127 string match {[k-w]} "r"
129 test stringmatch-5.33 {Tcl_StringMatch: forwards range} {
130 string match {[k-w]} "k"
132 test stringmatch-5.34 {Tcl_StringMatch: forwards range} {
133 string match {[k-w]} "a"
135 test stringmatch-5.35 {Tcl_StringMatch: reverse range} {
136 string match {[w-k]} "z"
138 test stringmatch-5.36 {Tcl_StringMatch: reverse range} {
139 string match {[w-k]} "w"
141 test stringmatch-5.37 {Tcl_StringMatch: reverse range} {
142 string match {[w-k]} "r"
144 test stringmatch-5.38 {Tcl_StringMatch: reverse range} {
145 string match {[w-k]} "k"
147 test stringmatch-5.39 {Tcl_StringMatch: reverse range} {
148 string match {[w-k]} "a"
150 test stringmatch-5.40 {Tcl_StringMatch: skip correct number of ']'} {
151 string match {[A-]x} Ax
153 test stringmatch-5.41 {Tcl_StringMatch: skip correct number of ']'} {
154 string match {[A-]]x} Ax
156 test stringmatch-5.42 {Tcl_StringMatch: skip correct number of ']'} {
157 string match {[A-]]x} \ue1x
159 test stringmatch-5.43 {Tcl_StringMatch: skip correct number of ']'} utf8 {
160 string match \[A-]\ue1]x \ue1x
162 test stringmatch-5.44 {Tcl_StringMatch: skip correct number of ']'} {
163 string match {[A-]h]x} hx
165 test stringmatch-5.45 {Tcl_StringMatch} {
166 # if (*pattern == '\0')
167 # badly formed pattern, still treats as a set
171 test stringmatch-5.46 {Tcl_StringMatch} {
172 string match {a\*b} a*b
174 test stringmatch-5.47 {Tcl_StringMatch} {
175 string match {a\*b} ab
177 test stringmatch-5.48 {Tcl_StringMatch} {
178 string match {a\*\?\[\]\\\x} "a*?\[\]\\x"
180 test stringmatch-5.49 {Tcl_StringMatch} {
183 test stringmatch-5.50 {Tcl_StringMatch} {
186 test stringmatch-5.51 {Tcl_StringMatch} {
190 # 'string match' doesn't support ^, which is different
193 test stringmatch-6.1 {bracket in charset} {
194 string match {a[]b]c} {a]c}
197 test stringmatch-6.2 {bracket in charset} {
198 string match {a[]b]c} {abc}
201 test stringmatch-6.3 {charset with ^} {
202 string match {a[^]b]c} {axc}
205 test stringmatch-6.4 {charset with ^} {
206 string match {a[^]b]c} {a]c}
209 test stringmatch-6.5 {charset with ^} {
210 string match {a[^bc]d} {axd}
213 test stringmatch-6.6 {charset with ^} {
214 string match {a[\]]c} {a]c}
217 test stringmatch=7.1 {short string with ?} {
218 string match {ab?} ab
221 test stringmatch=7.1 {multiple * to end} {
222 string match {ab**} ab