mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 01:34:21 +00:00
ffi::c_str added tests for empty strings
This commit is contained in:
parent
d4c96de64f
commit
84542d22a7
@ -193,3 +193,19 @@ fn cstr_index_from_empty() {
|
||||
let cstr = CStr::from_bytes_with_nul(original).unwrap();
|
||||
let _ = &cstr[original.len()..];
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn c_string_from_empty_string() {
|
||||
let original = "";
|
||||
let cstring = CString::new(original).unwrap();
|
||||
assert_eq!(original.as_bytes(), cstring.as_bytes());
|
||||
assert_eq!([b'\0'], cstring.as_bytes_with_nul());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn c_str_from_empty_string() {
|
||||
let original = b"\0";
|
||||
let cstr = CStr::from_bytes_with_nul(original).unwrap();
|
||||
assert_eq!([] as [u8; 0], cstr.to_bytes());
|
||||
assert_eq!([b'\0'], cstr.to_bytes_with_nul());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user