diff --git a/src/os_string_extension.rs b/src/os_string_extension.rs index ae1e907..37a8e74 100644 --- a/src/os_string_extension.rs +++ b/src/os_string_extension.rs @@ -79,4 +79,45 @@ where } } -//TODO unit test! \ No newline at end of file +#[cfg(test)] +mod test { + use crate::os_string_extension::OsStrExtension; + use std::ffi::OsString; + + #[test] + fn test_starts_with() { + assert!(OsString::from("Hello world").starts_with("Hell")); + assert!(!OsString::from("Hello world").starts_with("world")); + } + + #[test] + fn test_ends_with() { + assert!(OsString::from("Hello world").ends_with("ld")); + assert!(!OsString::from("Hello world").ends_with("Hello")); + } + + #[test] + fn test_split() { + assert_eq!(vec![OsString::from("Hello"), OsString::from("world")], OsString::from("Hello world").split(b' ')); + } + + #[test] + fn test_splitn() { + assert_eq!(vec![OsString::from("a"), OsString::from("b"), OsString::from("c d")], OsString::from("a b c d").splitn(3, b' ')); + } + + #[test] + fn test_split_once() { + assert_eq!(Some((OsString::from("a").as_ref(), OsString::from("b c").as_ref())), OsString::from("a b c").split_once(b' ')); + } + + #[test] + fn test_rsplitn() { + assert_eq!(vec![OsString::from("a b"), OsString::from("c"), OsString::from("d")], OsString::from("a b c d").rsplitn(3, b' ')); + } + + #[test] + fn test_rsplit_once() { + assert_eq!(Some((OsString::from("a b").as_ref(), OsString::from("c").as_ref())), OsString::from("a b c").rsplit_once(b' ')); + } +}