1 #![cfg(feature = "raw_os_str")]
2
3 use os_str_bytes::RawOsStr;
4 use os_str_bytes::RawOsString;
5
6 mod random_common;
7 use random_common::ITERATIONS;
8 use random_common::SMALL_LENGTH;
9
10 #[test]
test_complex() -> Result<(), getrandom::Error>11 fn test_complex() -> Result<(), getrandom::Error> {
12 macro_rules! test {
13 ( $result:expr , $method:ident ( $(& $arg:ident),+) ) => {
14 assert_eq!(
15 $result,
16 RawOsStr::$method($(&$arg),+),
17 concat!(stringify!($method), "({:?}, {:?})"),
18 $($arg,)+
19 );
20 };
21 }
22
23 for _ in 0..ITERATIONS {
24 let mut string = random_common::random_os_string(SMALL_LENGTH)?;
25 let prefix = RawOsStr::new(&string).into_owned();
26 let suffix = random_common::random_os_string(SMALL_LENGTH)?;
27 string.push(&suffix);
28
29 let string = RawOsString::new(string);
30 let suffix = RawOsString::new(suffix);
31
32 test!(true, ends_with_os(&string, &suffix));
33 test!(true, starts_with_os(&string, &prefix));
34
35 if prefix != suffix {
36 test!(false, ends_with_os(&string, &prefix));
37 test!(false, starts_with_os(&string, &suffix));
38 }
39 }
40 Ok(())
41 }
42