moss_core/resolve/
folder_class.rs1pub trait FolderIndex {
7 fn is_dir(&self, root_rel: &str) -> bool;
9 fn dir_has_markdown_index(&self, root_rel: &str) -> bool;
13 fn dir_has_static_index(&self, root_rel: &str) -> Option<String>;
16}
17
18#[cfg(test)]
19pub(crate) struct FakeFolderIndex {
20 pub dirs: std::collections::HashSet<String>,
21 pub md_index: std::collections::HashSet<String>,
22 pub static_index: std::collections::HashMap<String, String>,
23}
24
25#[cfg(test)]
26impl FakeFolderIndex {
27 pub fn new() -> Self {
28 FakeFolderIndex {
29 dirs: Default::default(),
30 md_index: Default::default(),
31 static_index: Default::default(),
32 }
33 }
34}
35
36#[cfg(test)]
37impl FolderIndex for FakeFolderIndex {
38 fn is_dir(&self, p: &str) -> bool {
39 self.dirs.contains(p)
40 }
41 fn dir_has_markdown_index(&self, p: &str) -> bool {
42 self.md_index.contains(p)
43 }
44 fn dir_has_static_index(&self, p: &str) -> Option<String> {
45 self.static_index.get(p).cloned()
46 }
47}
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn fake_reports_dir_kinds() {
55 let mut idx = FakeFolderIndex::new();
56 idx.dirs.insert("Resources/app".into());
57 idx.static_index
58 .insert("Resources/app".into(), "index.html".into());
59 assert!(idx.is_dir("Resources/app"));
60 assert!(!idx.dir_has_markdown_index("Resources/app"));
61 assert_eq!(
62 idx.dir_has_static_index("Resources/app"),
63 Some("index.html".into())
64 );
65 }
66}