Skip to content

Commit

Permalink
Switch serde test to fnv to advoid 32bit issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tkaitchuck committed Nov 25, 2020
1 parent b226638 commit 6649ebc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ alloc = { version = "1.0.0", optional = true, package = "rustc-std-workspace-all
lazy_static = "1.2"
rand = { version = "0.7.3", features = ["small_rng"] }
rayon = "1.0"
rustc-hash = "=1.0"
fnv = "1.0.7"
serde_test = "1.0"
doc-comment = "0.3.1"

Expand Down
22 changes: 11 additions & 11 deletions tests/serde.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#![cfg(feature = "serde")]

use core::hash::BuildHasherDefault;
use fnv::FnvHasher;
use hashbrown::{HashMap, HashSet};
use rustc_hash::FxHasher;
use serde_test::{assert_tokens, Token};

// We use FxHash for this test because we rely on the ordering
type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
type FxHashSet<T> = HashSet<T, BuildHasherDefault<FxHasher>>;
// We use FnvHash for this test because we rely on the ordering
type FnvHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FnvHasher>>;
type FnvHashSet<T> = HashSet<T, BuildHasherDefault<FnvHasher>>;

#[test]
fn map_serde_tokens_empty() {
let map = FxHashMap::<char, u32>::default();
let map = FnvHashMap::<char, u32>::default();

assert_tokens(&map, &[Token::Map { len: Some(0) }, Token::MapEnd]);
}

#[test]
fn map_serde_tokens() {
let mut map = FxHashMap::default();
let mut map = FnvHashMap::default();
map.insert('b', 20);
map.insert('a', 10);
map.insert('c', 30);
Expand All @@ -29,25 +29,25 @@ fn map_serde_tokens() {
Token::Map { len: Some(3) },
Token::Char('a'),
Token::I32(10),
Token::Char('b'),
Token::I32(20),
Token::Char('c'),
Token::I32(30),
Token::Char('b'),
Token::I32(20),
Token::MapEnd,
],
);
}

#[test]
fn set_serde_tokens_empty() {
let set = FxHashSet::<u32>::default();
let set = FnvHashSet::<u32>::default();

assert_tokens(&set, &[Token::Seq { len: Some(0) }, Token::SeqEnd]);
}

#[test]
fn set_serde_tokens() {
let mut set = FxHashSet::default();
let mut set = FnvHashSet::default();
set.insert(20);
set.insert(10);
set.insert(30);
Expand All @@ -56,9 +56,9 @@ fn set_serde_tokens() {
&set,
&[
Token::Seq { len: Some(3) },
Token::I32(30),
Token::I32(20),
Token::I32(10),
Token::I32(30),
Token::SeqEnd,
],
);
Expand Down

0 comments on commit 6649ebc

Please sign in to comment.