Skip to content

Commit

Permalink
add file inclusion tests (#84)
Browse files Browse the repository at this point in the history
* add file inclusion tests

* Fix Diagnostics import

This shall fix the clippy error

Co-authored-by: tirix <[email protected]>
  • Loading branch information
digama0 and tirix authored Apr 6, 2022
1 parent 69ec97b commit 79f36f6
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/parser_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,49 @@ fn test_stref_v() {
assert_eq!(zz, vec![b"Y", b"Z"]);
}

#[test]
fn test_inclusion() {
use Diagnostic::*;
macro_rules! test {
( $start:literal: { $($name:literal = $text:literal),* $(,)? };
parse [$($e:expr),* $(,)?];
errors [$($parse:expr),* $(,)?];
) => {{
use StatementType::*;
let mut db = Database::default();
db.parse($start.to_owned(), vec![$(($name.to_owned(), $text.to_vec()),)*]);
assert_eq!(
db.parse_result()
.segments(..)
.map(|seg| {
seg.into_iter()
.map(|stmt| stmt.statement_type())
.collect::<Vec<_>>()
})
.collect::<Vec<_>>(),
[$($e.to_vec(),)*].to_vec()
);
let diags = db.parse_result().parse_diagnostics();
assert_eq!(diags.into_iter().map(|e| e.1).collect::<Vec<_>>(), vec![$($parse,)*]);
}}
}
test!(
"A": { "A" = b"$[ B $] $c a $.", "B" = b"$[ B $] ${ $}" };
parse [[FileInclude], [FileInclude], [OpenGroup, CloseGroup, Eof], [Constant, Eof]];
errors [];
);
test!(
"A": { "A" = b"${ $[ B $] $}", "B" = b"$c b $." };
parse [[OpenGroup, FileInclude], [Constant, Eof], [CloseGroup, Eof]];
errors [UnclosedBeforeInclude(1), UnmatchedCloseGroup];
);
test!(
"A": { "A" = b"${ $c b $. $}" };
parse [[OpenGroup, Constant, CloseGroup, Eof]];
errors [ConstantNotTopLevel];
);
}

macro_rules! parse_test {
($name:ident, $text:expr, $diags:expr) => {
#[test]
Expand Down

0 comments on commit 79f36f6

Please sign in to comment.