4d2252373e
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VdfEGXA7aJ6ftMsCc9PJze
63 lines
2.3 KiB
Rust
63 lines
2.3 KiB
Rust
//! Every `.improv` document this repository ships must load (improvise-odbc).
|
|
//! Why a DIRECTORY WALK and not a list: `context/test-evidence/tui.md`.
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
/// The directories `.gitignore` un-ignores `*.improv` in: the definition of
|
|
/// "shipped", read from the one place that states it (improvise-qlrh).
|
|
fn shipped_directories(root: &Path) -> Vec<PathBuf> {
|
|
let gitignore = std::fs::read_to_string(root.join(".gitignore")).expect("a .gitignore");
|
|
gitignore
|
|
.lines()
|
|
.filter_map(|line| line.trim().strip_prefix('!'))
|
|
.filter_map(|pattern| pattern.strip_suffix("/*.improv"))
|
|
.map(|dir| root.join(dir))
|
|
.collect()
|
|
}
|
|
|
|
fn documents_in(dir: &Path) -> Vec<PathBuf> {
|
|
let mut found: Vec<PathBuf> = std::fs::read_dir(dir)
|
|
.expect("a shipped-document directory")
|
|
.map(|entry| entry.expect("a readable directory entry").path())
|
|
// `extension()` of `x.improv.gz` is `gz`, so matching on the extension
|
|
// alone would skip it and put back the hole this test closes.
|
|
.filter(|p| {
|
|
p.to_str()
|
|
.is_some_and(|s| s.ends_with(".improv") || s.ends_with(".improv.gz"))
|
|
})
|
|
.collect();
|
|
found.sort();
|
|
found
|
|
}
|
|
|
|
#[test]
|
|
fn every_shipped_document_loads() {
|
|
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
|
|
let dirs = shipped_directories(root);
|
|
assert!(
|
|
!dirs.is_empty(),
|
|
"precondition: .gitignore must un-ignore at least one *.improv directory"
|
|
);
|
|
|
|
for dir in dirs {
|
|
let documents = documents_in(&dir);
|
|
// Per directory, so a walk that silently loses one cannot pass (qlrh).
|
|
assert!(
|
|
!documents.is_empty(),
|
|
"precondition: {} is un-ignored for *.improv but the walk found none there",
|
|
dir.display()
|
|
);
|
|
for path in documents {
|
|
let workbook = improvise::persistence::load(&path)
|
|
.unwrap_or_else(|e| panic!("{} does not load: {e}", path.display()));
|
|
assert!(
|
|
workbook.views.contains_key(&workbook.active_view),
|
|
"{} loads but its initial view {:?} is not one of {:?}",
|
|
path.display(),
|
|
workbook.active_view,
|
|
workbook.views.keys().collect::<Vec<_>>()
|
|
);
|
|
}
|
|
}
|
|
}
|