Skip to content

Commit

Permalink
test: add unit test for json serde (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCroxx authored Nov 18, 2024
1 parent f26df42 commit 3a9a14b
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 @@ -512,4 +512,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 3a9a14b

Please sign in to comment.