tests: Add tests to exercise lexer; and some more complex number tests.

This commit is contained in:
Damien George
2015-04-04 23:16:22 +01:00
parent 9dd3640464
commit 97abe22963
6 changed files with 122 additions and 3 deletions

View File

@@ -4,9 +4,28 @@ def test_syntax(code):
try:
exec(code)
print("no SyntaxError")
except IndentationError:
print("IndentationError")
except SyntaxError:
print("SyntaxError")
# non-newline after line-continuation character (lexer error)
test_syntax("a \\a\n")
# dedent mismatch (lexer error)
test_syntax("def f():\n a\n a\n")
# unclosed string (lexer error)
test_syntax("'abc")
# invalid (lexer error)
test_syntax("!")
test_syntax("$")
test_syntax("`")
# bad indentation (lexer error)
test_syntax(" a\n")
# can't assign to literals
test_syntax("1 = 2")
test_syntax("'' = 1")