From 3abe7b4c02a1b4887b9932feeb4a4901cf422bda Mon Sep 17 00:00:00 2001 From: Pascal Kuthe Date: Tue, 8 Aug 2023 00:06:49 +0200 Subject: [PATCH] fix negative matches --- src/pattern.rs | 2 +- src/pattern/tests.rs | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/pattern.rs b/src/pattern.rs index 58a0530..9475a13 100644 --- a/src/pattern.rs +++ b/src/pattern.rs @@ -351,8 +351,8 @@ impl Pattern { } pub fn parse_from(&mut self, pattern: &str, append: bool) { - self.atoms.clear(); let invert = self.atoms.last().map_or(false, |pat| pat.invert); + self.atoms.clear(); let atoms = pattern_atoms(pattern).filter_map(|atom| { let atom = PatternAtom::parse(atom, self.normalize, self.case_matching); if atom.needle.is_empty() { diff --git a/src/pattern/tests.rs b/src/pattern/tests.rs index a822f1c..4eaeb40 100644 --- a/src/pattern/tests.rs +++ b/src/pattern/tests.rs @@ -1,4 +1,4 @@ -use crate::pattern::PatternAtom; +use crate::pattern::{PatternAtom, Status}; use crate::{CaseMatching, Pattern, PatternKind}; fn parse_atom(pat: &str) -> PatternAtom { @@ -6,14 +6,14 @@ fn parse_atom(pat: &str) -> PatternAtom { } fn parse_atom_with(pat: &str, case_matching: CaseMatching) -> PatternAtom { - let mut pat = parse_with(pat, case_matching); + let mut pat = parse_with(pat, case_matching, false); assert_eq!(pat.atoms.len(), 1); pat.atoms.remove(0) } -fn parse_with(pat: &str, case_matching: CaseMatching) -> Pattern { +fn parse_with(pat: &str, case_matching: CaseMatching, append: bool) -> Pattern { let mut res = Pattern::new(&nucleo_matcher::MatcherConfig::DEFAULT, case_matching); - res.parse_from(pat, false); + res.parse_from(pat, append); res } @@ -133,3 +133,13 @@ fn escape() { assert_eq!(pat.needle.to_string(), "^foo$"); assert_eq!(pat.kind, PatternKind::Substring); } + +#[test] +fn append() { + let mut pat = parse_with("!", CaseMatching::Smart, true); + assert_eq!(pat.status, Status::Update); + pat.parse_from("!f", true); + assert_eq!(pat.status, Status::Update); + pat.parse_from("!fo", true); + assert_eq!(pat.status, Status::Rescore); +}