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
isDone
, and lets you check that the value returned as theO
type of theIResult
is equal to the second parameter - assert_
error - This asserts that the
IResult
is anErr
- assert_
error_ and_ eq - This asserts that the
IResult
is anErr
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 anIncomplete
- assert_
needs - This lets the user specify how much input the parser should need