about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2013-05-07 01:32:34 +1000
committerHuon Wilson <dbau.pp+github@gmail.com>2013-05-07 01:33:54 +1000
commit4a43c1babbdf453fc4af25cf06aae7c96213d918 (patch)
tree7179974e151a23d70944ebaf92283c4b09ec58b5 /src
parent5e1d6c2c8011f466d2a524231e5386df0b5ed841 (diff)
downloadrust-4a43c1babbdf453fc4af25cf06aae7c96213d918.tar.gz
rust-4a43c1babbdf453fc4af25cf06aae7c96213d918.zip
testsuite: tests for deriving changes and additions
Diffstat (limited to 'src')
-rw-r--r--src/test/run-pass/deriving-rand.rs38
-rw-r--r--src/test/run-pass/deriving-self-lifetime-totalord-totaleq.rs32
-rw-r--r--src/test/run-pass/deriving-self-lifetime.rs33
-rw-r--r--src/test/run-pass/deriving-to-str.rs44
4 files changed, 147 insertions, 0 deletions
diff --git a/src/test/run-pass/deriving-rand.rs b/src/test/run-pass/deriving-rand.rs
new file mode 100644
index 00000000000..290dc02dcdb
--- /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 <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>();
+    }
+}
\ 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 00000000000..b0b03d8419b
--- /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 <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);
+}
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 00000000000..549a9b398a2
--- /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 <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);
+}
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 00000000000..10f6bcbeff7
--- /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 <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);
+    }
+}
\ No newline at end of file