Crate nom_test_helpers

Source
Expand description

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.

Modules§

prelude
Instead of importing the helper macros individually, this can be star-imported to get all of them

Macros§

assert_done
This macro checks to make sure that the IResult it is passed is Done. That is, it checks that the parser completed successfully but doesn’t make any assumptions about the remaining input.
assert_done_and_eq
This checks that the IResult is Done, and lets you check that the value returned as the O type of the IResult is equal to the second parameter
assert_error
This asserts that the IResult is an Err
assert_error_and_eq
This asserts that the IResult is an Err and that the error is what is expected
assert_finished
This does the same thing as assert_done!, except that this also asserts that the input slice is empty
assert_finished_and_eq
Same as assert_done_and_eq!, but asserts that the input slice is empty
assert_needed
This asserts that the IResult is an Incomplete
assert_needs
This lets the user specify how much input the parser should need