How to test for a nom::Error?

I can't figure out how to create an Error for my assertion:

assert_eq!(check_eye_color("  ecl:amb"), Err(nom::Err::Error("")));

I tried most variations and searched the common sites, but people neglected to document how to do this, the source code has this and that does not tell me how to create an error either:

pub enum Err<E> {
  /// There was not enough data
  Incomplete(Needed),
  /// The parser had an error (recoverable)
  Error(E),
  /// The parser had an unrecoverable error: we got to the right
  /// branch and we know other branches won't work, so backtrack
  /// as fast as possible
  Failure(E),
}

Looking in the source code docs for the right module yielded the answer, and the solution seems to be this:

assert_eq!(
        check_eye_color("  ecl:amb"),
        Err(nom::Err::Error(nom::error::Error::new(
            "  ecl:amb",
            nom::error::ErrorKind::Tag
        )))
    );

This is awful. Especially the random difference between: nom::Error and nom:error.

Do you want to compare the error contents or could

assert!(check_eye_color("  ecl:amb").is_err());

work for you?

That would be fine and so much shorter.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.