Skip to content

Commit 23ef747

Browse files
committed
Test
1 parent 19d2c2e commit 23ef747

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

rmp-serde/tests/round.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,23 @@ use std::net::{IpAddr, Ipv4Addr};
385385

386386
#[test]
387387
fn roundtrip_ip_addr() {
388-
let addr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
389-
let addr1: IpAddr = rmp_serde::from_slice(&rmp_serde::to_vec(&addr).unwrap()).unwrap();
388+
assert_roundtrips(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)));
389+
}
390+
391+
#[test]
392+
fn roundtrip_some() {
393+
#[derive(PartialEq, Debug, Serialize, Deserialize)]
394+
struct Wrapper<T>(T);
395+
396+
assert_roundtrips(Some(99));
397+
assert_roundtrips(Wrapper(Some(99)));
398+
assert_roundtrips(Some(Wrapper(99)));
399+
assert_roundtrips(Some("hi".to_string()));
400+
}
390401

391-
assert_eq!(addr1, addr);
402+
#[cfg(test)]
403+
fn assert_roundtrips<T: PartialEq + std::fmt::Debug + Serialize + for<'a> Deserialize<'a>>(val: T) {
404+
let seriaized = rmp_serde::to_vec(&val).unwrap();
405+
let val2: T = rmp_serde::from_slice(&seriaized).unwrap();
406+
assert_eq!(val2, val);
392407
}

0 commit comments

Comments
 (0)