mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-22 21:48:02 +00:00
@@ -8,6 +8,9 @@ use std::time::Duration;
|
||||
use std::default::Default;
|
||||
use std::ffi::CString;
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
use std::ffi::CStr;
|
||||
|
||||
extern crate serde;
|
||||
use serde::Deserialize;
|
||||
|
||||
@@ -886,6 +889,13 @@ declare_tests! {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
#[test]
|
||||
fn test_cstr() {
|
||||
assert_de_tokens::<Box<CStr>>(&CString::new("abc").unwrap().into_boxed_c_str(),
|
||||
&[Token::Bytes(b"abc")]);
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
#[test]
|
||||
fn test_net_ipaddr() {
|
||||
@@ -895,6 +905,28 @@ fn test_net_ipaddr() {
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
#[test]
|
||||
fn test_cstr_internal_null() {
|
||||
assert_de_tokens_error::<Box<CStr>>(
|
||||
&[
|
||||
Token::Bytes(b"a\0c"),
|
||||
],
|
||||
Error::Message("nul byte found in provided data at position: 1".into())
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
#[test]
|
||||
fn test_cstr_internal_null_end() {
|
||||
assert_de_tokens_error::<Box<CStr>>(
|
||||
&[
|
||||
Token::Bytes(b"ac\0"),
|
||||
],
|
||||
Error::Message("nul byte found in provided data at position: 2".into())
|
||||
);
|
||||
}
|
||||
|
||||
declare_error_tests! {
|
||||
test_unknown_field<StructDenyUnknown> {
|
||||
&[
|
||||
|
||||
Reference in New Issue
Block a user