Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add tests for parsing errors #41

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
),
}
}
}
Loading