diff --git a/src/js_regex/_impl.py b/src/js_regex/_impl.py index 22931d3..ea75b1e 100644 --- a/src/js_regex/_impl.py +++ b/src/js_regex/_impl.py @@ -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]"), ]: diff --git a/test_js_regex.py b/test_js_regex.py index 79e1b6e..6166e3b 100644 --- a/test_js_regex.py +++ b/test_js_regex.py @@ -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) @@ -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"),