diff options
author | Jack O'Connor <oconnor663@gmail.com> | 2023-09-19 23:42:39 -0700 |
---|---|---|
committer | Jack O'Connor <oconnor663@gmail.com> | 2023-09-19 23:43:47 -0700 |
commit | d7e9365be1751cceb83df2e4cb0086ac8f869357 (patch) | |
tree | 6aa290bb7c24ed7b6e07927e76f7154883160d4f | |
parent | 5e3eb949a78f767a5a458022afedeb3e66398659 (diff) |
add a test for the new serde feature
-rw-r--r-- | .github/workflows/ci.yml | 8 | ||||
-rw-r--r-- | Cargo.toml | 5 | ||||
-rw-r--r-- | src/lib.rs | 8 | ||||
-rw-r--r-- | src/test.rs | 14 |
4 files changed, 26 insertions, 9 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 16a5468..2de4fdd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,17 +52,17 @@ jobs: - name: print instruction set support run: cargo run --quiet working-directory: ./tools/instruction_set_support - # Default tests plus Rayon and RustCrypto trait implementations. - - run: cargo test --features=rayon,traits-preview,zeroize + # Default tests plus Rayon and trait implementations. + - run: cargo test --features=rayon,traits-preview,serde,zeroize # Same but with only one thread in the Rayon pool. This can find deadlocks. - name: "again with RAYON_NUM_THREADS=1" - run: cargo test --features=rayon,traits-preview,zeroize + run: cargo test --features=rayon,traits-preview,serde,zeroize env: RAYON_NUM_THREADS: 1 # The mmap feature by itself (update_mmap_rayon is omitted). - run: cargo test --features=mmap # All public features put together. - - run: cargo test --features=mmap,rayon,traits-preview,zeroize + - run: cargo test --features=mmap,rayon,traits-preview,serde,zeroize # no_std tests. - run: cargo test --no-default-features @@ -88,8 +88,8 @@ no_avx512 = [] no_neon = [] [package.metadata.docs.rs] -# Document the rayon/mmap methods and the Zeroize impls on docs.rs. -features = ["mmap", "rayon", "zeroize"] +# Document the rayon/mmap methods and the Serialize/Deserialize/Zeroize impls on docs.rs. +features = ["mmap", "rayon", "serde", "zeroize"] [dependencies] arrayref = "0.3.5" @@ -110,6 +110,7 @@ rand = "0.8.0" rand_chacha = "0.3.0" reference_impl = { path = "./reference_impl" } tempfile = "3.8.0" +serde_json = "1.0.107" [build-dependencies] cc = "1.0.4" @@ -56,6 +56,11 @@ //! [`Zeroize`](https://docs.rs/zeroize/latest/zeroize/trait.Zeroize.html) for //! this crate's types. //! +//! The `serde` feature (disabled by default, but enabled for [docs.rs]) implements +//! [`serde::Serialize`](https://docs.rs/serde/latest/serde/trait.Serialize.html) and +//! [`serde::Deserialize`](https://docs.rs/serde/latest/serde/trait.Deserialize.html) +//! for [`Hash`](struct@Hash). +//! //! The NEON implementation is enabled by default for AArch64 but requires the //! `neon` feature for other ARM targets. Not all ARMv7 CPUs support NEON, and //! enabling this feature will produce a binary that's not portable to CPUs @@ -69,9 +74,6 @@ //! expect breaking changes between patch versions. (The "-preview" feature name //! follows the conventions of the RustCrypto [`signature`] crate.) //! -//! The `serde` feature (disabled by default) enables serde compatibility for -//! the `Hash` struct. -//! //! [`Hasher::update_rayon`]: struct.Hasher.html#method.update_rayon //! [BLAKE3]: https://blake3.io //! [Rayon]: https://github.com/rayon-rs/rayon diff --git a/src/test.rs b/src/test.rs index c98192f..fb1e849 100644 --- a/src/test.rs +++ b/src/test.rs @@ -806,3 +806,17 @@ fn test_mmap_rayon() -> Result<(), std::io::Error> { ); Ok(()) } + +#[test] +#[cfg(feature = "std")] +#[cfg(feature = "serde")] +fn test_serde() { + let hash: crate::Hash = [7; 32].into(); + let json = serde_json::to_string(&hash).unwrap(); + assert_eq!( + json, + "[7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7]", + ); + let hash2: crate::Hash = serde_json::from_str(&json).unwrap(); + assert_eq!(hash, hash2); +} |