From 2f9ea9b12e6dac8afea443cc9e9f8891f76d2047 Mon Sep 17 00:00:00 2001 From: Tahaa-Dev Date: Wed, 22 Jul 2026 04:38:26 +0300 Subject: [PATCH] Add alias test cases to query test --- src/db/stream.rs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/db/stream.rs b/src/db/stream.rs index aa9251c..8f8bce2 100644 --- a/src/db/stream.rs +++ b/src/db/stream.rs @@ -111,8 +111,7 @@ impl<'a> Stream<'a> { } fn match_aliases(&self, aliases: &HashSet>) -> bool { - for keyword in self.options.keywords.iter().rev() { - // Alias matching is intended to be case-sensitive + for keyword in &self.options.keywords { if aliases.contains(keyword.as_str()) { return true; } @@ -218,10 +217,32 @@ mod tests { #[case(&["foo", "o", "bar"], "/foo/bar", false)] #[case(&["/foo/", "/bar"], "/foo/bar", false)] #[case(&["/foo/", "/bar"], "/foo/baz/bar", true)] + // Aliases + // Case normalization + #[case(&["fOo", "BaR"], "ALIASES=foo,bar", true)] + #[case(&["foo", "BaR"], "ALIASES=foo,bar", true)] + // Exact matches + #[case(&["fo", "ar"], "ALIASES=foo,bar", false)] + #[case(&["foo", "bar"], "ALIASES=foo,bar", true)] + // Mixed aliases and paths + #[case(&["/foo/", "bar", "/baz"], "ALIASES=foo,bar", true)] fn query(#[case] keywords: &[&str], #[case] path: &str, #[case] is_match: bool) { let db = &mut Database::new(PathBuf::new(), Vec::new(), |_| Vec::new(), false); let options = StreamOptions::new(0).with_keywords(keywords.iter()); let stream = Stream::new(db, options); - assert_eq!(is_match, stream.filter_by_keywords(path)); + assert_eq!( + is_match, + if path.starts_with("ALIASES=") { + stream.match_aliases( + &path + .trim_start_matches("ALIASES=") + .split(",") + .map(|alias| Cow::Borrowed(alias)) + .collect::>>(), + ) + } else { + stream.filter_by_keywords(path) + } + ); } }