Add unit tests for osstring extensions
This commit is contained in:
parent
ad710581b3
commit
67eca84f9d
@ -79,4 +79,45 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO unit test!
|
#[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' '));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user