Commit 97abe229 authored by Damien George's avatar Damien George
Browse files

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

parent 9dd36404
# literals
print(b'123')
print(br'123')
print(rb'123')
print(b'\u1234')
# construction
print(bytes())
print(bytes(b'abc'))
a = b"123"
print(a)
......
# test the lexer
# __debug__ is a special symbol
print(type(__debug__))
# short input
exec("")
exec("\n")
exec("\n\n")
exec("\r")
exec("\r\r")
print(eval("1"))
print(eval("12"))
print(eval("123"))
print(eval("1\n"))
print(eval("12\n"))
print(eval("123\n"))
print(eval("1\r"))
print(eval("12\r"))
print(eval("123\r"))
# lots of indentation
def a(x):
if x:
if x:
if x:
if x:
if x:
if x:
if x:
if x:
if x:
if x:
if x:
if x:
if x:
if x:
if x:
print(x)
a(1)
# basic strings
# literals
print('abc')
print(r'abc')
print(u'abc')
print(repr('\a\b\t\n\v\f\r'))
print('\z') # unrecognised escape char
# construction
print(str())
print(str('abc'))
# inplace addition
x = 'abc'
print(x)
x += 'def'
print(x)
# binary ops
print('123' + "456")
print('123' * 5)
# subscription
print('abc'[1])
print('abc'[-1])
try:
......
......@@ -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")
......
......@@ -25,10 +25,17 @@ print(1j - 2j)
print(1j * 2)
print(1j * 2j)
print(1j / 2)
print((1j / 2j).real)
print(1j / (1 + 2j))
ans = 0j ** 0; print("%.5g %.5g" % (ans.real, ans.imag))
ans = 0j ** 0j; print("%.5g %.5g" % (ans.real, ans.imag))
ans = 1j ** 2.5; print("%.5g %.5g" % (ans.real, ans.imag))
ans = 1j ** 2.5j; print("%.5g %.5g" % (ans.real, ans.imag))
# comparison
print(1j == 1)
print(1j == 1j)
# builtin abs
print(abs(1j))
print("%.5g" % abs(1j + 2))
......@@ -44,3 +51,33 @@ try:
1j + []
except TypeError:
print("TypeError")
# unsupported unary op
try:
~(1j)
except TypeError:
print("TypeError")
# unsupported binary op
try:
1j // 2
except TypeError:
print("TypeError")
# unsupported binary op
try:
1j < 2j
except TypeError:
print("TypeError")
# zero division
try:
1j / 0
except ZeroDivisionError:
print("ZeroDivisionError")
# zero division via power
try:
0j ** 1j
except ZeroDivisionError:
print("ZeroDivisionError")
# test basic float capabilities
# literals
print(.12)
print(1.)
print(1.2)
# float construction
print(float(1.2))
......
Supports Markdown
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