Commit f2b126a1 authored by Damien George's avatar Damien George

leon: Add leon-tests test suite.

parent 4cc6054b
CORE_BASICS/string_cr_conversion.py -text
CORE_BASICS/string_crlf_conversion.py -text
# all tests need print to work! make sure it does work
print(1)
print('abc')
# test short circuit expressions outside if conditionals
print(() or 1)
print((1,) or 1)
print(() and 1)
print((1,) and 1)
array('B', [1, 2, 3]) 3
array('I', [1, 2, 3]) 3
1
3
0
array('i')
False
True
ValueError
import array
a = array.array('B', [1, 2, 3])
print(a, len(a))
i = array.array('I', [1, 2, 3])
print(i, len(i))
print(a[0])
print(i[-1])
# Empty arrays
print(len(array.array('h')))
print(array.array('i'))
# bool operator acting on arrays
print(bool(array.array('i')))
print(bool(array.array('i', [1])))
# bad typecode
try:
array.array('X')
except ValueError:
print("ValueError")
array('I', [1, 2])
array('I', [1, 3, 4])
array('I', [1, 3, 4, 5])
# test array + array
import array
a1 = array.array('I', [1])
a2 = array.array('I', [2])
print(a1 + a2)
a1 += array.array('I', [3, 4])
print(a1)
a1.extend(array.array('I', [5]))
print(a1)
array('b', [1, 2])
array('h', [1, 2])
array('h', [12850])
array('h', [0])
array('i', [0])
array('H', [1, 2])
array('b', [1, 2])
# test construction of array.array from different objects
from array import array
# tuple, list
print(array('b', (1, 2)))
print(array('h', [1, 2]))
# raw copy from bytes, bytearray
print(array('h', b'22')) # should be byteorder-neutral
print(array('h', bytearray(2)))
print(array('i', bytearray(4)))
# convert from other arrays
print(array('H', array('b', [1, 2])))
print(array('b', array('I', [1, 2])))
array('i', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
from array import array
# construct from something with unknown length (requires generators)
print(array('i', (i for i in range(10))))
# test construction of array.array from different objects
from array import array
# raw copy from bytes, bytearray
print(array('h', b'12'))
array('q')
array('Q')
array('q', [0])
array('Q', [0])
array('q', [-9223372036854775808, -1, 0, 1, 2, 9223372036854775807])
array('Q', [0, 1, 2, 18446744073709551615])
b'\xff\xff\xff\xff\xff\xff\xff\xff'
b'\xff\xff\xff\xff\xff\xff\xff\xff'
# test array('q') and array('Q')
from array import array
print(array('q'))
print(array('Q'))
print(array('q', [0]))
print(array('Q', [0]))
print(array('q', [-2**63, -1, 0, 1, 2, 2**63-1]))
print(array('Q', [0, 1, 2, 2**64-1]))
print(bytes(array('q', [-1])))
print(bytes(array('Q', [2**64-1])))
# test assignments
a = 1
print(a)
a = b = 2
print(a, b)
a = b = c = 3
print(a, b, c)
# test attrtuple
# we can't test this type directly so we use sys.implementation object
import sys
t = sys.implementation
# test printing of attrtuple
print(str(t).find("version=") > 0)
# test read attr
print(isinstance(t.name, str))
True
False
False
True
1
-1
TypeError
# tests for bool objects
# basic logic
print(not False)
print(not True)
print(False and True)
print(False or True)
# unary operators
print(+True)
print(-True)
# unsupported unary op
try:
len(False)
except TypeError:
print('TypeError')
# tests basics of bound methods
# uPy and CPython differ when printing a bound method, so just print the type
print(type(repr([].append)))
class A:
def f(self):
return 0
def g(self, a):
return a
def h(self, a, b, c, d, e, f):
return a + b + c + d + e + f
# bound method with no extra args
m = A().f
print(m())
# bound method with 1 extra arg
m = A().g
print(m(1))
# bound method with lots of extra args
m = A().h
print(m(1, 2, 3, 4, 5, 6))
one 0
two 0
one 1
two 1
one 2
two 2
one 3
1
2
while True:
break
for i in range(4):
print('one', i)
if i > 2:
break
print('two', i)
for i in [1, 2, 3, 4]:
if i == 3:
break
print(i)
0
1
1
1
123456789012345678901234567890
123456789012345678901234567890
1073741824
4611686018427387904