mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 19:20:22 +01:00
tests: Add test for array slice assignment.
This commit is contained in:
43
tests/basics/bytearray_slice_assign.py
Normal file
43
tests/basics/bytearray_slice_assign.py
Normal file
@@ -0,0 +1,43 @@
|
||||
try:
|
||||
bytearray()[:] = bytearray()
|
||||
except TypeError:
|
||||
print("SKIP")
|
||||
import sys
|
||||
sys.exit()
|
||||
|
||||
# test slices; only 2 argument version supported by Micro Python at the moment
|
||||
x = bytearray(range(10))
|
||||
|
||||
# Assignment
|
||||
l = bytearray(x)
|
||||
l[1:3] = bytearray([10, 20])
|
||||
print(l)
|
||||
l = bytearray(x)
|
||||
l[1:3] = bytearray([10])
|
||||
print(l)
|
||||
l = bytearray(x)
|
||||
l[1:3] = bytearray()
|
||||
print(l)
|
||||
l = bytearray(x)
|
||||
#del l[1:3]
|
||||
print(l)
|
||||
|
||||
l = bytearray(x)
|
||||
l[:3] = bytearray([10, 20])
|
||||
print(l)
|
||||
l = bytearray(x)
|
||||
l[:3] = bytearray()
|
||||
print(l)
|
||||
l = bytearray(x)
|
||||
#del l[:3]
|
||||
print(l)
|
||||
|
||||
l = bytearray(x)
|
||||
l[:-3] = bytearray([10, 20])
|
||||
print(l)
|
||||
l = bytearray(x)
|
||||
l[:-3] = bytearray()
|
||||
print(l)
|
||||
l = bytearray(x)
|
||||
#del l[:-3]
|
||||
print(l)
|
||||
Reference in New Issue
Block a user