aboutsummaryrefslogtreecommitdiff
path: root/tests/stringmatch.test
blob: 7fe3fcce84fda6429da3959472c599b0b3eb2a64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# This file is a Tcl script to test the code in the file tclUtil.c.
# This file is organized in the standard fashion for Tcl tests.
#
# Copyright (c) 1995-1998 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# RCS: @(#) $Id: util.test,v 1.7.2.1 2001/07/16 23:14:13 hobbs Exp $

source [file dirname [info script]]/testing.tcl

test stringmatch-5.1 {Tcl_StringMatch} {
    string match ab*c abc
} 1
test stringmatch-5.2 {Tcl_StringMatch} {
    string match ab**c abc
} 1
test stringmatch-5.3 {Tcl_StringMatch} {
    string match ab* abcdef
} 1
test stringmatch-5.4 {Tcl_StringMatch} {
    string match *c abc
} 1
test stringmatch-5.5 {Tcl_StringMatch} {
    string match *3*6*9 0123456789
} 1
test stringmatch-5.6 {Tcl_StringMatch} {
    string match *3*6*9 01234567890
} 0
test stringmatch-5.7 {Tcl_StringMatch: UTF-8} {
    string match *u \u4e4fu
} 1
test stringmatch-5.8 {Tcl_StringMatch} {
    string match a?c abc
} 1
test stringmatch-5.9 {Tcl_StringMatch: UTF-8} utf8 {
    # skip one character in string

    string match a?c a\u4e4fc
} 1
test stringmatch-5.10 {Tcl_StringMatch} {
    string match a??c abc
} 0
test stringmatch-5.11 {Tcl_StringMatch} {
    string match ?1??4???8? 0123456789
} 1
test stringmatch-5.12 {Tcl_StringMatch} {
    string match {[abc]bc} abc
} 1
test stringmatch-5.13 {Tcl_StringMatch: UTF-8} utf8 {
    # string += Tcl_UtfToUniChar(string, &ch);

    string match "\[\u4e4fxy\]bc" "\u4e4fbc"
} 1
test stringmatch-5.14 {Tcl_StringMatch} {
    # if ((*pattern == ']') || (*pattern == '\0'))
    # badly formed pattern

    string match {[]} {[]}
} 0
test stringmatch-5.15 {Tcl_StringMatch} {
    # if ((*pattern == ']') || (*pattern == '\0'))
    # badly formed pattern

    string match {[} {[}
} 0
test stringmatch-5.16 {Tcl_StringMatch} {
    string match {a[abc]c} abc
} 1
test stringmatch-5.17 {Tcl_StringMatch: UTF-8} utf8 {
    # pattern += Tcl_UtfToUniChar(pattern, &endChar);
    # get 1 UTF-8 character

    string match "a\[a\u4e4fc]c" "a\u4e4fc"
} 1
test stringmatch-5.18 {Tcl_StringMatch: UTF-8} {
    # pattern += Tcl_UtfToUniChar(pattern, &endChar);
    # proper advance: wrong answer would match on UTF trail byte of \u4e4f

    string match {a[a\u4e4fc]c} a\u008fc
} 0
test stringmatch-5.19 {Tcl_StringMatch: UTF-8} {
    # pattern += Tcl_UtfToUniChar(pattern, &endChar);
    # proper advance.

    string match {a[a\u4e4fc]c} "acc"
} 1
test stringmatch-5.20 {Tcl_StringMatch} {
    string match {a[xyz]c} abc
} 0
test stringmatch-5.21 {Tcl_StringMatch} {
    string match {12[2-7]45} 12345
} 1
test stringmatch-5.22 {Tcl_StringMatch: UTF-8 range} {
    string match "\[\u4e00-\u4e4f]" "0"
} 0
test stringmatch-5.23 {Tcl_StringMatch: UTF-8 range} utf8 {
    string match "\[\u4e00-\u4e4f]" "\u4e33"
} 1
test stringmatch-5.24 {Tcl_StringMatch: UTF-8 range} utf8 {
    string match "\[\u4e00-\u4e4f]" "\uff08"
} 0
test stringmatch-5.25 {Tcl_StringMatch} {
    string match {12[ab2-4cd]45} 12345
} 1
test stringmatch-5.26 {Tcl_StringMatch} {
    string match {12[ab2-4cd]45} 12b45
} 1
test stringmatch-5.27 {Tcl_StringMatch} {
    string match {12[ab2-4cd]45} 12d45
} 1
test stringmatch-5.28 {Tcl_StringMatch} {
    string match {12[ab2-4cd]45} 12145
} 0
test stringmatch-5.29 {Tcl_StringMatch} {
    string match {12[ab2-4cd]45} 12545
} 0
test stringmatch-5.30 {Tcl_StringMatch: forwards range} {
    string match {[k-w]} "z"
} 0
test stringmatch-5.31 {Tcl_StringMatch: forwards range} {
    string match {[k-w]} "w"
} 1
test stringmatch-5.32 {Tcl_StringMatch: forwards range} {
    string match {[k-w]} "r"
} 1
test stringmatch-5.33 {Tcl_StringMatch: forwards range} {
    string match {[k-w]} "k"
} 1
test stringmatch-5.34 {Tcl_StringMatch: forwards range} {
    string match {[k-w]} "a"
} 0
test stringmatch-5.35 {Tcl_StringMatch: reverse range} {
    string match {[w-k]} "z"
} 0
test stringmatch-5.36 {Tcl_StringMatch: reverse range} {
    string match {[w-k]} "w"
} 1
test stringmatch-5.37 {Tcl_StringMatch: reverse range} {
    string match {[w-k]} "r"
} 1
test stringmatch-5.38 {Tcl_StringMatch: reverse range} {
    string match {[w-k]} "k"
} 1
test stringmatch-5.39 {Tcl_StringMatch: reverse range} {
    string match {[w-k]} "a"
} 0
test stringmatch-5.40 {Tcl_StringMatch: skip correct number of ']'} {
    string match {[A-]x} Ax
} 0
test stringmatch-5.41 {Tcl_StringMatch: skip correct number of ']'} {
    string match {[A-]]x} Ax
} 1
test stringmatch-5.42 {Tcl_StringMatch: skip correct number of ']'} {
    string match {[A-]]x} \ue1x
} 0
test stringmatch-5.43 {Tcl_StringMatch: skip correct number of ']'} utf8 {
    string match \[A-]\ue1]x \ue1x
} 1
test stringmatch-5.44 {Tcl_StringMatch: skip correct number of ']'} {
    string match {[A-]h]x} hx
} 1
test stringmatch-5.45 {Tcl_StringMatch} {
    # if (*pattern == '\0')
    # badly formed pattern, still treats as a set

    string match {[a} a
} 1
test stringmatch-5.46 {Tcl_StringMatch} {
    string match {a\*b} a*b
} 1
test stringmatch-5.47 {Tcl_StringMatch} {
    string match {a\*b} ab
} 0
test stringmatch-5.48 {Tcl_StringMatch} {
    string match {a\*\?\[\]\\\x} "a*?\[\]\\x"
} 1
test stringmatch-5.49 {Tcl_StringMatch} {
    string match ** ""
} 1
test stringmatch-5.50 {Tcl_StringMatch} {
    string match *. ""
} 0
test stringmatch-5.51 {Tcl_StringMatch} {
    string match "" ""
} 1

# 'string match' doesn't support ^, which is different
# from 'scan'

test stringmatch-6.1 {bracket in charset} {
    string match {a[]b]c} {a]c}
} 0

test stringmatch-6.2 {bracket in charset} {
    string match {a[]b]c} {abc}
} 0

test stringmatch-6.3 {charset with ^} {
    string match {a[^]b]c} {axc}
} 0

test stringmatch-6.4 {charset with ^} {
    string match {a[^]b]c} {a]c}
} 0

test stringmatch-6.5 {charset with ^} {
    string match {a[^bc]d} {axd}
} 0

test stringmatch-6.6 {charset with ^} {
    string match {a[\]]c} {a]c}
} 0

test stringmatch=7.1 {short string with ?} {
    string match {ab?} ab
} 0

test stringmatch=7.1 {multiple * to end} {
    string match {ab**} ab
} 1

testreport