add tests

This commit is contained in:
Kat Lim Ruiz
2025-03-30 11:12:15 -05:00
parent a69b1c609c
commit 0c2b984cb4

View File

@@ -25,3 +25,21 @@ pub fn parse_query(query: &str) -> Result<UserInputAst, Error> {
pub fn parse_query_lenient(query: &str) -> (UserInputAst, Vec<LenientError>) {
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());
}
}