<commit_before>use std::io::MemWriter;
use std::fmt::Show;
use std::io::MemReader;
use std::io::IoError;
use std::collections::hashmap::HashMap;

use serialize::{
    Encoder,
    Decoder,
    Encodable,
    Decodable
};

use super::EncoderWriter;
use super::DecoderReader;
use super::encode;
use super::decode;

fn the_same<
            V: Encodable<EncoderWriter<MemWriter>, IoError>  +
               Decodable<DecoderReader<MemReader>, IoError> +
               PartialEq + Show>(element: V) {
    assert!(element == decode(encode(&element).unwrap()).unwrap());
}

#[test]
fn test_numbers() {
    // unsigned positive
    the_same(5u8);
    the_same(5u16);
    the_same(5u32);
    the_same(5u64);
    // signed positive
    the_same(5i8);
    the_same(5i16);
    the_same(5i32);
    the_same(5i64);
    // signed negative
    the_same(-5i8);
    the_same(-5i16);
    the_same(-5i32);
    the_same(-5i64);
    // floating
    the_same(-100f32);
    the_same(0f32);
    the_same(5f32);
    the_same(-100f64);
    the_same(5f64);
}

#[test]
fn test_string() {
    the_same("".to_string());
    the_same("a".to_string());
}

#[test]
fn test_tuple() {
    the_same((1i,));
    the_same((1i,2i,3i));
    the_same((1i,"foo".to_string(),()));
}

#[test]
fn test_basic_struct() {
    #[deriving(Encodable, Decodable, PartialEq, Show)]
    struct Easy {
        x: int,
        s: String,
        y: uint
    }
    the_same(Easy{x: -4, s: "foo".to_string(), y: 10});
}

#[test]
fn test_nested_struct() {
    #[deriving(Encodable, Decodable, PartialEq, Show)]
    struct Easy {
        x: int,
        s: String,
        y: uint
    }
    #[deriving(Encodable, Decodable, PartialEq, Show)]
    struct Nest {
        f: Easy,
        b: uint,
        s: Easy
    }

    the_same(Nest {
        f: Easy {x: -1, s: "foo".to_string(), y: 20},
        b: 100,
        s: Easy {x: -100, s: "bar".to_string(), y: 20}
    });
}

#[test]
fn test_struct_tuple() {
    #[deriving(Encodable, Decodable, PartialEq, Show)]
    struct TubStr(uint, String, f32);

    the_same(TubStr(5, "hello".to_string(), 3.2));
}

#[test]
fn option() {
    the_same(Some(5u));
    the_same(Some("foo bar".to_string()));
    the_same(None::<uint>);
}

#[test]
fn enm() {
    #[deriving(Encodable, Decodable, PartialEq, Show)]
    enum TestEnum {
        NoArg,
        OneArg(uint),
        AnotherNoArg
    }
    the_same(NoArg);
    the_same(OneArg(4));
    the_same(AnotherNoArg);
}


#[test]
fn struct_enum() {
    #[deriving(Encodable, Decodable, PartialEq, Show)]
    enum TestEnum {
        NoArg,
        OneArg(uint),
        AnotherNoArg,
        StructLike{x: uint, y: f32}
    }
    the_same(NoArg);
    the_same(OneArg(4));
    the_same(AnotherNoArg);
    the_same(StructLike{x: 4, y: 3.14159});
}
<commit_msg>test vec of enums<commit_after>use std::io::MemWriter;
use std::fmt::Show;
use std::io::MemReader;
use std::io::IoError;
use std::collections::hashmap::HashMap;

use serialize::{
    Encoder,
    Decoder,
    Encodable,
    Decodable
};

use super::EncoderWriter;
use super::DecoderReader;
use super::encode;
use super::decode;

fn the_same<
            V: Encodable<EncoderWriter<MemWriter>, IoError>  +
               Decodable<DecoderReader<MemReader>, IoError> +
               PartialEq + Show>(element: V) {
    assert!(element == decode(encode(&element).unwrap()).unwrap());
}

#[test]
fn test_numbers() {
    // unsigned positive
    the_same(5u8);
    the_same(5u16);
    the_same(5u32);
    the_same(5u64);
    // signed positive
    the_same(5i8);
    the_same(5i16);
    the_same(5i32);
    the_same(5i64);
    // signed negative
    the_same(-5i8);
    the_same(-5i16);
    the_same(-5i32);
    the_same(-5i64);
    // floating
    the_same(-100f32);
    the_same(0f32);
    the_same(5f32);
    the_same(-100f64);
    the_same(5f64);
}

#[test]
fn test_string() {
    the_same("".to_string());
    the_same("a".to_string());
}

#[test]
fn test_tuple() {
    the_same((1i,));
    the_same((1i,2i,3i));
    the_same((1i,"foo".to_string(),()));
}

#[test]
fn test_basic_struct() {
    #[deriving(Encodable, Decodable, PartialEq, Show)]
    struct Easy {
        x: int,
        s: String,
        y: uint
    }
    the_same(Easy{x: -4, s: "foo".to_string(), y: 10});
}

#[test]
fn test_nested_struct() {
    #[deriving(Encodable, Decodable, PartialEq, Show)]
    struct Easy {
        x: int,
        s: String,
        y: uint
    }
    #[deriving(Encodable, Decodable, PartialEq, Show)]
    struct Nest {
        f: Easy,
        b: uint,
        s: Easy
    }

    the_same(Nest {
        f: Easy {x: -1, s: "foo".to_string(), y: 20},
        b: 100,
        s: Easy {x: -100, s: "bar".to_string(), y: 20}
    });
}

#[test]
fn test_struct_tuple() {
    #[deriving(Encodable, Decodable, PartialEq, Show)]
    struct TubStr(uint, String, f32);

    the_same(TubStr(5, "hello".to_string(), 3.2));
}

#[test]
fn option() {
    the_same(Some(5u));
    the_same(Some("foo bar".to_string()));
    the_same(None::<uint>);
}

#[test]
fn enm() {
    #[deriving(Encodable, Decodable, PartialEq, Show)]
    enum TestEnum {
        NoArg,
        OneArg(uint),
        AnotherNoArg
    }
    the_same(NoArg);
    the_same(OneArg(4));
    the_same(AnotherNoArg);
}


#[test]
fn struct_enum() {
    #[deriving(Encodable, Decodable, PartialEq, Show)]
    enum TestEnum {
        NoArg,
        OneArg(uint),
        AnotherNoArg,
        StructLike{x: uint, y: f32}
    }
    the_same(NoArg);
    the_same(OneArg(4));
    the_same(AnotherNoArg);
    the_same(StructLike{x: 4, y: 3.14159});
    the_same(vec![NoArg, OneArg(5), AnotherNoArg, StructLike{x: 4, y:1.4}]);
}

{'fraction_non_alphanumeric': 0.16893684769149125, 'fraction_numerical': 0.03184150008844861, 'mean_word_length': 2.8436437797416723, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1006926', 'n_tokens_mistral': 2264, 'n_tokens_neox': 2206, 'n_words': 409}