Skip to content
This repository was archived by the owner on Aug 26, 2020. It is now read-only.

_impl.py: Fix alphanum character class #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/js_regex/_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def compile(pattern, flags=0):
(r"\a", "\a"),
(r"\d", "[0-9]"),
(r"\D", "[^0-9]"),
(r"\w", "[A-Za-z]"),
(r"\W", "[^A-Za-z]"),
(r"\w", "[A-Za-z0-9_]"),
(r"\W", "[^A-Za-z0-9_]"),
(r"\s", "[ \t\n\r\x0b\x0c]"),
(r"\S", "[^ \t\n\r\x0b\x0c]"),
]:
Expand Down
19 changes: 19 additions & 0 deletions test_js_regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@
def test_expected_transforms(pattern, good_match, bad_match):
regex = js_regex.compile(pattern)
assert regex.search(good_match)
assert len(regex.findall(good_match)) == 1
assert not regex.search(bad_match)


@pytest.mark.parametrize(
"pattern,good_match,bad_match",
[
("^abc\n$", "abc\n", "abc"),
("^abc$|^def$", "abc", "abc\n"),
("^abc$|^def$", "def", "def\n"),
(r"^abc\$", "abc$", "abc"),
],
)
def test_expected_multiline_transforms(pattern, good_match, bad_match):
regex = js_regex.compile(pattern, re.MULTILINE)
assert regex.search(good_match)
assert len(regex.findall(good_match)) == 1
assert not regex.search(bad_match)


Expand All @@ -41,6 +58,8 @@ def test_expected_transforms(pattern, good_match, bad_match):
pytest.param(r"\d", "1", "߀", marks=SKIP_ON_PY2), # NKO DIGIT ZERO
(r"\D", "߀", "1"),
pytest.param(r"\w", "a", "é", marks=SKIP_ON_PY2), # Latin-1 e-acute
(r"\w", "1", "߀"),
(r"\w", "_", "/"),
(r"\W", "é", "a"),
pytest.param(r"\s", "\t", "\xa0", marks=SKIP_ON_PY2), # non-breaking space
(r"\S", "\xa0", "\t"),
Expand Down