Skip to content

Commit

Permalink
Restore tests to working condition when serialization is enabled
Browse files Browse the repository at this point in the history
Primarily, serde_json adds some inference failures. Some traits
were missing and some other warnings had popped up.
  • Loading branch information
shepmaster committed Oct 9, 2024
1 parent 39d1b39 commit 19b73de
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
12 changes: 8 additions & 4 deletions src/xxhash32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ mod test {

use super::*;

const EMPTY_BYTES: [u8; 0] = [];

#[test]
fn ingesting_byte_by_byte_is_equivalent_to_large_chunks() {
let bytes = [0; 32];
Expand All @@ -409,7 +411,7 @@ mod test {
#[test]
fn hash_of_nothing_matches_c_implementation() {
let mut hasher = Hasher::with_seed(0);
hasher.write(&[]);
hasher.write(&EMPTY_BYTES);
assert_eq!(hasher.finish(), 0x02cc_5d05);
}

Expand Down Expand Up @@ -438,7 +440,7 @@ mod test {
#[test]
fn hash_with_different_seed_matches_c_implementation() {
let mut hasher = Hasher::with_seed(0x42c9_1977);
hasher.write(&[]);
hasher.write(&EMPTY_BYTES);
assert_eq!(hasher.finish(), 0xd6bf_8459);
}

Expand Down Expand Up @@ -628,6 +630,8 @@ mod serialize_impl {

#[cfg(test)]
mod test {
use std::hash::Hasher as _;

use super::*;

type Result<T = (), E = serde_json::Error> = core::result::Result<T, E>;
Expand All @@ -636,7 +640,7 @@ mod serialize_impl {
fn test_serialization_cycle() -> Result {
let mut hasher = Hasher::with_seed(0);
hasher.write(b"Hello, world!\0");
hasher.finish();
let _ = hasher.finish();

let serialized = serde_json::to_string(&hasher)?;
let unserialized: Hasher = serde_json::from_str(&serialized)?;
Expand All @@ -648,7 +652,7 @@ mod serialize_impl {
fn test_serialization_stability() -> Result {
let mut hasher = Hasher::with_seed(0);
hasher.write(b"Hello, world!\0");
hasher.finish();
let _ = hasher.finish();

let expected_serialized = r#"{
"total_len": 14,
Expand Down
14 changes: 8 additions & 6 deletions src/xxhash3_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,8 @@ mod test {

use super::*;

const EMPTY_BYTES: [u8; 0] = [];

#[test]
fn default_secret_is_valid() {
assert!(DEFAULT_SECRET.is_valid())
Expand Down Expand Up @@ -1377,13 +1379,13 @@ mod test {

#[test]
fn oneshot_empty() {
let hash = Hasher::oneshot(&[]);
let hash = Hasher::oneshot(&EMPTY_BYTES);
assert_eq!(hash, 0x2d06_8005_38d3_94c2);
}

#[test]
fn streaming_empty() {
let hash = hash_byte_by_byte(&[]);
let hash = hash_byte_by_byte(&EMPTY_BYTES);
assert_eq!(hash, 0x2d06_8005_38d3_94c2);
}

Expand Down Expand Up @@ -1614,7 +1616,7 @@ mod test {

let (a, b) = x.bp_as_chunks::<1>();
assert_eq!(a, &[[1], [2], [3], [4], [5]]);
assert_eq!(b, &[]);
assert_eq!(b, &[] as &[i32]);

let (a, b) = x.bp_as_chunks::<2>();
assert_eq!(a, &[[1, 2], [3, 4]]);
Expand All @@ -1630,7 +1632,7 @@ mod test {

let (a, b) = x.bp_as_chunks::<5>();
assert_eq!(a, &[[1, 2, 3, 4, 5]]);
assert_eq!(b, &[]);
assert_eq!(b, &[] as &[i32]);

let (a, b) = x.bp_as_chunks::<6>();
assert_eq!(a, &[] as &[[i32; 6]]);
Expand All @@ -1642,7 +1644,7 @@ mod test {
let x = [1, 2, 3, 4, 5];

let (a, b) = x.bp_as_rchunks::<1>();
assert_eq!(a, &[]);
assert_eq!(a, &[] as &[i32]);
assert_eq!(b, &[[1], [2], [3], [4], [5]]);

let (a, b) = x.bp_as_rchunks::<2>();
Expand All @@ -1658,7 +1660,7 @@ mod test {
assert_eq!(b, &[[2, 3, 4, 5]]);

let (a, b) = x.bp_as_rchunks::<5>();
assert_eq!(a, &[]);
assert_eq!(a, &[] as &[i32]);
assert_eq!(b, &[[1, 2, 3, 4, 5]]);

let (a, b) = x.bp_as_rchunks::<6>();
Expand Down
12 changes: 8 additions & 4 deletions src/xxhash64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ mod test {

use super::*;

const EMPTY_BYTES: [u8; 0] = [];

#[test]
fn ingesting_byte_by_byte_is_equivalent_to_large_chunks() {
let bytes = [0x9c; 32];
Expand All @@ -420,7 +422,7 @@ mod test {
#[test]
fn hash_of_nothing_matches_c_implementation() {
let mut hasher = Hasher::with_seed(0);
hasher.write(&[]);
hasher.write(&EMPTY_BYTES);
assert_eq!(hasher.finish(), 0xef46_db37_51d8_e999);
}

Expand Down Expand Up @@ -449,7 +451,7 @@ mod test {
#[test]
fn hash_with_different_seed_matches_c_implementation() {
let mut hasher = Hasher::with_seed(0xae05_4331_1b70_2d91);
hasher.write(&[]);
hasher.write(&EMPTY_BYTES);
assert_eq!(hasher.finish(), 0x4b6a_04fc_df7a_4672);
}

Expand Down Expand Up @@ -617,6 +619,8 @@ mod serialize_impl {

#[cfg(test)]
mod test {
use std::hash::Hasher as _;

use super::*;

type Result<T = (), E = serde_json::Error> = core::result::Result<T, E>;
Expand All @@ -625,7 +629,7 @@ mod serialize_impl {
fn test_serialization_cycle() -> Result {
let mut hasher = Hasher::with_seed(0);
hasher.write(b"Hello, world!\0");
hasher.finish();
let _ = hasher.finish();

let serialized = serde_json::to_string(&hasher)?;
let unserialized: Hasher = serde_json::from_str(&serialized)?;
Expand All @@ -637,7 +641,7 @@ mod serialize_impl {
fn test_serialization_stability() -> Result {
let mut hasher = Hasher::with_seed(0);
hasher.write(b"Hello, world!\0");
hasher.finish();
let _ = hasher.finish();

let expected_serialized = r#"{
"total_len": 14,
Expand Down

0 comments on commit 19b73de

Please sign in to comment.