We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d4c96de commit 84542d2Copy full SHA for 84542d2
library/std/src/ffi/c_str/tests.rs
@@ -193,3 +193,19 @@ fn cstr_index_from_empty() {
193
let cstr = CStr::from_bytes_with_nul(original).unwrap();
194
let _ = &cstr[original.len()..];
195
}
196
+
197
+#[test]
198
+fn c_string_from_empty_string() {
199
+ let original = "";
200
+ let cstring = CString::new(original).unwrap();
201
+ assert_eq!(original.as_bytes(), cstring.as_bytes());
202
+ assert_eq!([b'\0'], cstring.as_bytes_with_nul());
203
+}
204
205
206
+fn c_str_from_empty_string() {
207
+ let original = b"\0";
208
+ let cstr = CStr::from_bytes_with_nul(original).unwrap();
209
+ assert_eq!([] as [u8; 0], cstr.to_bytes());
210
+ assert_eq!([b'\0'], cstr.to_bytes_with_nul());
211
0 commit comments