Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
4994657c
Commit
4994657c
authored
Jul 18, 1997
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some new tests by Jeffrey
parent
71fa97c6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
11 deletions
+72
-11
Lib/test/test_re.py
Lib/test/test_re.py
+72
-11
No files found.
Lib/test/test_re.py
View file @
4994657c
...
@@ -9,36 +9,98 @@ import sys, os, string, traceback
...
@@ -9,36 +9,98 @@ import sys, os, string, traceback
# Misc tests from Tim Peters' re.doc
# Misc tests from Tim Peters' re.doc
try
:
if
verbose
:
print
'Running tests on re.sub'
try
:
assert
re
.
sub
(
"(?i)b+"
,
"x"
,
"bbbb BBBB"
)
==
'x x'
assert
re
.
sub
(
"(?i)b+"
,
"x"
,
"bbbb BBBB"
)
==
'x x'
def
bump_num
(
matchobj
):
def
bump_num
(
matchobj
):
int_value
=
int
(
matchobj
.
group
(
0
))
int_value
=
int
(
matchobj
.
group
(
0
))
return
str
(
int_value
+
1
)
return
str
(
int_value
+
1
)
assert
re
.
sub
(
r
"\
d+
"
, bump_num, '08.2 -2 23x99y') == '9.3 -3 24x100y'
assert
re
.
sub
(
r
'\
d+
'
, bump_num, '
08.2
-
2
23
x99y
') == '
9.3
-
3
24
x100y
'
assert re.sub('
.
', lambda m: r"
\
n
", '
x
') == '
\\
n
'
assert re.sub('
.
', lambda m: r"
\
n
", '
x
') == '
\\
n
'
assert re.sub('
.
', r"
\
n
", '
x
') == '
\
n
'
assert re.sub('
.
', r"
\
n
", '
x
') == '
\
n
'
s = r"
\
1
\
1
"
s = r"
\
1
\
1
"
assert re.sub('
(.)
', s, '
x
') == '
xx
'
assert re.sub('
(.)
', s, '
x
') == '
xx
'
assert re.sub('
(.)
', re.escape(s), '
x
') == s
assert re.sub('
(.)
', re.escape(s), '
x
') == s
assert re.sub('
(.)
', lambda m: s, '
x
') == s
assert re.sub('
(.)
', lambda m: s, '
x
') == s
assert re.sub('
(
?
P
<
a
>
x
)
', '
\
g
<
a
>
\
g
<
a
>
', '
xx
') == '
xxxx
'
except AssertionError:
except AssertionError:
raise TestFailed, "re.sub"
raise TestFailed, "re.sub"
if verbose:
print '
Running
tests
on
symbolic
references
'
try:
re.sub('
(
?
P
<
a
>
x
)
', '
\
g
<
a
', '
xx
')
except re.error, reason:
pass
else:
raise TestFailed, "symbolic reference"
try:
re.sub('
(
?
P
<
a
>
x
)
', '
\
g
<
', '
xx
')
except re.error, reason:
pass
else:
raise TestFailed, "symbolic reference"
try:
re.sub('
(
?
P
<
a
>
x
)
', '
\
g
', '
xx
')
except re.error, reason:
pass
else:
raise TestFailed, "symbolic reference"
try:
re.sub('
(
?
P
<
a
>
x
)
', '
\
g
<
a
a
>
', '
xx
')
except re.error, reason:
pass
else:
raise TestFailed, "symbolic reference"
try:
re.sub('
(
?
P
<
a
>
x
)
', '
\
g
<
ab
>
', '
xx
')
except IndexError, reason:
pass
else:
raise TestFailed, "symbolic reference"
try:
re.sub('
(
?
P
<
a
>
x
)
|
(
?
P
<
b
>
y
)
', '
\
g
<
b
>
', '
xx
')
except re.error, reason:
pass
else:
raise TestFailed, "symbolic reference"
try:
re.sub('
(
?
P
<
a
>
x
)
|
(
?
P
<
b
>
y
)
', '
\\
2
', '
xx
')
except re.error, reason:
pass
else:
raise TestFailed, "symbolic reference"
if verbose:
print '
Running
tests
on
re
.
subn
'
try:
try:
assert re.subn("(?i)b+", "x", "bbbb BBBB") == ('
x
x
', 2)
assert re.subn("(?i)b+", "x", "bbbb BBBB") == ('
x
x
', 2)
assert re.subn("b+", "x", "bbbb BBBB") == ('
x
BBBB
', 1)
assert re.subn("b+", "x", "bbbb BBBB") == ('
x
BBBB
', 1)
assert re.subn("b+", "x", "xyz") == ('
xyz
', 0)
assert re.subn("b+", "x", "xyz") == ('
xyz
', 0)
assert re.subn("b*", "x", "xyz") == ('
xxxyxzx
', 4)
assert re.subn("b*", "x", "xyz") == ('
xxxyxzx
', 4)
except AssertionError:
except AssertionError:
raise TestFailed, "re.subn"
raise TestFailed, "re.subn"
if verbose:
print '
Running
tests
on
re
.
split
'
try:
try:
assert re.split(":", ":a:b::c") == ['', '
a
', 'b', '', '
c
']
assert re.split(":", ":a:b::c") == ['', '
a
', 'b', '', '
c
']
assert re.split(":*", ":a:b::c") == ['', '
a
', 'b', '
c
']
assert re.split(":*", ":a:b::c") == ['', '
a
', 'b', '
c
']
...
@@ -47,14 +109,15 @@ try:
...
@@ -47,14 +109,15 @@ try:
assert re.split("(:)*", ":a:b::c") == ['', '
:
', '
a
', '
:
', 'b', '
:
', '
c
']
assert re.split("(:)*", ":a:b::c") == ['', '
:
', '
a
', '
:
', 'b', '
:
', '
c
']
assert re.split("([b:]+)", ":a:b::c") == ['', '
:
', '
a
', '
:
b
::
', '
c
']
assert re.split("([b:]+)", ":a:b::c") == ['', '
:
', '
a
', '
:
b
::
', '
c
']
assert re.split("(b)|(:+)", ":a:b::c") ==
\
assert re.split("(b)|(:+)", ":a:b::c") ==
\
['', None, ':', 'a', None, ':', '', 'b', None, '', None, '::', 'c']
['', None, '
:
', '
a
', None, '
:
', '', 'b', None, '', None, '
::
', '
c
']
assert re.split("(?:b)|(?::+)", ":a:b::c") == ['', '
a
', '', '', '
c
']
assert re.split("(?:b)|(?::+)", ":a:b::c") == ['', '
a
', '', '', '
c
']
except AssertionError:
except AssertionError:
raise TestFailed, "re.split"
raise TestFailed, "re.split"
from re_tests import *
from re_tests import *
if verbose: print 'Running re_tests test suite'
if verbose:
print '
Running
re_tests
test
suite
'
for t in tests:
for t in tests:
print t
print t
...
@@ -73,8 +136,6 @@ for t in tests:
...
@@ -73,8 +136,6 @@ for t in tests:
if outcome==SYNTAX_ERROR: pass # Expected a syntax error
if outcome==SYNTAX_ERROR: pass # Expected a syntax error
else:
else:
print '
===
Syntax
error
:
', t
print '
===
Syntax
error
:
', t
except KeyboardInterrupt:
raise KeyboardInterrupt
except:
except:
print '
***
Unexpected
error
***
'
print '
***
Unexpected
error
***
'
if verbose:
if verbose:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment