unit test parse_query_lenient

This commit is contained in:
Kat Lim Ruiz
2025-03-30 11:22:22 -05:00
parent 0c2b984cb4
commit 3e660905a7
2 changed files with 8 additions and 9 deletions

View File

@@ -29,10 +29,10 @@ pub fn parse_query_lenient(query: &str) -> (UserInputAst, Vec<LenientError>) {
#[cfg(test)]
mod tests {
use crate::parse_query;
use crate::{parse_query, parse_query_lenient};
#[test]
fn test_serialization() {
fn test_parse_query_serialization() {
let ast = parse_query("title:hello").unwrap();
let json = serde_json::to_string(&ast).unwrap();
assert_eq!(json, r#"{"Leaf":{"Literal":{"field_name":"title","phrase":"hello","delimiter":"None","slop":0,"prefix":false}}}"#);
@@ -42,4 +42,10 @@ mod tests {
fn test_parse_query_wrong_query() {
assert!(parse_query("title:").is_err());
}
#[test]
fn test_parse_query_lenient_wrong_query() {
let (_, errors) = parse_query_lenient("title:");
assert!(errors.len() == 1);
}
}

View File

@@ -323,11 +323,4 @@ mod tests {
let json = serde_json::to_string(&ast).unwrap();
assert_eq!(json, r#"{"Leaf":{"Range":{"field":"price","lower":{"Inclusive":"10"},"upper":{"Exclusive":"100"}}}}"#);
}
#[test]
fn test_all_leaf_deserialization() {
let json = r#"{"Leaf":"All"}"#;
let ast: UserInputAst = serde_json::from_str(json).unwrap();
assert_eq!(ast, UserInputAst::Leaf(Box::new(UserInputLeaf::All)));
}
}