Skip to content
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

Add new test for _parse_file #181

Merged
merged 1 commit into from
Sep 28, 2018
Merged
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
2 changes: 2 additions & 0 deletions lookout/style/format/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,8 @@ def _parse_file(self, contents: str, root: bblfsh.Node, path: str) -> \
parser = self.tokens.PARSER
searchsorted = numpy.searchsorted
for node in node_tokens:
if node.start_position.offset < pos:
continue
if node.start_position.offset > pos:
sumlen = 0
diff = contents[pos:node.start_position.offset]
Expand Down
Binary file added lookout/style/format/tests/for_parse_test.js.xz
Binary file not shown.
9 changes: 9 additions & 0 deletions lookout/style/format/tests/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ def setUpClass(cls):
cls.uast = bblfsh.Node.FromString(fin.read())
cls.extractor = FeatureExtractor("javascript", parents_depth=2, siblings_window=5)

def test_parse_file_exact_match(self):
test_js_code_filepath = Path(__file__).parent / "for_parse_test.js.xz"
with lzma.open(str(test_js_code_filepath), mode="rt") as f:
code = f.read()
uast = bblfsh.BblfshClient("0.0.0.0:9432").parse(
filename="", language="javascript", contents=code.encode()).uast
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to specify filename when contents is set. It could also be good to just bypass babelfish and just use a saved uast as we do in the other tests. Up to you :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope. here the header of parse function: def parse(self, filename, language=None, contents=None, timeout=None): also the file name goes to bblfsh logs.
When we update to the next version of a bblfsh driver, we have to update this files.
I prefer to have it like that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, even though we will have to update all the other files in the folder anyway. And huh, this function signature needs refactoring, I'll open an issue.

nodes, parents = self.extractor._parse_file(code, uast, test_js_code_filepath)
self.assertEqual("".join(n.value for n in nodes), code)

def test_parse_file(self):
nodes, parents = self.extractor._parse_file(self.contents, self.uast, "test_file")
text = []
Expand Down