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 std::collections::{BTreeSet, HashMap, HashSet};
|
||||||
|
|
||||||
|
use maplit::hashset;
|
||||||
|
|
||||||
use crate::repo_path::{RepoPath, RepoPathComponent};
|
use crate::repo_path::{RepoPath, RepoPathComponent};
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug)]
|
#[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)]
|
#[derive(PartialEq, Eq, Debug)]
|
||||||
pub enum VisitDirs {
|
pub enum VisitDirs {
|
||||||
All,
|
All,
|
||||||
|
@ -46,6 +57,19 @@ pub trait Matcher {
|
||||||
fn visit(&self, dir: &RepoPath) -> Visit;
|
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)]
|
#[derive(PartialEq, Eq, Debug)]
|
||||||
pub struct EverythingMatcher;
|
pub struct EverythingMatcher;
|
||||||
|
|
||||||
|
@ -230,18 +254,20 @@ mod tests {
|
||||||
assert_eq!(dirs.get_files(&RepoPath::root()), hashset! {});
|
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]
|
#[test]
|
||||||
fn test_filesmatcher_empty() {
|
fn test_filesmatcher_empty() {
|
||||||
let m = FilesMatcher::new(hashset! {});
|
let m = FilesMatcher::new(hashset! {});
|
||||||
assert!(!m.matches(&RepoPath::from_internal_string("file")));
|
assert!(!m.matches(&RepoPath::from_internal_string("file")));
|
||||||
assert!(!m.matches(&RepoPath::from_internal_string("dir/file")));
|
assert!(!m.matches(&RepoPath::from_internal_string("dir/file")));
|
||||||
assert_eq!(
|
assert_eq!(m.visit(&RepoPath::root()), Visit::nothing());
|
||||||
m.visit(&RepoPath::root()),
|
|
||||||
Visit::Specific {
|
|
||||||
dirs: VisitDirs::Set(hashset! {}),
|
|
||||||
files: VisitFiles::Set(hashset! {}),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -292,13 +318,7 @@ mod tests {
|
||||||
let m = PrefixMatcher::new(&[]);
|
let m = PrefixMatcher::new(&[]);
|
||||||
assert!(!m.matches(&RepoPath::from_internal_string("file")));
|
assert!(!m.matches(&RepoPath::from_internal_string("file")));
|
||||||
assert!(!m.matches(&RepoPath::from_internal_string("dir/file")));
|
assert!(!m.matches(&RepoPath::from_internal_string("dir/file")));
|
||||||
assert_eq!(
|
assert_eq!(m.visit(&RepoPath::root()), Visit::nothing());
|
||||||
m.visit(&RepoPath::root()),
|
|
||||||
Visit::Specific {
|
|
||||||
dirs: VisitDirs::Set(hashset! {}),
|
|
||||||
files: VisitFiles::Set(hashset! {}),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -364,10 +384,7 @@ mod tests {
|
||||||
// visit
|
// visit
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
m.visit(&RepoPath::from_internal_string("bar")),
|
m.visit(&RepoPath::from_internal_string("bar")),
|
||||||
Visit::Specific {
|
Visit::nothing()
|
||||||
dirs: VisitDirs::Set(hashset! {}),
|
|
||||||
files: VisitFiles::Set(hashset! {}),
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue