From 0c2b984cb4f0ff27775350fe629cc76d285fc193 Mon Sep 17 00:00:00 2001 From: Kat Lim Ruiz Date: Sun, 30 Mar 2025 11:12:15 -0500 Subject: [PATCH] add tests --- query-grammar/src/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/query-grammar/src/lib.rs b/query-grammar/src/lib.rs index 0208b93cd..974894f62 100644 --- a/query-grammar/src/lib.rs +++ b/query-grammar/src/lib.rs @@ -25,3 +25,21 @@ pub fn parse_query(query: &str) -> Result { pub fn parse_query_lenient(query: &str) -> (UserInputAst, Vec) { parse_to_ast_lenient(query) } + + +#[cfg(test)] +mod tests { + use crate::parse_query; + + #[test] + fn test_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}}}"#); + } + + #[test] + fn test_parse_query_wrong_query() { + assert!(parse_query("title:").is_err()); + } +}