summary refs log tree commit diff stats
path: root/src/new/mod.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-09-29 10:35:23 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-09-29 10:35:23 +0200
commit0f9dcd571465a338fb0a0928f4cba430aabac343 (patch)
treefeef2f1563cba72ba7861c38bde44274221fde94 /src/new/mod.rs
parentfeat(templates): Provide a consistent syntax for replacements (diff)
downloadlpm-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.rs40
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");
+    }
+}