third_party/rust/indexmap/tests/serde.rs
author Bastien Orivel <eijebong@bananium.fr>
Wed, 22 Aug 2018 20:19:04 +0200
changeset 488156 03df1a267ea54f1024d3f015f4bf781477262c92
permissions -rw-r--r--
Bug 1484462 - Revendor Rust dependencies. r=ato

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

#[macro_use]
extern crate indexmap;
extern crate serde_test;
extern crate fnv;

use serde_test::{Token, assert_tokens};

#[test]
fn test_serde() {
    let map = indexmap! { 1 => 2, 3 => 4 };
    assert_tokens(&map,
                  &[Token::Map { len: Some(2) },
                    Token::I32(1),
                    Token::I32(2),
                    Token::I32(3),
                    Token::I32(4),
                    Token::MapEnd]);
}

#[test]
fn test_serde_set() {
    let set = indexset! { 1, 2, 3, 4 };
    assert_tokens(&set,
                  &[Token::Seq { len: Some(4) },
                    Token::I32(1),
                    Token::I32(2),
                    Token::I32(3),
                    Token::I32(4),
                    Token::SeqEnd]);
}

#[test]
fn test_serde_fnv_hasher() {
    let mut map: ::indexmap::IndexMap<i32, i32, ::fnv::FnvBuildHasher> = Default::default();
    map.insert(1, 2);
    map.insert(3, 4);
    assert_tokens(&map,
                  &[Token::Map { len: Some(2) },
                    Token::I32(1),
                    Token::I32(2),
                    Token::I32(3),
                    Token::I32(4),
                    Token::MapEnd]);
}

#[test]
fn test_serde_map_fnv_hasher() {
    let mut set: ::indexmap::IndexSet<i32, ::fnv::FnvBuildHasher> = Default::default();
    set.extend(1..5);
    assert_tokens(&set,
                  &[Token::Seq { len: Some(4) },
                    Token::I32(1),
                    Token::I32(2),
                    Token::I32(3),
                    Token::I32(4),
                    Token::SeqEnd]);
}