use flash_watcher::should_skip_dir;
use std::path::Path;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_should_skip_dir_common_ignores() {
assert!(should_skip_dir(Path::new(".git"), &[]));
assert!(should_skip_dir(Path::new("node_modules"), &[]));
assert!(should_skip_dir(Path::new("target"), &[]));
assert!(should_skip_dir(Path::new(".svn"), &[]));
assert!(should_skip_dir(Path::new(".hg"), &[]));
assert!(should_skip_dir(Path::new("project/.git/hooks"), &[]));
assert!(should_skip_dir(Path::new("app/node_modules/package"), &[]));
assert!(should_skip_dir(Path::new("rust-project/target/debug"), &[]));
assert!(should_skip_dir(Path::new("repo/.svn/pristine"), &[]));
assert!(should_skip_dir(Path::new("project/.hg/store"), &[]));
}
#[test]
fn test_should_skip_dir_case_sensitivity() {
assert!(!should_skip_dir(Path::new("Git"), &[])); assert!(!should_skip_dir(Path::new("NODE_MODULES"), &[])); assert!(!should_skip_dir(Path::new("Target"), &[])); assert!(!should_skip_dir(Path::new(".GIT"), &[])); }
#[test]
fn test_should_skip_dir_partial_matches() {
assert!(should_skip_dir(Path::new("my-target-dir"), &[])); assert!(!should_skip_dir(Path::new("git-repo"), &[])); assert!(should_skip_dir(Path::new("node_modules_backup"), &[]));
assert!(should_skip_dir(Path::new("project/target"), &[])); assert!(should_skip_dir(Path::new("src/.git"), &[]));
assert!(!should_skip_dir(Path::new("src"), &[])); assert!(!should_skip_dir(Path::new("tests"), &[])); assert!(!should_skip_dir(Path::new("git-repo"), &[])); }
#[test]
fn test_should_skip_dir_custom_patterns() {
let ignore_patterns = vec!["build".to_string(), "dist".to_string(), "cache".to_string()];
assert!(should_skip_dir(Path::new("build"), &ignore_patterns));
assert!(should_skip_dir(Path::new("dist"), &ignore_patterns));
assert!(should_skip_dir(Path::new("cache"), &ignore_patterns));
assert!(!should_skip_dir(Path::new("src"), &ignore_patterns));
assert!(!should_skip_dir(Path::new("tests"), &ignore_patterns));
}
#[test]
fn test_should_skip_dir_glob_patterns() {
let ignore_patterns = vec![
"dist/**".to_string(),
"*.tmp".to_string(),
"cache-*".to_string(),
"**/temp/**".to_string(),
];
assert!(should_skip_dir(Path::new("dist/assets"), &ignore_patterns));
assert!(should_skip_dir(Path::new("temp.tmp"), &ignore_patterns));
assert!(should_skip_dir(Path::new("cache-files"), &ignore_patterns));
assert!(should_skip_dir(
Path::new("project/temp/files"),
&ignore_patterns
));
assert!(!should_skip_dir(Path::new("src"), &ignore_patterns));
assert!(!should_skip_dir(Path::new("building"), &ignore_patterns)); }
#[test]
fn test_should_skip_dir_invalid_patterns() {
let invalid_patterns = vec![
"[invalid".to_string(), "valid-pattern".to_string(),
"another[invalid".to_string(),
];
assert!(!should_skip_dir(Path::new("some-dir"), &invalid_patterns));
assert!(should_skip_dir(
Path::new("valid-pattern"),
&invalid_patterns
));
assert!(!should_skip_dir(
Path::new("invalid-dir"),
&invalid_patterns
));
}
#[test]
fn test_should_skip_dir_empty_patterns() {
let empty_patterns = vec![];
assert!(should_skip_dir(Path::new(".git"), &empty_patterns));
assert!(should_skip_dir(Path::new("node_modules"), &empty_patterns));
assert!(!should_skip_dir(Path::new("src"), &empty_patterns));
assert!(!should_skip_dir(Path::new("custom-dir"), &empty_patterns));
}
#[test]
fn test_should_skip_dir_complex_paths() {
let ignore_patterns = vec!["**/build/**".to_string(), "temp*".to_string()];
assert!(should_skip_dir(
Path::new("project/frontend/build/assets"),
&ignore_patterns
));
assert!(should_skip_dir(Path::new("temp_files"), &ignore_patterns));
assert!(should_skip_dir(Path::new("temporary"), &ignore_patterns));
assert!(!should_skip_dir(
Path::new("project/src/components"),
&ignore_patterns
));
assert!(!should_skip_dir(Path::new("app/tests"), &ignore_patterns));
let simple_patterns = vec!["build".to_string()];
assert!(should_skip_dir(Path::new("build"), &simple_patterns));
assert!(!should_skip_dir(
Path::new("app/backend/build"),
&simple_patterns
)); }
#[test]
fn test_should_skip_dir_absolute_vs_relative() {
let ignore_patterns = vec!["build".to_string()];
assert!(!should_skip_dir(
Path::new("/home/user/project/build"),
&ignore_patterns
)); assert!(!should_skip_dir(Path::new("./build"), &ignore_patterns)); assert!(!should_skip_dir(Path::new("../build"), &ignore_patterns)); assert!(should_skip_dir(Path::new("build"), &ignore_patterns));
let nested_patterns = vec!["**/build".to_string(), "**/build/**".to_string()];
assert!(should_skip_dir(
Path::new("/home/user/project/build"),
&nested_patterns
));
assert!(should_skip_dir(Path::new("./build"), &nested_patterns));
assert!(should_skip_dir(Path::new("../build"), &nested_patterns));
assert!(should_skip_dir(Path::new("build"), &nested_patterns));
assert!(!should_skip_dir(
Path::new("/home/user/project/src"),
&ignore_patterns
));
assert!(!should_skip_dir(Path::new("./src"), &ignore_patterns));
assert!(!should_skip_dir(Path::new("../src"), &ignore_patterns));
}
#[test]
fn test_should_skip_dir_special_characters() {
let ignore_patterns = vec![
"dir with spaces".to_string(),
"dir-with-dashes".to_string(),
"dir_with_underscores".to_string(),
];
assert!(should_skip_dir(
Path::new("dir with spaces"),
&ignore_patterns
));
assert!(should_skip_dir(
Path::new("dir-with-dashes"),
&ignore_patterns
));
assert!(should_skip_dir(
Path::new("dir_with_underscores"),
&ignore_patterns
));
assert!(!should_skip_dir(Path::new("normal-dir"), &ignore_patterns));
}
#[test]
fn test_should_skip_dir_unicode() {
let ignore_patterns = vec![
"папка".to_string(), "文件夹".to_string(), ];
assert!(should_skip_dir(Path::new("папка"), &ignore_patterns));
assert!(should_skip_dir(Path::new("文件夹"), &ignore_patterns));
assert!(!should_skip_dir(Path::new("folder"), &ignore_patterns));
}
#[test]
fn test_should_skip_dir_no_match() {
let ignore_patterns = vec!["specific-dir".to_string()];
assert!(!should_skip_dir(Path::new("src"), &ignore_patterns));
assert!(!should_skip_dir(Path::new("tests"), &ignore_patterns));
assert!(!should_skip_dir(Path::new("docs"), &ignore_patterns));
assert!(!should_skip_dir(Path::new("lib"), &ignore_patterns));
assert!(!should_skip_dir(Path::new("bin"), &ignore_patterns));
assert!(!should_skip_dir(Path::new("examples"), &ignore_patterns));
assert!(should_skip_dir(Path::new(".git"), &ignore_patterns));
assert!(should_skip_dir(Path::new("node_modules"), &ignore_patterns));
assert!(should_skip_dir(Path::new("target"), &ignore_patterns));
}
}