summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics/bytearray_add.py
blob: 1f30a3b740e9591b822ada418800cfe471833479 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# test bytearray + bytearray

b = bytearray(2)
b[0] = 1
b[1] = 2
print(b + bytearray(2))

# inplace add
b += bytearray(3)
print(b)

# extend
b.extend(bytearray(4))
print(b)

# this inplace add tests the code when the buffer doesn't need to be increased
b = bytearray()
b += b""

# extend a bytearray from itself
b = bytearray(b"abcdefgh")
for _ in range(4):
    c = bytearray(b)  # extra allocation, as above
    b.extend(b)
print(b)