49 lines
1.2 KiB
Plaintext
49 lines
1.2 KiB
Plaintext
import stdio
|
|
|
|
# Test: class with inline list[struct, N] field
|
|
|
|
class Inner:
|
|
code: uint
|
|
bits: int
|
|
|
|
class Container:
|
|
items: [10]Inner
|
|
count: int
|
|
|
|
def __init__(self):
|
|
self.count = 0
|
|
|
|
def fill(self):
|
|
for i in range(10):
|
|
self.items[i].code = uint(i * 100)
|
|
self.items[i].bits = i
|
|
self.count += 1
|
|
|
|
def check(self):
|
|
ok: int = 1
|
|
for i in range(10):
|
|
if self.items[i].code != uint(i * 100):
|
|
stdio.printf("FAIL: items[%d].code=%u expect %d\n", i, self.items[i].code, i * 100)
|
|
ok = 0
|
|
if self.items[i].bits != i:
|
|
stdio.printf("FAIL: items[%d].bits=%d expect %d\n", i, self.items[i].bits, i)
|
|
ok = 0
|
|
if ok:
|
|
stdio.printf("PASS: inline list[struct, N] in Container\n")
|
|
else:
|
|
stdio.printf("FAIL: inline list[struct, N] in Container\n")
|
|
|
|
def inline_array_test() -> int:
|
|
stdio.printf("=== InlineArrayTest ===\n")
|
|
c1 = Container()
|
|
c1.fill()
|
|
c1.check()
|
|
|
|
# Also test: local variable of Container type
|
|
c2 = Container()
|
|
c2.fill()
|
|
c2.check()
|
|
|
|
stdio.printf("=== InlineArrayTest Complete ===\n")
|
|
return 0
|