diff --git a/src/test/run-pass/deriving-rand.rs b/src/test/run-pass/deriving-rand.rs new file mode 100644 index 000000000000..290dc02dcdb2 --- /dev/null +++ b/src/test/run-pass/deriving-rand.rs @@ -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 or the MIT license +// , 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::(); + rand::random::(); + rand::random::(); + rand::random::(); + } +} \ No newline at end of file diff --git a/src/test/run-pass/deriving-self-lifetime-totalord-totaleq.rs b/src/test/run-pass/deriving-self-lifetime-totalord-totaleq.rs new file mode 100644 index 000000000000..b0b03d8419b8 --- /dev/null +++ b/src/test/run-pass/deriving-self-lifetime-totalord-totaleq.rs @@ -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 or the MIT license +// , 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); +} diff --git a/src/test/run-pass/deriving-self-lifetime.rs b/src/test/run-pass/deriving-self-lifetime.rs new file mode 100644 index 000000000000..549a9b398a21 --- /dev/null +++ b/src/test/run-pass/deriving-self-lifetime.rs @@ -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 or the MIT license +// , 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); +} diff --git a/src/test/run-pass/deriving-to-str.rs b/src/test/run-pass/deriving-to-str.rs new file mode 100644 index 000000000000..10f6bcbeff76 --- /dev/null +++ b/src/test/run-pass/deriving-to-str.rs @@ -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 or the MIT license +// , 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); + } +} \ No newline at end of file