Skip to content

Commit 70a9fdd

Browse files
MrCroxxrobjtede
authored andcommitted
test: add unit test for json serde (bytesize-rs#54)
1 parent cf581a0 commit 70a9fdd

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

0 commit comments

Comments
 (0)