[v2] utils: Add tests of sanitise_path()
diff mbox series

Message ID 20190225111254.31152-1-mpe@ellerman.id.au
State Accepted
Headers show
Series
  • [v2] utils: Add tests of sanitise_path()
Related show

Commit Message

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

v2: rustfmt it, doh!

Comments

Andrew Donnellan Feb. 26, 2019, 4:25 a.m. UTC | #1
On 25/2/19 10:12 pm, Michael Ellerman wrote:
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

Woot, tests!

Applied to master: a45eaa8d7941ef4d8e80c1267b8f4718b564c1e0

Patch
diff mbox series

diff --git a/src/utils.rs b/src/utils.rs
index ec98bb4..6650884 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -16,3 +16,42 @@ 
 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__");
+    }
+}