mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 18:27:38 +00:00
matchers: add a matcher not matching anything (#52)
It can be useful for at least testing purposes to have a matcher that doesn't match any paths.
This commit is contained in:
parent
d4732574f4
commit
4c2c1fedff
1 changed files with 35 additions and 18 deletions
|
@ -16,6 +16,8 @@
|
|||
|
||||
use std::collections::{BTreeSet, HashMap, HashSet};
|
||||
|
||||
use maplit::hashset;
|
||||
|
||||
use crate::repo_path::{RepoPath, RepoPathComponent};
|
||||
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
|
@ -29,6 +31,15 @@ pub enum Visit {
|
|||
},
|
||||
}
|
||||
|
||||
impl Visit {
|
||||
pub fn nothing() -> Self {
|
||||
Self::Specific {
|
||||
dirs: VisitDirs::Set(hashset! {}),
|
||||
files: VisitFiles::Set(hashset! {}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
pub enum VisitDirs {
|
||||
All,
|
||||
|
@ -46,6 +57,19 @@ pub trait Matcher {
|
|||
fn visit(&self, dir: &RepoPath) -> Visit;
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
pub struct NothingMatcher;
|
||||
|
||||
impl Matcher for NothingMatcher {
|
||||
fn matches(&self, _file: &RepoPath) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn visit(&self, _dir: &RepoPath) -> Visit {
|
||||
Visit::nothing()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
pub struct EverythingMatcher;
|
||||
|
||||
|
@ -230,18 +254,20 @@ mod tests {
|
|||
assert_eq!(dirs.get_files(&RepoPath::root()), hashset! {});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_nothingmatcher() {
|
||||
let m = NothingMatcher;
|
||||
assert!(!m.matches(&RepoPath::from_internal_string("file")));
|
||||
assert!(!m.matches(&RepoPath::from_internal_string("dir/file")));
|
||||
assert_eq!(m.visit(&RepoPath::root()), Visit::nothing());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filesmatcher_empty() {
|
||||
let m = FilesMatcher::new(hashset! {});
|
||||
assert!(!m.matches(&RepoPath::from_internal_string("file")));
|
||||
assert!(!m.matches(&RepoPath::from_internal_string("dir/file")));
|
||||
assert_eq!(
|
||||
m.visit(&RepoPath::root()),
|
||||
Visit::Specific {
|
||||
dirs: VisitDirs::Set(hashset! {}),
|
||||
files: VisitFiles::Set(hashset! {}),
|
||||
}
|
||||
);
|
||||
assert_eq!(m.visit(&RepoPath::root()), Visit::nothing());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -292,13 +318,7 @@ mod tests {
|
|||
let m = PrefixMatcher::new(&[]);
|
||||
assert!(!m.matches(&RepoPath::from_internal_string("file")));
|
||||
assert!(!m.matches(&RepoPath::from_internal_string("dir/file")));
|
||||
assert_eq!(
|
||||
m.visit(&RepoPath::root()),
|
||||
Visit::Specific {
|
||||
dirs: VisitDirs::Set(hashset! {}),
|
||||
files: VisitFiles::Set(hashset! {}),
|
||||
}
|
||||
);
|
||||
assert_eq!(m.visit(&RepoPath::root()), Visit::nothing());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -364,10 +384,7 @@ mod tests {
|
|||
// visit
|
||||
assert_eq!(
|
||||
m.visit(&RepoPath::from_internal_string("bar")),
|
||||
Visit::Specific {
|
||||
dirs: VisitDirs::Set(hashset! {}),
|
||||
files: VisitFiles::Set(hashset! {}),
|
||||
}
|
||||
Visit::nothing()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue