summaryrefslogtreecommitdiff
path: root/Cython/Compiler/Tests
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2016-03-19 15:24:56 +0100
committerStefan Behnel <stefan_ml@behnel.de>2016-03-19 15:24:56 +0100
commit53fc37a9f073b9a39ea7785f22c3f0ac051eb364 (patch)
treed9ff5e4fe93ee513a0772aacb69d362ef128b7ae /Cython/Compiler/Tests
parentd7ac5174229a4fe94e7f3e8dead9c32069bc79aa (diff)
downloadcython-53fc37a9f073b9a39ea7785f22c3f0ac051eb364.tar.gz
adapt to stricter version of the CPython implementation (that follows the actual PEP)
Diffstat (limited to 'Cython/Compiler/Tests')
-rw-r--r--Cython/Compiler/Tests/TestGrammar.py88
1 files changed, 40 insertions, 48 deletions
diff --git a/Cython/Compiler/Tests/TestGrammar.py b/Cython/Compiler/Tests/TestGrammar.py
index f73334162..a6b839c9d 100644
--- a/Cython/Compiler/Tests/TestGrammar.py
+++ b/Cython/Compiler/Tests/TestGrammar.py
@@ -10,58 +10,66 @@ from __future__ import absolute_import
from ...TestUtils import CythonTest
from ..Errors import CompileError
-
+# Copied from CPython's test_grammar.py
VALID_UNDERSCORE_LITERALS = [
- # Copied from CPython's test_grammar.py
'0_0_0',
'4_2',
- '4_______2',
'1_0000_0000',
- '0b_1001_0100',
- '0x_ffff_ffff',
- '0o_5_7_7',
- '1__.4',
- '42_j',
- '1.4_j',
- '1.4e5_j',
- '1_00_00_.5',
- '1_e10',
- '1_E10',
- '1_e1_0',
+ '0b1001_0100',
+ '0xffff_ffff',
+ '0o5_7_7',
+ '1_00_00.5',
+ '1e1_0',
'.1_4',
+]
+
+# Copied from CPython's test_grammar.py
+INVALID_UNDERSCORE_LITERALS = [
+ # Trailing underscores:
'0_',
'42_',
+ '1.4j_',
'0b1_',
'0xf_',
'0o5_',
-]
-
-INVALID_UNDERSCORE_LITERALS = [
- # Copied from CPython's test_grammar.py
- # Trailing underscores:
# Underscores in the base selector:
'0_b0',
'0_xf',
'0_o5',
+ # Underscore right after the base selector:
+ '0b_0',
+ '0x_f',
+ '0o_5',
# Old-style octal, still disallowed:
#'0_7',
#'09_99',
- # Underscore after non-digit:
- '1.4j_',
- '1.4e_1',
- '.1_4e_1',
- '1.0e+_1',
+ # Special case with exponent:
+ '0 if 1_Else 1',
+ # Underscore right before a dot:
+ '1_.4',
+ '1_.4j',
+ # Underscore right after a dot:
'1._4',
'1._4j',
- '1._4e5_j',
'._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),
+ # Underscore right after a sign:
+ '1.0e+_1',
+ # Multiple consecutive underscores:
+ '4_______2',
+ '0.1__4',
+ '0b1001__0100',
+ '0xffff__ffff',
+ '0o5__77',
+ '1e1__0',
+ # Underscore right before j:
+ '1.4_j',
+ '1.4e5_j',
+ # Underscore right before e:
+ '1_e1',
+ '1.4_e1',
+ # Underscore right after e:
+ '1e_1',
+ '1.4e_1',
]
@@ -88,22 +96,6 @@ 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