blob: 45bb3b14ec7c0c7189451f36deda3ab788545950 [file] [log] [blame]
Guido van Rossum8430c581998-04-03 21:47:12 +00001import sys
Fred Drake8ae9ce52000-08-18 16:09:56 +00002sys.path = ['.'] + sys.path
Guido van Rossum8430c581998-04-03 21:47:12 +00003
Marc-André Lemburg36619082001-01-17 19:11:13 +00004from test_support import verify, verbose, TestFailed
Guido van Rossum8e0ce301997-07-11 19:34:44 +00005import re
Eric S. Raymond2846b0a2001-02-09 12:00:47 +00006import sys, os, traceback
Guido van Rossum8e0ce301997-07-11 19:34:44 +00007
Guido van Rossum23b22571997-07-17 22:36:14 +00008# Misc tests from Tim Peters' re.doc
9
Guido van Rossum49946571997-07-18 04:26:25 +000010if verbose:
Guido van Rossum8430c581998-04-03 21:47:12 +000011 print 'Running tests on re.search and re.match'
12
13try:
Marc-André Lemburg36619082001-01-17 19:11:13 +000014 verify(re.search('x*', 'axx').span(0) == (0, 0))
15 verify(re.search('x*', 'axx').span() == (0, 0))
16 verify(re.search('x+', 'axx').span(0) == (1, 3))
17 verify(re.search('x+', 'axx').span() == (1, 3))
18 verify(re.search('x', 'aaa') is None)
Guido van Rossum8430c581998-04-03 21:47:12 +000019except:
20 raise TestFailed, "re.search"
21
22try:
Marc-André Lemburg36619082001-01-17 19:11:13 +000023 verify(re.match('a*', 'xxx').span(0) == (0, 0))
24 verify(re.match('a*', 'xxx').span() == (0, 0))
25 verify(re.match('x*', 'xxxa').span(0) == (0, 3))
26 verify(re.match('x*', 'xxxa').span() == (0, 3))
27 verify(re.match('a+', 'xxx') is None)
Guido van Rossum8430c581998-04-03 21:47:12 +000028except:
29 raise TestFailed, "re.search"
30
31if verbose:
Guido van Rossum49946571997-07-18 04:26:25 +000032 print 'Running tests on re.sub'
33
Guido van Rossum23b22571997-07-17 22:36:14 +000034try:
Marc-André Lemburg36619082001-01-17 19:11:13 +000035 verify(re.sub("(?i)b+", "x", "bbbb BBBB") == 'x x')
Fredrik Lundh1151a8c2000-08-08 16:47:42 +000036
Guido van Rossum23b22571997-07-17 22:36:14 +000037 def bump_num(matchobj):
Guido van Rossum41360a41998-03-26 19:42:58 +000038 int_value = int(matchobj.group(0))
39 return str(int_value + 1)
Guido van Rossum23b22571997-07-17 22:36:14 +000040
Marc-André Lemburg36619082001-01-17 19:11:13 +000041 verify(re.sub(r'\d+', bump_num, '08.2 -2 23x99y') == '9.3 -3 24x100y')
42 verify(re.sub(r'\d+', bump_num, '08.2 -2 23x99y', 3) == '9.3 -3 23x99y')
Fredrik Lundh1151a8c2000-08-08 16:47:42 +000043
Marc-André Lemburg36619082001-01-17 19:11:13 +000044 verify(re.sub('.', lambda m: r"\n", 'x') == '\\n')
45 verify(re.sub('.', r"\n", 'x') == '\n')
Guido van Rossumdfa67901997-12-08 17:12:06 +000046
Guido van Rossum23b22571997-07-17 22:36:14 +000047 s = r"\1\1"
Marc-André Lemburg36619082001-01-17 19:11:13 +000048 verify(re.sub('(.)', s, 'x') == 'xx')
49 verify(re.sub('(.)', re.escape(s), 'x') == s)
50 verify(re.sub('(.)', lambda m: s, 'x') == s)
Guido van Rossum23b22571997-07-17 22:36:14 +000051
Marc-André Lemburg36619082001-01-17 19:11:13 +000052 verify(re.sub('(?P<a>x)', '\g<a>\g<a>', 'xx') == 'xxxx')
53 verify(re.sub('(?P<a>x)', '\g<a>\g<1>', 'xx') == 'xxxx')
54 verify(re.sub('(?P<unk>x)', '\g<unk>\g<unk>', 'xx') == 'xxxx')
55 verify(re.sub('(?P<unk>x)', '\g<1>\g<1>', 'xx') == 'xxxx')
Guido van Rossum49946571997-07-18 04:26:25 +000056
Marc-André Lemburg36619082001-01-17 19:11:13 +000057 verify(re.sub('a', r'\t\n\v\r\f\a\b\B\Z\a\A\w\W\s\S\d\D', 'a') == '\t\n\v\r\f\a\b\\B\\Z\a\\A\\w\\W\\s\\S\\d\\D')
58 verify(re.sub('a', '\t\n\v\r\f\a', 'a') == '\t\n\v\r\f\a')
59 verify(re.sub('a', '\t\n\v\r\f\a', 'a') == (chr(9)+chr(10)+chr(11)+chr(13)+chr(12)+chr(7)))
Guido van Rossum95e80531997-08-13 22:34:14 +000060
Marc-André Lemburg36619082001-01-17 19:11:13 +000061 verify(re.sub('^\s*', 'X', 'test') == 'Xtest')
Guido van Rossume056e4d2001-08-10 14:52:48 +000062
63 # Test for sub() on escaped characters, see SF bug #449000
64 verify(re.sub(r'\r\n', r'\n', 'abc\r\ndef\r\n') == 'abc\ndef\n')
65 verify(re.sub('\r\n', r'\n', 'abc\r\ndef\r\n') == 'abc\ndef\n')
66 verify(re.sub(r'\r\n', '\n', 'abc\r\ndef\r\n') == 'abc\ndef\n')
67 verify(re.sub('\r\n', '\n', 'abc\r\ndef\r\n') == 'abc\ndef\n')
Guido van Rossum23b22571997-07-17 22:36:14 +000068except AssertionError:
69 raise TestFailed, "re.sub"
70
Guido van Rossum8430c581998-04-03 21:47:12 +000071
Guido van Rossumf473cb01998-01-14 16:42:17 +000072try:
Marc-André Lemburg36619082001-01-17 19:11:13 +000073 verify(re.sub('a', 'b', 'aaaaa') == 'bbbbb')
74 verify(re.sub('a', 'b', 'aaaaa', 1) == 'baaaa')
Guido van Rossumf473cb01998-01-14 16:42:17 +000075except AssertionError:
76 raise TestFailed, "qualified re.sub"
77
Guido van Rossum49946571997-07-18 04:26:25 +000078if verbose:
79 print 'Running tests on symbolic references'
80
81try:
82 re.sub('(?P<a>x)', '\g<a', 'xx')
83except re.error, reason:
84 pass
85else:
86 raise TestFailed, "symbolic reference"
87
88try:
89 re.sub('(?P<a>x)', '\g<', 'xx')
90except re.error, reason:
91 pass
92else:
93 raise TestFailed, "symbolic reference"
94
95try:
96 re.sub('(?P<a>x)', '\g', 'xx')
97except re.error, reason:
98 pass
99else:
100 raise TestFailed, "symbolic reference"
101
102try:
103 re.sub('(?P<a>x)', '\g<a a>', 'xx')
104except re.error, reason:
105 pass
106else:
107 raise TestFailed, "symbolic reference"
108
109try:
Guido van Rossum8430c581998-04-03 21:47:12 +0000110 re.sub('(?P<a>x)', '\g<1a1>', 'xx')
111except re.error, reason:
112 pass
113else:
114 raise TestFailed, "symbolic reference"
115
116try:
Guido van Rossum49946571997-07-18 04:26:25 +0000117 re.sub('(?P<a>x)', '\g<ab>', 'xx')
118except IndexError, reason:
119 pass
120else:
121 raise TestFailed, "symbolic reference"
122
123try:
124 re.sub('(?P<a>x)|(?P<b>y)', '\g<b>', 'xx')
125except re.error, reason:
126 pass
127else:
128 raise TestFailed, "symbolic reference"
129
130try:
131 re.sub('(?P<a>x)|(?P<b>y)', '\\2', 'xx')
132except re.error, reason:
133 pass
134else:
135 raise TestFailed, "symbolic reference"
136
137if verbose:
138 print 'Running tests on re.subn'
139
Guido van Rossum23b22571997-07-17 22:36:14 +0000140try:
Marc-André Lemburg36619082001-01-17 19:11:13 +0000141 verify(re.subn("(?i)b+", "x", "bbbb BBBB") == ('x x', 2))
142 verify(re.subn("b+", "x", "bbbb BBBB") == ('x BBBB', 1))
143 verify(re.subn("b+", "x", "xyz") == ('xyz', 0))
144 verify(re.subn("b*", "x", "xyz") == ('xxxyxzx', 4))
145 verify(re.subn("b*", "x", "xyz", 2) == ('xxxyz', 2))
Guido van Rossum23b22571997-07-17 22:36:14 +0000146except AssertionError:
147 raise TestFailed, "re.subn"
148
Guido van Rossum8430c581998-04-03 21:47:12 +0000149if verbose:
150 print 'Running tests on re.split'
Fredrik Lundh1151a8c2000-08-08 16:47:42 +0000151
Guido van Rossum23b22571997-07-17 22:36:14 +0000152try:
Marc-André Lemburg36619082001-01-17 19:11:13 +0000153 verify(re.split(":", ":a:b::c") == ['', 'a', 'b', '', 'c'])
154 verify(re.split(":*", ":a:b::c") == ['', 'a', 'b', 'c'])
155 verify(re.split("(:*)", ":a:b::c") == ['', ':', 'a', ':', 'b', '::', 'c'])
156 verify(re.split("(?::*)", ":a:b::c") == ['', 'a', 'b', 'c'])
157 verify(re.split("(:)*", ":a:b::c") == ['', ':', 'a', ':', 'b', ':', 'c'])
158 verify(re.split("([b:]+)", ":a:b::c") == ['', ':', 'a', ':b::', 'c'])
159 verify(re.split("(b)|(:+)", ":a:b::c") == \
160 ['', None, ':', 'a', None, ':', '', 'b', None, '', None, '::', 'c'] )
161 verify(re.split("(?:b)|(?::+)", ":a:b::c") == ['', 'a', '', '', 'c'])
Guido van Rossum23b22571997-07-17 22:36:14 +0000162except AssertionError:
163 raise TestFailed, "re.split"
164
Guido van Rossumf473cb01998-01-14 16:42:17 +0000165try:
Marc-André Lemburg36619082001-01-17 19:11:13 +0000166 verify(re.split(":", ":a:b::c", 2) == ['', 'a', 'b::c'])
167 verify(re.split(':', 'a:b:c:d', 2) == ['a', 'b', 'c:d'])
Guido van Rossumf473cb01998-01-14 16:42:17 +0000168
Marc-André Lemburg36619082001-01-17 19:11:13 +0000169 verify(re.split("(:)", ":a:b::c", 2) == ['', ':', 'a', ':', 'b::c'])
170 verify(re.split("(:*)", ":a:b::c", 2) == ['', ':', 'a', ':', 'b::c'])
Guido van Rossumf473cb01998-01-14 16:42:17 +0000171except AssertionError:
172 raise TestFailed, "qualified re.split"
173
Guido van Rossumc364cf81998-07-17 20:05:02 +0000174if verbose:
175 print "Running tests on re.findall"
176
177try:
Marc-André Lemburg36619082001-01-17 19:11:13 +0000178 verify(re.findall(":+", "abc") == [])
179 verify(re.findall(":+", "a:b::c:::d") == [":", "::", ":::"])
180 verify(re.findall("(:+)", "a:b::c:::d") == [":", "::", ":::"])
181 verify(re.findall("(:)(:*)", "a:b::c:::d") == [(":", ""),
Guido van Rossumc364cf81998-07-17 20:05:02 +0000182 (":", ":"),
Marc-André Lemburg36619082001-01-17 19:11:13 +0000183 (":", "::")] )
Guido van Rossumc364cf81998-07-17 20:05:02 +0000184except AssertionError:
185 raise TestFailed, "re.findall"
186
187if verbose:
188 print "Running tests on re.match"
189
Guido van Rossum8430c581998-04-03 21:47:12 +0000190try:
191 # No groups at all
Marc-André Lemburg36619082001-01-17 19:11:13 +0000192 m = re.match('a', 'a') ; verify(m.groups() == ())
Guido van Rossum8430c581998-04-03 21:47:12 +0000193 # A single group
Marc-André Lemburg36619082001-01-17 19:11:13 +0000194 m = re.match('(a)', 'a') ; verify(m.groups() == ('a',))
Guido van Rossum8430c581998-04-03 21:47:12 +0000195
196 pat = re.compile('((a)|(b))(c)?')
Marc-André Lemburg36619082001-01-17 19:11:13 +0000197 verify(pat.match('a').groups() == ('a', 'a', None, None))
198 verify(pat.match('b').groups() == ('b', None, 'b', None))
199 verify(pat.match('ac').groups() == ('a', 'a', None, 'c'))
200 verify(pat.match('bc').groups() == ('b', None, 'b', 'c'))
201 verify(pat.match('bc').groups("") == ('b', "", 'b', 'c'))
Guido van Rossum8430c581998-04-03 21:47:12 +0000202except AssertionError:
203 raise TestFailed, "match .groups() method"
204
205try:
206 # A single group
Fredrik Lundh1151a8c2000-08-08 16:47:42 +0000207 m = re.match('(a)', 'a')
Marc-André Lemburg36619082001-01-17 19:11:13 +0000208 verify(m.group(0) == 'a')
209 verify(m.group(0) == 'a')
210 verify(m.group(1) == 'a')
211 verify(m.group(1, 1) == ('a', 'a'))
Guido van Rossum8430c581998-04-03 21:47:12 +0000212
213 pat = re.compile('(?:(?P<a1>a)|(?P<b2>b))(?P<c3>c)?')
Marc-André Lemburg36619082001-01-17 19:11:13 +0000214 verify(pat.match('a').group(1, 2, 3) == ('a', None, None))
215 verify(pat.match('b').group('a1', 'b2', 'c3') == (None, 'b', None))
216 verify(pat.match('ac').group(1, 'b2', 3) == ('a', None, 'c'))
Guido van Rossum8430c581998-04-03 21:47:12 +0000217except AssertionError:
218 raise TestFailed, "match .group() method"
219
Guido van Rossumc364cf81998-07-17 20:05:02 +0000220if verbose:
221 print "Running tests on re.escape"
222
Guido van Rossum8430c581998-04-03 21:47:12 +0000223try:
224 p=""
225 for i in range(0, 256):
226 p = p + chr(i)
Marc-André Lemburg36619082001-01-17 19:11:13 +0000227 verify(re.match(re.escape(chr(i)), chr(i)) is not None)
228 verify(re.match(re.escape(chr(i)), chr(i)).span() == (0,1))
Guido van Rossum8430c581998-04-03 21:47:12 +0000229
230 pat=re.compile( re.escape(p) )
Marc-André Lemburg36619082001-01-17 19:11:13 +0000231 verify(pat.match(p) is not None)
232 verify(pat.match(p).span() == (0,256))
Guido van Rossum8430c581998-04-03 21:47:12 +0000233except AssertionError:
234 raise TestFailed, "re.escape"
Guido van Rossumc364cf81998-07-17 20:05:02 +0000235
Guido van Rossumdfa67901997-12-08 17:12:06 +0000236
237if verbose:
Guido van Rossum8430c581998-04-03 21:47:12 +0000238 print 'Pickling a RegexObject instance'
239
240import pickle
241pat = re.compile('a(?:b|(c|e){1,2}?|d)+?(.)')
242s = pickle.dumps(pat)
243pat = pickle.loads(s)
244
Guido van Rossumdfa67901997-12-08 17:12:06 +0000245try:
Marc-André Lemburg36619082001-01-17 19:11:13 +0000246 verify(re.I == re.IGNORECASE)
247 verify(re.L == re.LOCALE)
248 verify(re.M == re.MULTILINE)
249 verify(re.S == re.DOTALL)
250 verify(re.X == re.VERBOSE)
Guido van Rossumdfa67901997-12-08 17:12:06 +0000251except AssertionError:
252 raise TestFailed, 're module constants'
253
Guido van Rossumf5910e41997-12-30 17:32:33 +0000254for flags in [re.I, re.M, re.X, re.S, re.L]:
Guido van Rossumdfa67901997-12-08 17:12:06 +0000255 try:
Guido van Rossum41360a41998-03-26 19:42:58 +0000256 r = re.compile('^pattern$', flags)
Guido van Rossumdfa67901997-12-08 17:12:06 +0000257 except:
Guido van Rossum41360a41998-03-26 19:42:58 +0000258 print 'Exception raised on flag', flags
Guido van Rossumdfa67901997-12-08 17:12:06 +0000259
Fredrik Lundh8e6d5712000-08-08 17:06:53 +0000260if verbose:
261 print 'Test engine limitations'
262
263# Try nasty case that overflows the straightforward recursive
264# implementation of repeated groups.
265try:
Marc-André Lemburg36619082001-01-17 19:11:13 +0000266 verify(re.match('(x)*', 50000*'x').span() == (0, 50000))
Fredrik Lundh8e6d5712000-08-08 17:06:53 +0000267except RuntimeError, v:
268 print v
269
Guido van Rossum8e0ce301997-07-11 19:34:44 +0000270from re_tests import *
Guido van Rossum8430c581998-04-03 21:47:12 +0000271
Guido van Rossum49946571997-07-18 04:26:25 +0000272if verbose:
273 print 'Running re_tests test suite'
Guido van Rossumd807b751997-09-04 14:35:45 +0000274else:
275 # To save time, only run the first and last 10 tests
Guido van Rossum8430c581998-04-03 21:47:12 +0000276 #tests = tests[:10] + tests[-10:]
Fredrik Lundh1151a8c2000-08-08 16:47:42 +0000277 pass
Guido van Rossum8e0ce301997-07-11 19:34:44 +0000278
279for t in tests:
Guido van Rossuma0e4c1b1997-07-17 14:52:48 +0000280 sys.stdout.flush()
Fred Drake8ae9ce52000-08-18 16:09:56 +0000281 pattern = s = outcome = repl = expected = None
282 if len(t) == 5:
Guido van Rossum41360a41998-03-26 19:42:58 +0000283 pattern, s, outcome, repl, expected = t
Fred Drake8ae9ce52000-08-18 16:09:56 +0000284 elif len(t) == 3:
Fredrik Lundh1151a8c2000-08-08 16:47:42 +0000285 pattern, s, outcome = t
Guido van Rossum8e0ce301997-07-11 19:34:44 +0000286 else:
Fred Drake8ae9ce52000-08-18 16:09:56 +0000287 raise ValueError, ('Test tuples should have 3 or 5 fields', t)
Guido van Rossum8e0ce301997-07-11 19:34:44 +0000288
289 try:
Fred Drake8ae9ce52000-08-18 16:09:56 +0000290 obj = re.compile(pattern)
Guido van Rossum8e0ce301997-07-11 19:34:44 +0000291 except re.error:
Fred Drake8ae9ce52000-08-18 16:09:56 +0000292 if outcome == SYNTAX_ERROR: pass # Expected a syntax error
Fredrik Lundh1151a8c2000-08-08 16:47:42 +0000293 else:
Guido van Rossum41360a41998-03-26 19:42:58 +0000294 print '=== Syntax error:', t
Guido van Rossum95e80531997-08-13 22:34:14 +0000295 except KeyboardInterrupt: raise KeyboardInterrupt
Guido van Rossum8e0ce301997-07-11 19:34:44 +0000296 except:
Guido van Rossum8430c581998-04-03 21:47:12 +0000297 print '*** Unexpected error ***', t
Guido van Rossum41360a41998-03-26 19:42:58 +0000298 if verbose:
299 traceback.print_exc(file=sys.stdout)
Guido van Rossum8e0ce301997-07-11 19:34:44 +0000300 else:
Guido van Rossum41360a41998-03-26 19:42:58 +0000301 try:
Fred Drake8ae9ce52000-08-18 16:09:56 +0000302 result = obj.search(s)
303 except re.error, msg:
Guido van Rossum41360a41998-03-26 19:42:58 +0000304 print '=== Unexpected exception', t, repr(msg)
Fred Drake8ae9ce52000-08-18 16:09:56 +0000305 if outcome == SYNTAX_ERROR:
Guido van Rossum41360a41998-03-26 19:42:58 +0000306 # This should have been a syntax error; forget it.
307 pass
Fred Drake8ae9ce52000-08-18 16:09:56 +0000308 elif outcome == FAIL:
Guido van Rossum41360a41998-03-26 19:42:58 +0000309 if result is None: pass # No match, as expected
310 else: print '=== Succeeded incorrectly', t
Fred Drake8ae9ce52000-08-18 16:09:56 +0000311 elif outcome == SUCCEED:
Guido van Rossum41360a41998-03-26 19:42:58 +0000312 if result is not None:
313 # Matched, as expected, so now we compute the
314 # result string and compare it to our expected result.
315 start, end = result.span(0)
316 vardict={'found': result.group(0),
317 'groups': result.group(),
318 'flags': result.re.flags}
319 for i in range(1, 100):
320 try:
321 gi = result.group(i)
322 # Special hack because else the string concat fails:
323 if gi is None:
324 gi = "None"
325 except IndexError:
326 gi = "Error"
327 vardict['g%d' % i] = gi
328 for i in result.re.groupindex.keys():
329 try:
330 gi = result.group(i)
331 if gi is None:
332 gi = "None"
333 except IndexError:
334 gi = "Error"
335 vardict[i] = gi
Fred Drake8ae9ce52000-08-18 16:09:56 +0000336 repl = eval(repl, vardict)
337 if repl != expected:
Guido van Rossum41360a41998-03-26 19:42:58 +0000338 print '=== grouping error', t,
Fred Drake8ae9ce52000-08-18 16:09:56 +0000339 print repr(repl) + ' should be ' + repr(expected)
Guido van Rossum41360a41998-03-26 19:42:58 +0000340 else:
341 print '=== Failed incorrectly', t
Guido van Rossum95e80531997-08-13 22:34:14 +0000342
Fredrik Lundh8e6d5712000-08-08 17:06:53 +0000343 # Try the match on a unicode string, and check that it
344 # still succeeds.
Fredrik Lundh17741be2001-03-22 15:51:28 +0000345 try:
346 result = obj.search(unicode(s, "latin-1"))
347 if result is None:
348 print '=== Fails on unicode match', t
349 except NameError:
350 continue # 1.5.2
351 except TypeError:
352 continue # unicode test case
Fredrik Lundh8e6d5712000-08-08 17:06:53 +0000353
354 # Try the match on a unicode pattern, and check that it
355 # still succeeds.
356 obj=re.compile(unicode(pattern, "latin-1"))
Fred Drake8ae9ce52000-08-18 16:09:56 +0000357 result = obj.search(s)
Fred Drake132dce22000-12-12 23:11:42 +0000358 if result is None:
Fredrik Lundh8e6d5712000-08-08 17:06:53 +0000359 print '=== Fails on unicode pattern match', t
360
Guido van Rossum41360a41998-03-26 19:42:58 +0000361 # Try the match with the search area limited to the extent
362 # of the match and see if it still succeeds. \B will
363 # break (because it won't match at the end or start of a
364 # string), so we'll ignore patterns that feature it.
Fredrik Lundh1151a8c2000-08-08 16:47:42 +0000365
Fred Drake8ae9ce52000-08-18 16:09:56 +0000366 if pattern[:2] != '\\B' and pattern[-2:] != '\\B' \
Fred Drake132dce22000-12-12 23:11:42 +0000367 and result is not None:
Fred Drake8ae9ce52000-08-18 16:09:56 +0000368 obj = re.compile(pattern)
369 result = obj.search(s, result.start(0), result.end(0) + 1)
Fred Drake132dce22000-12-12 23:11:42 +0000370 if result is None:
Guido van Rossum41360a41998-03-26 19:42:58 +0000371 print '=== Failed on range-limited match', t
Guido van Rossumdfa67901997-12-08 17:12:06 +0000372
Guido van Rossum95e80531997-08-13 22:34:14 +0000373 # Try the match with IGNORECASE enabled, and check that it
Guido van Rossum41360a41998-03-26 19:42:58 +0000374 # still succeeds.
Fred Drake8ae9ce52000-08-18 16:09:56 +0000375 obj = re.compile(pattern, re.IGNORECASE)
376 result = obj.search(s)
Fred Drake132dce22000-12-12 23:11:42 +0000377 if result is None:
Guido van Rossum95e80531997-08-13 22:34:14 +0000378 print '=== Fails on case-insensitive match', t
Guido van Rossumdfa67901997-12-08 17:12:06 +0000379
Guido van Rossumf5910e41997-12-30 17:32:33 +0000380 # Try the match with LOCALE enabled, and check that it
Guido van Rossum41360a41998-03-26 19:42:58 +0000381 # still succeeds.
Fred Drake8ae9ce52000-08-18 16:09:56 +0000382 obj = re.compile(pattern, re.LOCALE)
383 result = obj.search(s)
Fred Drake132dce22000-12-12 23:11:42 +0000384 if result is None:
Guido van Rossumf5910e41997-12-30 17:32:33 +0000385 print '=== Fails on locale-sensitive match', t
Fredrik Lundh8e6d5712000-08-08 17:06:53 +0000386
387 # Try the match with UNICODE locale enabled, and check
388 # that it still succeeds.
Fred Drake8ae9ce52000-08-18 16:09:56 +0000389 obj = re.compile(pattern, re.UNICODE)
390 result = obj.search(s)
Fred Drake132dce22000-12-12 23:11:42 +0000391 if result is None:
Fredrik Lundh8e6d5712000-08-08 17:06:53 +0000392 print '=== Fails on unicode-sensitive match', t