tests: Add tests for things that are not already tested.

The aim here is to improve coverage of the code.
pull/1156/head
Damien George 2015-03-12 22:47:44 +00:00
rodzic 848dd0e762
commit af43565322
14 zmienionych plików z 185 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,11 @@
# test assignments
a = 1
print(a)
a = b = 2
print(a, b)
a = b = c = 3
print(a, b, c)

Wyświetl plik

@ -0,0 +1,24 @@
# test decorators
def dec(f):
print('dec')
return f
def dec_arg(x):
print(x)
return lambda f:f
# plain decorator
@dec
def f():
pass
# decorator with arg
@dec_arg('dec_arg')
def g():
pass
# decorator of class
@dec
class A:
pass

Wyświetl plik

@ -16,3 +16,41 @@ try:
except: # NameError:
# FIXME uPy returns KeyError for this
print("NameError")
# delete globals using a list
a = 1
del (a,)
try:
print(a)
except NameError:
print("NameError")
a = 2
b = 3
del (a, b)
try:
print(a)
except NameError:
print("NameError")
try:
print(b)
except NameError:
print("NameError")
a = 1
b = 2
c = 3
del (a, b, c)
try:
print(a)
except NameError:
print("NameError")
try:
print(b)
except NameError:
print("NameError")
try:
print(c)
except NameError:
print("NameError")

Wyświetl plik

@ -11,3 +11,8 @@ del d[3]
print(d)
del d[5]
print(d)
# delete nested subscr
d = {0:{0:0}}
del d[0][0]
print(d)

Wyświetl plik

@ -33,6 +33,30 @@ elif 0:
else:
print(17)
if not False:
print('a')
if not True:
print('a')
else:
print('b')
if False:
print('a')
else:
print('b')
if True:
print('a')
if (1,):
print('a')
if not (1,):
print('a')
else:
print('b')
f2 = 0
def f(t1, t2, f1):

Wyświetl plik

@ -24,6 +24,17 @@ print(-1073741823)
# Operations tests
# compile-time constexprs
print(1 + 3)
print(3 - 2)
print(2 * 3)
print(1 & 3)
print(1 | 2)
print(1 ^ 3)
print(+3)
print(-3)
print(~3)
a = 0x3fffff
print(a)
a *= 0x10

Wyświetl plik

@ -0,0 +1,13 @@
# test return statement
def f():
return
print(f())
def g():
return 1
print(g())
def f(x):
return 1 if x else 2
print(f(0), f(1))

Wyświetl plik

@ -14,6 +14,13 @@ print(a, b)
[a, b] = 100, 200
print(a, b)
# optimised 3-way swap
a = 1
b = 2
c = 3
a, b, c = b, c, a
print(a, b, c)
try:
a, b, c = (1, 2)
except ValueError:

Wyświetl plik

@ -22,3 +22,6 @@ try:
print(','.join([b'abc', b'123']))
except TypeError:
print("TypeError")
# joined by the compiler
print("a" "b")

Wyświetl plik

@ -2,8 +2,23 @@
a, = 1, ; print(a)
a, b = 2, 3 ; print(a, b)
a, b, c = 1, 2, 3; print(a, b, c)
a, = range(1); print(a)
a, b = range(2); print(a, b)
a, b, c = range(3); print(a, b, c)
(a) = range(1); print(a)
(a,) = range(1); print(a)
(a, b) = range(2); print(a, b)
(a, b, c) = range(3); print(a, b, c)
# lists
[] = []
[a] = range(1); print(a)
[a, b] = range(2); print(a, b)
[a, b, c] = range(3); print(a, b, c)
# with star
@ -27,6 +42,9 @@ a = [28, 29]
*b, = a
print(a, b, a == b)
[*a] = [1, 2, 3]
print(a)
try:
a, *b, c = (30,)
except ValueError:

Wyświetl plik

@ -16,3 +16,21 @@ while 2:
while -1:
print(4)
break
while False:
print('a')
else:
print('b')
while True:
print('a')
break
while not False:
print('a')
break
while not True:
print('a')
else:
print('b')

Wyświetl plik

@ -2,6 +2,11 @@
x = 1 / 2
print(x)
# /= operator
a = 1
a /= 2
print(a)
print(1.0 // 2)
print(2.0 // 2)

Wyświetl plik

@ -0,0 +1,7 @@
# test micropython-specific decorators
@micropython.bytecode
def f():
return 'bytecode'
print(f())

Wyświetl plik

@ -0,0 +1 @@
bytecode