testsuite: tests for deriving changes and additions
This commit is contained in:
parent
5e1d6c2c80
commit
4a43c1babb
38
src/test/run-pass/deriving-rand.rs
Normal file
38
src/test/run-pass/deriving-rand.rs
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright 2013 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.
|
||||
|
||||
#[deriving(Rand)]
|
||||
struct A;
|
||||
|
||||
#[deriving(Rand)]
|
||||
struct B(int, int);
|
||||
|
||||
#[deriving(Rand)]
|
||||
struct C {
|
||||
x: f64,
|
||||
y: (u8, u8)
|
||||
}
|
||||
|
||||
#[deriving(Rand)]
|
||||
enum D {
|
||||
D0,
|
||||
D1(uint),
|
||||
D2 { x: (), y: () }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// check there's no segfaults
|
||||
for 20.times {
|
||||
rand::random::<A>();
|
||||
rand::random::<B>();
|
||||
rand::random::<C>();
|
||||
rand::random::<D>();
|
||||
}
|
||||
}
|
32
src/test/run-pass/deriving-self-lifetime-totalord-totaleq.rs
Normal file
32
src/test/run-pass/deriving-self-lifetime-totalord-totaleq.rs
Normal file
@ -0,0 +1,32 @@
|
||||
// xfail-test FIXME #6257
|
||||
|
||||
// Copyright 2013 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.
|
||||
|
||||
use core::cmp::{Less,Equal,Greater};
|
||||
|
||||
#[deriving(TotalEq,TotalOrd)]
|
||||
struct A<'self> {
|
||||
x: &'self int
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let a = A { x: &1 }, b = A { x: &2 };
|
||||
|
||||
assert!(a.equals(&a));
|
||||
assert!(b.equals(&b));
|
||||
|
||||
|
||||
assert_eq!(a.cmp(&a), Equal);
|
||||
assert_eq!(b.cmp(&b), Equal);
|
||||
|
||||
assert_eq!(a.cmp(&b), Less);
|
||||
assert_eq!(b.cmp(&a), Greater);
|
||||
}
|
33
src/test/run-pass/deriving-self-lifetime.rs
Normal file
33
src/test/run-pass/deriving-self-lifetime.rs
Normal file
@ -0,0 +1,33 @@
|
||||
// Copyright 2013 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.
|
||||
|
||||
#[deriving(Eq,Ord)]
|
||||
struct A<'self> {
|
||||
x: &'self int
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let a = A { x: &1 }, b = A { x: &2 };
|
||||
|
||||
assert_eq!(a, a);
|
||||
assert_eq!(b, b);
|
||||
|
||||
|
||||
assert!(a < b);
|
||||
assert!(b > a);
|
||||
|
||||
assert!(a <= b);
|
||||
assert!(a <= a);
|
||||
assert!(b <= b);
|
||||
|
||||
assert!(b >= a);
|
||||
assert!(b >= b);
|
||||
assert!(a >= a);
|
||||
}
|
44
src/test/run-pass/deriving-to-str.rs
Normal file
44
src/test/run-pass/deriving-to-str.rs
Normal file
@ -0,0 +1,44 @@
|
||||
// Copyright 2013 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.
|
||||
|
||||
#[deriving(Rand,ToStr)]
|
||||
struct A;
|
||||
|
||||
#[deriving(Rand,ToStr)]
|
||||
struct B(int, int);
|
||||
|
||||
#[deriving(Rand,ToStr)]
|
||||
struct C {
|
||||
x: f64,
|
||||
y: (u8, u8)
|
||||
}
|
||||
|
||||
#[deriving(Rand,ToStr)]
|
||||
enum D {
|
||||
D0,
|
||||
D1(uint),
|
||||
D2 { x: (), y: () }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
macro_rules! t(
|
||||
($ty:ty) => {{
|
||||
let x =rand::random::<$ty>();
|
||||
assert_eq!(x.to_str(), fmt!("%?", x));
|
||||
}}
|
||||
);
|
||||
|
||||
for 20.times {
|
||||
t!(A);
|
||||
t!(B);
|
||||
t!(C);
|
||||
t!(D);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user