Skip to content

Commit e8ea294

Browse files
committed
test negative indexes (closes #1119)
1 parent 19ef2be commit e8ea294

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/fields/fields.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,14 @@ def reset_post():
11731173
post.reload()
11741174
self.assertEqual(post.info, ['0', '1', '2', '3', 'a', '5'])
11751175

1176+
# __setitem__(index, value) with a negative index
1177+
reset_post()
1178+
post.info[-2] = 'a'
1179+
self.assertEqual(post.info, ['0', '1', '2', '3', 'a', '5'])
1180+
post.save()
1181+
post.reload()
1182+
self.assertEqual(post.info, ['0', '1', '2', '3', 'a', '5'])
1183+
11761184
# '__setitem__(slice(i, j), listB)'
11771185
# aka 'listA[i:j] = listB'
11781186
# aka 'setitem(listA, slice(i, j), listB)'
@@ -1183,6 +1191,16 @@ def reset_post():
11831191
post.reload()
11841192
self.assertEqual(post.info, ['0', 'h', 'e', 'l', 'l', 'o', '3', '4', '5'])
11851193

1194+
# '__setitem__(slice(i, j), listB)' with negative i and j
1195+
reset_post()
1196+
post.info[-5:-3] = ['h', 'e', 'l', 'l', 'o']
1197+
self.assertEqual(post.info, ['0', 'h', 'e', 'l', 'l', 'o', '3', '4', '5'])
1198+
post.save()
1199+
post.reload()
1200+
self.assertEqual(post.info, ['0', 'h', 'e', 'l', 'l', 'o', '3', '4', '5'])
1201+
1202+
# negative
1203+
11861204
# 'append'
11871205
reset_post()
11881206
post.info.append('h')

0 commit comments

Comments
 (0)