Skip to content

Commit 2cca583

Browse files
authored
add test of serde serialization (#71)
1 parent 0a4fb8e commit 2cca583

File tree

3 files changed

+39
-28
lines changed

3 files changed

+39
-28
lines changed

Cargo.lock

Lines changed: 29 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ rkyv = { version = "0.8", default-features = false, optional = true }
1818
[dev-dependencies]
1919
criterion = { version = "0.5", features = ["html_reports"] }
2020
rand = { version = "0.8", default-features = false, features = ["small_rng"] }
21+
serde_json = "1.0"
2122

2223
[features]
2324
# Derives the `Serialize` and `Deserialize` traits from the [`serde`](https://crates.io/crates/serde) crate for the `Primes` struct, as well as a few others.

src/cache/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,4 +923,13 @@ mod test {
923923
const P: Primes<3> = Primes::new();
924924
assert_eq!(P.as_bytes(), &[2, 0, 0, 0, 3, 0, 0, 0, 5, 0, 0, 0]);
925925
}
926+
927+
#[cfg(feature = "serde")]
928+
#[test]
929+
fn test_serde() {
930+
const P: Primes<3> = Primes::new();
931+
const STRING_VERSION: &str = "[2,3,5]";
932+
assert_eq!(serde_json::to_string(&P).unwrap(), STRING_VERSION);
933+
assert_eq!(P, serde_json::from_str(STRING_VERSION).unwrap());
934+
}
926935
}

0 commit comments

Comments
 (0)