From 8addf2b55e89600b76a75f0dd02417013697d05b Mon Sep 17 00:00:00 2001 From: ychenfo Date: Wed, 1 Jun 2022 04:27:18 +0800 Subject: [PATCH] nac3standalone: add more tests --- nac3standalone/demo/src/inheritance.py | 32 ++++++++++++++++++++ nac3standalone/demo/src/recursive_type.py | 36 +++++++++++++++++++++++ nac3standalone/demo/src/typevar.py | 4 +++ 3 files changed, 72 insertions(+) create mode 100644 nac3standalone/demo/src/inheritance.py create mode 100644 nac3standalone/demo/src/recursive_type.py diff --git a/nac3standalone/demo/src/inheritance.py b/nac3standalone/demo/src/inheritance.py new file mode 100644 index 00000000..d280e3a5 --- /dev/null +++ b/nac3standalone/demo/src/inheritance.py @@ -0,0 +1,32 @@ +from __future__ import annotations + +@extern +def output_int32(x: int32): + ... + +class A: + a: int32 + + def __init__(self, a: int32): + self.a = a + + def f1(self): + self.f2() + + def f2(self): + output_int32(self.a) + +class B(A): + b: int32 + + def __init__(self, b: int32): + self.a = b + 1 + self.b = b + + +def run() -> int32: + aaa = A(5) + bbb = B(2) + aaa.f1() + bbb.f1() + return 0 diff --git a/nac3standalone/demo/src/recursive_type.py b/nac3standalone/demo/src/recursive_type.py new file mode 100644 index 00000000..1444f5ac --- /dev/null +++ b/nac3standalone/demo/src/recursive_type.py @@ -0,0 +1,36 @@ +from __future__ import annotations + +@extern +def output_int32(a: int32): + ... + +class A: + d: int32 + a: list[B] + def __init__(self, b: list[B]): + self.d = 123 + self.a = b + + def f(self): + output_int32(self.d) + +class B: + a: A + def __init__(self, a: A): + self.a = a + + def ff(self): + self.a.f() + +class Demo: + a: A + def __init__(self, a: A): + self.a = a + +def run() -> int32: + aa = A([]) + bb = B(aa) + aa.a = [bb] + d = Demo(aa) + d.a.a[0].ff() + return 0 \ No newline at end of file diff --git a/nac3standalone/demo/src/typevar.py b/nac3standalone/demo/src/typevar.py index e9def8b3..9b062214 100644 --- a/nac3standalone/demo/src/typevar.py +++ b/nac3standalone/demo/src/typevar.py @@ -34,5 +34,9 @@ def run() -> int32: insta = A() inst = C(insta) inst.foo() + + insta2 = B() + inst2 = C(insta2) + inst2.foo() return 0