This repo contains code to mirror other repos. It also contains the code that is getting mirrored.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
988 B

  1. from __future__ import absolute_import
  2. import sys
  3. import unittest
  4. from unittest import TestCase
  5. from lark.tree import Tree
  6. from lark.tools import standalone
  7. try:
  8. from StringIO import StringIO
  9. except ImportError:
  10. from io import StringIO
  11. class TestStandalone(TestCase):
  12. def setUp(self):
  13. pass
  14. def test_simple(self):
  15. grammar = """
  16. start: NUMBER WORD
  17. %import common.NUMBER
  18. %import common.WORD
  19. %import common.WS
  20. %ignore WS
  21. """
  22. code_buf = StringIO()
  23. temp = sys.stdout
  24. sys.stdout = code_buf
  25. standalone.main(StringIO(grammar), 'start')
  26. sys.stdout = temp
  27. code = code_buf.getvalue()
  28. context = {}
  29. exec(code, context)
  30. _Lark = context['Lark_StandAlone']
  31. l = _Lark()
  32. x = l.parse('12 elephants')
  33. self.assertEqual(x.children, ['12', 'elephants'])
  34. if __name__ == '__main__':
  35. unittest.main()