From bdd5f80fd9332cff757dd06d74183eb2c9096628 Mon Sep 17 00:00:00 2001 From: Kat Lim Ruiz Date: Tue, 1 Apr 2025 18:04:19 -0500 Subject: [PATCH] add clause unit test --- query-grammar/src/user_input_ast.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/query-grammar/src/user_input_ast.rs b/query-grammar/src/user_input_ast.rs index 2824e8079..0b512f675 100644 --- a/query-grammar/src/user_input_ast.rs +++ b/query-grammar/src/user_input_ast.rs @@ -345,4 +345,23 @@ mod tests { r#"{"Boost":[{"Leaf":{"type":"All"}},2.5]}"# ); } + + #[test] + fn test_clause_serialization() { + let clause = UserInputAst::Clause(vec![ + (Some(Occur::Must), UserInputAst::Leaf(Box::new(UserInputLeaf::All))), + (Some(Occur::Should), UserInputAst::Leaf(Box::new(UserInputLeaf::Literal(UserInputLiteral { + field_name: Some("title".to_string()), + phrase: "hello".to_string(), + delimiter: Delimiter::None, + slop: 0, + prefix: false, + })))) + ]); + let json = serde_json::to_string(&clause).unwrap(); + assert_eq!( + json, + r#"{"Clause":[["Must",{"Leaf":{"type":"All"}}],["Should",{"Leaf":{"type":"Literal","field_name":"title","phrase":"hello","delimiter":"None","slop":0,"prefix":false}}]]}"# + ); + } }