From 45ae761ed9cf6c21c0c2b812eff9e7c684657b7e Mon Sep 17 00:00:00 2001 From: abdul124 Date: Fri, 30 Aug 2024 18:04:37 +0800 Subject: [PATCH] core/toplevel: update tests --- ...el__test__test_analyze__generic_class.snap | 6 +-- ...t__test_analyze__simple_class_compose.snap | 4 +- nac3core/src/toplevel/test.rs | 48 +++++++++---------- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/nac3core/src/toplevel/snapshots/nac3core__toplevel__test__test_analyze__generic_class.snap b/nac3core/src/toplevel/snapshots/nac3core__toplevel__test__test_analyze__generic_class.snap index 53ff774f..1b0c9b80 100644 --- a/nac3core/src/toplevel/snapshots/nac3core__toplevel__test__test_analyze__generic_class.snap +++ b/nac3core/src/toplevel/snapshots/nac3core__toplevel__test__test_analyze__generic_class.snap @@ -3,10 +3,10 @@ source: nac3core/src/toplevel/test.rs expression: res_vec --- [ - "Class {\nname: \"Generic_A\",\nancestors: [\"Generic_A[V]\", \"B\"],\nfields: [\"aa\", \"a\"],\nmethods: [(\"__init__\", \"fn[[], none]\"), (\"foo\", \"fn[[b:T], none]\"), (\"fun\", \"fn[[a:int32], V]\")],\ntype_vars: [\"V\"]\n}\n", - "Function {\nname: \"Generic_A.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n", - "Function {\nname: \"Generic_A.fun\",\nsig: \"fn[[a:int32], V]\",\nvar_id: [TypeVarId(241)]\n}\n", "Class {\nname: \"B\",\nancestors: [\"B\"],\nfields: [\"aa\"],\nmethods: [(\"__init__\", \"fn[[], none]\"), (\"foo\", \"fn[[b:T], none]\")],\ntype_vars: []\n}\n", "Function {\nname: \"B.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n", "Function {\nname: \"B.foo\",\nsig: \"fn[[b:T], none]\",\nvar_id: []\n}\n", + "Class {\nname: \"Generic_A\",\nancestors: [\"Generic_A[V]\", \"B\"],\nfields: [\"aa\", \"a\"],\nmethods: [(\"__init__\", \"fn[[], none]\"), (\"foo\", \"fn[[b:T], none]\"), (\"fun\", \"fn[[a:int32], V]\")],\ntype_vars: [\"V\"]\n}\n", + "Function {\nname: \"Generic_A.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n", + "Function {\nname: \"Generic_A.fun\",\nsig: \"fn[[a:int32], V]\",\nvar_id: [TypeVarId(246)]\n}\n", ] diff --git a/nac3core/src/toplevel/snapshots/nac3core__toplevel__test__test_analyze__simple_class_compose.snap b/nac3core/src/toplevel/snapshots/nac3core__toplevel__test__test_analyze__simple_class_compose.snap index 502abbd6..9a9c4dd6 100644 --- a/nac3core/src/toplevel/snapshots/nac3core__toplevel__test__test_analyze__simple_class_compose.snap +++ b/nac3core/src/toplevel/snapshots/nac3core__toplevel__test__test_analyze__simple_class_compose.snap @@ -7,11 +7,11 @@ expression: res_vec "Function {\nname: \"A.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n", "Function {\nname: \"A.fun\",\nsig: \"fn[[b:B], none]\",\nvar_id: []\n}\n", "Function {\nname: \"A.foo\",\nsig: \"fn[[a:T, b:V], none]\",\nvar_id: [TypeVarId(249)]\n}\n", - "Class {\nname: \"B\",\nancestors: [\"B\", \"C\", \"A\"],\nfields: [\"a\"],\nmethods: [(\"__init__\", \"fn[[], none]\"), (\"fun\", \"fn[[b:B], none]\"), (\"foo\", \"fn[[a:T, b:V], none]\")],\ntype_vars: []\n}\n", - "Function {\nname: \"B.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n", "Class {\nname: \"C\",\nancestors: [\"C\", \"A\"],\nfields: [\"a\"],\nmethods: [(\"__init__\", \"fn[[], none]\"), (\"fun\", \"fn[[b:B], none]\"), (\"foo\", \"fn[[a:T, b:V], none]\")],\ntype_vars: []\n}\n", "Function {\nname: \"C.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n", "Function {\nname: \"C.fun\",\nsig: \"fn[[b:B], none]\",\nvar_id: []\n}\n", + "Class {\nname: \"B\",\nancestors: [\"B\", \"C\", \"A\"],\nfields: [\"a\"],\nmethods: [(\"__init__\", \"fn[[], none]\"), (\"fun\", \"fn[[b:B], none]\"), (\"foo\", \"fn[[a:T, b:V], none]\")],\ntype_vars: []\n}\n", + "Function {\nname: \"B.__init__\",\nsig: \"fn[[], none]\",\nvar_id: []\n}\n", "Function {\nname: \"foo\",\nsig: \"fn[[a:A], none]\",\nvar_id: []\n}\n", "Function {\nname: \"ff\",\nsig: \"fn[[a:T], V]\",\nvar_id: [TypeVarId(257)]\n}\n", ] diff --git a/nac3core/src/toplevel/test.rs b/nac3core/src/toplevel/test.rs index 077f6ab9..5d18aba5 100644 --- a/nac3core/src/toplevel/test.rs +++ b/nac3core/src/toplevel/test.rs @@ -230,11 +230,6 @@ fn test_simple_function_analyze(source: &[&str], tys: &[&str], names: &[&str]) { def foo(self, a: T, b: V): pass "}, - indoc! {" - class B(C): - def __init__(self): - pass - "}, indoc! {" class C(A): def __init__(self): @@ -243,6 +238,11 @@ fn test_simple_function_analyze(source: &[&str], tys: &[&str], names: &[&str]) { a = 1 pass "}, + indoc! {" + class B(C): + def __init__(self): + pass + "}, indoc! {" def foo(a: A): pass @@ -257,6 +257,14 @@ fn test_simple_function_analyze(source: &[&str], tys: &[&str], names: &[&str]) { )] #[test_case( &[ + indoc! {" + class B: + aa: bool + def __init__(self): + self.aa = False + def foo(self, b: T): + pass + "}, indoc! {" class Generic_A(Generic[V], B): a: int64 @@ -264,14 +272,6 @@ fn test_simple_function_analyze(source: &[&str], tys: &[&str], names: &[&str]) { self.a = 123123123123 def fun(self, a: int32) -> V: pass - "}, - indoc! {" - class B: - aa: bool - def __init__(self): - self.aa = False - def foo(self, b: T): - pass "} ], &[]; @@ -391,18 +391,18 @@ fn test_simple_function_analyze(source: &[&str], tys: &[&str], names: &[&str]) { pass "} ], - &["cyclic inheritance detected"]; + &["NameError: name 'B' is not defined (at unknown:1:9)"]; "cyclic1" )] #[test_case( &[ indoc! {" - class A(B[bool, int64]): - def __init__(self): - pass + class B(Generic[V, T], C[int32]): + def __init__(self): + pass "}, indoc! {" - class B(Generic[V, T], C[int32]): + class A(B[bool, int64]): def __init__(self): pass "}, @@ -412,7 +412,7 @@ fn test_simple_function_analyze(source: &[&str], tys: &[&str], names: &[&str]) { pass "}, ], - &["cyclic inheritance detected"]; + &["NameError: name 'C' is not defined (at unknown:1:25)"]; "cyclic2" )] #[test_case( @@ -436,11 +436,6 @@ fn test_simple_function_analyze(source: &[&str], tys: &[&str], names: &[&str]) { )] #[test_case( &[ - indoc! {" - class A(B, Generic[T], C): - def __init__(self): - pass - "}, indoc! {" class B: def __init__(self): @@ -450,6 +445,11 @@ fn test_simple_function_analyze(source: &[&str], tys: &[&str], names: &[&str]) { class C: def __init__(self): pass + "}, + indoc! {" + class A(B, Generic[T], C): + def __init__(self): + pass "} ],