2012-12-13 15:05:22 -06:00
|
|
|
// xfail-fast
|
|
|
|
|
2012-12-10 19:32:48 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// 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.
|
|
|
|
|
2012-11-27 00:31:48 -06:00
|
|
|
#[forbid(deprecated_pattern)];
|
|
|
|
|
2012-09-18 14:08:42 -05:00
|
|
|
extern mod std;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
use cmp::Eq;
|
2012-10-07 18:33:20 -05:00
|
|
|
use std::ebml;
|
2012-12-06 18:13:54 -06:00
|
|
|
use EBReader = std::ebml::reader;
|
|
|
|
use EBWriter = std::ebml::writer;
|
2012-09-18 14:08:42 -05:00
|
|
|
use io::Writer;
|
2012-12-19 18:08:48 -06:00
|
|
|
use std::serialize::{Encodable, Decodable};
|
2012-10-07 18:33:20 -05:00
|
|
|
use std::prettyprint;
|
2012-11-25 22:54:19 -06:00
|
|
|
use std::time;
|
2012-09-18 14:08:42 -05:00
|
|
|
|
2013-02-20 19:07:17 -06:00
|
|
|
fn test_prettyprint<A:Encodable<prettyprint::Serializer>>(
|
2012-10-13 11:11:33 -05:00
|
|
|
a: &A,
|
|
|
|
expected: &~str
|
2012-09-18 14:08:42 -05:00
|
|
|
) {
|
2012-09-25 12:50:54 -05:00
|
|
|
let s = do io::with_str_writer |w| {
|
2012-12-28 19:17:05 -06:00
|
|
|
a.encode(&prettyprint::Serializer(w))
|
2012-09-25 12:50:54 -05:00
|
|
|
};
|
2012-09-18 14:08:42 -05:00
|
|
|
debug!("s == %?", s);
|
2012-10-13 11:11:33 -05:00
|
|
|
assert s == *expected;
|
|
|
|
}
|
2012-09-18 14:08:42 -05:00
|
|
|
|
2012-10-13 11:11:33 -05:00
|
|
|
fn test_ebml<A:
|
2013-02-20 20:04:57 -06:00
|
|
|
Eq +
|
|
|
|
Encodable<EBWriter::Encoder> +
|
2012-12-17 21:31:04 -06:00
|
|
|
Decodable<EBReader::Decoder>
|
2012-10-13 11:11:33 -05:00
|
|
|
>(a1: &A) {
|
2012-09-18 14:08:42 -05:00
|
|
|
let bytes = do io::with_bytes_writer |wr| {
|
2012-12-17 21:31:04 -06:00
|
|
|
let ebml_w = &EBWriter::Encoder(wr);
|
|
|
|
a1.encode(ebml_w)
|
2012-09-18 14:08:42 -05:00
|
|
|
};
|
2013-02-15 04:44:18 -06:00
|
|
|
let d = EBReader::Doc(@bytes);
|
2012-12-18 20:05:16 -06:00
|
|
|
let a2: A = Decodable::decode(&EBReader::Decoder(d));
|
2012-10-01 13:35:27 -05:00
|
|
|
assert *a1 == a2;
|
2012-09-18 14:08:42 -05:00
|
|
|
}
|
|
|
|
|
2012-12-17 21:31:04 -06:00
|
|
|
#[auto_encode]
|
|
|
|
#[auto_decode]
|
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 {
|
2012-11-14 20:59:30 -06:00
|
|
|
pure fn eq(&self, other: &Expr) -> bool {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-14 20:59:30 -06:00
|
|
|
pure 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 AnEnum {
|
2012-11-14 20:59:30 -06:00
|
|
|
pure fn eq(&self, other: &AnEnum) -> bool {
|
|
|
|
(*self).v == other.v
|
2012-09-18 14:08:42 -05:00
|
|
|
}
|
2012-11-14 20:59:30 -06:00
|
|
|
pure fn ne(&self, other: &AnEnum) -> bool { !(*self).eq(other) }
|
2012-09-18 14:08:42 -05:00
|
|
|
}
|
|
|
|
|
2013-02-14 13:47:00 -06:00
|
|
|
impl cmp::Eq for Point {
|
2012-11-14 20:59:30 -06:00
|
|
|
pure fn eq(&self, other: &Point) -> bool {
|
2012-09-18 14:08:42 -05:00
|
|
|
self.x == other.x && self.y == other.y
|
|
|
|
}
|
2012-11-14 20:59:30 -06:00
|
|
|
pure 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> {
|
2012-11-14 20:59:30 -06:00
|
|
|
pure fn eq(&self, other: &Quark<T>) -> bool {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2012-11-14 20:59:30 -06:00
|
|
|
pure 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 {
|
2012-11-14 20:59:30 -06:00
|
|
|
pure fn eq(&self, other: &CLike) -> bool {
|
|
|
|
(*self) as int == *other as int
|
2012-09-18 14:08:42 -05:00
|
|
|
}
|
2013-01-18 00:21:07 -06:00
|
|
|
pure fn ne(&self, other: &CLike) -> bool { !self.eq(other) }
|
2012-09-18 14:08:42 -05:00
|
|
|
}
|
|
|
|
|
2012-12-17 21:31:04 -06:00
|
|
|
#[auto_encode]
|
|
|
|
#[auto_decode]
|
2013-01-25 18:57:39 -06:00
|
|
|
#[deriving_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
|
|
|
|
2012-12-17 21:31:04 -06:00
|
|
|
#[auto_encode]
|
|
|
|
#[auto_decode]
|
2013-01-18 00:21:07 -06:00
|
|
|
struct SomeStruct { v: ~[uint] }
|
2012-09-18 14:08:42 -05:00
|
|
|
|
2012-12-17 21:31:04 -06:00
|
|
|
#[auto_encode]
|
|
|
|
#[auto_decode]
|
2013-01-18 00:21:07 -06:00
|
|
|
enum AnEnum = SomeStruct;
|
2012-09-18 14:08:42 -05:00
|
|
|
|
2012-12-17 21:31:04 -06:00
|
|
|
#[auto_encode]
|
|
|
|
#[auto_decode]
|
2012-10-01 13:35:27 -05:00
|
|
|
struct Point {x: uint, y: uint}
|
2012-09-18 14:08:42 -05:00
|
|
|
|
2012-12-17 21:31:04 -06:00
|
|
|
#[auto_encode]
|
|
|
|
#[auto_decode]
|
2012-09-18 14:08:42 -05:00
|
|
|
enum Quark<T> {
|
|
|
|
Top(T),
|
|
|
|
Bottom(T)
|
|
|
|
}
|
|
|
|
|
2012-12-17 21:31:04 -06:00
|
|
|
#[auto_encode]
|
|
|
|
#[auto_decode]
|
2012-09-18 14:08:42 -05:00
|
|
|
enum CLike { A, B, C }
|
|
|
|
|
2013-02-01 21:43:17 -06:00
|
|
|
pub fn main() {
|
2012-10-13 11:11:33 -05:00
|
|
|
let a = &Plus(@Minus(@Val(3u), @Val(10u)), @Plus(@Val(22u), @Val(5u)));
|
|
|
|
test_prettyprint(a, &~"Plus(@Minus(@Val(3u), @Val(10u)), \
|
|
|
|
@Plus(@Val(22u), @Val(5u)))");
|
|
|
|
test_ebml(a);
|
|
|
|
|
2013-01-18 00:21:07 -06:00
|
|
|
let a = &Spanned {lo: 0u, hi: 5u, node: 22u};
|
|
|
|
test_prettyprint(a, &~"Spanned {lo: 0u, hi: 5u, node: 22u}");
|
2012-10-13 11:11:33 -05:00
|
|
|
test_ebml(a);
|
|
|
|
|
2013-01-18 00:21:07 -06:00
|
|
|
let a = &AnEnum(SomeStruct {v: ~[1u, 2u, 3u]});
|
|
|
|
test_prettyprint(a, &~"AnEnum(SomeStruct {v: ~[1u, 2u, 3u]})");
|
2012-10-13 11:11:33 -05:00
|
|
|
test_ebml(a);
|
|
|
|
|
|
|
|
let a = &Point {x: 3u, y: 5u};
|
|
|
|
test_prettyprint(a, &~"Point {x: 3u, y: 5u}");
|
|
|
|
test_ebml(a);
|
|
|
|
|
|
|
|
let a = &@[1u, 2u, 3u];
|
|
|
|
test_prettyprint(a, &~"@[1u, 2u, 3u]");
|
|
|
|
test_ebml(a);
|
|
|
|
|
|
|
|
let a = &Top(22u);
|
|
|
|
test_prettyprint(a, &~"Top(22u)");
|
|
|
|
test_ebml(a);
|
|
|
|
|
|
|
|
let a = &Bottom(222u);
|
|
|
|
test_prettyprint(a, &~"Bottom(222u)");
|
|
|
|
test_ebml(a);
|
|
|
|
|
|
|
|
let a = &A;
|
|
|
|
test_prettyprint(a, &~"A");
|
|
|
|
test_ebml(a);
|
|
|
|
|
|
|
|
let a = &B;
|
|
|
|
test_prettyprint(a, &~"B");
|
|
|
|
test_ebml(a);
|
2012-11-25 22:54:19 -06:00
|
|
|
|
|
|
|
let a = &time::now();
|
|
|
|
test_ebml(a);
|
2012-09-18 14:08:42 -05:00
|
|
|
}
|