Skip to content

Commit

Permalink
Verify that ItemEnum can be serialized and then deserialized using …
Browse files Browse the repository at this point in the history
…bincode
  • Loading branch information
LukeMathWalker committed May 22, 2023
1 parent a5e5101 commit cd7688b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -4351,6 +4360,7 @@ dependencies = [
name = "rustdoc-json-types"
version = "0.1.0"
dependencies = [
"bincode",
"rustc-hash",
"serde",
"serde_json",
Expand Down
1 change: 1 addition & 0 deletions src/rustdoc-json-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ rustc-hash = "1.1.0"

[dev-dependencies]
serde_json = "1.0"
bincode = "1"
16 changes: 12 additions & 4 deletions src/rustdoc-json-types/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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);
}

0 comments on commit cd7688b

Please sign in to comment.