Fix case conversion

This commit is contained in:
Ajeet D'Souza 2024-05-05 19:40:13 +05:30
parent be53c7f0db
commit 302f21f904
2 changed files with 4 additions and 5 deletions

View File

@ -78,7 +78,7 @@ impl Query {
fn get_stream<'a>(&self, db: &'a mut Database, now: Epoch) -> Result<Stream<'a>> {
let mut options = StreamOptions::new(now)
.with_keywords(self.keywords.to_owned())
.with_keywords(self.keywords.iter().map(|s| s.as_str()))
.with_exclude(config::exclude_dirs()?);
if !self.all {
let resolve_symlinks = config::resolve_symlinks();

View File

@ -122,8 +122,8 @@ impl StreamOptions {
}
}
pub fn with_keywords(mut self, keywords: Vec<String>) -> Self {
self.keywords = keywords;
pub fn with_keywords<I: Iterator<Item = S>, S: AsRef<str>>(mut self, keywords: I) -> Self {
self.keywords = keywords.into_iter().map(util::to_lowercase).collect();
self
}
@ -173,8 +173,7 @@ mod tests {
#[case(&["/foo/", "/bar"], "/foo/baz/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().map(|s| s.to_string()).collect());
let options = StreamOptions::new(0).with_keywords(keywords.iter());
let stream = Stream::new(db, options);
assert_eq!(is_match, stream.filter_by_keywords(path));
}