mirror of
https://github.com/Noratrieb/dilaria.git
synced 2026-01-14 17:35:03 +01:00
add more tests
This commit is contained in:
parent
61fa5434f9
commit
386ed99810
24 changed files with 61 additions and 31 deletions
|
|
@ -42,21 +42,28 @@ where {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_literal_bin_op<F: FnOnce(Vec<Token>, &Bump) -> Expr>(token_type: TokenType, parser: F) {
|
//fn test_literal_bin_op<F: FnOnce(Vec<Token>, &Bump) -> Expr>(token_type: TokenType, parser: F) {
|
||||||
let tokens = [Number(10.0), token_type, Number(4.0)].map(token).into();
|
macro_rules! test_literal_bin_op {
|
||||||
|
($token_type:expr, $parser:expr) => {
|
||||||
|
let tokens = [Number(10.0), $token_type, Number(4.0)].map(token).into();
|
||||||
|
|
||||||
let alloc = Bump::new();
|
let alloc = Bump::new();
|
||||||
let ast = parser(tokens, &alloc);
|
let ast = ($parser)(tokens, &alloc);
|
||||||
insta::assert_debug_snapshot!(ast);
|
insta::assert_debug_snapshot!(ast);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
use test_literal_bin_op;
|
||||||
|
|
||||||
fn test_number_literal<F: FnOnce(Vec<Token>, &Bump) -> Expr>(parser: F) {
|
macro_rules! test_number_literal {
|
||||||
let tokens = [Number(10.0)].map(token).into();
|
($parser:expr) => {
|
||||||
|
let tokens = [Number(10.0)].map(token).into();
|
||||||
|
|
||||||
let alloc = Bump::new();
|
let alloc = Bump::new();
|
||||||
let ast = parser(tokens, &alloc);
|
let ast = ($parser)(tokens, &alloc);
|
||||||
insta::assert_debug_snapshot!(ast);
|
insta::assert_debug_snapshot!(ast);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
use test_number_literal;
|
||||||
|
|
||||||
mod assignment {
|
mod assignment {
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
|
|
@ -343,7 +350,7 @@ mod expr {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn number_literal() {
|
fn number_literal() {
|
||||||
test_number_literal(parse_expr);
|
test_number_literal!(parse_expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -395,12 +402,12 @@ mod logical_or {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn number_literal() {
|
fn number_literal() {
|
||||||
test_number_literal(parse_logical_or);
|
test_number_literal!(parse_logical_or);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn or() {
|
fn or() {
|
||||||
test_literal_bin_op(Or, parse_logical_or);
|
test_literal_bin_op!(Or, parse_logical_or);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -414,12 +421,12 @@ mod logical_and {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn number_literal() {
|
fn number_literal() {
|
||||||
test_number_literal(parse_logical_and);
|
test_number_literal!(parse_logical_and);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn and() {
|
fn and() {
|
||||||
test_literal_bin_op(And, parse_logical_and);
|
test_literal_bin_op!(And, parse_logical_and);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -433,17 +440,17 @@ mod equality {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn number_literal() {
|
fn number_literal() {
|
||||||
test_number_literal(parse_equality);
|
test_number_literal!(parse_equality);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn not_equal() {
|
fn not_equal() {
|
||||||
test_literal_bin_op(BangEqual, parse_equality);
|
test_literal_bin_op!(BangEqual, parse_equality);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn equal() {
|
fn equal() {
|
||||||
test_literal_bin_op(EqualEqual, parse_equality);
|
test_literal_bin_op!(EqualEqual, parse_equality);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -457,27 +464,27 @@ mod comparison {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn number_literal() {
|
fn number_literal() {
|
||||||
test_number_literal(parse_comparison);
|
test_number_literal!(parse_comparison);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn greater() {
|
fn greater() {
|
||||||
test_literal_bin_op(Greater, parse_comparison);
|
test_literal_bin_op!(Greater, parse_comparison);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn greater_equal() {
|
fn greater_equal() {
|
||||||
test_literal_bin_op(GreaterEqual, parse_comparison);
|
test_literal_bin_op!(GreaterEqual, parse_comparison);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn less() {
|
fn less() {
|
||||||
test_literal_bin_op(Less, parse_comparison);
|
test_literal_bin_op!(Less, parse_comparison);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn less_equal() {
|
fn less_equal() {
|
||||||
test_literal_bin_op(LessEqual, parse_comparison);
|
test_literal_bin_op!(LessEqual, parse_comparison);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -491,17 +498,17 @@ mod term {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn number_literal() {
|
fn number_literal() {
|
||||||
test_number_literal(parse_term);
|
test_number_literal!(parse_term);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn add() {
|
fn add() {
|
||||||
test_literal_bin_op(Plus, parse_term);
|
test_literal_bin_op!(Plus, parse_term);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn sub() {
|
fn sub() {
|
||||||
test_literal_bin_op(Minus, parse_term);
|
test_literal_bin_op!(Minus, parse_term);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -515,22 +522,22 @@ mod factor {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn number_literal() {
|
fn number_literal() {
|
||||||
test_number_literal(parse_factor);
|
test_number_literal!(parse_factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn multiply() {
|
fn multiply() {
|
||||||
test_literal_bin_op(Asterisk, parse_factor);
|
test_literal_bin_op!(Asterisk, parse_factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn divide() {
|
fn divide() {
|
||||||
test_literal_bin_op(Slash, parse_factor);
|
test_literal_bin_op!(Slash, parse_factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn modulo() {
|
fn modulo() {
|
||||||
test_literal_bin_op(Percent, parse_factor);
|
test_literal_bin_op!(Percent, parse_factor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -544,7 +551,7 @@ mod unary {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn number_literal() {
|
fn number_literal() {
|
||||||
test_number_literal(parse_unary);
|
test_number_literal!(parse_unary);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
|
|
@ -23,3 +23,21 @@ test();
|
||||||
print "correct2";
|
print "correct2";
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
|
||||||
|
run_test!(
|
||||||
|
multiple_calls,
|
||||||
|
r#"
|
||||||
|
fn test1() {
|
||||||
|
print "correct1";
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test2() {
|
||||||
|
print "correct2";
|
||||||
|
}
|
||||||
|
|
||||||
|
test1();
|
||||||
|
test2();
|
||||||
|
|
||||||
|
print "correct3";
|
||||||
|
"#
|
||||||
|
);
|
||||||
|
|
|
||||||
5
tests/snapshots/functions__multiple_calls.snap
Normal file
5
tests/snapshots/functions__multiple_calls.snap
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
source: tests/functions.rs
|
||||||
|
expression: output
|
||||||
|
---
|
||||||
|
"correct1\ncorrect2\ncorrect3\n"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue