From 6f770834930138fcefbfb0b239b76eadfb03a629 Mon Sep 17 00:00:00 2001 From: Kat Lim Ruiz Date: Wed, 2 Apr 2025 18:06:20 -0500 Subject: [PATCH] create more complex unit test --- query-grammar/src/user_input_ast.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/query-grammar/src/user_input_ast.rs b/query-grammar/src/user_input_ast.rs index 76269a725..25cb01f72 100644 --- a/query-grammar/src/user_input_ast.rs +++ b/query-grammar/src/user_input_ast.rs @@ -197,7 +197,6 @@ impl UserInputBound { #[derive(PartialEq, Clone, Serialize)] #[serde(rename_all = "snake_case")] -//#[serde(tag = "type", content = "value")] pub enum UserInputAst { Clause(Vec<(Option, UserInputAst)>), Boost(Box, f64), @@ -369,6 +368,28 @@ mod tests { ); } + #[test] + fn test_boost_serialization2() { + let boost_ast = UserInputAst::Boost( + Box::new(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, + })))) + ])), + 2.5, + ); + let json = serde_json::to_string(&boost_ast).unwrap(); + assert_eq!( + json, + r#"{"boost":[{"clause":[["must",{"type":"all"}],["should",{"type":"literal","field_name":"title","phrase":"hello","delimiter":"none","slop":0,"prefix":false}]]},2.5]}"# + ); + } + #[test] fn test_clause_serialization() { let clause = UserInputAst::Clause(vec![