diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-09-29 10:35:23 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-09-29 10:35:23 +0200 |
commit | 0f9dcd571465a338fb0a0928f4cba430aabac343 (patch) | |
tree | feef2f1563cba72ba7861c38bde44274221fde94 /src/new/mod.rs | |
parent | feat(templates): Provide a consistent syntax for replacements (diff) | |
download | lpm-0f9dcd571465a338fb0a0928f4cba430aabac343.tar.gz lpm-0f9dcd571465a338fb0a0928f4cba430aabac343.zip |
fix(MangledName): Ensure that the mangled names are actually correct
Diffstat (limited to 'src/new/mod.rs')
-rw-r--r-- | src/new/mod.rs | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/src/new/mod.rs b/src/new/mod.rs index 04b75ef..0c4114c 100644 --- a/src/new/mod.rs +++ b/src/new/mod.rs @@ -12,8 +12,15 @@ pub struct MangledName(String); impl MangledName { pub fn new(name: &str) -> 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"); + } +} |