Skip to content

Commit dd089d3

Browse files
committed
Actually test Hash implementations
The existing tests were comparing `()`s
1 parent 4ca084d commit dd089d3

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

tests/oks.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use std::char;
1313
use std::str::{self,FromStr};
1414
use std::cmp::Ordering;
15-
use std::hash::Hash;
15+
use std::hash::{Hash,Hasher};
1616
use std::collections::hash_map::DefaultHasher;
1717
#[allow(deprecated,unused)]
1818
use std::ascii::AsciiExt;
@@ -82,17 +82,22 @@ const EDGES_AND_BETWEEN: [u32;19] = [
8282
];
8383

8484
fn eq_cmp_hash(c: char) -> (Utf8Char, Utf16Char) {
85-
let sh = &mut DefaultHasher::new();
85+
fn hash<T:Hash>(v: T) -> u64 {
86+
#[allow(deprecated)]
87+
let mut hasher = DefaultHasher::new();
88+
v.hash(&mut hasher);
89+
hasher.finish()
90+
}
8691
let u8c = c.to_utf8();
8792
assert_eq!(u8c.to_char(), c);
8893
assert_eq!(u8c, u8c);
89-
assert_eq!(u8c.hash(sh), c.hash(sh));
94+
assert_eq!(hash(u8c), hash(u8c));
9095
assert_eq!(u8c.cmp(&u8c), Ordering::Equal);
9196
assert!(u8c.eq_ignore_ascii_case(&u8c));
9297
let u16c = c.to_utf16();
9398
assert_eq!(u16c.to_char(), c);
9499
assert_eq!(u16c, u16c);
95-
assert_eq!(u16c.hash(sh), c.hash(sh));
100+
assert_eq!(hash(u16c), hash(c));
96101
assert_eq!(u16c.cmp(&u16c), Ordering::Equal);
97102
assert!(u16c.eq_ignore_ascii_case(&u16c));
98103

@@ -101,13 +106,13 @@ fn eq_cmp_hash(c: char) -> (Utf8Char, Utf16Char) {
101106

102107
let u8other = other.to_utf8();
103108
assert_eq!(u8c == u8other, c == other);
104-
assert_eq!(u8c.hash(sh)==other.hash(sh), c.hash(sh)==u8other.hash(sh));
109+
assert_eq!(hash(u8c)==hash(u8other), hash(c)==hash(other));
105110
assert_eq!(u8c.cmp(&u8other), c.cmp(&other));
106111
assert_eq!(u8c.eq_ignore_ascii_case(&u8other), c.eq_ignore_ascii_case(&other));
107112

108113
let u16other = other.to_utf16();
109114
assert_eq!(u16c == u16other, c == other);
110-
assert_eq!(u16c.hash(sh)==other.hash(sh), c.hash(sh)==u16other.hash(sh));
115+
assert_eq!(hash(u16c)==hash(u16other), hash(c)==hash(other));
111116
assert_eq!(u16c.cmp(&u16other), c.cmp(&other));
112117
assert_eq!(u16c.eq_ignore_ascii_case(&u16other), c.eq_ignore_ascii_case(&other));
113118
}

0 commit comments

Comments
 (0)