From 0f9dcd571465a338fb0a0928f4cba430aabac343 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sun, 29 Sep 2024 10:35:23 +0200 Subject: fix(MangledName): Ensure that the mangled names are actually correct --- src/new/chapter.rs | 7 ++++++- src/new/mod.rs | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/new/chapter.rs b/src/new/chapter.rs index fcc075d..7628db6 100644 --- a/src/new/chapter.rs +++ b/src/new/chapter.rs @@ -113,7 +113,12 @@ fn get_last_chapter_name(project_root: &Path) -> anyhow::Result Self { - let ascii_name = deunicode(&name); - Self(ascii_name.to_case(Case::Snake)) + let safe_name = name + // TeX fails to include/input stuff with a colon in it. + .replace(':', "_") + // This obviously creates weird extra directories + .replace('/', "_"); + + let ascii_name = deunicode(&safe_name.to_case(Case::Snake)).to_case(Case::Snake); + + Self(ascii_name) } pub fn from_str_unsafe(name: &str) -> Self { @@ -40,3 +47,32 @@ impl Display for MangledName { f.write_str(&self.0) } } + +#[cfg(test)] +mod test { + use crate::new::MangledName; + + #[test] + fn test_names() { + let name = MangledName::new("Æneid"); + assert_eq!(name.to_string().as_str(), "aeneid"); + + let name = MangledName::new("étude"); + assert_eq!(name.to_string().as_str(), "etude"); + + let name = MangledName::new("Ästhetik"); + assert_eq!(name.to_string().as_str(), "asthetik"); + + let name = MangledName::new("北亰"); + assert_eq!(name.to_string().as_str(), "bei_jing"); + + let name = MangledName::new("ᔕᓇᓇ"); + assert_eq!(name.to_string().as_str(), "shanana"); + + let name = MangledName::new("げんまい茶"); + assert_eq!(name.to_string().as_str(), "genmai_cha"); + + let name = MangledName::new("🦄☣"); + assert_eq!(name.to_string().as_str(), "unicorn_biohazard"); + } +} -- cgit 1.4.1