Rollup merge of #146481 - ferrocene:pvdrz/improve-hash-coverage, r=jhpratt
Improve `core::hash` coverage This PR improves the `core::hash` coverage by adding a new test to `coretests` and extending one of the existing tests to use 128-bit integers r? libs
This commit is contained in:
commit
ec0f3bd2ed
1 changed files with 13 additions and 0 deletions
|
|
@ -53,12 +53,14 @@ fn test_writer_hasher() {
|
|||
assert_eq!(hash(&5_u16), 5);
|
||||
assert_eq!(hash(&5_u32), 5);
|
||||
assert_eq!(hash(&5_u64), 5);
|
||||
assert_eq!(hash(&5_u128), 5);
|
||||
assert_eq!(hash(&5_usize), 5);
|
||||
|
||||
assert_eq!(hash(&5_i8), 5);
|
||||
assert_eq!(hash(&5_i16), 5);
|
||||
assert_eq!(hash(&5_i32), 5);
|
||||
assert_eq!(hash(&5_i64), 5);
|
||||
assert_eq!(hash(&5_i128), 5);
|
||||
assert_eq!(hash(&5_isize), 5);
|
||||
|
||||
assert_eq!(hash(&false), 0);
|
||||
|
|
@ -85,6 +87,17 @@ fn test_writer_hasher() {
|
|||
let ptr = ptr::without_provenance_mut::<i32>(5_usize);
|
||||
assert_eq!(hash(&ptr), 5);
|
||||
|
||||
// Use a newtype to test the `Hash::hash_slice` default implementation.
|
||||
struct Byte(u8);
|
||||
|
||||
impl Hash for Byte {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
state.write_u8(self.0)
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(hash(&[Byte(b'a')]), 97 + 1);
|
||||
|
||||
if cfg!(miri) {
|
||||
// Miri cannot hash pointers
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue