Add corpus tests for decl

main
trivernis 4 months ago
parent ef07ffd2d9
commit 1b1cf7dd6e
Signed by: Trivernis
GPG Key ID: 7E6D18B61C8D2F4B

@ -1,46 +1,25 @@
use pest::{consumes_to, parses_to}; use pest::{consumes_to, parses_to};
use pest_test::PestTester;
use crate::{Rule, SnekParser}; use crate::{Rule, SnekParser};
use lazy_static::lazy_static;
lazy_static! {
static ref TESTER: PestTester<Rule, SnekParser> = super::s_tester("statements");
}
#[test] #[test]
fn it_parses_plain_assignments() { fn it_parses_simple_decl() {
parses_to!(parser: SnekParser, input: "let a = 1", rule: Rule::statement, tokens: [ if let Err(e) = (*TESTER).evaluate_strict("simple-decl") {
statement(0, 9, [ panic!("{e}")
decl(0, 9, [ }
ident(4, 5),
expr(8, 9, [
literal(8, 9, [
integer(8, 9)
]),
])
]),
EOI(9, 9)
])
]);
} }
#[test] #[test]
fn it_parses_assignments_with_args() { fn it_parses_decl_with_args() {
parses_to!(parser: SnekParser, input: "let add a = a + 1", rule: Rule::statement, tokens: [ if let Err(e) = (*TESTER).evaluate_strict("fn-decl") {
statement(0, 17, [ panic!("{e}")
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)
]),
]);
} }
#[test] #[test]

@ -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: "")
)

@ -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: "")
)

@ -12,29 +12,29 @@ type MyRec = rec {
(file (file
(statement (statement
(type_decl (type_decl
(type_ident (type_ident
(ident: "MyRec") (ident: "MyRec")
) )
(type_expr (type_expr
(rec (rec
(rec_field (rec_field
(ident: "first") (ident: "first")
(type_expr (type_expr
(type_ident (type_ident
(ident: "Num") (ident: "Num")
) )
) )
) )
(rec_field (rec_field
(ident: "second") (ident: "second")
(type_expr (type_expr
(type_ident (type_ident
(ident: "Str") (ident: "Str")
) )
) )
) )
) )
) )
) )
) )
(EOI: "") (EOI: "")

Loading…
Cancel
Save