2014-02-07 13:08:32 -06:00
|
|
|
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
|
2012-12-10 19:32:48 -06:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-02-07 13:08:32 -06:00
|
|
|
// ignore-test FIXME(#5121)
|
2013-12-18 16:10:28 -06:00
|
|
|
|
2014-07-29 19:06:37 -05:00
|
|
|
extern crate rbml;
|
2014-02-21 17:41:51 -06:00
|
|
|
extern crate serialize;
|
2014-07-29 19:06:37 -05:00
|
|
|
extern crate time;
|
2012-09-18 14:08:42 -05:00
|
|
|
|
|
|
|
// These tests used to be separate files, but I wanted to refactor all
|
2013-01-29 01:54:39 -06:00
|
|
|
// the common code.
|
2012-09-18 14:08:42 -05:00
|
|
|
|
2014-10-30 20:25:08 -05:00
|
|
|
use std::collections::{HashMap, HashSet};
|
2013-05-30 23:42:00 -05:00
|
|
|
|
2014-08-12 21:25:05 -05:00
|
|
|
use rbml::reader as EBReader;
|
|
|
|
use rbml::writer as EBWriter;
|
2013-05-20 19:07:24 -05:00
|
|
|
use std::cmp::Eq;
|
2013-05-24 21:35:29 -05:00
|
|
|
use std::cmp;
|
|
|
|
use std::io;
|
2014-02-05 10:52:54 -06:00
|
|
|
use serialize::{Decodable, Encodable};
|
2012-09-18 14:08:42 -05:00
|
|
|
|
2014-07-29 19:06:37 -05:00
|
|
|
fn test_rbml<'a, 'b, A:
|
2013-02-20 20:04:57 -06:00
|
|
|
Eq +
|
2014-02-21 17:41:51 -06:00
|
|
|
Encodable<EBWriter::Encoder<'a>> +
|
|
|
|
Decodable<EBReader::Decoder<'b>>
|
2012-10-13 11:11:33 -05:00
|
|
|
>(a1: &A) {
|
2014-11-11 15:01:29 -06:00
|
|
|
let mut wr = Vec::new();
|
2014-07-29 19:06:37 -05:00
|
|
|
let mut rbml_w = EBwriter::Encoder::new(&mut wr);
|
|
|
|
a1.encode(&mut rbml_w);
|
2013-12-16 08:14:37 -06:00
|
|
|
|
2015-02-05 10:58:30 -06:00
|
|
|
let d: serialize::rbml::Doc<'a> = EBDoc::new(&wr);
|
2014-05-25 20:32:04 -05:00
|
|
|
let mut decoder: EBReader::Decoder<'a> = EBreader::Decoder::new(d);
|
2013-05-01 19:54:54 -05:00
|
|
|
let a2: A = Decodable::decode(&mut decoder);
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!(*a1 == a2);
|
2012-09-18 14:08:42 -05:00
|
|
|
}
|
|
|
|
|
2014-12-30 22:32:49 -06:00
|
|
|
#[derive(Decodable, Encodable)]
|
2012-09-26 23:35:13 -05:00
|
|
|
enum Expr {
|
|
|
|
Val(uint),
|
|
|
|
Plus(@Expr, @Expr),
|
|
|
|
Minus(@Expr, @Expr)
|
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl cmp::Eq for Expr {
|
2013-03-22 13:23:21 -05:00
|
|
|
fn eq(&self, other: &Expr) -> bool {
|
2012-11-14 20:59:30 -06:00
|
|
|
match *self {
|
2012-09-26 23:35:13 -05:00
|
|
|
Val(e0a) => {
|
|
|
|
match *other {
|
|
|
|
Val(e0b) => e0a == e0b,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Plus(e0a, e1a) => {
|
|
|
|
match *other {
|
|
|
|
Plus(e0b, e1b) => e0a == e0b && e1a == e1b,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Minus(e0a, e1a) => {
|
|
|
|
match *other {
|
|
|
|
Minus(e0b, e1b) => e0a == e0b && e1a == e1b,
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-22 13:23:21 -05:00
|
|
|
fn ne(&self, other: &Expr) -> bool { !(*self).eq(other) }
|
2012-09-26 23:35:13 -05:00
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl cmp::Eq for Point {
|
2013-03-22 13:23:21 -05:00
|
|
|
fn eq(&self, other: &Point) -> bool {
|
2012-09-18 14:08:42 -05:00
|
|
|
self.x == other.x && self.y == other.y
|
|
|
|
}
|
2013-03-22 13:23:21 -05:00
|
|
|
fn ne(&self, other: &Point) -> bool { !(*self).eq(other) }
|
2012-09-18 14:08:42 -05:00
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl<T:cmp::Eq> cmp::Eq for Quark<T> {
|
2013-03-22 13:23:21 -05:00
|
|
|
fn eq(&self, other: &Quark<T>) -> bool {
|
2012-11-14 20:59:30 -06:00
|
|
|
match *self {
|
2012-09-25 12:50:54 -05:00
|
|
|
Top(ref q) => {
|
|
|
|
match *other {
|
|
|
|
Top(ref r) => q == r,
|
|
|
|
Bottom(_) => false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Bottom(ref q) => {
|
|
|
|
match *other {
|
|
|
|
Top(_) => false,
|
|
|
|
Bottom(ref r) => q == r
|
|
|
|
}
|
|
|
|
},
|
2012-09-18 14:08:42 -05:00
|
|
|
}
|
|
|
|
}
|
2013-03-22 13:23:21 -05:00
|
|
|
fn ne(&self, other: &Quark<T>) -> bool { !(*self).eq(other) }
|
2012-09-18 14:08:42 -05:00
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl cmp::Eq for CLike {
|
2013-03-22 13:23:21 -05:00
|
|
|
fn eq(&self, other: &CLike) -> bool {
|
2012-11-14 20:59:30 -06:00
|
|
|
(*self) as int == *other as int
|
2012-09-18 14:08:42 -05:00
|
|
|
}
|
2013-03-22 13:23:21 -05:00
|
|
|
fn ne(&self, other: &CLike) -> bool { !self.eq(other) }
|
2012-09-18 14:08:42 -05:00
|
|
|
}
|
|
|
|
|
2014-12-30 22:32:49 -06:00
|
|
|
#[derive(Decodable, Encodable, Eq)]
|
2013-01-18 00:21:07 -06:00
|
|
|
struct Spanned<T> {
|
|
|
|
lo: uint,
|
|
|
|
hi: uint,
|
|
|
|
node: T,
|
|
|
|
}
|
2012-09-18 14:08:42 -05:00
|
|
|
|
2014-12-30 22:32:49 -06:00
|
|
|
#[derive(Decodable, Encodable)]
|
2014-03-05 16:02:44 -06:00
|
|
|
struct SomeStruct { v: Vec<uint> }
|
2012-09-18 14:08:42 -05:00
|
|
|
|
2014-12-30 22:32:49 -06:00
|
|
|
#[derive(Decodable, Encodable)]
|
2012-10-01 13:35:27 -05:00
|
|
|
struct Point {x: uint, y: uint}
|
2012-09-18 14:08:42 -05:00
|
|
|
|
2014-12-30 22:32:49 -06:00
|
|
|
#[derive(Decodable, Encodable)]
|
2012-09-18 14:08:42 -05:00
|
|
|
enum Quark<T> {
|
|
|
|
Top(T),
|
|
|
|
Bottom(T)
|
|
|
|
}
|
|
|
|
|
2014-12-30 22:32:49 -06:00
|
|
|
#[derive(Decodable, Encodable)]
|
2012-09-18 14:08:42 -05:00
|
|
|
enum CLike { A, B, C }
|
|
|
|
|
2013-02-01 21:43:17 -06:00
|
|
|
pub fn main() {
|
2015-02-18 04:42:01 -06:00
|
|
|
let a = &Plus(@Minus(@Val(3_usize), @Val(10_usize)), @Plus(@Val(22_usize), @Val(5_usize)));
|
2014-07-29 19:06:37 -05:00
|
|
|
test_rbml(a);
|
2012-10-13 11:11:33 -05:00
|
|
|
|
2015-02-18 04:42:01 -06:00
|
|
|
let a = &Spanned {lo: 0_usize, hi: 5_usize, node: 22_usize};
|
2014-07-29 19:06:37 -05:00
|
|
|
test_rbml(a);
|
2012-10-13 11:11:33 -05:00
|
|
|
|
2015-02-18 04:42:01 -06:00
|
|
|
let a = &Point {x: 3_usize, y: 5_usize};
|
2014-07-29 19:06:37 -05:00
|
|
|
test_rbml(a);
|
2013-12-16 08:14:37 -06:00
|
|
|
|
2015-02-18 04:42:01 -06:00
|
|
|
let a = &Top(22_usize);
|
2014-07-29 19:06:37 -05:00
|
|
|
test_rbml(a);
|
2013-12-16 08:14:37 -06:00
|
|
|
|
2015-02-18 04:42:01 -06:00
|
|
|
let a = &Bottom(222_usize);
|
2014-07-29 19:06:37 -05:00
|
|
|
test_rbml(a);
|
2013-12-16 08:14:37 -06:00
|
|
|
|
|
|
|
let a = &A;
|
2014-07-29 19:06:37 -05:00
|
|
|
test_rbml(a);
|
2013-12-16 08:14:37 -06:00
|
|
|
|
|
|
|
let a = &B;
|
2014-07-29 19:06:37 -05:00
|
|
|
test_rbml(a);
|
2012-11-25 22:54:19 -06:00
|
|
|
|
|
|
|
let a = &time::now();
|
2014-07-29 19:06:37 -05:00
|
|
|
test_rbml(a);
|
2013-05-30 23:42:00 -05:00
|
|
|
|
2014-07-29 19:06:37 -05:00
|
|
|
test_rbml(&1.0f32);
|
|
|
|
test_rbml(&1.0f64);
|
|
|
|
test_rbml(&'a');
|
2013-05-30 23:42:00 -05:00
|
|
|
|
|
|
|
let mut a = HashMap::new();
|
2014-07-29 19:06:37 -05:00
|
|
|
test_rbml(&a);
|
2013-05-30 23:42:00 -05:00
|
|
|
a.insert(1, 2);
|
2014-07-29 19:06:37 -05:00
|
|
|
test_rbml(&a);
|
2013-05-30 23:42:00 -05:00
|
|
|
|
2013-12-16 08:14:37 -06:00
|
|
|
let mut a = HashSet::new();
|
2014-07-29 19:06:37 -05:00
|
|
|
test_rbml(&a);
|
2013-12-16 08:14:37 -06:00
|
|
|
a.insert(1);
|
2014-07-29 19:06:37 -05:00
|
|
|
test_rbml(&a);
|
2012-09-18 14:08:42 -05:00
|
|
|
}
|