Skip to content

Commit

Permalink
test: Add tests for parsing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Aug 8, 2024
1 parent dfac53b commit 838a5e3
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/filter/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ mod tests {
#[case("null", FilterValue::Null)]
#[case("[]", FilterValue::Tuple(vec![]))]
#[case("[true]", FilterValue::Tuple(vec![true.into()]))]
#[case("[\ntrue,\n]", FilterValue::Tuple(vec![true.into()]))]
#[case("[true, false, \"test\", 123, null]", FilterValue::Tuple(vec![true.into(), false.into(), "test".into(), 123.into(), FilterValue::Null]))]
fn parsing_literals(#[case] input: &str, #[case] value: FilterValue) {
let tokens = crate::filter::lexer::Scanner::new(input);
Expand Down Expand Up @@ -240,4 +241,38 @@ mod tests {
Err(e) => panic!("Error: {}", e),
}
}

#[rstest]
#[case(
"true false",
"Your filter expression contained an unexpected 'false' at line 1, column 6."
)]
#[case(
"true ==",
"We reached the end of your filter expression while waiting for a [true, false, \"string\", number, (group), or property.name]."
)]
#[case(
"(true",
"When attempting to parse a grouped filter expression starting at line 1, column 1, we didn't find the closing ')' where we expected to."
)]
#[case(
"[true, false",
"When attempting to parse a list filter expression starting at line 1, column 1, we didn't find the closing ']' where we expected to."
)]
#[case(
")",
"While parsing your filter, we found an unexpected ')' at line 1, column 1."
)]
fn invalid_filters(#[case] input: &str, #[case] message: &str) {
let tokens = crate::filter::lexer::Scanner::new(input);
match Parser::parse(tokens.into_iter()) {
Ok(expr) => panic!("Expected an error, got {:?}", expr),
Err(e) => assert!(
e.to_string().contains(message),
"Expected error message to contain '{}', got '{}'",
message,
e
),
}
}
}

0 comments on commit 838a5e3

Please sign in to comment.