-
-
Notifications
You must be signed in to change notification settings - Fork 456
Support excluding multiline regexes (fix #996) #1807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
8911cd8
9a239ea
58927e1
7e6ed52
4ca93bb
5210066
1dd9914
efa4984
a0f9ac8
d9e53ca
f317ca9
dc125f5
312c79c
d653f54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -781,7 +781,7 @@ def function() -> int: | |
assert parser.raw_statements == {1, 3, 4, 5, 6, 8, 9} | ||
assert parser.statements == {1, 8, 9} | ||
|
||
def test_multiline_exclusion(self) -> None: | ||
def test_multiline_exclusion_single_line(self) -> None: | ||
regex = r"print\('.*'\)" | ||
parser = self.parse_text("""\ | ||
def foo(): | ||
|
@@ -791,17 +791,19 @@ def foo(): | |
assert parser.raw_statements == {1, 2} | ||
assert parser.statements == {1} | ||
|
||
regex = r"if True:\n\s+print\('Hello, world!'\)" | ||
def test_multiline_exclusion_suite(self) -> None: | ||
regex = r"if T:\n\s+print\('Hello, world!'\)" | ||
parser = self.parse_text("""\ | ||
def foo(): | ||
if True: | ||
if T: | ||
print('Hello, world!') | ||
print('This is a multiline regex test.') | ||
""", regex) | ||
devdanzin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
assert parser.lines_matching(regex) == {2, 3} | ||
assert parser.raw_statements == {1, 2, 3, 4} | ||
assert parser.statements == {1} | ||
|
||
def test_multiline_exclusion_no_match(self) -> None: | ||
regex = r"nonexistent" | ||
parser = self.parse_text("""\ | ||
def foo(): | ||
|
@@ -811,12 +813,14 @@ def foo(): | |
assert parser.raw_statements == {1, 2} | ||
assert parser.statements == {1, 2} | ||
|
||
def test_multiline_exclusion_no_source(self) -> None: | ||
regex = r"anything" | ||
parser = PythonParser(text="", filename="dummy.py", exclude=regex) | ||
assert parser.lines_matching(regex) == set() | ||
assert parser.raw_statements == set() | ||
assert parser.statements == set() | ||
|
||
def test_multiline_exclusion_multiple_matches(self) -> None: | ||
regex = r"print\('.*'\)" | ||
|
||
parser = self.parse_text("""\ | ||
def foo(): | ||
|
@@ -828,22 +832,25 @@ def bar(): | |
assert parser.raw_statements == {1, 2, 3, 4} | ||
assert parser.statements == {1, 3} | ||
|
||
regex = r"print\('Hello, world!'\)\n\s+if True:" | ||
def test_multiline_exclusion_suite2(self) -> None: | ||
regex = r"print\('Hello, world!'\)\n\s+if T:" | ||
parser = self.parse_text("""\ | ||
def foo(): | ||
print('Hello, world!') | ||
if True: | ||
if T: | ||
print('This is a test.') | ||
""", regex) | ||
devdanzin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
assert parser.lines_matching(regex) == {2, 3} | ||
assert parser.raw_statements == {1, 2, 3, 4} | ||
assert parser.statements == {1} | ||
|
||
regex = r"""def foo\(\):\n\s+print\('Hello, world!'\)\n\s+if True:\n\s+print\('This is a test\.'\)""" | ||
def test_multiline_exclusion_match_all(self) -> None: | ||
regex = (r"""def foo\(\):\n\s+print\('Hello, world!'\)\n" | ||
"\s+if T:\n\s+print\('This is a test\.'\)""") | ||
parser = self.parse_text("""\ | ||
def foo(): | ||
print('Hello, world!') | ||
if True: | ||
if T: | ||
print('This is a test.') | ||
""", regex) | ||
devdanzin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
assert parser.lines_matching(regex) == {1, 2, 3, 4} | ||
|
Uh oh!
There was an error while loading. Please reload this page.