]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_data_structures/src/small_c_str/tests.rs
Rollup merge of #100823 - WaffleLapkin:less_offsets, r=scottmcm
[rust.git] / compiler / rustc_data_structures / src / small_c_str / tests.rs
1 use super::*;
2
3 #[test]
4 fn short() {
5     const TEXT: &str = "abcd";
6     let reference = ffi::CString::new(TEXT.to_string()).unwrap();
7
8     let scs = SmallCStr::new(TEXT);
9
10     assert_eq!(scs.len_with_nul(), TEXT.len() + 1);
11     assert_eq!(scs.as_c_str(), reference.as_c_str());
12     assert!(!scs.spilled());
13 }
14
15 #[test]
16 fn empty() {
17     const TEXT: &str = "";
18     let reference = ffi::CString::new(TEXT.to_string()).unwrap();
19
20     let scs = SmallCStr::new(TEXT);
21
22     assert_eq!(scs.len_with_nul(), TEXT.len() + 1);
23     assert_eq!(scs.as_c_str(), reference.as_c_str());
24     assert!(!scs.spilled());
25 }
26
27 #[test]
28 fn long() {
29     const TEXT: &str = "01234567890123456789012345678901234567890123456789\
30                         01234567890123456789012345678901234567890123456789\
31                         01234567890123456789012345678901234567890123456789";
32     let reference = ffi::CString::new(TEXT.to_string()).unwrap();
33
34     let scs = SmallCStr::new(TEXT);
35
36     assert_eq!(scs.len_with_nul(), TEXT.len() + 1);
37     assert_eq!(scs.as_c_str(), reference.as_c_str());
38     assert!(scs.spilled());
39 }
40
41 #[test]
42 #[should_panic]
43 fn internal_nul() {
44     let _ = SmallCStr::new("abcd\0def");
45 }