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

Commit

Permalink
Add packed serialized test for struct
Browse files Browse the repository at this point in the history
See issue #144
  • Loading branch information
pyfisch committed Sep 8, 2019
1 parent d769647 commit 2c7ed27
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,21 @@ mod std_tests {

assert_eq!(value, data_de_value);
}

#[derive(Debug, Deserialize, Serialize)]
struct SmallStruct {
spam: u32,
eggs: u32,
}

#[test]
fn small_struct() {
// Test whether the packed format works.
// Field names should not be serialized,
// instead field indizes are serialized.
let value = SmallStruct { spam: 17, eggs: 42 };
let data = serde_cbor::ser::to_vec_packed(&value).unwrap();
let reference = b"\xa2\x00\x11\x01\x18\x2a";
assert_eq!(data, reference);
}
}

0 comments on commit 2c7ed27

Please sign in to comment.