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 cf581a0 commit 70a9fdd
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 @@ -511,4 +511,14 @@ mod tests {
let s: S = toml::from_str(r#"x = "9223372036854775807""#).unwrap();
assert_eq!(s.x, "9223372036854775807".parse::<ByteSize>().unwrap());
}

#[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 70a9fdd

Please sign in to comment.