diff options
Diffstat (limited to 'library/core/tests')
| -rw-r--r-- | library/core/tests/ffi.rs | 1 | ||||
| -rw-r--r-- | library/core/tests/ffi/cstr.rs | 15 | ||||
| -rw-r--r-- | library/core/tests/lib.rs | 1 |
3 files changed, 17 insertions, 0 deletions
diff --git a/library/core/tests/ffi.rs b/library/core/tests/ffi.rs new file mode 100644 index 00000000000..2b33fbd95f0 --- /dev/null +++ b/library/core/tests/ffi.rs @@ -0,0 +1 @@ +mod cstr; diff --git a/library/core/tests/ffi/cstr.rs b/library/core/tests/ffi/cstr.rs new file mode 100644 index 00000000000..9bf4c21a9ab --- /dev/null +++ b/library/core/tests/ffi/cstr.rs @@ -0,0 +1,15 @@ +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)); +} diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 83a615fcd8b..04aaa3f35b7 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -132,6 +132,7 @@ mod clone; mod cmp; mod const_ptr; mod convert; +mod ffi; mod fmt; mod future; mod hash; |
