Verify that `ItemEnum` can be serialized and then deserialized using bincode

This commit is contained in:
Luca Palmieri 2023-05-22 18:26:20 +01:00
parent a5e5101375
commit cd7688bd30
3 changed files with 23 additions and 4 deletions

View File

@ -246,6 +246,15 @@ dependencies = [
"serde",
]
[[package]]
name = "bincode"
version = "1.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
dependencies = [
"serde",
]
[[package]]
name = "bitflags"
version = "1.3.2"
@ -4351,6 +4360,7 @@ dependencies = [
name = "rustdoc-json-types"
version = "0.1.0"
dependencies = [
"bincode",
"rustc-hash",
"serde",
"serde_json",

View File

@ -12,3 +12,4 @@ rustc-hash = "1.1.0"
[dev-dependencies]
serde_json = "1.0"
bincode = "1"

View File

@ -8,11 +8,15 @@ fn test_struct_info_roundtrip() {
impls: vec![],
});
// JSON
let struct_json = serde_json::to_string(&s).unwrap();
let de_s = serde_json::from_str(&struct_json).unwrap();
assert_eq!(s, de_s);
// Bincode
let encoded: Vec<u8> = bincode::serialize(&s).unwrap();
let decoded: ItemEnum = bincode::deserialize(&encoded).unwrap();
assert_eq!(s, decoded);
}
#[test]
@ -24,9 +28,13 @@ fn test_union_info_roundtrip() {
impls: vec![],
});
// JSON
let union_json = serde_json::to_string(&u).unwrap();
let de_u = serde_json::from_str(&union_json).unwrap();
assert_eq!(u, de_u);
// Bincode
let encoded: Vec<u8> = bincode::serialize(&u).unwrap();
let decoded: ItemEnum = bincode::deserialize(&encoded).unwrap();
assert_eq!(u, decoded);
}