-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve newlines when removing comments (#43)
- Loading branch information
Showing
2 changed files
with
30 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from unittest.mock import Mock | ||
|
||
from dissect.cstruct.parser import TokenParser | ||
|
||
|
||
def test_preserve_comment_newlines(): | ||
cdef = """ | ||
// normal comment | ||
#define normal_anchor | ||
/* | ||
* Multi | ||
* line | ||
* comment | ||
*/ | ||
#define multi_anchor | ||
""" | ||
data = TokenParser._remove_comments(cdef) | ||
print(repr(data)) | ||
|
||
mock_token = Mock() | ||
mock_token.match.string = data | ||
mock_token.match.start.return_value = data.index("#define normal_anchor") | ||
assert TokenParser._lineno(mock_token) == 3 | ||
|
||
mock_token.match.start.return_value = data.index("#define multi_anchor") | ||
assert TokenParser._lineno(mock_token) == 9 |