tests: Add tests to improve coverage of objstr.c.

This commit is contained in:
Damien George 2015-09-03 23:06:18 +01:00
parent e2aa117798
commit 25afc7da0d
13 changed files with 81 additions and 0 deletions

View File

@ -20,3 +20,9 @@ try:
ord(b'')
except TypeError:
print("TypeError")
# argument must be a string
try:
ord(1)
except TypeError:
print('TypeError')

View File

@ -14,6 +14,18 @@ print(bytes(array('h', [0x101, 0x202])))
# long ints
print(ord(bytes([14953042807679334000 & 0xff])))
# constructor value out of range
try:
bytes([-1])
except ValueError:
print('ValueError')
# constructor value out of range
try:
bytes([256])
except ValueError:
print('ValueError')
# error in construction
try:
a = bytes([1, 2, 3], 1)

View File

@ -11,3 +11,8 @@ setattr(a, "var", 123)
setattr(a, "var2", 56)
print(a.var)
print(a.var2)
try:
setattr(a, b'var3', 1)
except TypeError:
print('TypeError')

View File

@ -24,6 +24,10 @@ try:
'123' * '1'
except TypeError:
print('TypeError')
try:
'123' + 1
except TypeError:
print('TypeError')
# subscription
print('abc'[1])

View File

@ -48,3 +48,8 @@ print("1" <= "10")
print("1" <= "1/")
print("10" <= "1")
print("1/" <= "1")
# this tests an internal string that doesn't have a hash with a string
# that does have a hash, but the lengths of the two strings are different
import sys
print(sys.version == 'a long string that has a hash')

View File

@ -207,3 +207,9 @@ try:
'{:*"1"}'.format('zz')
except ValueError:
print('ValueError')
# unknown format code for str arg
try:
'{:X}'.format('zz')
except ValueError:
print('ValueError')

View File

@ -52,3 +52,9 @@ print(struct.unpack("<Q", b"\xff\xff\xff\xff\xff\xff\xff\xff"))
# network byte order
print(struct.pack('!i', 123))
# first arg must be a string
try:
struct.pack(1, 2)
except TypeError:
print('TypeError')

View File

@ -0,0 +1,5 @@
# test uPy ujson behaviour that's not valid in CPy
import ujson
print(ujson.dumps(b'1234'))

View File

@ -0,0 +1 @@
"1234"

View File

@ -40,8 +40,26 @@ try:
except NotImplementedError:
print('NotImplementedError')
# str(...) with keywords not implemented
try:
str(b'abc', encoding='utf8')
except NotImplementedError:
print('NotImplementedError')
# str.rsplit(None, n) not implemented
try:
'a a a'.rsplit(None, 1)
except NotImplementedError:
print('NotImplementedError')
# bytes(...) with keywords not implemented
try:
bytes('abc', encoding='utf8')
except NotImplementedError:
print('NotImplementedError')
# bytes subscr with step!=1 not implemented
try:
b'123'[0:3:2]
except NotImplementedError:
print('NotImplementedError')

View File

@ -5,3 +5,6 @@ True
TypeError, ValueError
NotImplementedError
NotImplementedError
NotImplementedError
NotImplementedError
NotImplementedError

View File

@ -25,3 +25,5 @@ stderr exc_info print_exception
ementation
# attrtuple
(start=1, stop=2, step=3)
# str
1

View File

@ -75,6 +75,14 @@ STATIC mp_obj_t extra_coverage(void) {
printf("\n");
}
// str
{
printf("# str\n");
// intern string
printf("%d\n", MP_OBJ_IS_QSTR(mp_obj_str_intern(mp_obj_new_str("intern me", 9, false))));
}
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_0(extra_coverage_obj, extra_coverage);