Skip to content

Commit

Permalink
test: add unit test for json serde (bytesize-rs#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCroxx authored and robjtede committed Feb 10, 2025
1 parent 96851de commit 05a48ff
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,4 +465,14 @@ mod tests {
fn test_to_string() {
assert_to_string("609.0 PB", ByteSize::pb(609), true);
}

#[test]
#[cfg(feature = "serde")]
fn test_serde_json() {
let json = serde_json::to_string(&ByteSize::mib(1)).unwrap();
assert_eq!(json, "\"1.0 MiB\"");

let deserialized: ByteSize = serde_json::from_str(&json).unwrap();
assert_eq!(deserialized.0, 1048576);
}
}

0 comments on commit 05a48ff

Please sign in to comment.