-
-
Notifications
You must be signed in to change notification settings - Fork 437
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
Support excluding multiline regexes (fix #996) #1807
Changes from 3 commits
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
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -781,6 +781,82 @@ def function() -> int: | |
assert parser.raw_statements == {1, 3, 4, 5, 6, 8, 9} | ||
assert parser.statements == {1, 8, 9} | ||
|
||
def test_multiline_exclusion_single_line(self) -> None: | ||
regex = r"print\('.*'\)" | ||
parser = self.parse_text("""\ | ||
def foo(): | ||
print('Hello, world!') | ||
""", regex) | ||
devdanzin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert parser.lines_matching(regex) == {2} | ||
assert parser.raw_statements == {1, 2} | ||
assert parser.statements == {1} | ||
|
||
def test_multiline_exclusion_suite(self) -> None: | ||
devdanzin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
regex = r"if T:\n\s+print\('Hello, world!'\)" | ||
parser = self.parse_text("""\ | ||
def foo(): | ||
if T: | ||
print('Hello, world!') | ||
print('This is a multiline regex test.') | ||
""", regex) | ||
devdanzin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert parser.lines_matching(regex) == {2, 3} | ||
assert parser.raw_statements == {1, 2, 3, 4} | ||
assert parser.statements == {1} | ||
devdanzin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def test_multiline_exclusion_no_match(self) -> None: | ||
regex = r"nonexistent" | ||
parser = self.parse_text("""\ | ||
def foo(): | ||
print('Hello, world!') | ||
""", regex) | ||
devdanzin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert parser.lines_matching(regex) == set() | ||
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\('.*'\)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't a multi-line regex? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, that was just a sanity check from when I was sketching this that slipped through. I'll rewrite the test so it covers multiple multi-line matches. |
||
parser = self.parse_text("""\ | ||
def foo(): | ||
print('Hello, world!') | ||
def bar(): | ||
print('Hello again!') | ||
""", regex) | ||
devdanzin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert parser.lines_matching(regex) == {2, 4} | ||
assert parser.raw_statements == {1, 2, 3, 4} | ||
assert parser.statements == {1, 3} | ||
|
||
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 T: | ||
print('This is a test.') | ||
""", regex) | ||
devdanzin marked this conversation as resolved.
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_match_all(self) -> None: | ||
regex = (r"def foo\(\):\n\s+print\('Hello, world!'\)\n" | ||
r"\s+if T:\n\s+print\('This is a test\.'\)") | ||
devdanzin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
parser = self.parse_text("""\ | ||
def foo(): | ||
print('Hello, world!') | ||
if T: | ||
print('This is a test.') | ||
""", regex) | ||
devdanzin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert parser.lines_matching(regex) == {1, 2, 3, 4} | ||
assert parser.raw_statements == {1, 2, 3, 4} | ||
assert parser.statements == set() | ||
|
||
|
||
class ParserMissingArcDescriptionTest(PythonParserTestBase): | ||
"""Tests for PythonParser.missing_arc_description.""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please indent the code strings like this:
This should match the way other code is included in tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Done.