pub trait FolderIndex {
fn is_dir(&self, root_rel: &str) -> bool;
fn dir_has_markdown_index(&self, root_rel: &str) -> bool;
fn dir_has_static_index(&self, root_rel: &str) -> Option<String>;
}
#[cfg(test)]
pub(crate) struct FakeFolderIndex {
pub dirs: std::collections::HashSet<String>,
pub md_index: std::collections::HashSet<String>,
pub static_index: std::collections::HashMap<String, String>,
}
#[cfg(test)]
impl FakeFolderIndex {
pub fn new() -> Self {
FakeFolderIndex {
dirs: Default::default(),
md_index: Default::default(),
static_index: Default::default(),
}
}
}
#[cfg(test)]
impl FolderIndex for FakeFolderIndex {
fn is_dir(&self, p: &str) -> bool {
self.dirs.contains(p)
}
fn dir_has_markdown_index(&self, p: &str) -> bool {
self.md_index.contains(p)
}
fn dir_has_static_index(&self, p: &str) -> Option<String> {
self.static_index.get(p).cloned()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn fake_reports_dir_kinds() {
let mut idx = FakeFolderIndex::new();
idx.dirs.insert("Resources/app".into());
idx.static_index
.insert("Resources/app".into(), "index.html".into());
assert!(idx.is_dir("Resources/app"));
assert!(!idx.dir_has_markdown_index("Resources/app"));
assert_eq!(
idx.dir_has_static_index("Resources/app"),
Some("index.html".into())
);
}
}