Skip to content
This repository was archived by the owner on Aug 15, 2021. It is now read-only.

Commit 848b811

Browse files
committed
Add roundtrip example test case.
1 parent 7d1d6d3 commit 848b811

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/roundtrip.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#[macro_use]
2+
extern crate serde_derive;
3+
4+
use serde_cbor;
5+
use serde_cbor::de;
6+
7+
#[derive(Serialize, Deserialize, Debug, PartialEq)]
8+
struct MyStuff {
9+
#[serde(flatten)]
10+
data: MyStuffType,
11+
}
12+
13+
#[derive(Serialize, Deserialize, Debug, PartialEq)]
14+
enum MyStuffType {
15+
ver1 {
16+
x: f64,
17+
},
18+
ver2
19+
}
20+
21+
#[test]
22+
/// Test roundtrip operation on a serde data structure.
23+
fn test_roundtrip() {
24+
let stuff1 = MyStuff {
25+
data: MyStuffType::ver1 {
26+
x: 2.5
27+
}
28+
};
29+
let data_bytes = serde_cbor::to_vec(&stuff1).unwrap();
30+
let stuff2 = serde_cbor::from_slice(&data_bytes).unwrap();
31+
assert_eq!(stuff1, stuff2);
32+
}

0 commit comments

Comments
 (0)