parser-test

Crates.ioparser-test
lib.rsparser-test
version0.3.3
sourcesrc
created_at2022-01-16 23:15:07.760866
updated_at2022-05-28 17:54:52.704132
descriptionDeclarative tester for parsers
homepage
repositoryhttps://github.com/romixlab/parser-test
max_upload_size
id515184
size9,997
Roman Isaikin (romixlab)

documentation

README

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));
Commit count: 9

cargo fmt