Skip to content

Commit

Permalink
Add test for global matches
Browse files Browse the repository at this point in the history
  • Loading branch information
radiac committed Sep 14, 2019
1 parent 2767ea5 commit 781144a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,26 @@ def test_utils__re_match():

# Clean up builtins
reset_vars()


def test_utils__re_match_global():
"""
Match with global flag
example::
var =~ /foo/g
"""
matches_iter = re.finditer(r"(.+?) ", "one two three four ")
assert hasattr(matches_iter, "__iter__")
matches = list(matches_iter)
assert len(matches) == 4
assert matches[0].groups() == ("one",)
assert matches[1].groups() == ("two",)
assert matches[2].groups() == ("three",)
assert matches[3].groups() == ("four",)

returned_matches_iter = re_match(re.finditer(r"(.+?) ", "one two three four "))
assert hasattr(returned_matches_iter, "__iter__")
returned_matches = list(returned_matches_iter)
assert [m.groups() for m in matches] == [m.groups() for m in returned_matches]

0 comments on commit 781144a

Please sign in to comment.