#nom #test #helpers #macro

nom-test-helpers

Macros to help with testing nom parsers

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

#1815 in Parser implementations

Download history 28/week @ 2023-11-02 100/week @ 2023-11-09 31/week @ 2023-11-16 24/week @ 2023-11-23 39/week @ 2023-11-30 27/week @ 2023-12-07 26/week @ 2023-12-14 35/week @ 2023-12-21 21/week @ 2023-12-28 13/week @ 2024-01-04 19/week @ 2024-01-11 33/week @ 2024-01-18 21/week @ 2024-01-25 18/week @ 2024-02-01 27/week @ 2024-02-08 108/week @ 2024-02-15

175 downloads per month
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
~42K SLoC