test: 对象化前的最后稳定版本

- OopInheritTest 全部类补类体字段声明(x/y/r/w/h/health/battery 等), 保证父类字段展平与 GEP 偏移正确
- 多个测试适配 i8* 指针比较语义(== 指针地址比较改 string.strcmp)
- 删除 ZlibTest/__zlib 旧实现与 find.py 调试脚本
- 更新 TODO 与 TestProject
This commit is contained in:
TermiNexus committed 2026-08-09 22:19:29 +08:00
1 parent cd1f662e17
commit e1cb560df0
23 files changed
+151 -3265

No files matched your search

+13 -13
View File
@@ -41,7 +41,7 @@ def test_construct(pool: memhub.MemPool | t.CPtr):
# string
v7: json.JsonValue | t.CPtr = json.string_val(pool, "hello")
testcheck.check(v7.is_string(), "string is_string", "string is_string")
testcheck.check(v7.as_string() == "hello", "string == hello", "string == hello")
testcheck.check(string.strcmp(v7.as_string(), "hello") == 0, "string == hello", "string == hello")
# array
v8: json.JsonValue | t.CPtr = json.array(pool)
@@ -78,7 +78,7 @@ def test_build_structures(pool: memhub.MemPool | t.CPtr):
# Python风格取值:obj["key"]
name_val: json.JsonValue | t.CPtr = obj["name"]
testcheck.check(name_val != None and name_val.as_string() == "Viper", "obj['name']==Viper", "obj['name']==Viper")
testcheck.check(name_val != None and string.strcmp(name_val.as_string(), "Viper") == 0, "obj['name']==Viper", "obj['name']==Viper")
ver_val: json.JsonValue | t.CPtr = obj["version"]
testcheck.check(ver_val != None and ver_val.as_int() == 1, "obj['version']==1", "obj['version']==1")
missing: json.JsonValue | t.CPtr = obj["missing"]
@@ -108,7 +108,7 @@ def test_parse(pool: memhub.MemPool | t.CPtr):
# 解析字符串
v4: json.JsonValue | t.CPtr = json.parse(pool, '"hello world"')
testcheck.check(v4.is_string(), "parse string is_string", "parse string is_string")
testcheck.check(v4.as_string() == "hello world", "parse string == hello world", "parse string == hello world")
testcheck.check(string.strcmp(v4.as_string(), "hello world") == 0, "parse string == hello world", "parse string == hello world")
# 解析布尔
v5: json.JsonValue | t.CPtr = json.parse(pool, "true")
@@ -148,7 +148,7 @@ def test_write(pool: memhub.MemPool | t.CPtr):
# 写整数
v1: json.JsonValue | t.CPtr = json.int_val(pool, 42)
s1: t.CChar | t.CPtr = json.write(pool, v1, False)
testcheck.check(s1 == "42", "write int 42", "write int 42")
testcheck.check(string.strcmp(s1, "42") == 0, "write int 42", "write int 42")
# 写字符串
v2: json.JsonValue | t.CPtr = json.string_val(pool, "hello")
@@ -158,16 +158,16 @@ def test_write(pool: memhub.MemPool | t.CPtr):
# 写布尔
v3: json.JsonValue | t.CPtr = json.bool_val(pool, True)
s3: t.CChar | t.CPtr = json.write(pool, v3, False)
testcheck.check(s3 == "true", "write bool true", "write bool true")
testcheck.check(string.strcmp(s3, "true") == 0, "write bool true", "write bool true")
v4: json.JsonValue | t.CPtr = json.bool_val(pool, False)
s4: t.CChar | t.CPtr = json.write(pool, v4, False)
testcheck.check(s4 == "false", "write bool false", "write bool false")
testcheck.check(string.strcmp(s4, "false") == 0, "write bool false", "write bool false")
# 写 null
v5: json.JsonValue | t.CPtr = json.null(pool)
s5: t.CChar | t.CPtr = json.write(pool, v5, False)
testcheck.check(s5 == "null", "write null", "write null")
testcheck.check(string.strcmp(s5, "null") == 0, "write null", "write null")
# 写数组
arr: json.JsonValue | t.CPtr = json.array(pool)
@@ -175,7 +175,7 @@ def test_write(pool: memhub.MemPool | t.CPtr):
json.array_append(pool, arr, json.int_val(pool, 2))
json.array_append(pool, arr, json.int_val(pool, 3))
s6: t.CChar | t.CPtr = json.write(pool, arr, False)
testcheck.check(s6 == "[1,2,3]", "write array [1,2,3]", "write array [1,2,3]")
testcheck.check(string.strcmp(s6, "[1,2,3]") == 0, "write array [1,2,3]", "write array [1,2,3]")
# 写对象
obj: json.JsonValue | t.CPtr = json.object(pool)
@@ -198,7 +198,7 @@ def test_nested(pool: memhub.MemPool | t.CPtr):
# Python风格取值:root["name"]
name: json.JsonValue | t.CPtr = root["name"]
testcheck.check(name != None and name.as_string() == "Viper", "root['name']==Viper", "root['name']==Viper")
testcheck.check(name != None and string.strcmp(name.as_string(), "Viper") == 0, "root['name']==Viper", "root['name']==Viper")
# root["version"]
ver: json.JsonValue | t.CPtr = root["version"]
@@ -208,14 +208,14 @@ def test_nested(pool: memhub.MemPool | t.CPtr):
feat: json.JsonValue | t.CPtr = root["features"]
testcheck.check(feat != None and feat.is_array(), "root['features'] is_array", "root['features'] is_array")
testcheck.check(feat != None and len(feat) == 3, "root['features'] len()==3", "root['features'] len()==3")
testcheck.check(feat != None and feat.get_item(0).as_string() == "fast", "root['features'][0]==fast", "root['features'][0]==fast")
testcheck.check(feat != None and feat.get_item(2).as_string() == "portable", "root['features'][2]==portable", "root['features'][2]==portable")
testcheck.check(feat != None and string.strcmp(feat.get_item(0).as_string(), "fast") == 0, "root['features'][0]==fast", "root['features'][0]==fast")
testcheck.check(feat != None and string.strcmp(feat.get_item(2).as_string(), "portable") == 0, "root['features'][2]==portable", "root['features'][2]==portable")
# root["nested"] 对象
nested: json.JsonValue | t.CPtr = root["nested"]
testcheck.check(nested != None and nested.is_object(), "root['nested'] is_object", "root['nested'] is_object")
nk: json.JsonValue | t.CPtr = nested["key"] if nested != None else None
testcheck.check(nk != None and nk.as_string() == "value", "root['nested']['key']==value", "root['nested']['key']==value")
testcheck.check(nk != None and string.strcmp(nk.as_string(), "value") == 0, "root['nested']['key']==value", "root['nested']['key']==value")
nn: json.JsonValue | t.CPtr = nested["num"] if nested != None else None
testcheck.check(nn != None and nn.as_int() == 99, "root['nested']['num']==99", "root['nested']['num']==99")
@@ -241,7 +241,7 @@ def test_mpool_reuse():
# 第二次使用(内存复用)
v2: json.JsonValue | t.CPtr = json.string_val(pool, "reused")
testcheck.check(v2.as_string() == "reused", "reuse round2 string==reused", "reuse round2 string==reused")
testcheck.check(string.strcmp(v2.as_string(), "reused") == 0, "reuse round2 string==reused", "reuse round2 string==reused")
# 重置后再解析
pool.reset()