mirror of
https://github.com/watchexec/watchexec.git
synced 2024-11-16 09:08:37 +01:00
Start a test harness for globset
This commit is contained in:
parent
34d7c5ee9c
commit
110e1d4c96
1 changed files with 56 additions and 0 deletions
56
lib/tests/filter_globset.rs
Normal file
56
lib/tests/filter_globset.rs
Normal file
|
@ -0,0 +1,56 @@
|
|||
use watchexec::{
|
||||
error::RuntimeError,
|
||||
event::{Event, Tag},
|
||||
filter::{globset::GlobsetFilterer, Filterer},
|
||||
};
|
||||
|
||||
trait Harness {
|
||||
fn check_path(&self, path: &str) -> std::result::Result<bool, RuntimeError>;
|
||||
|
||||
fn does_pass(&self, path: &str) {
|
||||
assert!(
|
||||
matches!(self.check_path(path), Ok(true)),
|
||||
"path {:?} (expected pass)",
|
||||
path
|
||||
);
|
||||
}
|
||||
|
||||
fn doesnt_pass(&self, path: &str) {
|
||||
assert!(
|
||||
matches!(self.check_path(path), Ok(false)),
|
||||
"path {:?} (expected fail)",
|
||||
path
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
impl Harness for GlobsetFilterer {
|
||||
fn check_path(&self, path: &str) -> std::result::Result<bool, RuntimeError> {
|
||||
let event = Event {
|
||||
tags: vec![Tag::Path {
|
||||
path: path.into(),
|
||||
file_type: None,
|
||||
}],
|
||||
metadata: Default::default(),
|
||||
};
|
||||
|
||||
self.check_event(&event)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exact_filename() {
|
||||
let filterer = GlobsetFilterer::new(
|
||||
"/test",
|
||||
vec![("Cargo.toml".to_owned(), None)],
|
||||
vec![],
|
||||
vec![],
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
filterer.does_pass("Cargo.toml");
|
||||
filterer.doesnt_pass("Cargo.json");
|
||||
filterer.doesnt_pass("Gemfile.toml");
|
||||
filterer.doesnt_pass("FINAL-FINAL.docx");
|
||||
filterer.doesnt_pass("/a/folder");
|
||||
}
|
Loading…
Reference in a new issue