diff options
| author | klensy <klensy@users.noreply.github.com> | 2021-03-28 19:34:38 +0300 |
|---|---|---|
| committer | klensy <klensy@users.noreply.github.com> | 2021-03-28 19:58:49 +0300 |
| commit | 84542d22a71cb486b0f79cf3bfd7a264b688030c (patch) | |
| tree | 5601a1077bb1bc159ca74be90920789139676aa5 | |
| parent | d4c96de64f8c1872f275f9eef7ce17d2c80e6877 (diff) | |
| download | rust-84542d22a71cb486b0f79cf3bfd7a264b688030c.tar.gz rust-84542d22a71cb486b0f79cf3bfd7a264b688030c.zip | |
ffi::c_str added tests for empty strings
| -rw-r--r-- | library/std/src/ffi/c_str/tests.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/library/std/src/ffi/c_str/tests.rs b/library/std/src/ffi/c_str/tests.rs index 4dff3df63a8..4f7ba9ad437 100644 --- a/library/std/src/ffi/c_str/tests.rs +++ b/library/std/src/ffi/c_str/tests.rs @@ -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()); +} |
