chore(test): 迁移测试夹具到新语法

机械规则 R2/R3/R4/R6/R7/R8/R13 + R16 保守子集,共 86 文件 2127 行。R1(T | t.CPtr)与 R12(while 下标循环)未做,仍列为待办。全量 77/77 顺序回归通过。
This commit is contained in:
TermiNexus committed 2026-10-05 19:59:02 +08:00
1 parent c9d741c202
commit f5da836fbb
86 files changed
+2121 -2121

No files matched your search

+9 -9
View File
@@ -18,7 +18,7 @@ from linkedlist import GSListNode, GSList
# G5Node: 继承 GSListNode[G5Node](Phase2 路径,正确特化)
@t.NoVTable
class G5Node(GSListNode[G5Node]):
Value: t.CInt
Value: int
def __init__(self):
self.Next = None
@@ -28,7 +28,7 @@ class G5Node(GSListNode[G5Node]):
# G5ListWrapper: 包装 GSList[G5Node],测试 GSList 字段访问
# 注意:GSList[G5Node] 走 Phase2 特化路径
# 用 pool 工厂函数分配 GSList,避免栈分配悬垂指针
GSLIST_SIZE: t.CDefine = 24 # Head(8) + Tail(8) + Count(8)
define GSLIST_SIZE = 24 # Head(8) + Tail(8) + Count(8)
@t.NoVTable
class G5ListWrapper:
@@ -51,7 +51,7 @@ def test_g5node_create():
testcheck.section("Test 1: G5Node create and field access")
n: G5Node = G5Node()
n.Value = 42
v: t.CInt = n.Value
v: int = n.Value
testcheck.check(v == 42, "G5Node.Value = 42", "expect 42")
@@ -66,7 +66,7 @@ def test_g5node_next():
if next_node is None:
testcheck.check(False, "n1.Next is None", "FAIL")
return
v: t.CInt = next_node.Value
v: int = next_node.Value
testcheck.check(v == 20, "n1.Next.Value = 20", "expect 20")
@@ -83,7 +83,7 @@ def test_gslist_create():
# 检查初始状态
head: G5Node | t.CPtr = lst.Head
tail: G5Node | t.CPtr = lst.Tail
count: t.CSizeT = lst.Count
count: sizet = lst.Count
testcheck.check(head is None, "initial Head is None", "expect None")
testcheck.check(tail is None, "initial Tail is None", "expect None")
testcheck.check(count == 0, "initial Count = 0", "expect 0")
@@ -107,7 +107,7 @@ def test_gslist_append():
lst.append(c)
# 验证 Count
count: t.CSizeT = lst.Count
count: sizet = lst.Count
testcheck.check(count == 3, "Count = 3 after 3 appends", "expect 3")
# 验证 Head
@@ -125,7 +125,7 @@ def test_gslist_append():
testcheck.check(tail.Value == 3, "Tail.Value = 3", "expect 3")
# 遍历链表验证顺序
sum: t.CInt = 0
sum: int = 0
cur: G5Node | t.CPtr = lst.Head
while cur is not None:
sum = sum + cur.Value
@@ -161,12 +161,12 @@ def test_wrapper_list_field():
if head is None:
testcheck.check(False, "wrapper.List.Head is None", "FAIL")
return
count: t.CSizeT = wrapper.List.Count
count: sizet = wrapper.List.Count
testcheck.check(head.Value == 999, "wrapper.List.Head.Value = 999", "expect 999")
testcheck.check(count == 1, "wrapper.List.Count = 1", "expect 1")
def main() -> t.CInt:
def main() -> int:
testcheck.begin("G5: GSList[T] field access (Phase2 path, pool alloc for wrapper)")
test_g5node_create()
test_g5node_next()
+8 -8
View File
@@ -15,7 +15,7 @@ import memhub
@t.NoVTable
class G5Node(GSListNode[G5Node]):
Value: t.CInt
Value: int
# ============================================================
@@ -40,7 +40,7 @@ class G5Container:
# ============================================================
# G5Node 硬编码大小: Next(8) + Value(4) + padding(4) = 16 字节
G5NODE_SIZE: t.CDefine = 16
define G5NODE_SIZE = 16
def new_g5node(pool: memhub.MemBuddy | t.CPtr) -> G5Node | t.CPtr:
"""从 pool 分配并零初始化一个 G5Node"""
@@ -51,7 +51,7 @@ def new_g5node(pool: memhub.MemBuddy | t.CPtr) -> G5Node | t.CPtr:
# GSList 硬编码大小: Head(8) + Tail(8) + Count(8) = 24 字节
G5LIST_SIZE: t.CDefine = 24
define G5LIST_SIZE = 24
def new_g5list(pool: memhub.MemBuddy | t.CPtr) -> GSList[G5Node] | t.CPtr:
"""从 pool 分配并零初始化一个 GSList 容器(Head/Tail/Count 全零)"""
@@ -62,7 +62,7 @@ def new_g5list(pool: memhub.MemBuddy | t.CPtr) -> GSList[G5Node] | t.CPtr:
# G5Container 硬编码大小: List(8) = 8 字节
G5CONTAINER_SIZE: t.CDefine = 8
define G5CONTAINER_SIZE = 8
def new_g5container(pool: memhub.MemBuddy | t.CPtr) -> G5Container | t.CPtr:
"""从 pool 分配并零初始化一个 G5Container"""
@@ -95,7 +95,7 @@ def g5list_get_tail(lst: GSList[G5Node] | t.CPtr) -> G5Node | t.CPtr:
return lst.Tail
def g5list_get_count(lst: GSList[G5Node] | t.CPtr) -> t.CSizeT:
def g5list_get_count(lst: GSList[G5Node] | t.CPtr) -> sizet:
"""获取链表节点数"""
if lst is None: return 0
return lst.Count
@@ -113,7 +113,7 @@ def g5list_set_tail(lst: GSList[G5Node] | t.CPtr, node: G5Node | t.CPtr):
lst.Tail = node
def g5list_set_count(lst: GSList[G5Node] | t.CPtr, count: t.CSizeT):
def g5list_set_count(lst: GSList[G5Node] | t.CPtr, count: sizet):
"""设置链表节点数"""
if lst is None: return
lst.Count = count
@@ -139,12 +139,12 @@ def g5list_append(lst: GSList[G5Node] | t.CPtr, node: G5Node | t.CPtr):
# G5Node 访问器
# ============================================================
def g5node_get_value(node: G5Node | t.CPtr) -> t.CInt:
def g5node_get_value(node: G5Node | t.CPtr) -> int:
if node is None: return 0
return node.Value
def g5node_set_value(node: G5Node | t.CPtr, value: t.CInt):
def g5node_set_value(node: G5Node | t.CPtr, value: int):
if node is None: return
node.Value = value