Adds lexed token and parsed tree tests to class_with_many_statements

This commit is contained in:
Deukhoofd 2022-04-07 20:55:50 +02:00
parent 08eb97cf38
commit 32636c7724
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
3 changed files with 1884 additions and 0 deletions

View File

@ -42,6 +42,294 @@ fn integration_class_with_many_statements() {
let parsed_tree = parse(lexed_tokens, &mut panic_on_error);
println!("Parsed Tree JSON: {}", serde_json::to_string(&parsed_tree).unwrap());
let expected_tree: Box<ParsedStatement> =
serde_json::from_str(r#"{
"Script": {
"statements": [
{
"ClassDeclaration": {
"modifiers": 10,
"name": "Foobar",
"inherits": [],
"statements": [
{
"Var": {
"modifier": 0,
"var_type": {
"Type": {
"is_const": false,
"scope": null,
"datatype": {
"DataTypePrimType": {
"prim_type": "Int32"
}
},
"modifiers": []
}
},
"identifier": "_a",
"assignment": null
}
},
{
"Var": {
"modifier": 0,
"var_type": {
"Type": {
"is_const": false,
"scope": null,
"datatype": {
"DataTypePrimType": {
"prim_type": "Int32"
}
},
"modifiers": []
}
},
"identifier": "_b",
"assignment": null
}
},
{
"FuncDeclaration": {
"modifiers": 0,
"field_mod": null,
"is_destructor": false,
"is_constructor": true,
"returns_reference": false,
"return_type": {
"Type": {
"is_const": false,
"scope": null,
"datatype": {
"DataTypeIdentifier": {
"identifier": "Foobar"
}
},
"modifiers": []
}
},
"name": "Foobar",
"param_list": {
"ParamList": {
"parameters": [
{
"parameter_type": {
"Type": {
"is_const": false,
"scope": null,
"datatype": {
"DataTypePrimType": {
"prim_type": "Int32"
}
},
"modifiers": []
}
},
"type_mod": null,
"identifier": "a",
"default": null
},
{
"parameter_type": {
"Type": {
"is_const": false,
"scope": null,
"datatype": {
"DataTypePrimType": {
"prim_type": "Int32"
}
},
"modifiers": []
}
},
"type_mod": null,
"identifier": "b",
"default": null
}
]
}
},
"is_const": false,
"func_attr": 0,
"block": {
"StatBlock": {
"statements": [
{
"Assignment": {
"left": {
"VarAccess": {
"scope": null,
"identifier": "_a"
}
},
"operator": "Assignment",
"right": {
"VarAccess": {
"scope": null,
"identifier": "a"
}
}
}
},
{
"Assignment": {
"left": {
"VarAccess": {
"scope": null,
"identifier": "_b"
}
},
"operator": "Assignment",
"right": {
"VarAccess": {
"scope": null,
"identifier": "b"
}
}
}
}
]
}
}
}
},
{
"FuncDeclaration": {
"modifiers": 0,
"field_mod": null,
"is_destructor": false,
"is_constructor": false,
"returns_reference": false,
"return_type": {
"Type": {
"is_const": false,
"scope": null,
"datatype": {
"DataTypePrimType": {
"prim_type": "Int32"
}
},
"modifiers": []
}
},
"name": "GetA",
"param_list": {
"ParamList": {
"parameters": []
}
},
"is_const": false,
"func_attr": 0,
"block": {
"StatBlock": {
"statements": [
{
"ReturnStatement": {
"expression": {
"VarAccess": {
"scope": null,
"identifier": "_a"
}
}
}
}
]
}
}
}
},
{
"FuncDeclaration": {
"modifiers": 0,
"field_mod": null,
"is_destructor": false,
"is_constructor": false,
"returns_reference": false,
"return_type": {
"Type": {
"is_const": false,
"scope": null,
"datatype": {
"DataTypePrimType": {
"prim_type": "Int32"
}
},
"modifiers": []
}
},
"name": "Add",
"param_list": {
"ParamList": {
"parameters": []
}
},
"is_const": false,
"func_attr": 0,
"block": {
"StatBlock": {
"statements": [
{
"ReturnStatement": {
"expression": {
"BinaryExpr": {
"left": {
"VarAccess": {
"scope": null,
"identifier": "_a"
}
},
"operator": "Addition",
"right": {
"VarAccess": {
"scope": null,
"identifier": "_b"
}
}
}
}
}
}
]
}
}
}
},
{
"ClassDeclaration": {
"modifiers": 0,
"name": "Inner",
"inherits": [],
"statements": [
{
"Var": {
"modifier": 0,
"var_type": {
"Type": {
"is_const": false,
"scope": null,
"datatype": {
"DataTypePrimType": {
"prim_type": "Int32"
}
},
"modifiers": []
}
},
"identifier": "a",
"assignment": null
}
}
]
}
}
]
}
}
]
}
}"#).unwrap();
assert_eq!(parsed_tree, expected_tree);
}
// A substring of a script should never panic, even though it might be completely invalid.
#[test]

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,286 @@
{
"Script": {
"statements": [
{
"ClassDeclaration": {
"modifiers": 10,
"name": "Foobar",
"inherits": [],
"statements": [
{
"Var": {
"modifier": 0,
"var_type": {
"Type": {
"is_const": false,
"scope": null,
"datatype": {
"DataTypePrimType": {
"prim_type": "Int32"
}
},
"modifiers": []
}
},
"identifier": "_a",
"assignment": null
}
},
{
"Var": {
"modifier": 0,
"var_type": {
"Type": {
"is_const": false,
"scope": null,
"datatype": {
"DataTypePrimType": {
"prim_type": "Int32"
}
},
"modifiers": []
}
},
"identifier": "_b",
"assignment": null
}
},
{
"FuncDeclaration": {
"modifiers": 0,
"field_mod": null,
"is_destructor": false,
"is_constructor": true,
"returns_reference": false,
"return_type": {
"Type": {
"is_const": false,
"scope": null,
"datatype": {
"DataTypeIdentifier": {
"identifier": "Foobar"
}
},
"modifiers": []
}
},
"name": "Foobar",
"param_list": {
"ParamList": {
"parameters": [
{
"parameter_type": {
"Type": {
"is_const": false,
"scope": null,
"datatype": {
"DataTypePrimType": {
"prim_type": "Int32"
}
},
"modifiers": []
}
},
"type_mod": null,
"identifier": "a",
"default": null
},
{
"parameter_type": {
"Type": {
"is_const": false,
"scope": null,
"datatype": {
"DataTypePrimType": {
"prim_type": "Int32"
}
},
"modifiers": []
}
},
"type_mod": null,
"identifier": "b",
"default": null
}
]
}
},
"is_const": false,
"func_attr": 0,
"block": {
"StatBlock": {
"statements": [
{
"Assignment": {
"left": {
"VarAccess": {
"scope": null,
"identifier": "_a"
}
},
"operator": "Assignment",
"right": {
"VarAccess": {
"scope": null,
"identifier": "a"
}
}
}
},
{
"Assignment": {
"left": {
"VarAccess": {
"scope": null,
"identifier": "_b"
}
},
"operator": "Assignment",
"right": {
"VarAccess": {
"scope": null,
"identifier": "b"
}
}
}
}
]
}
}
}
},
{
"FuncDeclaration": {
"modifiers": 0,
"field_mod": null,
"is_destructor": false,
"is_constructor": false,
"returns_reference": false,
"return_type": {
"Type": {
"is_const": false,
"scope": null,
"datatype": {
"DataTypePrimType": {
"prim_type": "Int32"
}
},
"modifiers": []
}
},
"name": "GetA",
"param_list": {
"ParamList": {
"parameters": []
}
},
"is_const": false,
"func_attr": 0,
"block": {
"StatBlock": {
"statements": [
{
"ReturnStatement": {
"expression": {
"VarAccess": {
"scope": null,
"identifier": "_a"
}
}
}
}
]
}
}
}
},
{
"FuncDeclaration": {
"modifiers": 0,
"field_mod": null,
"is_destructor": false,
"is_constructor": false,
"returns_reference": false,
"return_type": {
"Type": {
"is_const": false,
"scope": null,
"datatype": {
"DataTypePrimType": {
"prim_type": "Int32"
}
},
"modifiers": []
}
},
"name": "Add",
"param_list": {
"ParamList": {
"parameters": []
}
},
"is_const": false,
"func_attr": 0,
"block": {
"StatBlock": {
"statements": [
{
"ReturnStatement": {
"expression": {
"BinaryExpr": {
"left": {
"VarAccess": {
"scope": null,
"identifier": "_a"
}
},
"operator": "Addition",
"right": {
"VarAccess": {
"scope": null,
"identifier": "_b"
}
}
}
}
}
}
]
}
}
}
},
{
"ClassDeclaration": {
"modifiers": 0,
"name": "Inner",
"inherits": [],
"statements": [
{
"Var": {
"modifier": 0,
"var_type": {
"Type": {
"is_const": false,
"scope": null,
"datatype": {
"DataTypePrimType": {
"prim_type": "Int32"
}
},
"modifiers": []
}
},
"identifier": "a",
"assignment": null
}
}
]
}
}
]
}
}
]
}
}