fix tests and switch to insta

Use a library called 'insta' to better organize those longer correct test outputs in toplevel tests. 'insta' creates `.snap` files as snapshots of the test output, and will automatically do the diff if the output is different. This makes maintaining test cases with larger outputs a lot easier.

Reviewed-on: M-Labs/nac3#42
Co-authored-by: ychenfo <yc@m-labs.hk>
Co-committed-by: ychenfo <yc@m-labs.hk>
This commit is contained in:
ychenfo 2021-10-03 16:39:12 +08:00 committed by sb10q
parent 915460ecb7
commit f5ce1afe0b
9 changed files with 226 additions and 305 deletions

127
Cargo.lock generated
View File

@ -87,6 +87,19 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "console"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3993e6445baa160675931ec041a5e03ca84b9c6e32a056150d3aa2bdda0a1f45"
dependencies = [
"encode_unicode",
"lazy_static",
"libc",
"terminal_size",
"winapi",
]
[[package]] [[package]]
name = "crossbeam" name = "crossbeam"
version = "0.8.1" version = "0.8.1"
@ -188,6 +201,12 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "dtoa"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0"
[[package]] [[package]]
name = "either" name = "either"
version = "1.6.1" version = "1.6.1"
@ -203,6 +222,12 @@ dependencies = [
"log", "log",
] ]
[[package]]
name = "encode_unicode"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
[[package]] [[package]]
name = "fixedbitset" name = "fixedbitset"
version = "0.2.0" version = "0.2.0"
@ -313,6 +338,21 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "insta"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15226a375927344c78d39dc6b49e2d5562a5b0705e26a589093c6792e52eed8e"
dependencies = [
"console",
"lazy_static",
"serde",
"serde_json",
"serde_yaml",
"similar",
"uuid",
]
[[package]] [[package]]
name = "instant" name = "instant"
version = "0.1.10" version = "0.1.10"
@ -331,6 +371,12 @@ dependencies = [
"either", "either",
] ]
[[package]]
name = "itoa"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
[[package]] [[package]]
name = "lalrpop" name = "lalrpop"
version = "0.19.6" version = "0.19.6"
@ -375,6 +421,12 @@ version = "0.2.102"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2a5ac8f984bfcf3a823267e5fde638acc3325f6496633a5da6bb6eb2171e103" checksum = "a2a5ac8f984bfcf3a823267e5fde638acc3325f6496633a5da6bb6eb2171e103"
[[package]]
name = "linked-hash-map"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
[[package]] [[package]]
name = "llvm-sys" name = "llvm-sys"
version = "110.0.2" version = "110.0.2"
@ -439,6 +491,7 @@ dependencies = [
"crossbeam", "crossbeam",
"indoc 1.0.3", "indoc 1.0.3",
"inkwell", "inkwell",
"insta",
"itertools", "itertools",
"num-bigint 0.3.3", "num-bigint 0.3.3",
"num-traits", "num-traits",
@ -864,6 +917,12 @@ version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61b3909d758bb75c79f23d4736fac9433868679d3ad2ea7a61e3c25cfda9a088" checksum = "61b3909d758bb75c79f23d4736fac9433868679d3ad2ea7a61e3c25cfda9a088"
[[package]]
name = "ryu"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
[[package]] [[package]]
name = "scopeguard" name = "scopeguard"
version = "1.1.0" version = "1.1.0"
@ -893,6 +952,49 @@ name = "serde"
version = "1.0.130" version = "1.0.130"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "serde_yaml"
version = "0.8.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8c608a35705a5d3cdc9fbe403147647ff34b921f8e833e49306df898f9b20af"
dependencies = [
"dtoa",
"indexmap",
"serde",
"yaml-rust",
]
[[package]]
name = "similar"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ad1d488a557b235fc46dae55512ffbfc429d2482b08b4d9435ab07384ca8aec"
[[package]] [[package]]
name = "siphasher" name = "siphasher"
@ -951,6 +1053,16 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "terminal_size"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
dependencies = [
"libc",
"winapi",
]
[[package]] [[package]]
name = "test-case" name = "test-case"
version = "1.2.0" version = "1.2.0"
@ -1049,6 +1161,12 @@ version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f14ee04d9415b52b3aeab06258a3f07093182b88ba0f9b8d203f211a7a7d41c7" checksum = "f14ee04d9415b52b3aeab06258a3f07093182b88ba0f9b8d203f211a7a7d41c7"
[[package]]
name = "uuid"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.3" version = "0.9.3"
@ -1082,3 +1200,12 @@ name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "yaml-rust"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
dependencies = [
"linked-hash-map",
]

View File

@ -17,3 +17,4 @@ rayon = "1.5.1"
[dev-dependencies] [dev-dependencies]
test-case = "1.2.0" test-case = "1.2.0"
indoc = "1.0" indoc = "1.0"
insta = "1.5"

View File

@ -0,0 +1,13 @@
---
source: nac3core/src/toplevel/test.rs
expression: res_vec
---
[
"10: Class {\nname: \"Generic_A\",\ndef_id: DefinitionId(10),\nancestors: [CustomClassKind { id: DefinitionId(10), params: [TypeVarKind(UnificationKey(107))] }, CustomClassKind { id: DefinitionId(13), params: [] }],\nfields: [(\"aa\", \"class3\"), (\"a\", \"class1\")],\nmethods: [(\"__init__\", \"fn[[], class4]\", DefinitionId(11)), (\"foo\", \"fn[[b=tvar3], class4]\", DefinitionId(15)), (\"fun\", \"fn[[a=class0], tvar4]\", DefinitionId(12))],\ntype_vars: [UnificationKey(107)]\n}\n",
"11: Function {\nname: \"Generic_A.__init__\",\nsig: \"fn[[], class4]\",\nvar_id: [4]\n}\n",
"12: Function {\nname: \"Generic_A.fun\",\nsig: \"fn[[a=class0], tvar4]\",\nvar_id: [4]\n}\n",
"13: Class {\nname: \"B\",\ndef_id: DefinitionId(13),\nancestors: [CustomClassKind { id: DefinitionId(13), params: [] }],\nfields: [(\"aa\", \"class3\")],\nmethods: [(\"__init__\", \"fn[[], class4]\", DefinitionId(14)), (\"foo\", \"fn[[b=tvar3], class4]\", DefinitionId(15))],\ntype_vars: []\n}\n",
"14: Function {\nname: \"B.__init__\",\nsig: \"fn[[], class4]\",\nvar_id: []\n}\n",
"15: Function {\nname: \"B.foo\",\nsig: \"fn[[b=tvar3], class4]\",\nvar_id: [3]\n}\n",
]

View File

@ -0,0 +1,16 @@
---
source: nac3core/src/toplevel/test.rs
expression: res_vec
---
[
"10: Class {\nname: \"A\",\ndef_id: DefinitionId(10),\nancestors: [CustomClassKind { id: DefinitionId(10), params: [TypeVarKind(UnificationKey(106))] }],\nfields: [(\"a\", \"class0\"), (\"b\", \"tvar3\"), (\"c\", \"class10[3->class1]\")],\nmethods: [(\"__init__\", \"fn[[t=tvar3], class4]\", DefinitionId(11)), (\"fun\", \"fn[[a=class0, b=tvar3], list[virtual[class14[4->class3]]]]\", DefinitionId(12)), (\"foo\", \"fn[[c=class17], class4]\", DefinitionId(13))],\ntype_vars: [UnificationKey(106)]\n}\n",
"11: Function {\nname: \"A.__init__\",\nsig: \"fn[[t=tvar3], class4]\",\nvar_id: [3]\n}\n",
"12: Function {\nname: \"A.fun\",\nsig: \"fn[[a=class0, b=tvar3], list[virtual[class14[4->class3]]]]\",\nvar_id: [3]\n}\n",
"13: Function {\nname: \"A.foo\",\nsig: \"fn[[c=class17], class4]\",\nvar_id: [3]\n}\n",
"14: Class {\nname: \"B\",\ndef_id: DefinitionId(14),\nancestors: [CustomClassKind { id: DefinitionId(14), params: [TypeVarKind(UnificationKey(107))] }, CustomClassKind { id: DefinitionId(10), params: [PrimitiveKind(UnificationKey(2))] }],\nfields: [(\"a\", \"class0\"), (\"b\", \"tvar3\"), (\"c\", \"class10[3->class1]\"), (\"d\", \"class17\")],\nmethods: [(\"__init__\", \"fn[[], class4]\", DefinitionId(15)), (\"fun\", \"fn[[a=class0, b=tvar3], list[virtual[class14[4->class3]]]]\", DefinitionId(16)), (\"foo\", \"fn[[c=class17], class4]\", DefinitionId(13))],\ntype_vars: [UnificationKey(107)]\n}\n",
"15: Function {\nname: \"B.__init__\",\nsig: \"fn[[], class4]\",\nvar_id: [4]\n}\n",
"16: Function {\nname: \"B.fun\",\nsig: \"fn[[a=class0, b=tvar3], list[virtual[class14[4->class3]]]]\",\nvar_id: [3, 4]\n}\n",
"17: Class {\nname: \"C\",\ndef_id: DefinitionId(17),\nancestors: [CustomClassKind { id: DefinitionId(17), params: [] }, CustomClassKind { id: DefinitionId(14), params: [PrimitiveKind(UnificationKey(3))] }, CustomClassKind { id: DefinitionId(10), params: [PrimitiveKind(UnificationKey(2))] }],\nfields: [(\"a\", \"class0\"), (\"b\", \"tvar3\"), (\"c\", \"class10[3->class1]\"), (\"d\", \"class17\"), (\"e\", \"class1\")],\nmethods: [(\"__init__\", \"fn[[], class4]\", DefinitionId(18)), (\"fun\", \"fn[[a=class0, b=tvar3], list[virtual[class14[4->class3]]]]\", DefinitionId(16)), (\"foo\", \"fn[[c=class17], class4]\", DefinitionId(13))],\ntype_vars: []\n}\n",
"18: Function {\nname: \"C.__init__\",\nsig: \"fn[[], class4]\",\nvar_id: []\n}\n",
]

View File

@ -0,0 +1,14 @@
---
source: nac3core/src/toplevel/test.rs
expression: res_vec
---
[
"10: Function {\nname: \"foo\",\nsig: \"fn[[a=list[class0], b=tuple[tvar3, class2]], class11[3->class15, 4->class3]]\",\nvar_id: [3]\n}\n",
"11: Class {\nname: \"A\",\ndef_id: DefinitionId(11),\nancestors: [CustomClassKind { id: DefinitionId(11), params: [TypeVarKind(UnificationKey(106)), TypeVarKind(UnificationKey(107))] }],\nfields: [(\"a\", \"tvar3\"), (\"b\", \"tvar4\")],\nmethods: [(\"__init__\", \"fn[[v=tvar4], class4]\", DefinitionId(12)), (\"fun\", \"fn[[a=tvar3], tvar4]\", DefinitionId(13))],\ntype_vars: [UnificationKey(106), UnificationKey(107)]\n}\n",
"12: Function {\nname: \"A.__init__\",\nsig: \"fn[[v=tvar4], class4]\",\nvar_id: [3, 4]\n}\n",
"13: Function {\nname: \"A.fun\",\nsig: \"fn[[a=tvar3], tvar4]\",\nvar_id: [3, 4]\n}\n",
"14: Function {\nname: \"gfun\",\nsig: \"fn[[a=class11[3->list[class2], 4->class0]], class4]\",\nvar_id: []\n}\n",
"15: Class {\nname: \"B\",\ndef_id: DefinitionId(15),\nancestors: [CustomClassKind { id: DefinitionId(15), params: [] }],\nfields: [],\nmethods: [(\"__init__\", \"fn[[], class4]\", DefinitionId(16))],\ntype_vars: []\n}\n",
"16: Function {\nname: \"B.__init__\",\nsig: \"fn[[], class4]\",\nvar_id: []\n}\n",
]

View File

@ -0,0 +1,14 @@
---
source: nac3core/src/toplevel/test.rs
expression: res_vec
---
[
"10: Class {\nname: \"A\",\ndef_id: DefinitionId(10),\nancestors: [CustomClassKind { id: DefinitionId(10), params: [TypeVarKind(UnificationKey(106)), TypeVarKind(UnificationKey(107))] }],\nfields: [(\"a\", \"class10[3->class2, 4->class3]\"), (\"b\", \"class13\")],\nmethods: [(\"__init__\", \"fn[[a=class10[3->class2, 4->class3], b=class13], class4]\", DefinitionId(11)), (\"fun\", \"fn[[a=class10[3->class2, 4->class3]], class10[3->class3, 4->class0]]\", DefinitionId(12))],\ntype_vars: [UnificationKey(106), UnificationKey(107)]\n}\n",
"11: Function {\nname: \"A.__init__\",\nsig: \"fn[[a=class10[3->class2, 4->class3], b=class13], class4]\",\nvar_id: [3, 4]\n}\n",
"12: Function {\nname: \"A.fun\",\nsig: \"fn[[a=class10[3->class2, 4->class3]], class10[3->class3, 4->class0]]\",\nvar_id: [3, 4]\n}\n",
"13: Class {\nname: \"B\",\ndef_id: DefinitionId(13),\nancestors: [CustomClassKind { id: DefinitionId(13), params: [] }, CustomClassKind { id: DefinitionId(10), params: [PrimitiveKind(UnificationKey(1)), PrimitiveKind(UnificationKey(3))] }],\nfields: [(\"a\", \"class10[3->class2, 4->class3]\"), (\"b\", \"class13\")],\nmethods: [(\"__init__\", \"fn[[], class4]\", DefinitionId(14)), (\"fun\", \"fn[[a=class10[3->class2, 4->class3]], class10[3->class3, 4->class0]]\", DefinitionId(12)), (\"foo\", \"fn[[b=class13], class13]\", DefinitionId(15)), (\"bar\", \"fn[[a=class10[3->list[class13], 4->class0]], tuple[class10[3->virtual[class10[3->class13, 4->class0]], 4->class3], class13]]\", DefinitionId(16))],\ntype_vars: []\n}\n",
"14: Function {\nname: \"B.__init__\",\nsig: \"fn[[], class4]\",\nvar_id: []\n}\n",
"15: Function {\nname: \"B.foo\",\nsig: \"fn[[b=class13], class13]\",\nvar_id: []\n}\n",
"16: Function {\nname: \"B.bar\",\nsig: \"fn[[a=class10[3->list[class13], 4->class0]], tuple[class10[3->virtual[class10[3->class13, 4->class0]], 4->class3], class13]]\",\nvar_id: []\n}\n",
]

View File

@ -0,0 +1,18 @@
---
source: nac3core/src/toplevel/test.rs
expression: res_vec
---
[
"10: Class {\nname: \"A\",\ndef_id: DefinitionId(10),\nancestors: [CustomClassKind { id: DefinitionId(10), params: [] }],\nfields: [(\"a\", \"class0\")],\nmethods: [(\"__init__\", \"fn[[], class4]\", DefinitionId(11)), (\"fun\", \"fn[[b=class14], class4]\", DefinitionId(12)), (\"foo\", \"fn[[a=tvar3, b=tvar4], class4]\", DefinitionId(13))],\ntype_vars: []\n}\n",
"11: Function {\nname: \"A.__init__\",\nsig: \"fn[[], class4]\",\nvar_id: []\n}\n",
"12: Function {\nname: \"A.fun\",\nsig: \"fn[[b=class14], class4]\",\nvar_id: []\n}\n",
"13: Function {\nname: \"A.foo\",\nsig: \"fn[[a=tvar3, b=tvar4], class4]\",\nvar_id: [3, 4]\n}\n",
"14: Class {\nname: \"B\",\ndef_id: DefinitionId(14),\nancestors: [CustomClassKind { id: DefinitionId(14), params: [] }, CustomClassKind { id: DefinitionId(16), params: [] }, CustomClassKind { id: DefinitionId(10), params: [] }],\nfields: [(\"a\", \"class0\")],\nmethods: [(\"__init__\", \"fn[[], class4]\", DefinitionId(15)), (\"fun\", \"fn[[b=class14], class4]\", DefinitionId(18)), (\"foo\", \"fn[[a=tvar3, b=tvar4], class4]\", DefinitionId(13))],\ntype_vars: []\n}\n",
"15: Function {\nname: \"B.__init__\",\nsig: \"fn[[], class4]\",\nvar_id: []\n}\n",
"16: Class {\nname: \"C\",\ndef_id: DefinitionId(16),\nancestors: [CustomClassKind { id: DefinitionId(16), params: [] }, CustomClassKind { id: DefinitionId(10), params: [] }],\nfields: [(\"a\", \"class0\")],\nmethods: [(\"__init__\", \"fn[[], class4]\", DefinitionId(17)), (\"fun\", \"fn[[b=class14], class4]\", DefinitionId(18)), (\"foo\", \"fn[[a=tvar3, b=tvar4], class4]\", DefinitionId(13))],\ntype_vars: []\n}\n",
"17: Function {\nname: \"C.__init__\",\nsig: \"fn[[], class4]\",\nvar_id: []\n}\n",
"18: Function {\nname: \"C.fun\",\nsig: \"fn[[b=class14], class4]\",\nvar_id: []\n}\n",
"19: Function {\nname: \"foo\",\nsig: \"fn[[a=class10], class4]\",\nvar_id: []\n}\n",
"20: Function {\nname: \"ff\",\nsig: \"fn[[a=tvar3], tvar4]\",\nvar_id: [3, 4]\n}\n",
]

View File

@ -0,0 +1,8 @@
---
source: nac3core/src/toplevel/test.rs
expression: res_vec
---
[
"10: Class {\nname: \"A\",\ndef_id: DefinitionId(10),\nancestors: [CustomClassKind { id: DefinitionId(10), params: [] }],\nfields: [],\nmethods: [],\ntype_vars: []\n}\n",
]

View File

@ -199,82 +199,7 @@ fn test_simple_function_analyze(source: Vec<&str>, tys: Vec<&str>, names: Vec<&s
pass pass
"} "}
], ],
vec![ vec![];
indoc! {"5: Class {
name: \"A\",
def_id: DefinitionId(5),
ancestors: [CustomClassKind { id: DefinitionId(5), params: [] }],
fields: [(\"a\", \"class0\")],
methods: [(\"__init__\", \"fn[[], class4]\", DefinitionId(6)), (\"fun\", \"fn[[b=class9], class4]\", DefinitionId(7)), (\"foo\", \"fn[[a=tvar2, b=tvar3], class4]\", DefinitionId(8))],
type_vars: []
}"},
indoc! {"6: Function {
name: \"A.__init__\",
sig: \"fn[[], class4]\",
var_id: []
}"},
indoc! {"7: Function {
name: \"A.fun\",
sig: \"fn[[b=class9], class4]\",
var_id: []
}"},
indoc! {"8: Function {
name: \"A.foo\",
sig: \"fn[[a=tvar2, b=tvar3], class4]\",
var_id: [2, 3]
}"},
indoc! {"9: Class {
name: \"B\",
def_id: DefinitionId(9),
ancestors: [CustomClassKind { id: DefinitionId(9), params: [] }, CustomClassKind { id: DefinitionId(11), params: [] }, CustomClassKind { id: DefinitionId(5), params: [] }],
fields: [(\"a\", \"class0\")],
methods: [(\"__init__\", \"fn[[], class4]\", DefinitionId(10)), (\"fun\", \"fn[[b=class9], class4]\", DefinitionId(13)), (\"foo\", \"fn[[a=tvar2, b=tvar3], class4]\", DefinitionId(8))],
type_vars: []
}"},
indoc! {"10: Function {
name: \"B.__init__\",
sig: \"fn[[], class4]\",
var_id: []
}"},
indoc! {"11: Class {
name: \"C\",
def_id: DefinitionId(11),
ancestors: [CustomClassKind { id: DefinitionId(11), params: [] }, CustomClassKind { id: DefinitionId(5), params: [] }],
fields: [(\"a\", \"class0\")],
methods: [(\"__init__\", \"fn[[], class4]\", DefinitionId(12)), (\"fun\", \"fn[[b=class9], class4]\", DefinitionId(13)), (\"foo\", \"fn[[a=tvar2, b=tvar3], class4]\", DefinitionId(8))],
type_vars: []
}"},
indoc! {"12: Function {
name: \"C.__init__\",
sig: \"fn[[], class4]\",
var_id: []
}"},
indoc! {"13: Function {
name: \"C.fun\",
sig: \"fn[[b=class9], class4]\",
var_id: []
}"},
indoc! {"14: Function {
name: \"foo\",
sig: \"fn[[a=class5], class4]\",
var_id: []
}"},
indoc! {"15: Function {
name: \"ff\",
sig: \"fn[[a=tvar2], tvar3]\",
var_id: [2, 3]
}"},
];
"simple class compose" "simple class compose"
)] )]
#[test_case( #[test_case(
@ -296,49 +221,7 @@ fn test_simple_function_analyze(source: Vec<&str>, tys: Vec<&str>, names: Vec<&s
pass pass
"} "}
], ],
vec![ vec![];
indoc! {"5: Class {
name: \"Generic_A\",
def_id: DefinitionId(5),
ancestors: [CustomClassKind { id: DefinitionId(5), params: [TypeVarKind(UnificationKey(101))] }, CustomClassKind { id: DefinitionId(8), params: [] }],
fields: [(\"aa\", \"class3\"), (\"a\", \"class1\")],
methods: [(\"__init__\", \"fn[[], class4]\", DefinitionId(6)), (\"foo\", \"fn[[b=tvar2], class4]\", DefinitionId(10)), (\"fun\", \"fn[[a=class0], tvar3]\", DefinitionId(7))],
type_vars: [UnificationKey(101)]
}"},
indoc! {"6: Function {
name: \"Generic_A.__init__\",
sig: \"fn[[], class4]\",
var_id: [3]
}"},
indoc! {"7: Function {
name: \"Generic_A.fun\",
sig: \"fn[[a=class0], tvar3]\",
var_id: [3]
}"},
indoc! {"8: Class {
name: \"B\",
def_id: DefinitionId(8),
ancestors: [CustomClassKind { id: DefinitionId(8), params: [] }],
fields: [(\"aa\", \"class3\")],
methods: [(\"__init__\", \"fn[[], class4]\", DefinitionId(9)), (\"foo\", \"fn[[b=tvar2], class4]\", DefinitionId(10))],
type_vars: []
}"},
indoc! {"9: Function {
name: \"B.__init__\",
sig: \"fn[[], class4]\",
var_id: []
}"},
indoc! {"10: Function {
name: \"B.foo\",
sig: \"fn[[b=tvar2], class4]\",
var_id: [2]
}"},
];
"generic class" "generic class"
)] )]
#[test_case( #[test_case(
@ -367,55 +250,7 @@ fn test_simple_function_analyze(source: Vec<&str>, tys: Vec<&str>, names: Vec<&s
pass pass
"} "}
], ],
vec![ vec![];
indoc! {"5: Function {
name: \"foo\",
sig: \"fn[[a=list[class0], b=tuple[tvar2, class2]], class6[2->class10, 3->class3]]\",
var_id: [2]
}"},
indoc! {"6: Class {
name: \"A\",
def_id: DefinitionId(6),
ancestors: [CustomClassKind { id: DefinitionId(6), params: [TypeVarKind(UnificationKey(100)), TypeVarKind(UnificationKey(101))] }],
fields: [(\"a\", \"tvar2\"), (\"b\", \"tvar3\")],
methods: [(\"__init__\", \"fn[[v=tvar3], class4]\", DefinitionId(7)), (\"fun\", \"fn[[a=tvar2], tvar3]\", DefinitionId(8))],
type_vars: [UnificationKey(100), UnificationKey(101)]
}"},
indoc! {"7: Function {
name: \"A.__init__\",
sig: \"fn[[v=tvar3], class4]\",
var_id: [2, 3]
}"},
indoc! {"8: Function {
name: \"A.fun\",
sig: \"fn[[a=tvar2], tvar3]\",
var_id: [2, 3]
}"},
indoc! {"9: Function {
name: \"gfun\",
sig: \"fn[[a=class6[2->list[class2], 3->class0]], class4]\",
var_id: []
}"},
indoc! {"10: Class {
name: \"B\",
def_id: DefinitionId(10),
ancestors: [CustomClassKind { id: DefinitionId(10), params: [] }],
fields: [],
methods: [(\"__init__\", \"fn[[], class4]\", DefinitionId(11))],
type_vars: []
}"},
indoc! {"11: Function {
name: \"B.__init__\",
sig: \"fn[[], class4]\",
var_id: []
}"},
];
"list tuple generic" "list tuple generic"
)] )]
#[test_case( #[test_case(
@ -440,55 +275,7 @@ fn test_simple_function_analyze(source: Vec<&str>, tys: Vec<&str>, names: Vec<&s
pass pass
"} "}
], ],
vec![ vec![];
indoc! {"5: Class {
name: \"A\",
def_id: DefinitionId(5),
ancestors: [CustomClassKind { id: DefinitionId(5), params: [TypeVarKind(UnificationKey(100)), TypeVarKind(UnificationKey(101))] }],
fields: [(\"a\", \"class5[2->class2, 3->class3]\"), (\"b\", \"class8\")],
methods: [(\"__init__\", \"fn[[a=class5[2->class2, 3->class3], b=class8], class4]\", DefinitionId(6)), (\"fun\", \"fn[[a=class5[2->class2, 3->class3]], class5[2->class3, 3->class0]]\", DefinitionId(7))],
type_vars: [UnificationKey(100), UnificationKey(101)]
}"},
indoc! {"6: Function {
name: \"A.__init__\",
sig: \"fn[[a=class5[2->class2, 3->class3], b=class8], class4]\",
var_id: [2, 3]
}"},
indoc! {"7: Function {
name: \"A.fun\",
sig: \"fn[[a=class5[2->class2, 3->class3]], class5[2->class3, 3->class0]]\",
var_id: [2, 3]
}"},
indoc! {"8: Class {
name: \"B\",
def_id: DefinitionId(8),
ancestors: [CustomClassKind { id: DefinitionId(8), params: [] }, CustomClassKind { id: DefinitionId(5), params: [PrimitiveKind(UnificationKey(1)), PrimitiveKind(UnificationKey(3))] }],
fields: [(\"a\", \"class5[2->class2, 3->class3]\"), (\"b\", \"class8\")],
methods: [(\"__init__\", \"fn[[], class4]\", DefinitionId(9)), (\"fun\", \"fn[[a=class5[2->class2, 3->class3]], class5[2->class3, 3->class0]]\", DefinitionId(7)), (\"foo\", \"fn[[b=class8], class8]\", DefinitionId(10)), (\"bar\", \"fn[[a=class5[2->list[class8], 3->class0]], tuple[class5[2->virtual[class5[2->class8, 3->class0]], 3->class3], class8]]\", DefinitionId(11))],
type_vars: []
}"},
indoc! {"9: Function {
name: \"B.__init__\",
sig: \"fn[[], class4]\",
var_id: []
}"},
indoc! {"10: Function {
name: \"B.foo\",
sig: \"fn[[b=class8], class8]\",
var_id: []
}"},
indoc! {"11: Function {
name: \"B.bar\",
sig: \"fn[[a=class5[2->list[class8], 3->class0]], tuple[class5[2->virtual[class5[2->class8, 3->class0]], 3->class3], class8]]\",
var_id: []
}"},
];
"self1" "self1"
)] )]
#[test_case( #[test_case(
@ -522,70 +309,7 @@ fn test_simple_function_analyze(source: Vec<&str>, tys: Vec<&str>, names: Vec<&s
pass pass
"} "}
], ],
vec![ vec![];
indoc! {"5: Class {
name: \"A\",
def_id: DefinitionId(5),
ancestors: [CustomClassKind { id: DefinitionId(5), params: [TypeVarKind(UnificationKey(100))] }],
fields: [(\"a\", \"class0\"), (\"b\", \"tvar2\"), (\"c\", \"class5[2->class1]\")],
methods: [(\"__init__\", \"fn[[t=tvar2], class4]\", DefinitionId(6)), (\"fun\", \"fn[[a=class0, b=tvar2], list[virtual[class9[3->class3]]]]\", DefinitionId(7)), (\"foo\", \"fn[[c=class12], class4]\", DefinitionId(8))],
type_vars: [UnificationKey(100)]
}"},
indoc! {"6: Function {
name: \"A.__init__\",
sig: \"fn[[t=tvar2], class4]\",
var_id: [2]
}"},
indoc! {"7: Function {
name: \"A.fun\",
sig: \"fn[[a=class0, b=tvar2], list[virtual[class9[3->class3]]]]\",
var_id: [2]
}"},
indoc! {"8: Function {
name: \"A.foo\",
sig: \"fn[[c=class12], class4]\",
var_id: [2]
}"},
indoc! {"9: Class {
name: \"B\",
def_id: DefinitionId(9),
ancestors: [CustomClassKind { id: DefinitionId(9), params: [TypeVarKind(UnificationKey(101))] }, CustomClassKind { id: DefinitionId(5), params: [PrimitiveKind(UnificationKey(2))] }],
fields: [(\"a\", \"class0\"), (\"b\", \"tvar2\"), (\"c\", \"class5[2->class1]\"), (\"d\", \"class12\")],
methods: [(\"__init__\", \"fn[[], class4]\", DefinitionId(10)), (\"fun\", \"fn[[a=class0, b=tvar2], list[virtual[class9[3->class3]]]]\", DefinitionId(11)), (\"foo\", \"fn[[c=class12], class4]\", DefinitionId(8))],
type_vars: [UnificationKey(101)]
}"},
indoc! {"10: Function {
name: \"B.__init__\",
sig: \"fn[[], class4]\",
var_id: [3]
}"},
indoc! {"11: Function {
name: \"B.fun\",
sig: \"fn[[a=class0, b=tvar2], list[virtual[class9[3->class3]]]]\",
var_id: [2, 3]
}"},
indoc! {"12: Class {
name: \"C\",
def_id: DefinitionId(12),
ancestors: [CustomClassKind { id: DefinitionId(12), params: [] }, CustomClassKind { id: DefinitionId(9), params: [PrimitiveKind(UnificationKey(3))] }, CustomClassKind { id: DefinitionId(5), params: [PrimitiveKind(UnificationKey(2))] }],
fields: [(\"a\", \"class0\"), (\"b\", \"tvar2\"), (\"c\", \"class5[2->class1]\"), (\"d\", \"class12\"), (\"e\", \"class1\")],
methods: [(\"__init__\", \"fn[[], class4]\", DefinitionId(13)), (\"fun\", \"fn[[a=class0, b=tvar2], list[virtual[class9[3->class3]]]]\", DefinitionId(11)), (\"foo\", \"fn[[c=class12], class4]\", DefinitionId(8))],
type_vars: []
}"},
indoc! {"13: Function {
name: \"C.__init__\",
sig: \"fn[[], class4]\",
var_id: []
}"},
];
"inheritance_override" "inheritance_override"
)] )]
#[test_case( #[test_case(
@ -795,36 +519,22 @@ fn test_analyze(source: Vec<&str>, res: Vec<&str>) {
} }
} else { } else {
// skip 5 to skip primitives // skip 5 to skip primitives
let mut res_vec: Vec<String> = Vec::new();
for (i, (def, _)) in for (i, (def, _)) in
composer.definition_ast_list.iter().skip(composer.built_in_num).enumerate() composer.definition_ast_list.iter().skip(composer.built_in_num).enumerate()
{ {
let def = &*def.read(); let def = &*def.read();
res_vec.push(format!(
if print { "{}: {}\n",
println!( i + composer.built_in_num,
"{}: {}\n", def.to_string(
i + 5, composer.unifier.borrow_mut(),
def.to_string( &mut |id| format!("class{}", id),
composer.unifier.borrow_mut(), &mut |id| format!("tvar{}", id)
&mut |id| format!("class{}", id),
&mut |id| format!("tvar{}", id)
)
);
} else {
assert_eq!(
format!(
"{}: {}",
i + 5,
def.to_string(
composer.unifier.borrow_mut(),
&mut |id| format!("class{}", id.to_string()),
&mut |id| format!("tvar{}", id.to_string()),
)
),
res[i]
) )
} ));
} }
insta::assert_debug_snapshot!(res_vec);
} }
} }