#[must_use]
pub fn normalized_path(path: &str) -> String {
let names: Vec<&str> = path.split('/').filter(|name| !name.is_empty()).collect();
if names.is_empty() {
"/".to_owned()
} else {
format!("/{}", names.join("/"))
}
}
#[cfg(test)]
mod tests {
use super::normalized_path;
#[test]
fn normalizes_path_spellings() {
assert_eq!(normalized_path("/"), "/");
assert_eq!(normalized_path(""), "/");
assert_eq!(normalized_path("//"), "/");
assert_eq!(normalized_path("/content/dam"), "/content/dam");
assert_eq!(normalized_path("content/dam"), "/content/dam");
assert_eq!(normalized_path("/content//dam/"), "/content/dam");
}
}