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