Skip to content

Commit

Permalink
adds tests for error display
Browse files Browse the repository at this point in the history
  • Loading branch information
chanced committed Jul 2, 2024
1 parent 35e821a commit 102b431
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,38 @@ impl fmt::Display for ReplaceTokenError {

#[cfg(feature = "std")]
impl std::error::Error for ReplaceTokenError {}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn parse_error_display() {
assert_eq!(
ParseError::NoLeadingBackslash.to_string(),
"json pointer is malformed as it does not start with a backslash ('/')"
);
}

#[test]
fn parse_index_error_from_parse_int_error() {
assert_eq!(
Token::new("a").to_index().unwrap_err().to_string(),
"failed to parse token as an integer"
);
}

#[test]
fn invalid_encoding_error_display() {
assert_eq!(
Token::from_encoded("~").unwrap_err().to_string(),
"json pointer is malformed due to invalid encoding ('~' not followed by '0' or '1')"
);
}

#[test]
fn out_of_bounds_error_display() {
let error = Token::new("10").to_index().unwrap().for_len(5).unwrap_err();
assert_eq!(error.to_string(), "index 10 out of bounds (limit: 5)");
}
}

0 comments on commit 102b431

Please sign in to comment.