修复了大量存在的问题,增加了假鸭子类型等等机制
This commit is contained in:
@@ -1,18 +1,16 @@
|
||||
import t
|
||||
import stdio
|
||||
import string
|
||||
import testcheck
|
||||
|
||||
def test_strlen():
|
||||
stdio.printf("--- Test 1: strlen ---\n")
|
||||
testcheck.section("Test 1: strlen")
|
||||
s: t.CChar | t.CPtr = "Hello, World!"
|
||||
length: t.CUInt64T = string.strlen(s)
|
||||
if length == 13:
|
||||
stdio.printf("PASS: strlen (len=%lu)\n", length)
|
||||
else:
|
||||
stdio.printf("FAIL: strlen (len=%lu, expect 13)\n", length)
|
||||
testcheck.check(length == 13, "strlen (len=13)", "strlen (expect 13)")
|
||||
|
||||
def test_strcpy():
|
||||
stdio.printf("--- Test 2: strcpy ---\n")
|
||||
testcheck.section("Test 2: strcpy")
|
||||
buf: t.CChar | t.CPtr = w32.win32memory.VirtualAlloc(t.CVoid(0, t.CPtr), 64, 12288, 4)
|
||||
if t.CUInt64T(buf) == 0:
|
||||
stdio.printf("SKIP: VirtualAlloc returned NULL\n")
|
||||
@@ -20,13 +18,10 @@ def test_strcpy():
|
||||
string.memset(buf, 0, 64)
|
||||
string.strcpy(buf, "test string")
|
||||
cmp_result: t.CInt = string.strcmp(buf, "test string")
|
||||
if cmp_result == 0:
|
||||
stdio.printf("PASS: strcpy (result=%s)\n", buf)
|
||||
else:
|
||||
stdio.printf("FAIL: strcpy (cmp=%d)\n", cmp_result)
|
||||
testcheck.check(cmp_result == 0, "strcpy (result=test string)", "strcpy (cmp mismatch)")
|
||||
|
||||
def test_strcat():
|
||||
stdio.printf("--- Test 3: strcat (via memcpy) ---\n")
|
||||
testcheck.section("Test 3: strcat (via memcpy)")
|
||||
buf: t.CChar | t.CPtr = w32.win32memory.VirtualAlloc(t.CVoid(0, t.CPtr), 64, 12288, 4)
|
||||
if t.CUInt64T(buf) == 0:
|
||||
stdio.printf("SKIP: VirtualAlloc returned NULL\n")
|
||||
@@ -38,23 +33,17 @@ def test_strcat():
|
||||
string.memcpy(buf, hello, 5)
|
||||
string.memcpy(t.CVoid(t.CUInt64T(buf) + 5, t.CPtr), world, 6)
|
||||
cmp_result: t.CInt = string.strcmp(buf, "Hello World")
|
||||
if cmp_result == 0:
|
||||
stdio.printf("PASS: strcat via memcpy\n")
|
||||
else:
|
||||
stdio.printf("FAIL: strcat via memcpy (cmp=%d)\n", cmp_result)
|
||||
testcheck.check(cmp_result == 0, "strcat via memcpy", "strcat via memcpy (cmp mismatch)")
|
||||
|
||||
def test_strcmp():
|
||||
stdio.printf("--- Test 4: strcmp ---\n")
|
||||
testcheck.section("Test 4: strcmp")
|
||||
r1: t.CInt = string.strcmp("abc", "abc")
|
||||
r2: t.CInt = string.strcmp("abc", "abd")
|
||||
r3: t.CInt = string.strcmp("abd", "abc")
|
||||
if r1 == 0 and r2 < 0 and r3 > 0:
|
||||
stdio.printf("PASS: strcmp (eq=%d lt=%d gt=%d)\n", r1, r2, r3)
|
||||
else:
|
||||
stdio.printf("FAIL: strcmp (eq=%d lt=%d gt=%d)\n", r1, r2, r3)
|
||||
testcheck.check(r1 == 0 and r2 < 0 and r3 > 0, "strcmp (eq=0 lt<0 gt>0)", "strcmp (expect eq=0 lt<0 gt>0)")
|
||||
|
||||
def test_strncpy():
|
||||
stdio.printf("--- Test 5: strncpy ---\n")
|
||||
testcheck.section("Test 5: strncpy")
|
||||
buf: t.CChar | t.CPtr = w32.win32memory.VirtualAlloc(t.CVoid(0, t.CPtr), 64, 12288, 4)
|
||||
if t.CUInt64T(buf) == 0:
|
||||
stdio.printf("SKIP: VirtualAlloc returned NULL\n")
|
||||
@@ -62,22 +51,16 @@ def test_strncpy():
|
||||
string.memset(buf, 0, 64)
|
||||
string.strncpy(buf, "ABCDEFGHIJ", 5)
|
||||
cmp_result: t.CInt = string.strcmp(buf, "ABCDE")
|
||||
if cmp_result == 0:
|
||||
stdio.printf("PASS: strncpy (result=%s)\n", buf)
|
||||
else:
|
||||
stdio.printf("FAIL: strncpy (cmp=%d)\n", cmp_result)
|
||||
testcheck.check(cmp_result == 0, "strncpy (result=ABCDE)", "strncpy (cmp mismatch)")
|
||||
|
||||
def test_char_access():
|
||||
stdio.printf("--- Test 6: char access ---\n")
|
||||
testcheck.section("Test 6: char access")
|
||||
s: t.CChar | t.CPtr = "ABCDE"
|
||||
val: t.CUInt8T = s[2] # 'C' = 67
|
||||
if val == 67:
|
||||
stdio.printf("PASS: char access (s[2]=%d='C')\n", val)
|
||||
else:
|
||||
stdio.printf("FAIL: char access (s[2]=%d, expect 67)\n", val)
|
||||
testcheck.check(val == 67, "char access (s[2]=67='C')", "char access (s[2] expect 67)")
|
||||
|
||||
def test_snprintf():
|
||||
stdio.printf("--- Test 7: snprintf ---\n")
|
||||
testcheck.section("Test 7: snprintf")
|
||||
buf: t.CChar | t.CPtr = w32.win32memory.VirtualAlloc(t.CVoid(0, t.CPtr), 128, 12288, 4)
|
||||
if t.CUInt64T(buf) == 0:
|
||||
stdio.printf("SKIP: VirtualAlloc returned NULL\n")
|
||||
@@ -85,15 +68,12 @@ def test_snprintf():
|
||||
string.memset(buf, 0, 128)
|
||||
stdio.snprintf(buf, 128, "value=%d hex=0x%x str=%s", 42, 255, "test")
|
||||
cmp_result: t.CInt = string.strcmp(buf, "value=42 hex=0xff str=test")
|
||||
if cmp_result == 0:
|
||||
stdio.printf("PASS: snprintf (result=%s)\n", buf)
|
||||
else:
|
||||
stdio.printf("FAIL: snprintf (result='%s')\n", buf)
|
||||
testcheck.check(cmp_result == 0, "snprintf (result=value=42 hex=0xff str=test)", "snprintf (result mismatch)")
|
||||
|
||||
import w32.win32memory
|
||||
|
||||
def main() -> t.CInt:
|
||||
stdio.printf("=== StringTest: 字符串操作基准测试 ===\n\n")
|
||||
testcheck.begin("StringTest: 字符串操作基准测试")
|
||||
test_strlen()
|
||||
test_strcpy()
|
||||
test_strcat()
|
||||
@@ -101,5 +81,4 @@ def main() -> t.CInt:
|
||||
test_strncpy()
|
||||
test_char_access()
|
||||
test_snprintf()
|
||||
stdio.printf("\n=== StringTest Complete ===\n")
|
||||
return 0
|
||||
return testcheck.end()
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "string": "6aee24fdefa3cbc0", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "main": "7aa13c104a22528a", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3"}
|
||||
{"main": "39178dc5ba692b92", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3"}
|
||||
@@ -1 +1 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "string": "6aee24fdefa3cbc0", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "main": "7aa13c104a22528a", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3", "w32.win32sync": "29813d57621099a9", "win32sync": "29813d57621099a9"}
|
||||
{"main": "39178dc5ba692b92", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32process": "067c78e9f121dce3", "win32process": "067c78e9f121dce3", "w32.win32sync": "29813d57621099a9", "win32sync": "29813d57621099a9"}
|
||||
1
Test/StringTest/output/39178dc5ba692b92.deps.json
Normal file
1
Test/StringTest/output/39178dc5ba692b92.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd"}
|
||||
@@ -1 +1 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "string": "6aee24fdefa3cbc0", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "main": "7aa13c104a22528a", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950"}
|
||||
{"main": "39178dc5ba692b92", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd"}
|
||||
@@ -1 +0,0 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "string": "6aee24fdefa3cbc0", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "main": "7aa13c104a22528a"}
|
||||
@@ -1 +1 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "string": "6aee24fdefa3cbc0", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "main": "7aa13c104a22528a", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e"}
|
||||
{"main": "39178dc5ba692b92", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950"}
|
||||
@@ -1 +0,0 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "string": "6aee24fdefa3cbc0", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b"}
|
||||
1
Test/StringTest/output/9dbecd0942a39782.deps.json
Normal file
1
Test/StringTest/output/9dbecd0942a39782.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"main": "39178dc5ba692b92", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd"}
|
||||
@@ -1 +1 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "string": "6aee24fdefa3cbc0", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "main": "7aa13c104a22528a", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e"}
|
||||
{"main": "39178dc5ba692b92", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e"}
|
||||
1
Test/StringTest/output/b5f1dc665c52a1bd.deps.json
Normal file
1
Test/StringTest/output/b5f1dc665c52a1bd.deps.json
Normal file
@@ -0,0 +1 @@
|
||||
{"main": "39178dc5ba692b92", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd"}
|
||||
@@ -1 +1 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "string": "6aee24fdefa3cbc0", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "main": "7aa13c104a22528a", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c"}
|
||||
{"main": "39178dc5ba692b92", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c"}
|
||||
@@ -1 +1 @@
|
||||
{"stdint": "56cdd754a8a09347", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "string": "6aee24fdefa3cbc0", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "main": "7aa13c104a22528a", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950"}
|
||||
{"main": "39178dc5ba692b92", "stdint": "49bd8cba55979f76", "w32.win32base": "5a6a2137958c28c5", "win32base": "5a6a2137958c28c5", "w32.win32memory": "72e2d5ccb7cedcf1", "win32memory": "72e2d5ccb7cedcf1", "stdio": "73edbcf76e32d00b", "testcheck": "9dbecd0942a39782", "string": "b5f1dc665c52a1bd", "w32.win32console": "bbdf3bbd4c3bc28c", "win32console": "bbdf3bbd4c3bc28c", "w32.win32file": "abf9ce3160c9279e", "win32file": "abf9ce3160c9279e", "w32.fileio": "fa3691e66b426950", "fileio": "fa3691e66b426950"}
|
||||
@@ -9,6 +9,7 @@ import c
|
||||
import t
|
||||
import stdio
|
||||
import string
|
||||
import testcheck
|
||||
|
||||
def test_strlen() -> t.CInt: pass
|
||||
|
||||
@@ -64,4 +64,12 @@ CHAR16: t.CTypedef = t.CChar16T
|
||||
CHAR32: t.CTypedef = t.CChar32T
|
||||
CHAR8PTR: t.CTypedef = t.CChar8T | t.CPtr
|
||||
CHAR16PTR: t.CTypedef = t.CChar16T | t.CPtr
|
||||
CHAR32PTR: t.CTypedef = t.CChar32T | t.CPtr
|
||||
CHAR32PTR: t.CTypedef = t.CChar32T | t.CPtr
|
||||
i8: t.CTypedef = t.CInt8T
|
||||
i16: t.CTypedef = t.CInt16T
|
||||
i32: t.CTypedef = t.CInt32T
|
||||
i64: t.CTypedef = t.CInt64T
|
||||
u8: t.CTypedef = t.CUInt8T
|
||||
u16: t.CTypedef = t.CUInt16T
|
||||
u32: t.CTypedef = t.CUInt32T
|
||||
u64: t.CTypedef = t.CUInt64T
|
||||
25
Test/StringTest/temp/9dbecd0942a39782.pyi
Normal file
25
Test/StringTest/temp/9dbecd0942a39782.pyi
Normal file
@@ -0,0 +1,25 @@
|
||||
"""
|
||||
Auto-generated Python stub file from testcheck.py
|
||||
Module: testcheck
|
||||
"""
|
||||
|
||||
|
||||
import t, c
|
||||
import stdio
|
||||
|
||||
_pass_count: t.CExtern | t.CInt
|
||||
_fail_count: t.CExtern | t.CInt
|
||||
|
||||
def begin(name: str) -> t.CInt: pass
|
||||
|
||||
def section(name: str) -> t.CInt: pass
|
||||
|
||||
def ok(msg: str) -> t.CInt: pass
|
||||
|
||||
def fail(msg: str) -> t.CInt: pass
|
||||
|
||||
def check(cond: t.CInt, ok_msg: str, fail_msg: str) -> t.CInt: pass
|
||||
|
||||
def info(msg: str) -> t.CInt: pass
|
||||
|
||||
def end() -> t.CInt: pass
|
||||
@@ -1,6 +1,7 @@
|
||||
56cdd754a8a09347:includes/stdint.py
|
||||
39178dc5ba692b92:main.py
|
||||
49bd8cba55979f76:includes/stdint.py
|
||||
5a6a2137958c28c5:includes/w32\win32base.py
|
||||
6aee24fdefa3cbc0:includes/string.py
|
||||
72e2d5ccb7cedcf1:includes/w32\win32memory.py
|
||||
73edbcf76e32d00b:includes/stdio.py
|
||||
7aa13c104a22528a:main.py
|
||||
9dbecd0942a39782:includes/testcheck.py
|
||||
b5f1dc665c52a1bd:includes/string.py
|
||||
|
||||
@@ -41,4 +41,4 @@ def atoll(src: str) -> t.CInt64T: pass
|
||||
|
||||
def atof(src: str) -> t.CDouble: pass
|
||||
|
||||
def split(s: str, delim: str, result: list[str]) -> int: pass
|
||||
def split(s: str, delim: str, result: t.CArray[str]) -> int: pass
|
||||
Reference in New Issue
Block a user