test(ForAndLoopTest): 去除 fakeduck 依赖,list 改用 list[T](bd)+append 构造

移除 str.split/__mbuddy__ 魔法字段扩展依赖,zip/enumerate 输入改为
list[str](bd)+append 构造;保留纯 TPV 内置迭代测试(range/str/zip/enumerate)
This commit is contained in:
TermiNexus committed 2026-08-11 22:10:15 +08:00
1 parent f047f90a72
commit 99bf970452
1 file changed
+25 -19
+25 -19
View File
@@ -5,7 +5,6 @@ import stdlib
import string
import memhub
import testcheck
import _fakeduck
def test_for_in_range():
@@ -28,9 +27,11 @@ def test_for_in_list():
testcheck.section("Test 3: for v in list[str]")
arena: bytes = stdlib.malloc(65536)
bd: memhub.MemBuddy | t.CPtr = memhub.MemBuddy(arena, 65536)
src: str = "x,y,z,w"
src.__mbuddy__ = bd
lst: list[str] = src.split(',')
lst: list[str] = list[str](bd)
lst.append("x")
lst.append("y")
lst.append("z")
lst.append("w")
total: t.CInt = 0
for v in lst:
total += 1
@@ -42,12 +43,14 @@ def test_zip_list_list():
testcheck.section("Test 4: zip(list, list)")
arena: bytes = stdlib.malloc(65536)
bd: memhub.MemBuddy | t.CPtr = memhub.MemBuddy(arena, 65536)
a: str = "a,b,c"
a.__mbuddy__ = bd
b: str = "1,2,3"
b.__mbuddy__ = bd
la: list[str] = a.split(',')
lb: list[str] = b.split(',')
la: list[str] = list[str](bd)
la.append("a")
la.append("b")
la.append("c")
lb: list[str] = list[str](bd)
lb.append("1")
lb.append("2")
lb.append("3")
cnt: t.CInt = 0
for ca, cb in zip(la, lb):
stdio.printf("zip[%d]: '%s'='%s'\n", cnt, ca, cb)
@@ -60,9 +63,10 @@ def test_zip_range_list():
testcheck.section("Test 5: zip(range, list)")
arena: bytes = stdlib.malloc(65536)
bd: memhub.MemBuddy | t.CPtr = memhub.MemBuddy(arena, 65536)
s: str = "p,q,r"
s.__mbuddy__ = bd
lst: list[str] = s.split(',')
lst: list[str] = list[str](bd)
lst.append("p")
lst.append("q")
lst.append("r")
cnt: t.CInt = 0
for n, v in zip(range(3), lst):
stdio.printf("zip range+list[%d]: %d='%s'\n", cnt, n, v)
@@ -86,9 +90,10 @@ def test_zip_range_len_list():
testcheck.section("Test 7: zip(range(len), list)")
arena: bytes = stdlib.malloc(65536)
bd: memhub.MemBuddy | t.CPtr = memhub.MemBuddy(arena, 65536)
s: str = "www.gvsds.com"
s.__mbuddy__ = bd
lst: list[str] = s.split('.')
lst: list[str] = list[str](bd)
lst.append("www")
lst.append("gvsds")
lst.append("com")
cnt: t.CInt = 0
for idx, v in zip(range(len(lst)), lst):
stdio.printf("lst[%d]='%s'\n", idx, v)
@@ -101,9 +106,10 @@ def test_enumerate_list():
testcheck.section("Test 8: enumerate(list)")
arena: bytes = stdlib.malloc(65536)
bd: memhub.MemBuddy | t.CPtr = memhub.MemBuddy(arena, 65536)
s: str = "alpha,beta,gamma"
s.__mbuddy__ = bd
lst: list[str] = s.split(',')
lst: list[str] = list[str](bd)
lst.append("alpha")
lst.append("beta")
lst.append("gamma")
cnt: t.CInt = 0
last_idx: t.CInt = -1
for idx, v in enumerate(lst):