create more complex unit test

This commit is contained in:
Kat Lim Ruiz
2025-04-02 18:06:20 -05:00
parent cd7745da7a
commit 6f77083493

View File

@@ -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<Occur>, UserInputAst)>),
Boost(Box<UserInputAst>, 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![