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
acaff520
Commit
acaff520
authored
Aug 08, 2000
by
Fredrik Lundh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
-- whitespace cleanup (more tests to be added in the next commit)
parent
d5929b3c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
23 deletions
+23
-23
Lib/test/test_re.py
Lib/test/test_re.py
+23
-23
No files found.
Lib/test/test_re.py
View file @
acaff520
...
...
@@ -37,20 +37,20 @@ if verbose:
try
:
assert
re
.
sub
(
"(?i)b+"
,
"x"
,
"bbbb BBBB"
)
==
'x x'
def
bump_num
(
matchobj
):
int_value
=
int
(
matchobj
.
group
(
0
))
return
str
(
int_value
+
1
)
assert
re
.
sub
(
r'\
d+
', bump_num, '
08.2
-
2
23
x99y
') == '
9.3
-
3
24
x100y
'
assert re.sub(r'
\
d
+
', bump_num, '
08.2
-
2
23
x99y
', 3) == '
9.3
-
3
23
x99y
'
assert re.sub('
.
', lambda m: r"
\
n
", '
x
') == '
\\
n
'
assert re.sub('
.
', r"
\
n
", '
x
') == '
\
n
'
s = r"
\
1
\
1
"
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('
(
?
P
<
a
>
x
)
', '
\
g
<
a
>
\
g
<
a
>
', '
xx
') == '
xxxx
'
...
...
@@ -146,7 +146,7 @@ except AssertionError:
if verbose:
print '
Running
tests
on
re
.
split
'
try:
assert re.split(":", ":a:b::c") == ['', '
a
', 'b', '', '
c
']
assert re.split(":*", ":a:b::c") == ['', '
a
', 'b', '
c
']
...
...
@@ -165,7 +165,7 @@ try:
assert re.split('
:
', '
a
:
b
:
c
:
d
', 2) == ['
a
', 'b', '
c
:
d
']
assert re.split("(:)", ":a:b::c", 2) == ['', '
:
', '
a
', '
:
', '
b
::
c
']
assert re.split("(:*)", ":a:b::c", 2) == ['', '
:
', '
a
', '
:
', '
b
::
c
']
assert re.split("(:*)", ":a:b::c", 2) == ['', '
:
', '
a
', '
:
', '
b
::
c
']
except AssertionError:
raise TestFailed, "qualified re.split"
...
...
@@ -187,29 +187,29 @@ if verbose:
try:
# No groups at all
m = re.match('
a
', '
a
') ; assert m.groups() == ()
m = re.match('
a
', '
a
') ; assert m.groups() == ()
# A single group
m = re.match('
(
a
)
', '
a
') ; assert m.groups() == ('
a
',)
m = re.match('
(
a
)
', '
a
') ; assert m.groups() == ('
a
',)
pat = re.compile('
((
a
)
|
(
b
))(
c
)
?
')
assert pat.match('
a
').groups() == ('
a
', '
a
', None, None)
assert pat.match('b').groups() == ('b', None, 'b', None)
assert pat.match('
ac
').groups() == ('
a
', '
a
', None, '
c
')
assert pat.match('
bc
').groups() == ('b', None, 'b', '
c
')
assert pat.match('
bc
').groups("") == ('b', "", 'b', '
c
')
assert pat.match('
a
').groups() == ('
a
', '
a
', None, None)
assert pat.match('b').groups() == ('b', None, 'b', None)
assert pat.match('
ac
').groups() == ('
a
', '
a
', None, '
c
')
assert pat.match('
bc
').groups() == ('b', None, 'b', '
c
')
assert pat.match('
bc
').groups("") == ('b', "", 'b', '
c
')
except AssertionError:
raise TestFailed, "match .groups() method"
try:
# A single group
m = re.match('
(
a
)
', '
a
')
assert m.group(0) == '
a
' ; assert m.group(0) == '
a
'
m = re.match('
(
a
)
', '
a
')
assert m.group(0) == '
a
' ; assert m.group(0) == '
a
'
assert m.group(1) == '
a
' ; assert m.group(1, 1) == ('
a
', '
a
')
pat = re.compile('
(
?
:(
?
P
<
a1
>
a
)
|
(
?
P
<
b2
>
b
))(
?
P
<
c3
>
c
)
?
')
assert pat.match('
a
').group(1, 2, 3) == ('
a
', None, None)
assert pat.match('b').group('
a1
', '
b2
', '
c3
') == (None, 'b', None)
assert pat.match('
ac
').group(1, '
b2
', 3) == ('
a
', None, '
c
')
assert pat.match('
a
').group(1, 2, 3) == ('
a
', None, None)
assert pat.match('b').group('
a1
', '
b2
', '
c3
') == (None, 'b', None)
assert pat.match('
ac
').group(1, '
b2
', 3) == ('
a
', None, '
c
')
except AssertionError:
raise TestFailed, "match .group() method"
...
...
@@ -242,8 +242,8 @@ try:
assert re.I == re.IGNORECASE
assert re.L == re.LOCALE
assert re.M == re.MULTILINE
assert re.S == re.DOTALL
assert re.X == re.VERBOSE
assert re.S == re.DOTALL
assert re.X == re.VERBOSE
except AssertionError:
raise TestFailed, '
re
module
constants
'
...
...
@@ -260,7 +260,7 @@ if verbose:
else:
# To save time, only run the first and last 10 tests
#tests = tests[:10] + tests[-10:]
pass
pass
for t in tests:
sys.stdout.flush()
...
...
@@ -268,7 +268,7 @@ for t in tests:
if len(t)==5:
pattern, s, outcome, repl, expected = t
elif len(t)==3:
pattern, s, outcome = t
pattern, s, outcome = t
else:
raise ValueError, ('
Test
tuples
should
have
3
or
5
fields
',t)
...
...
@@ -276,7 +276,7 @@ for t in tests:
obj=re.compile(pattern)
except re.error:
if outcome==SYNTAX_ERROR: pass # Expected a syntax error
else:
else:
print '
===
Syntax
error
:
', t
except KeyboardInterrupt: raise KeyboardInterrupt
except:
...
...
@@ -330,7 +330,7 @@ for t in tests:
# of the match and see if it still succeeds.
\
B will
# break (because it won'
t
match
at
the
end
or
start
of
a
# string), so we'll ignore patterns that feature it.
if
pattern
[:
2
]
!=
'
\
\
B'
and
pattern
[
-
2
:]
!=
'
\
\
B'
and
result
!=
None
:
obj
=
re
.
compile
(
pattern
)
result
=
obj
.
search
(
s
,
result
.
start
(
0
),
result
.
end
(
0
)
+
1
)
...
...
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