Module test

Source
Expand description

Test framework for parsers.

use nom::bytes::complete::tag;
use kparse::combinators::with_code;
use kparse::examples::{ExSpan, ExTagB, ExTokenizerResult};
use kparse::test::{CheckDump, str_parse};

// run the parser and expect Ok(). Otherwise dump & panic.
str_parse(&mut None, "b", nom_parse_b).ok_any().q(CheckDump);

fn nom_parse_b(i: ExSpan<'_>) -> ExTokenizerResult<'_, ExSpan<'_>> {
    with_code(tag("b"), ExTagB)(i)
}

Runs the parser and works like a builder to evaluate the results. The final function is q() which runs the given report.

Note: The &mut None is because lifetimes.

Structs§

CheckDump
Dumps the Result data if any test failed.
CheckTrace
Dumps the full parser trace if any test failed.
Dump
Dumps the Result data.
NoReport
Do nothing report.
Test
Collected data of the test run.
Timing
Dumps the Result data.
Trace
Dumps the full parser trace.

Traits§

Report
Result reporting.

Functions§

byte_parse
Runs a parser for &u8 and records the results. Use ok(), err(), … to check specifics. Finish the test with q().
str_parse
Runs a parser for &str and records the results. Use ok(), err(), … to check specifics. Finish the test with q().

Type Aliases§

TestEqFn
Value comparison.