Skip to content

Commit 806a6e6

Browse files
committed
Add tests for setting slices on 'bytearray'.
1 parent 432309b commit 806a6e6

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_bytes.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,38 @@ def test_setitem():
183183
pass
184184

185185

186+
def test_setslice():
187+
# whole sequence
188+
b = bytearray(b"hello")
189+
b[0:5] = b"HELLO"
190+
assert b == bytearray(b"HELLO")
191+
192+
# whole same length as slice
193+
b = bytearray(b"hellohellohello")
194+
b[5:10] = b"HELLO"
195+
assert b == bytearray(b"helloHELLOhello")
196+
197+
# shrink
198+
b = bytearray(b"hellohellohello")
199+
b[5:10] = b"hi"
200+
assert b == bytearray(b"hellohihello")
201+
202+
# extend
203+
b = bytearray(b"hellohelloworld")
204+
b[5:10] = b"beautiful"
205+
assert b == bytearray(b"hellobeautifulworld")
206+
207+
# assign list with integers
208+
b = bytearray(b"hellohellohello")
209+
b[5:10] = [4, 5, 6, 7, 8]
210+
assert b == bytearray(b"hello\x04\x05\x06\x07\x08hello")
211+
212+
# assign range
213+
b = bytearray(b"hellohellohello")
214+
b[5:10] = range(5)
215+
assert b == bytearray(b"hello\x04\x05\x06\x07\x08hello")
216+
217+
186218
def test_delitem():
187219
b = bytearray(range(10))
188220
del b[0]

0 commit comments

Comments
 (0)