Skip to content

Commit 3a9a14b

Browse files
authored
test: add unit test for json serde (#54)
1 parent f26df42 commit 3a9a14b

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
@@ -512,4 +512,14 @@ mod tests {
512512
let s: S = toml::from_str(r#"x = "9223372036854775807""#).unwrap();
513513
assert_eq!(s.x, "9223372036854775807".parse::<ByteSize>().unwrap());
514514
}
515+
516+
#[test]
517+
#[cfg(feature = "serde")]
518+
fn test_serde_json() {
519+
let json = serde_json::to_string(&ByteSize::mib(1)).unwrap();
520+
assert_eq!(json, "\"1.0 MiB\"");
521+
522+
let deserialized: ByteSize = serde_json::from_str(&json).unwrap();
523+
assert_eq!(deserialized.0, 1048576);
524+
}
515525
}

0 commit comments

Comments
 (0)