2024-07-24 15:28:31 +03:00
|
|
|
|
use core::ffi::CStr;
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn compares_as_u8s() {
|
|
|
|
|
|
let a: &CStr = c"Hello!"; // Starts with ascii
|
|
|
|
|
|
let a_bytes: &[u8] = a.to_bytes();
|
|
|
|
|
|
assert!((..0b1000_0000).contains(&a_bytes[0]));
|
|
|
|
|
|
|
|
|
|
|
|
let b: &CStr = c"こんにちは!"; // Starts with non ascii
|
|
|
|
|
|
let b_bytes: &[u8] = b.to_bytes();
|
|
|
|
|
|
assert!((0b1000_0000..).contains(&b_bytes[0]));
|
|
|
|
|
|
|
|
|
|
|
|
assert_eq!(Ord::cmp(a, b), Ord::cmp(a_bytes, b_bytes));
|
|
|
|
|
|
assert_eq!(PartialOrd::partial_cmp(a, b), PartialOrd::partial_cmp(a_bytes, b_bytes));
|
|
|
|
|
|
}
|
2025-04-18 10:30:38 -04:00
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn debug() {
|
|
|
|
|
|
let s = c"abc\x01\x02\n\xE2\x80\xA6\xFF";
|
2025-04-18 11:18:25 -04:00
|
|
|
|
assert_eq!(format!("{s:?}"), r#""abc\x01\x02\n…\xff""#);
|
2025-04-18 10:30:38 -04:00
|
|
|
|
}
|
2025-04-17 19:43:56 -04:00
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn display() {
|
|
|
|
|
|
let s = c"\xf0\x28\x8c\xbc";
|
|
|
|
|
|
assert_eq!(format!("{}", s.display()), "<EFBFBD>(<28><>");
|
|
|
|
|
|
}
|