const OLDER_SIDECAR_SUFFIXES: [&str; 2] = [".indicatrix.toml", ".gemcut.toml"];
const DESIGN_SUFFIX: &str = ".indicatrix";
#[must_use]
pub(super) fn is_superseded_sidecar(existing: &str, new_path: &str) -> bool {
let new_lower = new_path.to_ascii_lowercase();
let Some(stem) = new_lower.strip_suffix(DESIGN_SUFFIX) else {
return false;
};
let existing_lower = existing.to_ascii_lowercase();
OLDER_SIDECAR_SUFFIXES
.iter()
.any(|suffix| existing_lower == format!("{stem}{suffix}"))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn a_design_file_supersedes_the_sidecars_of_the_same_stem() {
assert!(is_superseded_sidecar(
"C:/d/round.indicatrix.toml",
"C:/d/round.indicatrix"
));
assert!(is_superseded_sidecar(
"C:/d/Round.GemCut.toml",
"C:/d/round.indicatrix"
));
}
#[test]
fn other_stems_folders_and_kinds_are_not_superseded() {
assert!(!is_superseded_sidecar(
"C:/d/other.indicatrix.toml",
"C:/d/round.indicatrix"
));
assert!(!is_superseded_sidecar(
"C:/e/round.indicatrix.toml",
"C:/d/round.indicatrix"
));
assert!(!is_superseded_sidecar(
"C:/d/round.indicatrix",
"C:/d/round.indicatrix"
));
assert!(!is_superseded_sidecar(
"C:/d/round.indicatrix",
"C:/d/round.indicatrix.toml"
));
}
}