diff options
author | Thomas Robitaille <thomas.robitaille@gmail.com> | 2018-02-09 12:56:45 +0000 |
---|---|---|
committer | Thomas Robitaille <thomas.robitaille@gmail.com> | 2018-02-09 12:57:15 +0000 |
commit | 763acec600d5d491cea33fbf59cc61a098d816b9 (patch) | |
tree | ec4018fdccede1e629eaee3add406a31665f18e5 | |
parent | 6860652be4069eaac8be88af1400f69a5197284f (diff) | |
download | ply-763acec600d5d491cea33fbf59cc61a098d816b9.tar.gz |
Added regression test for bug in Python 3 with reflags and optimize=True (in Python 3, re module flags are RegexFlags instances, not integers)
-rw-r--r-- | test/lex_optimize4.py | 26 | ||||
-rwxr-xr-x | test/testlex.py | 20 |
2 files changed, 46 insertions, 0 deletions
diff --git a/test/lex_optimize4.py b/test/lex_optimize4.py new file mode 100644 index 0000000..cc6e2a9 --- /dev/null +++ b/test/lex_optimize4.py @@ -0,0 +1,26 @@ +# ----------------------------------------------------------------------------- +# lex_optimize4.py +# ----------------------------------------------------------------------------- +import re +import sys + +if ".." not in sys.path: sys.path.insert(0,"..") +import ply.lex as lex + +tokens = [ + "PLUS", + "MINUS", + "NUMBER", + ] + +t_PLUS = r'\+?' +t_MINUS = r'-' +t_NUMBER = r'(\d+)' + +def t_error(t): + pass + + +# Build the lexer +lex.lex(optimize=True, lextab="opt4tab", reflags=re.UNICODE) +lex.runmain(data="3+4") diff --git a/test/testlex.py b/test/testlex.py index 3880f6f..83070a7 100755 --- a/test/testlex.py +++ b/test/testlex.py @@ -514,6 +514,26 @@ class LexBuildOptionTests(unittest.TestCase): except OSError: pass + def test_lex_optimize4(self): + + # Regression test to make sure that reflags works correctly + # on Python 3. + + for extension in ['py', 'pyc']: + try: + os.remove("opt4tab.{0}".format(extension)) + except OSError: + pass + + run_import("lex_optimize4") + run_import("lex_optimize4") + + for extension in ['py', 'pyc']: + try: + os.remove("opt4tab.{0}".format(extension)) + except OSError: + pass + def test_lex_opt_alias(self): try: os.remove("aliastab.py") |