9 stable releases (3 major)

6.1.3 Mar 25, 2021
6.1.2 Jan 6, 2021
3.0.0 May 12, 2017
2.0.0 Nov 28, 2016
1.0.1 Nov 2, 2016

#1601 in Parser implementations


Used in 3 crates

CC-PDDC license

19KB
407 lines

Nom Test Helpers

Documentation

Usage

Put this in your Cargo.toml:

[source,toml]

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

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 Ok, with a specific value for it's output value:

[source,rust]

use nom::{named, tag};
use nom_test_helpers::{assert_done_and_eq, assert_finished_and_eq};

named!(abcd<&str, &str>, tag!("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");
}

lib.rs:

Macros for testing nom parsers

Often when I'm testing nom parsers, I end up defining a lot of little macros like this, so I thought I would bundle them all up into a crate so I didn't have to define them over and over.

This crate was first created back when nom had the concept of "Done" vs "Finished", which might seem a little out of place now but I still find it useful when testing. Basically, macros that test for "Done" check that the parser completed successfully, while macros that test for "Finished" check that the parser completed successfully while also asserting that the input is empty.

Dependencies

~2MB
~45K SLoC