Skip to content

Commit

Permalink
Merge pull request #1095 from dtolnay/hashtest
Browse files Browse the repository at this point in the history
Resolve manual_hash_one lint in test
  • Loading branch information
dtolnay authored Dec 28, 2023
2 parents fe031cd + b328ee7 commit c367091
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ use serde_json::{
from_reader, from_slice, from_str, from_value, json, to_string, to_string_pretty, to_value,
to_vec, Deserializer, Number, Value,
};
use std::collections::hash_map::DefaultHasher;
use std::collections::BTreeMap;
#[cfg(feature = "raw_value")]
use std::collections::HashMap;
use std::fmt::{self, Debug};
use std::hash::BuildHasher;
#[cfg(feature = "raw_value")]
use std::hash::{Hash, Hasher};
use std::io;
use std::iter;
Expand Down Expand Up @@ -2490,19 +2491,15 @@ fn test_value_into_deserializer() {

#[test]
fn hash_positive_and_negative_zero() {
fn hash(obj: impl Hash) -> u64 {
let mut hasher = DefaultHasher::new();
obj.hash(&mut hasher);
hasher.finish()
}
let rand = std::hash::RandomState::new();

let k1 = serde_json::from_str::<Number>("0.0").unwrap();
let k2 = serde_json::from_str::<Number>("-0.0").unwrap();
if cfg!(feature = "arbitrary_precision") {
assert_ne!(k1, k2);
assert_ne!(hash(k1), hash(k2));
assert_ne!(rand.hash_one(k1), rand.hash_one(k2));
} else {
assert_eq!(k1, k2);
assert_eq!(hash(k1), hash(k2));
assert_eq!(rand.hash_one(k1), rand.hash_one(k2));
}
}

0 comments on commit c367091

Please sign in to comment.