nom-test-helpers

Macros to help with testing nom parsers


License
CC-PDDC

Documentation

Nom Test Helpers

Usage

Put this in your Cargo.toml:

[dev-dependencies]
nom-test-helpers = "2"

And in your crate root:

#[cfg(test)]
#[macro_use] extern crate nom_test_helpers;

Examples

The macros in this crate are mostly focused on asserting things about IResult values returned from a nom parser.

For example, here is how you would test that an IResult is done, with a specific value for it’s output value:

#[macro_use] extern crate nom_test_helpers;
#[macro_use] extern crate nom;

named!(abcd<&str, &str>, tag_s!("abcd"));

fn main() {
    let r = abcd("abcd");
    assert_done_and_eq!(r, "abcd");

    // Additionally, if you want to assert that the I value of the IResult is empty,
    // you can use `assert_finished_and_eq!` instead:

    assert_finished_and_eq!(r, "abcd");
}