Skip to content

Commit 4a43c1b

Browse files
committed
testsuite: tests for deriving changes and additions
1 parent 5e1d6c2 commit 4a43c1b

File tree

4 files changed

+147
-0
lines changed

4 files changed

+147
-0
lines changed

src/test/run-pass/deriving-rand.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[deriving(Rand)]
12+
struct A;
13+
14+
#[deriving(Rand)]
15+
struct B(int, int);
16+
17+
#[deriving(Rand)]
18+
struct C {
19+
x: f64,
20+
y: (u8, u8)
21+
}
22+
23+
#[deriving(Rand)]
24+
enum D {
25+
D0,
26+
D1(uint),
27+
D2 { x: (), y: () }
28+
}
29+
30+
fn main() {
31+
// check there's no segfaults
32+
for 20.times {
33+
rand::random::<A>();
34+
rand::random::<B>();
35+
rand::random::<C>();
36+
rand::random::<D>();
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// xfail-test FIXME #6257
2+
3+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
4+
// file at the top-level directory of this distribution and at
5+
// http://rust-lang.org/COPYRIGHT.
6+
//
7+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10+
// option. This file may not be copied, modified, or distributed
11+
// except according to those terms.
12+
13+
use core::cmp::{Less,Equal,Greater};
14+
15+
#[deriving(TotalEq,TotalOrd)]
16+
struct A<'self> {
17+
x: &'self int
18+
}
19+
20+
fn main() {
21+
let a = A { x: &1 }, b = A { x: &2 };
22+
23+
assert!(a.equals(&a));
24+
assert!(b.equals(&b));
25+
26+
27+
assert_eq!(a.cmp(&a), Equal);
28+
assert_eq!(b.cmp(&b), Equal);
29+
30+
assert_eq!(a.cmp(&b), Less);
31+
assert_eq!(b.cmp(&a), Greater);
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[deriving(Eq,Ord)]
12+
struct A<'self> {
13+
x: &'self int
14+
}
15+
16+
fn main() {
17+
let a = A { x: &1 }, b = A { x: &2 };
18+
19+
assert_eq!(a, a);
20+
assert_eq!(b, b);
21+
22+
23+
assert!(a < b);
24+
assert!(b > a);
25+
26+
assert!(a <= b);
27+
assert!(a <= a);
28+
assert!(b <= b);
29+
30+
assert!(b >= a);
31+
assert!(b >= b);
32+
assert!(a >= a);
33+
}

src/test/run-pass/deriving-to-str.rs

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[deriving(Rand,ToStr)]
12+
struct A;
13+
14+
#[deriving(Rand,ToStr)]
15+
struct B(int, int);
16+
17+
#[deriving(Rand,ToStr)]
18+
struct C {
19+
x: f64,
20+
y: (u8, u8)
21+
}
22+
23+
#[deriving(Rand,ToStr)]
24+
enum D {
25+
D0,
26+
D1(uint),
27+
D2 { x: (), y: () }
28+
}
29+
30+
fn main() {
31+
macro_rules! t(
32+
($ty:ty) => {{
33+
let x =rand::random::<$ty>();
34+
assert_eq!(x.to_str(), fmt!("%?", x));
35+
}}
36+
);
37+
38+
for 20.times {
39+
t!(A);
40+
t!(B);
41+
t!(C);
42+
t!(D);
43+
}
44+
}

0 commit comments

Comments
 (0)