Commit d7ac5174 authored by Stefan Behnel's avatar Stefan Behnel

extend tests to include an ambiguity in Python 3.x grammar: "e" for exponent or start of "else"

parent 0c1a8b4d
...@@ -57,6 +57,13 @@ INVALID_UNDERSCORE_LITERALS = [ ...@@ -57,6 +57,13 @@ INVALID_UNDERSCORE_LITERALS = [
'._5', '._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): class TestGrammar(CythonTest):
...@@ -81,6 +88,22 @@ class TestGrammar(CythonTest): ...@@ -81,6 +88,22 @@ class TestGrammar(CythonTest):
# cython: language_level=3 # cython: language_level=3
''' + code) is not None ''' + 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__": if __name__ == "__main__":
import unittest import unittest
......
...@@ -35,6 +35,8 @@ def valid_underscore_literals(): ...@@ -35,6 +35,8 @@ def valid_underscore_literals():
assert 0b1_ == 0b1 assert 0b1_ == 0b1
assert 0xf_ == 0xf assert 0xf_ == 0xf
assert 0o5_ == 0o5 assert 0o5_ == 0o5
assert (0 if 1_____else 1) == 0
assert (0 if 1.0_____else 1) == 0
@cython.test_assert_path_exists( @cython.test_assert_path_exists(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment