diff --git a/src/path/mod.rs b/src/path/mod.rs index 3c0b4213..aaa55b12 100644 --- a/src/path/mod.rs +++ b/src/path/mod.rs @@ -27,7 +27,7 @@ impl FromStr for Expression { struct ParseError(String); impl ParseError { - fn new(inner: winnow::error::ContextError) -> Self { + fn new(inner: winnow::error::ParseError<&str, winnow::error::ContextError>) -> Self { Self(inner.to_string()) } } diff --git a/src/path/parser.rs b/src/path/parser.rs index 6bad9642..c34e2598 100644 --- a/src/path/parser.rs +++ b/src/path/parser.rs @@ -9,6 +9,7 @@ use winnow::combinator::opt; use winnow::combinator::repeat; use winnow::combinator::seq; use winnow::error::ContextError; +use winnow::error::ParseError; use winnow::error::StrContext; use winnow::error::StrContextValue; use winnow::prelude::*; @@ -17,9 +18,8 @@ use winnow::token::take_while; use crate::path::Expression; -pub(crate) fn from_str(mut input: &str) -> Result { - let input = &mut input; - path.parse(input).map_err(|e| e.into_inner()) +pub(crate) fn from_str(input: &str) -> Result> { + path.parse(input) } fn path(i: &mut &str) -> PResult { @@ -143,7 +143,11 @@ mod test { fn test_invalid_identifier() { let err = from_str("!").unwrap_err(); assert_eq!( - "invalid identifier\nexpected ASCII alphanumeric, underscore, hyphen", + "\ +! +^ +invalid identifier +expected ASCII alphanumeric, underscore, hyphen", err.to_string() ); } @@ -152,7 +156,11 @@ mod test { fn test_invalid_child() { let err = from_str("a..").unwrap_err(); assert_eq!( - "invalid identifier\nexpected ASCII alphanumeric, underscore, hyphen", + "\ +a.. + ^ +invalid identifier +expected ASCII alphanumeric, underscore, hyphen", err.to_string() ); } @@ -160,18 +168,38 @@ mod test { #[test] fn test_invalid_subscript() { let err = from_str("a[b]").unwrap_err(); - assert_eq!("invalid subscript\nexpected integer", err.to_string()); + assert_eq!( + "\ +a[b] + ^ +invalid subscript +expected integer", + err.to_string() + ); } #[test] fn test_incomplete_subscript() { let err = from_str("a[0").unwrap_err(); - assert_eq!("invalid subscript", err.to_string()); + assert_eq!( + "\ +a[0 + ^ +invalid subscript", + err.to_string() + ); } #[test] fn test_invalid_postfix() { let err = from_str("a!b").unwrap_err(); - assert_eq!("invalid postfix\nexpected `[`, `.`", err.to_string()); + assert_eq!( + "\ +a!b + ^ +invalid postfix +expected `[`, `.`", + err.to_string() + ); } }