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
cb491529
Commit
cb491529
authored
Apr 25, 2003
by
Skip Montanaro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
final bit of tests converted from test_sre
parent
71a89eb7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
8 deletions
+25
-8
Lib/test/test_re.py
Lib/test/test_re.py
+25
-8
No files found.
Lib/test/test_re.py
View file @
cb491529
...
@@ -16,12 +16,12 @@ class ReTests(unittest.TestCase):
...
@@ -16,12 +16,12 @@ class ReTests(unittest.TestCase):
self
.
assertEqual
(
re
.
search
(
'x*'
,
'axx'
).
span
(),
(
0
,
0
))
self
.
assertEqual
(
re
.
search
(
'x*'
,
'axx'
).
span
(),
(
0
,
0
))
self
.
assertEqual
(
re
.
search
(
'x+'
,
'axx'
).
span
(
0
),
(
1
,
3
))
self
.
assertEqual
(
re
.
search
(
'x+'
,
'axx'
).
span
(
0
),
(
1
,
3
))
self
.
assertEqual
(
re
.
search
(
'x+'
,
'axx'
).
span
(),
(
1
,
3
))
self
.
assertEqual
(
re
.
search
(
'x+'
,
'axx'
).
span
(),
(
1
,
3
))
self
.
assertEqual
(
re
.
search
(
'x'
,
'aaa'
)
is
None
,
Tru
e
)
self
.
assertEqual
(
re
.
search
(
'x'
,
'aaa'
)
,
Non
e
)
self
.
assertEqual
(
re
.
match
(
'a*'
,
'xxx'
).
span
(
0
),
(
0
,
0
))
self
.
assertEqual
(
re
.
match
(
'a*'
,
'xxx'
).
span
(
0
),
(
0
,
0
))
self
.
assertEqual
(
re
.
match
(
'a*'
,
'xxx'
).
span
(),
(
0
,
0
))
self
.
assertEqual
(
re
.
match
(
'a*'
,
'xxx'
).
span
(),
(
0
,
0
))
self
.
assertEqual
(
re
.
match
(
'x*'
,
'xxxa'
).
span
(
0
),
(
0
,
3
))
self
.
assertEqual
(
re
.
match
(
'x*'
,
'xxxa'
).
span
(
0
),
(
0
,
3
))
self
.
assertEqual
(
re
.
match
(
'x*'
,
'xxxa'
).
span
(),
(
0
,
3
))
self
.
assertEqual
(
re
.
match
(
'x*'
,
'xxxa'
).
span
(),
(
0
,
3
))
self
.
assertEqual
(
re
.
match
(
'a+'
,
'xxx'
)
is
None
,
Tru
e
)
self
.
assertEqual
(
re
.
match
(
'a+'
,
'xxx'
)
,
Non
e
)
def
bump_num
(
self
,
matchobj
):
def
bump_num
(
self
,
matchobj
):
int_value
=
int
(
matchobj
.
group
(
0
))
int_value
=
int
(
matchobj
.
group
(
0
))
...
@@ -133,13 +133,16 @@ class ReTests(unittest.TestCase):
...
@@ -133,13 +133,16 @@ class ReTests(unittest.TestCase):
(":", ":"),
(":", ":"),
(":", "::")])
(":", "::")])
def test_bug_117612(self):
self.assertEqual(re.findall(r"(a|(b))", "aba"),
[("a", ""),("b", "b"),("a", "")])
def test_re_match(self):
def test_re_match(self):
# No groups at all
self.assertEqual(re.match('
a
', '
a
').groups(), ())
m = re.match('
a
', '
a
')
self.assertEqual(re.match('
(
a
)
', '
a
').groups(), ('
a
',))
self.assertEqual(m.groups(), ())
self.assertEqual(re.match(r'
(
a
)
', '
a
').group(0), '
a
')
# A single group
self.assertEqual(re.match(r'
(
a
)
', '
a
').group(1), '
a
')
m = re.match('
(
a
)
', '
a
')
self.assertEqual(re.match(r'
(
a
)
', '
a
').group(1, 1), ('
a
', '
a
'))
self.assertEqual(m.groups(), ('
a
',))
pat = re.compile('
((
a
)
|
(
b
))(
c
)
?
')
pat = re.compile('
((
a
)
|
(
b
))(
c
)
?
')
self.assertEqual(pat.match('
a
').groups(), ('
a
', '
a
', None, None))
self.assertEqual(pat.match('
a
').groups(), ('
a
', '
a
', None, None))
...
@@ -264,6 +267,20 @@ class ReTests(unittest.TestCase):
...
@@ -264,6 +267,20 @@ class ReTests(unittest.TestCase):
(['sum', 'op=', 3, 'op*', 'foo', 'op+', 312.5,
(['sum', 'op=', 3, 'op*', 'foo', 'op+', 312.5,
'op+', 'bar'], ''))
'op+', 'bar'], ''))
def test_bug_448951(self):
# bug 448951 (similar to 429357, but with single char match)
# (Also test greedy matches.)
for op in '','?','*':
self.assertEqual(re.match(r'((.%s):)?z'%op, 'z').groups(),
(None, None))
self.assertEqual(re.match(r'((.%s):)?z'%op, 'a:z').groups(),
('a:', 'a'))
def test_finditer(self):
iter = re.finditer(r"
:
+
", "
a
:
b
::
c
:::
d
")
self.assertEqual([item.group(0) for item in iter],
["
:
", "
::
", "
:::
"])
def run_re_tests():
def run_re_tests():
from test.re_tests import benchmarks, tests, SUCCEED, FAIL, SYNTAX_ERROR
from test.re_tests import benchmarks, tests, SUCCEED, FAIL, SYNTAX_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