Add prettier workspace resolution test

This commit is contained in:
Kirill Bulatov 2023-11-01 11:53:00 +02:00
parent 6a89f7ce4f
commit d673efebd2
11 changed files with 426 additions and 45 deletions

View file

@ -1,4 +1,4 @@
use crate::{search::PathMatcher, worktree::WorktreeModelHandle, Event, *};
use crate::{worktree::WorktreeModelHandle, Event, *};
use fs::{FakeFs, RealFs};
use futures::{future, StreamExt};
use gpui::{executor::Deterministic, test::subscribe, AppContext};
@ -13,7 +13,7 @@ use pretty_assertions::assert_eq;
use serde_json::json;
use std::{cell::RefCell, os::unix, rc::Rc, task::Poll};
use unindent::Unindent as _;
use util::{assert_set_eq, test::temp_tree};
use util::{assert_set_eq, test::temp_tree, paths::PathMatcher};
#[cfg(test)]
#[ctor::ctor]

View file

@ -13,6 +13,7 @@ use std::{
path::{Path, PathBuf},
sync::Arc,
};
use util::paths::PathMatcher;
#[derive(Clone, Debug)]
pub struct SearchInputs {
@ -52,31 +53,6 @@ pub enum SearchQuery {
},
}
#[derive(Clone, Debug)]
pub struct PathMatcher {
maybe_path: PathBuf,
glob: GlobMatcher,
}
impl std::fmt::Display for PathMatcher {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.maybe_path.to_string_lossy().fmt(f)
}
}
impl PathMatcher {
pub fn new(maybe_glob: &str) -> Result<Self, globset::Error> {
Ok(PathMatcher {
glob: Glob::new(&maybe_glob)?.compile_matcher(),
maybe_path: PathBuf::from(maybe_glob),
})
}
pub fn is_match<P: AsRef<Path>>(&self, other: P) -> bool {
other.as_ref().starts_with(&self.maybe_path) || self.glob.is_match(other)
}
}
impl SearchQuery {
pub fn text(
query: impl ToString,