|
21 | 21 | import_helper, |
22 | 22 | skip_emscripten_stack_overflow, |
23 | 23 | skip_wasi_stack_overflow, |
| 24 | + subTests, |
24 | 25 | ) |
25 | 26 | from test.support.numbers import ( |
26 | 27 | VALID_UNDERSCORE_LITERALS, |
@@ -180,6 +181,27 @@ def check(test, error=False): |
180 | 181 | check("[0x1for x in ()]") |
181 | 182 | check("[0xfor x in ()]") |
182 | 183 |
|
| 184 | + @subTests('source,offset,msg', |
| 185 | + [("0xfg", 4, "hexadecimal"), |
| 186 | + ("0x9g", 4, "hexadecimal"), |
| 187 | + ("0b1z", 4, "binary"), |
| 188 | + ("0o7q", 4, "octal"), |
| 189 | + ("9spam", 2, " decimal"), |
| 190 | + ("0xfspam", 4, "hexadecimal"), |
| 191 | + ("1.0x", 4, " decimal"), |
| 192 | + ("1e3w", 4, " decimal"), |
| 193 | + ("1jz", 3, "imaginary"), |
| 194 | + ("0xI", 3, "hexadecimal"), |
| 195 | + ("0bz", 3, "binary"), |
| 196 | + ]) |
| 197 | + def test_end_of_numerical_literals_offset(self, source, offset, msg): |
| 198 | + # gh-149277: verify the error caret points at the first invalid |
| 199 | + # character, not the last valid digit. |
| 200 | + with self.assertRaises(SyntaxError) as cm: |
| 201 | + compile(source, "<test>", "eval") |
| 202 | + self.assertEqual(cm.exception.offset, offset) |
| 203 | + self.assertIn(msg, cm.exception.msg) |
| 204 | + |
183 | 205 | def test_string_literals(self): |
184 | 206 | x = ''; y = ""; self.assertTrue(len(x) == 0 and x == y) |
185 | 207 | x = '\''; y = "'"; self.assertTrue(len(x) == 1 and x == y and ord(x) == 39) |
|
0 commit comments