Skip to content

Commit 05a48ff

Browse files
MrCroxxrobjtede
authored andcommitted
test: add unit test for json serde (bytesize-rs#54)
1 parent 96851de commit 05a48ff

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,4 +465,14 @@ mod tests {
465465
fn test_to_string() {
466466
assert_to_string("609.0 PB", ByteSize::pb(609), true);
467467
}
468+
469+
#[test]
470+
#[cfg(feature = "serde")]
471+
fn test_serde_json() {
472+
let json = serde_json::to_string(&ByteSize::mib(1)).unwrap();
473+
assert_eq!(json, "\"1.0 MiB\"");
474+
475+
let deserialized: ByteSize = serde_json::from_str(&json).unwrap();
476+
assert_eq!(deserialized.0, 1048576);
477+
}
468478
}

0 commit comments

Comments
 (0)