| 1 | """ |
| 2 | These tests test Jedi's Parso usage. Basically there's not a lot of tests here, |
| 3 | because we're just checking if the API works. Bugfixes should be done in parso, |
| 4 | mostly. |
| 5 | """ |
| 6 | |
| 7 | from textwrap import dedent |
| 8 | |
| 9 | import pytest |
| 10 | |
| 11 | |
| 12 | @pytest.mark.parametrize( |
| 13 | 'code, line, column, until_line, until_column, message', [ |
| 14 | ('?\n', 1, 0, 1, 1, 'SyntaxError: invalid syntax'), |
| 15 | ('x %% y', 1, 3, 1, 4, 'SyntaxError: invalid syntax'), |
| 16 | ('"""\n\n', 1, 0, 3, 0, 'SyntaxError: EOF while scanning triple-quoted string literal'), |
| 17 | ('(1, 2\n', 2, 0, 2, 0, 'SyntaxError: invalid syntax'), |
| 18 | ('foo(1, 2\ndef x(): pass', 2, 0, 2, 3, 'SyntaxError: invalid syntax'), |
| 19 | ] |
| 20 | ) |
| 21 | def test_simple_syntax_errors(Script, code, line, column, until_line, until_column, message): |
| 22 | e, = Script(code).get_syntax_errors() |
| 23 | assert e.line == line |
| 24 | assert e.column == column |
| 25 | assert e.until_line == until_line |
| 26 | assert e.until_column == until_column |
| 27 | assert e.get_message() == message |
| 28 | |
| 29 | |
| 30 | @pytest.mark.parametrize( |
| 31 | 'code', [ |
| 32 | 'x % y', |
| 33 | 'def x(x): pass', |
| 34 | 'def x(x):\n pass', |
| 35 | ] |
| 36 | ) |
| 37 | def test_no_syntax_errors(Script, code): |
| 38 | assert not Script(code).get_syntax_errors() |
| 39 | |
| 40 | |
| 41 | def test_multi_syntax_error(Script): |
| 42 | code = dedent('''\ |
| 43 | def x(): |
| 44 | 1 |
| 45 | def y() |
| 46 | 1 + 1 |
| 47 | 1 *** 3 |
| 48 | ''') |
| 49 | x, y, power = Script(code).get_syntax_errors() |
| 50 | assert x.line == 2 |
| 51 | assert x.column == 0 |
| 52 | assert y.line == 3 |
| 53 | assert y.column == 7 |
| 54 | assert power.line == 5 |
| 55 | assert power.column == 4 |