utils: Add tests of sanitise_path()
diff mbox series

Message ID 20190225110744.29246-1-mpe@ellerman.id.au
State Superseded
Headers show
Series
  • utils: Add tests of sanitise_path()
Related show

Commit Message

Michael Ellerman Feb. 25, 2019, 11:07 a.m. UTC
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 src/utils.rs | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

Patch
diff mbox series

diff --git a/src/utils.rs b/src/utils.rs
index ec98bb4..00ef0ea 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -16,3 +16,39 @@ 
 pub fn sanitise_path(path: &str) -> String {
     path.replace(|c: char| !c.is_alphanumeric(), "_")
 }
+
+
+#[cfg(test)]
+mod test {
+    use super::sanitise_path;
+
+    #[test]
+    fn test_dereference() {
+        assert_eq!(sanitise_path("powerpc/64: Simplify __secondary_start paca->kstack handling"),
+                   "powerpc_64__Simplify___secondary_start_paca__kstack_handling");
+    }
+
+    #[test]
+    fn test_semi_colon() {
+        assert_eq!(sanitise_path("powerpc: hwrng; fix missing of_node_put()"),
+                   "powerpc__hwrng__fix_missing_of_node_put__");
+    }
+
+    #[test]
+    fn test_null() {
+        assert_eq!(sanitise_path("powerpc: There is a \0 in this subject"),
+                   "powerpc__There_is_a___in_this_subject");
+    }
+
+    #[test]
+    fn test_paths() {
+        assert_eq!(sanitise_path("cat /etc/passwd"),
+                   "cat__etc_passwd");
+    }
+
+    #[test]
+    fn test_options() {
+        assert_eq!(sanitise_path("rm -rf /"),
+                   "rm__rf__");
+    }
+}