use super::{ScanCoverage, is_scannable, scan};
fn scanned_names(names: &[&str]) -> Vec<String> {
let directory = tempfile::tempdir().expect("temporary project");
for name in names {
let marker = crate::core::hash::header(crate::core::hash::CommentStyle::Hash);
std::fs::write(directory.path().join(name), format!("{marker}\nseeded = true\n")).expect("seed stamped file");
}
let mut found: Vec<String> = scan(directory.path())
.0
.into_iter()
.filter_map(|(path, _, _)| path.file_name()?.to_str().map(str::to_owned))
.collect();
found.sort();
found
}
const EMIT_SIDE_FILENAME_KEYED: &[&str] = &[
"Makefile",
"GNUmakefile",
"go.mod",
"Rakefile",
"Makevars",
"Makevars.in",
"Makevars.win.in",
".clang-format",
];
#[test]
fn walk_opens_a_stamped_clang_format() {
assert_eq!(scanned_names(&[".clang-format"]), vec![".clang-format"]);
}
#[test]
fn every_filename_keyed_stamped_path_is_scannable() {
for name in EMIT_SIDE_FILENAME_KEYED {
let path = std::path::Path::new(name);
assert!(
crate::cli::pipeline::is_markable_path(path),
"{name} is listed as emit-side stamped but the emit table does not stamp it"
);
assert!(
is_scannable(path),
"{name} is stamped on write but the ownership walk would never open it"
);
}
}
#[test]
fn walk_still_skips_a_format_alef_never_stamps() {
assert!(scanned_names(&["notes.rtf", "archive.tar"]).is_empty());
assert!(!is_scannable(std::path::Path::new("notes.rtf")));
}
#[test]
fn scan_tallies_opened_marked_and_unexamined_separately() {
let directory = tempfile::tempdir().expect("temporary project");
let marker = crate::core::hash::header(crate::core::hash::CommentStyle::Hash);
std::fs::write(
directory.path().join("stamped.toml"),
format!("{marker}\nseeded = true\n"),
)
.expect("seed stamped file");
std::fs::write(directory.path().join("plain.toml"), "seeded = true\n").expect("seed unmarked scannable file");
std::fs::write(directory.path().join("notes.rtf"), "not scanned\n").expect("seed unscannable file");
let (found, coverage) = scan(directory.path());
assert_eq!(found.len(), 1, "only the stamped file is alef-owned");
assert_eq!(
coverage,
ScanCoverage {
opened: 2,
marked: 1,
unexamined: 1,
}
);
}