Sha256: 6bac8054db722dd049901b37a6e006535bac30f425eb5cd91af19b5bc1dfe78e

Contents?: true

Size: 1.45 KB

Versions: 73

Compression:

Stored size: 1.45 KB

Contents

#![cfg(feature = "serde")]

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

// 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 = FnvHashMap::<char, u32>::default();

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

#[test]
fn map_serde_tokens() {
    let mut map = FnvHashMap::default();
    map.insert('b', 20);
    map.insert('a', 10);
    map.insert('c', 30);

    assert_tokens(
        &map,
        &[
            Token::Map { len: Some(3) },
            Token::Char('a'),
            Token::I32(10),
            Token::Char('c'),
            Token::I32(30),
            Token::Char('b'),
            Token::I32(20),
            Token::MapEnd,
        ],
    );
}

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

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

#[test]
fn set_serde_tokens() {
    let mut set = FnvHashSet::default();
    set.insert(20);
    set.insert(10);
    set.insert(30);

    assert_tokens(
        &set,
        &[
            Token::Seq { len: Some(3) },
            Token::I32(30),
            Token::I32(20),
            Token::I32(10),
            Token::SeqEnd,
        ],
    );
}

Version data entries

73 entries across 38 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/hashbrown-0.15.2/tests/serde.rs
wasmtime-29.0.0 ./ext/cargo-vendor/hashbrown-0.14.5/tests/serde.rs
wasmtime-28.0.0 ./ext/cargo-vendor/hashbrown-0.14.5/tests/serde.rs
wasmtime-28.0.0 ./ext/cargo-vendor/hashbrown-0.15.2/tests/serde.rs
wasmtime-27.0.0 ./ext/cargo-vendor/hashbrown-0.14.5/tests/serde.rs
wasmtime-27.0.0 ./ext/cargo-vendor/hashbrown-0.15.1/tests/serde.rs
wasmtime-26.0.0 ./ext/cargo-vendor/hashbrown-0.15.0/tests/serde.rs
wasmtime-26.0.0 ./ext/cargo-vendor/hashbrown-0.14.5/tests/serde.rs
wasmtime-25.0.2 ./ext/cargo-vendor/hashbrown-0.14.5/tests/serde.rs
wasmtime-25.0.1 ./ext/cargo-vendor/hashbrown-0.14.5/tests/serde.rs
wasmtime-25.0.0 ./ext/cargo-vendor/hashbrown-0.14.5/tests/serde.rs
wasmtime-24.0.0 ./ext/cargo-vendor/hashbrown-0.14.5/tests/serde.rs
wasmtime-24.0.0 ./ext/cargo-vendor/hashbrown-0.13.2/tests/serde.rs
wasmtime-23.0.2 ./ext/cargo-vendor/hashbrown-0.13.2/tests/serde.rs
wasmtime-23.0.2 ./ext/cargo-vendor/hashbrown-0.14.3/tests/serde.rs
wasmtime-22.0.0 ./ext/cargo-vendor/hashbrown-0.13.2/tests/serde.rs
wasmtime-22.0.0 ./ext/cargo-vendor/hashbrown-0.14.3/tests/serde.rs
wasmtime-21.0.1 ./ext/cargo-vendor/hashbrown-0.13.2/tests/serde.rs
wasmtime-21.0.1 ./ext/cargo-vendor/hashbrown-0.14.3/tests/serde.rs
wasmtime-20.0.2 ./ext/cargo-vendor/hashbrown-0.14.3/tests/serde.rs