Crates.io | parser-test |
lib.rs | parser-test |
version | 0.3.3 |
source | src |
created_at | 2022-01-16 23:15:07.760866 |
updated_at | 2022-05-28 17:54:52.704132 |
description | Declarative tester for parsers |
homepage | |
repository | https://github.com/romixlab/parser-test |
max_upload_size | |
id | 515184 |
size | 9,997 |
This crate allows you to write parser's tests like follows:
let input = "#( a b #items x y )*";
let spans = " ^ ^ ^----^ ^ ^ ";
let expected = [
Rule::token,
Rule::token,
Rule::interpolate,
Rule::token,
Rule::token,
];
Highlight each token with ^
, ^^
or ^---^
to indicate it's span. parser_test::test()
will make sure that
parser output containts excactly those tokens in specified positions.
Any parser can be used, as long as you implement Token
trait for it's output.
Generic TestToken
is provided and can probably be used for all use cases.
So far this crate is used to test pest parsers:
let mut output = Lexer::parse(Rule::interpolate_repetition, input).unwrap();
let output = output.next().unwrap().into_inner().map(|t| {
let span = t.as_span();
TestToken {
start: span.start(),
end: span.end() - 1,
rule: t.as_rule()
}
});
assert!(parser_test::test(output, expected, spans));