Skip to content

Commit 70f3573

Browse files
committed
Create tests for list.copy()
tests and fixture for list.copy() moved to the correct locations
1 parent de725e0 commit 70f3573

File tree

5 files changed

+62
-62
lines changed

5 files changed

+62
-62
lines changed

mypyc/test-data/fixtures/ir.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ def sort(self) -> None: pass
231231
def reverse(self) -> None: pass
232232
def remove(self, o: _T) -> None: pass
233233
def index(self, o: _T) -> int: pass
234+
def copy(self) -> List[_T]: pass
234235

235236
class dict(Mapping[_K, _V]):
236237
@overload

mypyc/test-data/irbuild-lists.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,18 @@ L0:
182182
r1 = r0 << 1
183183
return r1
184184

185+
[case testListCopy]
186+
from typing import List
187+
from typing import Any
188+
def f(a: List[Any]) -> List[Any]:
189+
return a.copy()
190+
[out]
191+
def f(a):
192+
a, r0 :: list
193+
L0:
194+
r0 = CPyList_Copy(a)
195+
return r0
196+
185197
[case testListAppend]
186198
from typing import List
187199
def f(a: List[int], x: int) -> None:

mypyc/test-data/run-lists.test

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,55 @@ print(2, a)
5151
1 [-1, 5]
5252
2 [340282366920938463463374607431768211461, -170141183460469231731687303715884105736]
5353

54+
[case testListCopy]
55+
from typing import List
56+
from copysubclass import subc
57+
58+
def test_list_copy() -> None:
59+
l1 = [1, 2, 3, -4, 5]
60+
l2 = l1.copy()
61+
assert l1.copy() == l1
62+
assert l1.copy() == l2
63+
assert l1 == l2
64+
assert l1.copy() == l2.copy()
65+
l1 = l2.copy()
66+
assert l1 == l2
67+
assert l1.copy() == l2
68+
assert l1 == [1, 2, 3, -4, 5]
69+
l2 = [1, 2, -3]
70+
l1 = []
71+
assert l1.copy() == []
72+
assert l2.copy() != l1
73+
assert l2 == l2.copy()
74+
l1 = l2
75+
assert l1.copy().copy() == l2.copy().copy().copy()
76+
assert l1.copy() == l2.copy()
77+
l1 == [1, 2, -3].copy()
78+
assert l1 == l2
79+
l2 = [1, 2, 3].copy()
80+
assert l2 != l1
81+
l1 = [1, 2, 3]
82+
assert l1.copy() == l2.copy()
83+
l3 = [1, 2 , 3, "abcdef"]
84+
assert l3 == l3.copy()
85+
l4 = ["abc", 5, 10]
86+
l4 = l3.copy()
87+
assert l4 == l3
88+
#subclass testing
89+
l5: subc = subc([1, 2, 3])
90+
l6 = l5.copy()
91+
assert l6 == l5
92+
l6 = [1, 2, "3", 4, 5]
93+
l5 = subc([1,2,"3",4,5])
94+
assert l5.copy() == l6.copy()
95+
l6 = l5.copy()
96+
assert l5 == l6
97+
98+
[file copysubclass.py]
99+
from typing import Any
100+
class subc(list[Any]):
101+
pass
102+
54103
[case testSieve]
55104
from typing import List
56105

test-data/unit/check-listcopy

Lines changed: 0 additions & 31 deletions
This file was deleted.

test-data/unit/check-listcopy.test

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)