table 0.4.0

A specialized map for storing values of varying types.
Documentation
// Copyright (C) 2018  Project Tsukurou!
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

use serde_bytes::{Bytes, ByteBuf};

use value::Value;

#[test]
fn serialize_unit_to_null() {
    assert_eq!(Value::serialize(&()), Ok(Value::Null));
}

#[test]
fn deserialize_null_to_unit() {
    assert_eq!(Value::Null.deserialize::<()>(), Ok(()));
}

#[test]
fn deserialize_null_into_unit() {
    assert_eq!(Value::Null.deserialize_into::<()>(), Ok(()));
}

#[test]
fn serialize_bool_to_bool() {
    assert_eq!(Value::serialize(&true), Ok(Value::Bool(true)));
}

#[test]
fn deserialize_bool_to_bool() {
    assert_eq!(Value::Bool(false).deserialize::<bool>(), Ok(false));
}

#[test]
fn deserialize_bool_into_bool() {
    assert_eq!(Value::Bool(false).deserialize_into::<bool>(), Ok(false));
}

#[test]
fn serialize_i64_to_i64() {
    assert_eq!(Value::serialize::<i64>(&235), Ok(Value::I64(235)));
}

#[test]
fn deserialize_i64_to_i64() {
    assert_eq!(Value::I64(618).deserialize::<i64>(), Ok(618));
}

#[test]
fn deserialize_i64_into_i64() {
    assert_eq!(Value::I64(923).deserialize_into::<i64>(), Ok(923));
}

#[test]
fn serialize_f64_to_f64() {
    assert_eq!(Value::serialize::<f64>(&1.25), Ok(Value::F64(1.25)));
}

#[test]
fn deserialize_f64_to_f64() {
    assert_eq!(Value::F64(29.0625).deserialize::<f64>(), Ok(29.0625));
}

#[test]
fn deserialize_f64_into_f64() {
    assert_eq!(Value::F64(33.375).deserialize_into::<f64>(), Ok(33.375));
}

#[test]
fn serialize_bytes_to_bytes() {
    let bytes = vec![32, 68, 96];
    assert_eq!(
        Value::serialize(&Bytes::from(&bytes[..])),
        Ok(Value::from(bytes)),
    );
}

#[test]
fn deserialize_bytes_to_bytes() {
    let bytes = vec![194, 237, 39, 63];
    assert_eq!(
        Value::from(bytes.clone()).deserialize(), 
        Ok(Bytes::from(&bytes[..]))
    );
}

#[test]
fn deserialize_bytes_into_bytes() {
    let bytes = vec![221, 172, 193, 2];
    assert_eq!(
        Value::from(bytes.clone()).deserialize_into(),
        Ok(ByteBuf::from(bytes))
    );
}

#[test]
fn serialize_str_to_string() {
    assert_eq!(Value::serialize("foobar"), Ok(Value::from("foobar")));
}

#[test]
fn deserialize_string_to_str() {
    assert_eq!(Value::from("foobar").deserialize(), Ok("foobar"));
}

#[test]
fn deserialize_string_into_str() {
    assert_eq!(Value::from("foobar").deserialize_into(), Ok("foobar"));
}