Extend tests for new search parsing

(Also fix indentation)
This commit is contained in:
RumovZ 2020-11-15 12:00:20 +01:00
parent ae01a5b3a2
commit a16d271eb0
2 changed files with 46 additions and 11 deletions

View File

@ -592,7 +592,7 @@ mod test {
})] })]
); );
// partially quoted text should handle escaping the same way // escaping is independent of quotation
assert_eq!( assert_eq!(
parse(r#""field:va\"lue""#)?, parse(r#""field:va\"lue""#)?,
vec![Search(SingleField { vec![Search(SingleField {
@ -602,13 +602,44 @@ mod test {
})] })]
); );
assert_eq!(parse(r#""field:va\"lue""#)?, parse(r#"field:"va\"lue""#)?,); assert_eq!(parse(r#""field:va\"lue""#)?, parse(r#"field:"va\"lue""#)?,);
assert_eq!(parse(r#""field:va\"lue""#)?, parse(r#"field:va\"lue"#)?,);
// any character should be escapable in quotes // only \":()*_ are escapable
assert!(parse(r"\").is_err());
assert!(parse(r"\a").is_err());
assert!(parse(r"\%").is_err());
assert_eq!( assert_eq!(
parse(r#""re:\btest""#)?, parse(r#"\\\"\:\(\)\*\_"#)?,
vec![Search(Regex(r"\btest".into()))] vec![Search(UnqualifiedText(r#"\\":()*\_"#.into())),]
); );
// escaping parentheses is optional (only) inside quotes
assert_eq!(parse(r#""\)\(""#), parse(r#"")(""#));
assert!(parse(")(").is_err());
// escaping : is optional if it is preceded by another :
assert!(parse(":test").is_err());
assert!(parse(":").is_err());
assert_eq!(parse("field:val:ue"), parse(r"field:val\:ue"));
assert_eq!(parse(r#""field:val:ue""#), parse(r"field:val\:ue"));
assert_eq!(parse(r#"field:"val:ue""#), parse(r"field:val\:ue"));
// any character should be escapable on the right side of re:
assert_eq!(
parse(r#""re:\btest\%""#)?,
vec![Search(Regex(r"\btest\%".into()))]
);
// no exceptions for escaping "
assert_eq!(
parse(r#"re:te\"st"#)?,
vec![Search(Regex(r#"te"st"#.into()))]
);
assert!(parse(r#"re:te"st"#).is_err());
// spaces are optional if node separation is clear
assert_eq!(parse(r#"a"b"(c)"#)?, parse("a b (c)")?);
assert_eq!(parse("added:3")?, vec![Search(AddedInDays(3))]); assert_eq!(parse("added:3")?, vec![Search(AddedInDays(3))]);
assert_eq!( assert_eq!(
parse("card:front")?, parse("card:front")?,
@ -636,6 +667,10 @@ mod test {
vec![Search(NoteType(Text("basic".into())))] vec![Search(NoteType(Text("basic".into())))]
); );
assert_eq!(parse("tag:hard")?, vec![Search(Tag("hard".to_string()))]); assert_eq!(parse("tag:hard")?, vec![Search(Tag("hard".to_string()))]);
// wildcards in tags don't match whitespace
assert_eq!(parse("tag:ha_d")?, vec![Search(Tag(r"ha\Sd".to_string()))]);
assert_eq!(parse("tag:h*d")?, vec![Search(Tag(r"h\S*d".to_string()))]);
assert_eq!( assert_eq!(
parse("nid:1237123712,2,3")?, parse("nid:1237123712,2,3")?,
vec![Search(NoteIDs("1237123712,2,3".into()))] vec![Search(NoteIDs("1237123712,2,3".into()))]