diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2016-03-19 11:29:22 +0100 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2016-03-19 11:29:22 +0100 |
commit | d7ac5174229a4fe94e7f3e8dead9c32069bc79aa (patch) | |
tree | 0c3a41fe79b8f851b8d5bcb2e8d9b038d8a38d06 | |
parent | 0c1a8b4d079f6602a8da2c23abbadb0a8c59e5f7 (diff) | |
download | cython-d7ac5174229a4fe94e7f3e8dead9c32069bc79aa.tar.gz |
extend tests to include an ambiguity in Python 3.x grammar: "e" for exponent or start of "else"
-rw-r--r-- | Cython/Compiler/Tests/TestGrammar.py | 23 | ||||
-rw-r--r-- | tests/run/int_literals.pyx | 2 |
2 files changed, 25 insertions, 0 deletions
diff --git a/Cython/Compiler/Tests/TestGrammar.py b/Cython/Compiler/Tests/TestGrammar.py index b3212cd82..f73334162 100644 --- a/Cython/Compiler/Tests/TestGrammar.py +++ b/Cython/Compiler/Tests/TestGrammar.py @@ -57,6 +57,13 @@ INVALID_UNDERSCORE_LITERALS = [ '._5', ] +UNDERSCORE_EXPRESSIONS = [ + ('0 if 1_____else 1', True), + ('0 if 1_____Else 1', False), + ('0 if 1.0_____else 1', True), + ('0 if 1.0_____Else 1', False), +] + class TestGrammar(CythonTest): @@ -81,6 +88,22 @@ class TestGrammar(CythonTest): # cython: language_level=3 ''' + code) is not None + def test_underscore_number_expressions(self): + for expression, is_valid in UNDERSCORE_EXPRESSIONS: + code = 'x = ' + expression + fragment = u'''\ + # cython: language_level=3 + ''' + code + if is_valid: + assert self.fragment(fragment) is not None + else: + try: + self.fragment(fragment) + except CompileError as exc: + assert code in [s.strip() for s in str(exc).splitlines()], str(exc) + else: + assert False, "Invalid Cython code '%s' failed to raise an exception" % code + if __name__ == "__main__": import unittest diff --git a/tests/run/int_literals.pyx b/tests/run/int_literals.pyx index 014c48d57..790d1b70e 100644 --- a/tests/run/int_literals.pyx +++ b/tests/run/int_literals.pyx @@ -35,6 +35,8 @@ def valid_underscore_literals(): assert 0b1_ == 0b1 assert 0xf_ == 0xf assert 0o5_ == 0o5 + assert (0 if 1_____else 1) == 0 + assert (0 if 1.0_____else 1) == 0 @cython.test_assert_path_exists( |