Fix qstr in objlist.c; add more tests for list.index.

list.index fails on an edge case.
This commit is contained in:
Damien George 2014-01-05 13:44:06 +00:00
parent a3ab68e949
commit f0691f4ed5
2 changed files with 14 additions and 2 deletions

View File

@ -194,7 +194,7 @@ static mp_obj_t list_index(int n_args, const mp_obj_t *args) {
} }
} }
nlr_jump(mp_obj_new_exception_msg(rt_q_ValueError, "Object not in list.")); nlr_jump(mp_obj_new_exception_msg(MP_QSTR_ValueError, "object not in list"));
} }
static MP_DEFINE_CONST_FUN_OBJ_2(list_append_obj, mp_obj_list_append); static MP_DEFINE_CONST_FUN_OBJ_2(list_append_obj, mp_obj_list_append);

View File

@ -1,12 +1,24 @@
a = [1, 2, 3] a = [1, 2, 3]
print(a.index(1))
print(a.index(2))
print(a.index(3))
print(a.index(3, 2))
try:
print(a.index(3, 2, 2))
except ValueError:
print("Raised ValueError")
else:
print("Did not raise ValueError")
a = a + a a = a + a
b = [0, 0, a] b = [0, 0, a]
print(a.index(2)) print(a.index(2))
print(b.index(a)) print(b.index(a))
print(a.index(2, 2)) print(a.index(2, 2))
try: try:
a.index(2, 2, 2) a.index(2, 2, 2)
except ValueError: except ValueError:
print("Raised ValueError") print("Raised ValueError")
else: else:
raise AssertionError("Did not raise ValueError") print("Did not raise ValueError")