1cdb3e2c8Sopenharmony_ci#![cfg(feature = "raw_os_str")] 2cdb3e2c8Sopenharmony_ci 3cdb3e2c8Sopenharmony_ciuse os_str_bytes::RawOsStr; 4cdb3e2c8Sopenharmony_ci 5cdb3e2c8Sopenharmony_cimod raw_common; 6cdb3e2c8Sopenharmony_ciuse raw_common::RAW_WTF8_STRING; 7cdb3e2c8Sopenharmony_ci 8cdb3e2c8Sopenharmony_ci#[test] 9cdb3e2c8Sopenharmony_cifn test_ends_with() { 10cdb3e2c8Sopenharmony_ci #[track_caller] 11cdb3e2c8Sopenharmony_ci fn test(result: bool, suffix: &[u8]) { 12cdb3e2c8Sopenharmony_ci let suffix = RawOsStr::assert_from_raw_bytes(suffix); 13cdb3e2c8Sopenharmony_ci assert_eq!(result, RAW_WTF8_STRING.ends_with_os(suffix)); 14cdb3e2c8Sopenharmony_ci } 15cdb3e2c8Sopenharmony_ci 16cdb3e2c8Sopenharmony_ci test(true, b""); 17cdb3e2c8Sopenharmony_ci test(true, b"r"); 18cdb3e2c8Sopenharmony_ci test(true, b"ar"); 19cdb3e2c8Sopenharmony_ci test(true, b"bar"); 20cdb3e2c8Sopenharmony_ci if cfg!(not(windows)) { 21cdb3e2c8Sopenharmony_ci test(true, b"\xA9bar"); 22cdb3e2c8Sopenharmony_ci test(true, b"\x92\xA9bar"); 23cdb3e2c8Sopenharmony_ci test(true, b"\x9F\x92\xA9bar"); 24cdb3e2c8Sopenharmony_ci } 25cdb3e2c8Sopenharmony_ci test(cfg!(windows), b"\xED\xB2\xA9bar"); 26cdb3e2c8Sopenharmony_ci test(true, b"\xF0\x9F\x92\xA9bar"); 27cdb3e2c8Sopenharmony_ci test(true, b"\xED\xA0\xBD\xF0\x9F\x92\xA9bar"); 28cdb3e2c8Sopenharmony_ci test(true, b"o\xED\xA0\xBD\xF0\x9F\x92\xA9bar"); 29cdb3e2c8Sopenharmony_ci test(true, b"oo\xED\xA0\xBD\xF0\x9F\x92\xA9bar"); 30cdb3e2c8Sopenharmony_ci test(true, b"foo\xED\xA0\xBD\xF0\x9F\x92\xA9bar"); 31cdb3e2c8Sopenharmony_ci 32cdb3e2c8Sopenharmony_ci test(false, b"\xED\xA0\xBDbar"); 33cdb3e2c8Sopenharmony_ci test(false, b"\xED\xB2\xA9aar"); 34cdb3e2c8Sopenharmony_ci} 35cdb3e2c8Sopenharmony_ci 36cdb3e2c8Sopenharmony_ci#[test] 37cdb3e2c8Sopenharmony_cifn test_empty_ends_with() { 38cdb3e2c8Sopenharmony_ci #[track_caller] 39cdb3e2c8Sopenharmony_ci fn test(result: bool, suffix: &str) { 40cdb3e2c8Sopenharmony_ci assert_eq!( 41cdb3e2c8Sopenharmony_ci result, 42cdb3e2c8Sopenharmony_ci RawOsStr::from_str("").ends_with_os(RawOsStr::from_str(suffix)), 43cdb3e2c8Sopenharmony_ci ); 44cdb3e2c8Sopenharmony_ci } 45cdb3e2c8Sopenharmony_ci 46cdb3e2c8Sopenharmony_ci test(true, ""); 47cdb3e2c8Sopenharmony_ci test(false, "r"); 48cdb3e2c8Sopenharmony_ci test(false, "ar"); 49cdb3e2c8Sopenharmony_ci} 50cdb3e2c8Sopenharmony_ci 51cdb3e2c8Sopenharmony_ci#[test] 52cdb3e2c8Sopenharmony_cifn test_starts_with() { 53cdb3e2c8Sopenharmony_ci #[track_caller] 54cdb3e2c8Sopenharmony_ci fn test(result: bool, prefix: &[u8]) { 55cdb3e2c8Sopenharmony_ci let prefix = RawOsStr::assert_from_raw_bytes(prefix); 56cdb3e2c8Sopenharmony_ci assert_eq!(result, RAW_WTF8_STRING.starts_with_os(prefix)); 57cdb3e2c8Sopenharmony_ci } 58cdb3e2c8Sopenharmony_ci 59cdb3e2c8Sopenharmony_ci test(true, b""); 60cdb3e2c8Sopenharmony_ci test(true, b"f"); 61cdb3e2c8Sopenharmony_ci test(true, b"fo"); 62cdb3e2c8Sopenharmony_ci test(true, b"foo"); 63cdb3e2c8Sopenharmony_ci test(true, b"foo\xED\xA0\xBD"); 64cdb3e2c8Sopenharmony_ci if cfg!(not(windows)) { 65cdb3e2c8Sopenharmony_ci test(true, b"foo\xED\xA0\xBD\xF0"); 66cdb3e2c8Sopenharmony_ci test(true, b"foo\xED\xA0\xBD\xF0\x9F"); 67cdb3e2c8Sopenharmony_ci test(true, b"foo\xED\xA0\xBD\xF0\x9F\x92"); 68cdb3e2c8Sopenharmony_ci } 69cdb3e2c8Sopenharmony_ci test(cfg!(windows), b"foo\xED\xA0\xBD\xED\xA0\xBD"); 70cdb3e2c8Sopenharmony_ci test(true, b"foo\xED\xA0\xBD\xF0\x9F\x92\xA9"); 71cdb3e2c8Sopenharmony_ci test(true, b"foo\xED\xA0\xBD\xF0\x9F\x92\xA9b"); 72cdb3e2c8Sopenharmony_ci test(true, b"foo\xED\xA0\xBD\xF0\x9F\x92\xA9ba"); 73cdb3e2c8Sopenharmony_ci test(true, b"foo\xED\xA0\xBD\xF0\x9F\x92\xA9bar"); 74cdb3e2c8Sopenharmony_ci 75cdb3e2c8Sopenharmony_ci test(false, b"foo\xED\xB2\xA9"); 76cdb3e2c8Sopenharmony_ci test(false, b"fof\xED\xA0\xBD\xED\xA0\xBD"); 77cdb3e2c8Sopenharmony_ci} 78cdb3e2c8Sopenharmony_ci 79cdb3e2c8Sopenharmony_ci#[test] 80cdb3e2c8Sopenharmony_cifn test_empty_starts_with() { 81cdb3e2c8Sopenharmony_ci #[track_caller] 82cdb3e2c8Sopenharmony_ci fn test(result: bool, prefix: &str) { 83cdb3e2c8Sopenharmony_ci assert_eq!( 84cdb3e2c8Sopenharmony_ci result, 85cdb3e2c8Sopenharmony_ci RawOsStr::from_str("").starts_with_os(RawOsStr::from_str(prefix)), 86cdb3e2c8Sopenharmony_ci ); 87cdb3e2c8Sopenharmony_ci } 88cdb3e2c8Sopenharmony_ci 89cdb3e2c8Sopenharmony_ci test(true, ""); 90cdb3e2c8Sopenharmony_ci test(false, "f"); 91cdb3e2c8Sopenharmony_ci test(false, "fo"); 92cdb3e2c8Sopenharmony_ci} 93cdb3e2c8Sopenharmony_ci 94cdb3e2c8Sopenharmony_ci#[should_panic = "cannot split using an empty pattern"] 95cdb3e2c8Sopenharmony_ci#[test] 96cdb3e2c8Sopenharmony_cifn test_split_by_empty() { 97cdb3e2c8Sopenharmony_ci let _ = RAW_WTF8_STRING.split(""); 98cdb3e2c8Sopenharmony_ci} 99cdb3e2c8Sopenharmony_ci 100cdb3e2c8Sopenharmony_ci#[should_panic = "cannot split using an empty pattern"] 101cdb3e2c8Sopenharmony_ci#[test] 102cdb3e2c8Sopenharmony_cifn test_split_empty_by_empty() { 103cdb3e2c8Sopenharmony_ci let _ = RawOsStr::from_str("").split(""); 104cdb3e2c8Sopenharmony_ci} 105