4ed0362c8e
The serde_test Serializer and Deserializer panic in is_human_readable unless the readableness has been set explicitly through one of the hidden functions. This is to force types that have distinct readable/compact representations to be tested explicitly in one or the other, rather than with a plain assert_tokens which arbitrarily picks one. We need to follow up by designing a better API in serde_test to expose this publicly. For now serde_test cannot be used to test types that rely on is_human_readable. (The hidden functions are meant for our test suite only.)
46 lines
984 B
Rust
46 lines
984 B
Rust
extern crate serde_test;
|
|
use self::serde_test::{Token, assert_tokens_readable};
|
|
|
|
use std::net;
|
|
|
|
#[macro_use]
|
|
#[allow(unused_macros)]
|
|
mod macros;
|
|
|
|
#[test]
|
|
fn ip_addr_roundtrip() {
|
|
|
|
assert_tokens_readable(
|
|
&net::IpAddr::from(*b"1234"),
|
|
&seq![
|
|
Token::NewtypeVariant { name: "IpAddr", variant: "V4" },
|
|
|
|
Token::Tuple { len: 4 },
|
|
seq b"1234".iter().map(|&b| Token::U8(b)),
|
|
Token::TupleEnd,
|
|
],
|
|
Some(false),
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn socked_addr_roundtrip() {
|
|
|
|
assert_tokens_readable(
|
|
&net::SocketAddr::from((*b"1234567890123456", 1234)),
|
|
&seq![
|
|
Token::NewtypeVariant { name: "SocketAddr", variant: "V6" },
|
|
|
|
Token::Tuple { len: 2 },
|
|
|
|
Token::Tuple { len: 16 },
|
|
seq b"1234567890123456".iter().map(|&b| Token::U8(b)),
|
|
Token::TupleEnd,
|
|
|
|
Token::U16(1234),
|
|
Token::TupleEnd,
|
|
],
|
|
Some(false),
|
|
);
|
|
}
|