mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
Verify that '/' is parent of everything
Bug could occur when run with '/' as it wasn't considered the parent of '/usr' due to having the same number of '/'s in the name
This commit is contained in:
+15
-1
@@ -37,7 +37,7 @@ impl PartialEq for Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_a_parent_of(parent: &str, child: &str) -> bool {
|
pub fn is_a_parent_of(parent: &str, child: &str) -> bool {
|
||||||
child.starts_with(parent) && child.chars().nth(parent.chars().count()) == Some('/')
|
(child.starts_with(parent) && child.chars().nth(parent.chars().count()) == Some('/')) || parent == "/"
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn simplify_dir_names(filenames: Vec<&str>) -> HashSet<String> {
|
pub fn simplify_dir_names(filenames: Vec<&str>) -> HashSet<String> {
|
||||||
@@ -232,4 +232,18 @@ mod tests {
|
|||||||
correct.insert("src_v2".to_string());
|
correct.insert("src_v2".to_string());
|
||||||
assert_eq!(simplify_dir_names(vec!["src/", "src_v2"]), correct);
|
assert_eq!(simplify_dir_names(vec!["src/", "src_v2"]), correct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_is_a_parent_of() {
|
||||||
|
assert!(is_a_parent_of("/usr", "/usr/andy"));
|
||||||
|
assert!(is_a_parent_of("/usr", "/usr/andy/i/am/descendant"));
|
||||||
|
assert!(!is_a_parent_of("/usr/andy", "/usr"));
|
||||||
|
assert!(!is_a_parent_of("/usr/andy", "/usr/sibling"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_is_a_parent_of_root() {
|
||||||
|
assert!(is_a_parent_of("/", "/usr/andy"));
|
||||||
|
assert!(is_a_parent_of("/", "/usr"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user