Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
Adds encode to the Context class and tests encode / decode
Browse files Browse the repository at this point in the history
Signed-off-by: ncordon <[email protected]>
  • Loading branch information
ncordon committed Sep 11, 2019
1 parent 6806c93 commit 05f7ac2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bblfsh/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ def iterate(self, order: int) -> iterator:
TreeOrder.check_order(order)
return iterator(self.root, order)

def encode(self, fmt: int):
encoded = self.ctx.encode(self.root, fmt)
return encoded

def context(root: dict) -> Context:
return Context(root)
10 changes: 10 additions & 0 deletions bblfsh/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,16 @@ def testPythonContextFilter(self) -> None:
for nodeC, nodePy in zip(itC, itPy):
self.assertEqual(nodeC.get(), nodePy)

def testEncodeDecodePythonContext(self) -> None:
# C++ memory context
ctxC = self._parse_fixture()
# Python memory context
pyDict = ctxC.root.get()
ctxPy = bblfsh.context(pyDict)
encoded = ctxPy.encode(fmt = 1) # YAML
decoded = decode(encoded, format = 1)

self.assertEqual(encoded, decoded.load())

if __name__ == "__main__":
unittest.main()

0 comments on commit 05f7ac2

Please sign in to comment.