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.

38 lines
1.2 KiB

  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import
  3. import logging
  4. import sys
  5. import unittest
  6. logging.basicConfig(level=logging.INFO)
  7. from lark.lark import Lark
  8. class TestRegex(unittest.TestCase):
  9. @unittest.skipIf(sys.version_info[0] == 2, 'Unicode and Python 2 do not place nicely together.')
  10. def test_unicode_class(self):
  11. "Tests that character classes from the `regex` module work correctly."
  12. g = Lark(r"""
  13. ?start: NAME
  14. NAME: ID_START ID_CONTINUE*
  15. ID_START: /[\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}_]+/
  16. ID_CONTINUE: ID_START | /[\p{Mn}\p{Mc}\p{Nd}\p{Pc}·]+/
  17. """, regex=True)
  18. self.assertEqual(g.parse('வணக்கம்'), 'வணக்கம்')
  19. @unittest.skipIf(sys.version_info[0] == 2, 'Unicode and Python 2 do not place nicely together.')
  20. def test_unicode_word(self):
  21. "Tests that a persistent bug in the `re` module works when `regex` is enabled."
  22. g = Lark(r"""
  23. ?start: NAME
  24. NAME: /[\w]+/
  25. """, regex=True)
  26. self.assertEqual(g.parse('வணக்கம்'), 'வணக்கம்')
  27. if __name__ == '__main__':
  28. unittest.main()