From 1b1cf7dd6ec8b5c558ed9c9a644500735cfc87fe Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 21 Jul 2024 20:54:34 +0200 Subject: [PATCH] Add corpus tests for decl --- src/test/statements.rs | 49 +++++++------------------ tests/corpus/statements/fn-decl.txt | 43 ++++++++++++++++++++++ tests/corpus/statements/simple-decl.txt | 46 +++++++++++++++++++++++ tests/corpus/types/recs.txt | 46 +++++++++++------------ 4 files changed, 126 insertions(+), 58 deletions(-) create mode 100644 tests/corpus/statements/fn-decl.txt create mode 100644 tests/corpus/statements/simple-decl.txt diff --git a/src/test/statements.rs b/src/test/statements.rs index e2d63e9..9133ce7 100644 --- a/src/test/statements.rs +++ b/src/test/statements.rs @@ -1,46 +1,25 @@ use pest::{consumes_to, parses_to}; +use pest_test::PestTester; use crate::{Rule, SnekParser}; +use lazy_static::lazy_static; + +lazy_static! { + static ref TESTER: PestTester = super::s_tester("statements"); +} #[test] -fn it_parses_plain_assignments() { - parses_to!(parser: SnekParser, input: "let a = 1", rule: Rule::statement, tokens: [ - statement(0, 9, [ - decl(0, 9, [ - ident(4, 5), - expr(8, 9, [ - literal(8, 9, [ - integer(8, 9) - ]), - ]) - ]), - EOI(9, 9) - ]) - ]); +fn it_parses_simple_decl() { + if let Err(e) = (*TESTER).evaluate_strict("simple-decl") { + panic!("{e}") + } } #[test] -fn it_parses_assignments_with_args() { - parses_to!(parser: SnekParser, input: "let add a = a + 1", rule: Rule::statement, tokens: [ - statement(0, 17, [ - decl(0, 17, [ - ident(4, 7), - ident(8, 9), - expr(12, 17, [ - infix_expr(12, 17, [ - ident(12, 13), - operator(14, 15), - expr(16, 17, [ - literal(16, 17, [ - integer(16, 17) - ]) - ]) - ]) - ]) - ]), - EOI(17, 17) - ]), - ]); +fn it_parses_decl_with_args() { + if let Err(e) = (*TESTER).evaluate_strict("fn-decl") { + panic!("{e}") + } } #[test] diff --git a/tests/corpus/statements/fn-decl.txt b/tests/corpus/statements/fn-decl.txt new file mode 100644 index 0000000..7f7b197 --- /dev/null +++ b/tests/corpus/statements/fn-decl.txt @@ -0,0 +1,43 @@ +Args Declaration Test + +====== + +let add a b = a + b +let add1 a = add a 1 + +====== + +(file + (statement + (decl + (ident: "add") + (ident: "a") + (ident: "b") + (expr + (infix_expr + (ident: "a") + (operator: "+") + (expr + (ident: "b") + ) + ) + ) + ) + ) + (statement + (decl + (ident: "add1") + (ident: "a") + (expr + (call_expr + (ident: "add") + (ident: "a") + (literal + (integer: "1") + ) + ) + ) + ) + ) + (EOI: "") +) diff --git a/tests/corpus/statements/simple-decl.txt b/tests/corpus/statements/simple-decl.txt new file mode 100644 index 0000000..81aa4b5 --- /dev/null +++ b/tests/corpus/statements/simple-decl.txt @@ -0,0 +1,46 @@ +Declaration Test + +====== + +let a = 1 + 1 +let b = a + 2 + +====== + +(file + (statement + (decl + (ident: "a") + (expr + (infix_expr + (literal + (integer: "1") + ) + (operator: "+") + (expr + (literal + (integer: "1") + ) + ) + ) + ) + ) + ) + (statement + (decl + (ident: "b") + (expr + (infix_expr + (ident: "a") + (operator: "+") + (expr + (literal + (integer: "2") + ) + ) + ) + ) + ) + ) + (EOI: "") +) diff --git a/tests/corpus/types/recs.txt b/tests/corpus/types/recs.txt index 12ad6fd..12d00cd 100644 --- a/tests/corpus/types/recs.txt +++ b/tests/corpus/types/recs.txt @@ -12,29 +12,29 @@ type MyRec = rec { (file (statement (type_decl - (type_ident - (ident: "MyRec") - ) - (type_expr - (rec - (rec_field - (ident: "first") - (type_expr - (type_ident - (ident: "Num") - ) - ) - ) - (rec_field - (ident: "second") - (type_expr - (type_ident - (ident: "Str") - ) - ) - ) - ) - ) + (type_ident + (ident: "MyRec") + ) + (type_expr + (rec + (rec_field + (ident: "first") + (type_expr + (type_ident + (ident: "Num") + ) + ) + ) + (rec_field + (ident: "second") + (type_expr + (type_ident + (ident: "Str") + ) + ) + ) + ) + ) ) ) (EOI: "")