diff --git a/Cargo.lock b/Cargo.lock index 7c51319..2525cd0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,7 +13,7 @@ dependencies = [ [[package]] name = "ai-rules" -version = "1.1.0" +version = "1.2.0" dependencies = [ "anyhow", "clap", diff --git a/src/utils/file_utils.rs b/src/utils/file_utils.rs index 8912114..a7e243f 100644 --- a/src/utils/file_utils.rs +++ b/src/utils/file_utils.rs @@ -24,7 +24,9 @@ pub fn find_files_by_extension(dir: &Path, extension: &str) -> Result = md_files + .iter() + .filter_map(|p| p.file_name()) + .filter_map(|n| n.to_str()) + .map(|s| s.to_string()) + .collect(); + + assert!(filenames.contains(&"regular.md".to_string())); + assert!(filenames.contains(&"target.md".to_string())); + assert!(filenames.contains(&"link.md".to_string())); + } + + #[test] + #[cfg(unix)] + fn test_find_files_by_extension_with_broken_symlink() { + let temp_dir = TempDir::new().unwrap(); + let temp_path = temp_dir.path(); + + fs::write(temp_path.join("regular.md"), "regular file").unwrap(); + symlink("nonexistent.md", temp_path.join("broken_link.md")).unwrap(); + + let result = find_files_by_extension(temp_path, "md"); + assert!(result.is_err()); + } }