From cb35ef0ebb38e2d3d4afb7a17c9c13e7ac7b7163 Mon Sep 17 00:00:00 2001 From: Antoine Gersant Date: Wed, 25 Sep 2024 17:27:14 -0700 Subject: [PATCH] Reserve ! character --- src/app/index/query.rs | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/app/index/query.rs b/src/app/index/query.rs index fc2c43d..bae2727 100644 --- a/src/app/index/query.rs +++ b/src/app/index/query.rs @@ -71,7 +71,7 @@ pub fn make_parser() -> impl Parser> { .ignore_then(none_of('"').repeated().collect::()) .then_ignore(just('"')); - let symbols = r#"()<>"|&="#.chars().collect::>(); + let symbols = r#"()<>"|&=!"#.chars().collect::>(); let raw_str = filter(move |c: &char| !c.is_whitespace() && !symbols.contains(c)) .repeated() @@ -295,7 +295,7 @@ fn can_parse_number_operators() { } #[test] -fn can_use_boolean_operators() { +fn can_use_and_operator() { let parser = make_parser(); assert_eq!( @@ -314,6 +314,11 @@ fn can_use_boolean_operators() { )) ), ); +} + +#[test] +fn can_use_or_operator() { + let parser = make_parser(); assert_eq!( parser.parse(r#"album % lands || title % "sword""#).unwrap(), @@ -333,6 +338,28 @@ fn can_use_boolean_operators() { ); } +#[test] +fn can_use_not_operator() { + let parser = make_parser(); + + assert_eq!( + parser.parse(r#"album % lands !! title % "sword""#).unwrap(), + Expr::Combined( + Box::new(Expr::TextCmp( + TextField::Album, + TextOp::Like, + "lands".to_owned() + )), + BoolOp::Not, + Box::new(Expr::TextCmp( + TextField::Title, + TextOp::Like, + "sword".to_owned() + )) + ), + ); +} + #[test] fn boolean_operators_share_precedence() { let parser = make_parser();