Support constructor func calls, more integration tests
This commit is contained in:
@@ -20,7 +20,7 @@ fn integration_add_function() {
|
||||
return a + b;
|
||||
}";
|
||||
let lexed_tokens = lex(script, &mut panic_on_error);
|
||||
println!("{}", serde_json::to_string(&lexed_tokens).unwrap());
|
||||
println!("Lexed tokens JSON: {}", serde_json::to_string(&lexed_tokens).unwrap());
|
||||
let expected_tokens: Vec<LexToken> =
|
||||
serde_json::from_str(r#"[
|
||||
{
|
||||
@@ -254,7 +254,7 @@ fn integration_add_function() {
|
||||
assert_eq!(lexed_tokens, expected_tokens);
|
||||
|
||||
let parsed_tree = parse(lexed_tokens, &mut panic_on_error);
|
||||
println!("{}", serde_json::to_string(&parsed_tree).unwrap());
|
||||
println!("Parsed Tree JSON: {}", serde_json::to_string(&parsed_tree).unwrap());
|
||||
let expected_tree: Box<ParsedStatement> =
|
||||
serde_json::from_str(r#"{
|
||||
"Script": {
|
||||
@@ -264,6 +264,7 @@ fn integration_add_function() {
|
||||
"modifiers": 0,
|
||||
"field_mod": null,
|
||||
"is_destructor": false,
|
||||
"is_constructor": false,
|
||||
"returns_reference": false,
|
||||
"return_type": {
|
||||
"Type": {
|
||||
|
||||
@@ -68,7 +68,7 @@ fn panic_on_error(msg: Message, _: Span) {{
|
||||
fn integration_{name}() {{
|
||||
let script = "{script}";
|
||||
let lexed_tokens = lex(script, &mut panic_on_error);
|
||||
println!("{{}}", serde_json::to_string(&lexed_tokens).unwrap());
|
||||
println!("Lexed tokens JSON: {{}}", serde_json::to_string(&lexed_tokens).unwrap());
|
||||
"#,
|
||||
name = test_name,
|
||||
script = script.as_str()
|
||||
@@ -94,7 +94,7 @@ fn integration_{name}() {{
|
||||
testfile,
|
||||
r##"
|
||||
let parsed_tree = parse(lexed_tokens, &mut panic_on_error);
|
||||
println!("{{}}", serde_json::to_string(&parsed_tree).unwrap());
|
||||
println!("Parsed Tree JSON: {{}}", serde_json::to_string(&parsed_tree).unwrap());
|
||||
"##
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
77
src/integration_tests/class_with_many_statements.rs
Normal file
77
src/integration_tests/class_with_many_statements.rs
Normal file
@@ -0,0 +1,77 @@
|
||||
////////////////////////////
|
||||
// Automatically Generated//
|
||||
////////////////////////////
|
||||
use crate::logger::messages::Message;
|
||||
use crate::parsing::lexer::lex;
|
||||
use crate::parsing::lexer::lex_tokens::LexToken;
|
||||
use crate::parsing::parser::parse;
|
||||
use crate::parsing::parser::parsed_statement::ParsedStatement;
|
||||
use crate::span::Span;
|
||||
|
||||
fn ignore_error(_msg: Message, _: Span) {
|
||||
}
|
||||
|
||||
fn panic_on_error(msg: Message, _: Span) {
|
||||
std::panic::panic_any(msg.stringify());
|
||||
}
|
||||
#[test]
|
||||
fn integration_class_with_many_statements() {
|
||||
let script = "final shared class Foobar {
|
||||
int _a;
|
||||
int _b;
|
||||
|
||||
Foobar(int a, int b) {
|
||||
_a = a;
|
||||
_b = b;
|
||||
}
|
||||
|
||||
int GetA(){
|
||||
return _a;
|
||||
}
|
||||
|
||||
int Add() {
|
||||
return _a + _b;
|
||||
}
|
||||
|
||||
class Inner {
|
||||
int a;
|
||||
}
|
||||
}";
|
||||
let lexed_tokens = lex(script, &mut panic_on_error);
|
||||
println!("Lexed tokens JSON: {}", serde_json::to_string(&lexed_tokens).unwrap());
|
||||
|
||||
let parsed_tree = parse(lexed_tokens, &mut panic_on_error);
|
||||
println!("Parsed Tree JSON: {}", serde_json::to_string(&parsed_tree).unwrap());
|
||||
}
|
||||
// A substring of a script should never panic, even though it might be completely invalid.
|
||||
#[test]
|
||||
fn integration_class_with_many_statements_substring() {
|
||||
let mut script = "final shared class Foobar {
|
||||
int _a;
|
||||
int _b;
|
||||
|
||||
Foobar(int a, int b) {
|
||||
_a = a;
|
||||
_b = b;
|
||||
}
|
||||
|
||||
int GetA(){
|
||||
return _a;
|
||||
}
|
||||
|
||||
int Add() {
|
||||
return _a + _b;
|
||||
}
|
||||
|
||||
class Inner {
|
||||
int a;
|
||||
}
|
||||
}".to_string();
|
||||
for _ in 0..script.len() {
|
||||
script.pop();
|
||||
let lexed_tokens = lex(script.as_str(), &mut ignore_error);
|
||||
let _parsed_tree = parse(lexed_tokens, &mut ignore_error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ fn panic_on_error(msg: Message, _: Span) {
|
||||
fn integration_empty_class_declaration() {
|
||||
let script = "class Foo {}";
|
||||
let lexed_tokens = lex(script, &mut panic_on_error);
|
||||
println!("{}", serde_json::to_string(&lexed_tokens).unwrap());
|
||||
println!("Lexed tokens JSON: {}", serde_json::to_string(&lexed_tokens).unwrap());
|
||||
let expected_tokens: Vec<LexToken> =
|
||||
serde_json::from_str(r#"[
|
||||
{
|
||||
@@ -76,7 +76,7 @@ fn integration_empty_class_declaration() {
|
||||
assert_eq!(lexed_tokens, expected_tokens);
|
||||
|
||||
let parsed_tree = parse(lexed_tokens, &mut panic_on_error);
|
||||
println!("{}", serde_json::to_string(&parsed_tree).unwrap());
|
||||
println!("Parsed Tree JSON: {}", serde_json::to_string(&parsed_tree).unwrap());
|
||||
let expected_tree: Box<ParsedStatement> =
|
||||
serde_json::from_str(r#"{
|
||||
"Script": {
|
||||
|
||||
@@ -24,7 +24,7 @@ fn integration_enum_definition() {
|
||||
e
|
||||
}";
|
||||
let lexed_tokens = lex(script, &mut panic_on_error);
|
||||
println!("{}", serde_json::to_string(&lexed_tokens).unwrap());
|
||||
println!("Lexed tokens JSON: {}", serde_json::to_string(&lexed_tokens).unwrap());
|
||||
let expected_tokens: Vec<LexToken> =
|
||||
serde_json::from_str(r#"[
|
||||
{
|
||||
@@ -395,7 +395,7 @@ fn integration_enum_definition() {
|
||||
assert_eq!(lexed_tokens, expected_tokens);
|
||||
|
||||
let parsed_tree = parse(lexed_tokens, &mut panic_on_error);
|
||||
println!("{}", serde_json::to_string(&parsed_tree).unwrap());
|
||||
println!("Parsed Tree JSON: {}", serde_json::to_string(&parsed_tree).unwrap());
|
||||
let expected_tree: Box<ParsedStatement> =
|
||||
serde_json::from_str(r#"{
|
||||
"Script": {
|
||||
|
||||
@@ -3,4 +3,5 @@
|
||||
////////////////////////////mod enum_definition;
|
||||
mod multiple_inheritance_class;
|
||||
mod empty_class_declaration;
|
||||
mod class_with_many_statements;
|
||||
mod add_function;
|
||||
|
||||
@@ -18,7 +18,7 @@ fn panic_on_error(msg: Message, _: Span) {
|
||||
fn integration_multiple_inheritance_class() {
|
||||
let script = "class Foo : Zom, Aar, Bar {}";
|
||||
let lexed_tokens = lex(script, &mut panic_on_error);
|
||||
println!("{}", serde_json::to_string(&lexed_tokens).unwrap());
|
||||
println!("Lexed tokens JSON: {}", serde_json::to_string(&lexed_tokens).unwrap());
|
||||
let expected_tokens: Vec<LexToken> =
|
||||
serde_json::from_str(r#"[
|
||||
{
|
||||
@@ -152,7 +152,7 @@ fn integration_multiple_inheritance_class() {
|
||||
assert_eq!(lexed_tokens, expected_tokens);
|
||||
|
||||
let parsed_tree = parse(lexed_tokens, &mut panic_on_error);
|
||||
println!("{}", serde_json::to_string(&parsed_tree).unwrap());
|
||||
println!("Parsed Tree JSON: {}", serde_json::to_string(&parsed_tree).unwrap());
|
||||
let expected_tree: Box<ParsedStatement> =
|
||||
serde_json::from_str(r#"{
|
||||
"Script": {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
"modifiers": 0,
|
||||
"field_mod": null,
|
||||
"is_destructor": false,
|
||||
"is_constructor": false,
|
||||
"returns_reference": false,
|
||||
"return_type": {
|
||||
"Type": {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
final shared class Foobar {
|
||||
int _a;
|
||||
int _b;
|
||||
|
||||
Foobar(int a, int b) {
|
||||
_a = a;
|
||||
_b = b;
|
||||
}
|
||||
|
||||
int GetA(){
|
||||
return _a;
|
||||
}
|
||||
|
||||
int Add() {
|
||||
return _a + _b;
|
||||
}
|
||||
|
||||
class Inner {
|
||||
int a;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user