summary refs log tree commit diff stats
path: root/src/new/mod.rs
diff options
context:
space:
mode:
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");
+    }
+}