[snowpatch] [PATCH v2] utils: Add tests of sanitise_path()
Michael Ellerman
mpe at ellerman.id.au
Mon Feb 25 22:12:54 AEDT 2019
Signed-off-by: Michael Ellerman <mpe at ellerman.id.au>
---
src/utils.rs | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
v2: rustfmt it, doh!
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__");
+ }
+}
--
2.20.1
More information about the snowpatch
mailing list