about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-01-21 09:18:56 -0800
committerAlex Crichton <alex@alexcrichton.com>2015-01-21 09:18:56 -0800
commitefea645c94451efbb6ac4be29c6307b434057ff2 (patch)
tree244a8ba3e4756a1a8da1a54c86a0deb285341173 /src/liballoc
parent907db6c8344a4df070ee2b21479062a63c3ae2be (diff)
parentace2f09d3f89e20a7caa67bb0548212b07f696c2 (diff)
downloadrust-efea645c94451efbb6ac4be29c6307b434057ff2.tar.gz
rust-efea645c94451efbb6ac4be29c6307b434057ff2.zip
rollup merge of #21446: stepancheg/boxed-test
Conflicts:
	src/liballoc/boxed.rs
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/boxed.rs54
-rw-r--r--src/liballoc/boxed_test.rs75
-rw-r--r--src/liballoc/lib.rs2
3 files changed, 77 insertions, 54 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs
index 92ac41e2058..dd953cabe7e 100644
--- a/src/liballoc/boxed.rs
+++ b/src/liballoc/boxed.rs
@@ -201,57 +201,3 @@ impl<'a, T> Iterator for Box<Iterator<Item=T> + 'a> {
         (**self).size_hint()
     }
 }
-
-#[cfg(test)]
-mod test {
-    #[test]
-    fn test_owned_clone() {
-        let a = Box::new(5i);
-        let b: Box<int> = a.clone();
-        assert!(a == b);
-    }
-
-    #[test]
-    fn any_move() {
-        let a = Box::new(8u) as Box<Any>;
-        let b = Box::new(Test) as Box<Any>;
-
-        match a.downcast::<uint>() {
-            Ok(a) => { assert!(a == Box::new(8u)); }
-            Err(..) => panic!()
-        }
-        match b.downcast::<Test>() {
-            Ok(a) => { assert!(a == Box::new(Test)); }
-            Err(..) => panic!()
-        }
-
-        let a = Box::new(8u) as Box<Any>;
-        let b = Box::new(Test) as Box<Any>;
-
-        assert!(a.downcast::<Box<Test>>().is_err());
-        assert!(b.downcast::<Box<uint>>().is_err());
-    }
-
-    #[test]
-    fn test_show() {
-        let a = Box::new(8u) as Box<Any>;
-        let b = Box::new(Test) as Box<Any>;
-        let a_str = a.to_str();
-        let b_str = b.to_str();
-        assert_eq!(a_str, "Box<Any>");
-        assert_eq!(b_str, "Box<Any>");
-
-        let a = &8u as &Any;
-        let b = &Test as &Any;
-        let s = format!("{}", a);
-        assert_eq!(s, "&Any");
-        let s = format!("{}", b);
-        assert_eq!(s, "&Any");
-    }
-
-    #[test]
-    fn deref() {
-        fn homura<T: Deref<Target=i32>>(_: T) { }
-        homura(Box::new(765i32));
-    }
-}
diff --git a/src/liballoc/boxed_test.rs b/src/liballoc/boxed_test.rs
new file mode 100644
index 00000000000..c47a771f60d
--- /dev/null
+++ b/src/liballoc/boxed_test.rs
@@ -0,0 +1,75 @@
+// Copyright 2012-2015 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.
+
+//! Test for `boxed` mod.
+
+use core::any::Any;
+use core::ops::Deref;
+use core::result::Result::{Ok, Err};
+use core::clone::Clone;
+
+use std::boxed::Box;
+use std::boxed::BoxAny;
+
+#[test]
+fn test_owned_clone() {
+    let a = Box::new(5i);
+    let b: Box<int> = a.clone();
+    assert!(a == b);
+}
+
+#[derive(PartialEq, Eq)]
+struct Test;
+
+#[test]
+fn any_move() {
+    let a = Box::new(8u) as Box<Any>;
+    let b = Box::new(Test) as Box<Any>;
+
+    match a.downcast::<uint>() {
+        Ok(a) => { assert!(a == Box::new(8u)); }
+        Err(..) => panic!()
+    }
+    match b.downcast::<Test>() {
+        Ok(a) => { assert!(a == Box::new(Test)); }
+        Err(..) => panic!()
+    }
+
+    let a = Box::new(8u) as Box<Any>;
+    let b = Box::new(Test) as Box<Any>;
+
+    assert!(a.downcast::<Box<Test>>().is_err());
+    assert!(b.downcast::<Box<uint>>().is_err());
+}
+
+#[test]
+fn test_show() {
+    let a = Box::new(8u) as Box<Any>;
+    let b = Box::new(Test) as Box<Any>;
+    let a_str = format!("{:?}", a);
+    let b_str = format!("{:?}", b);
+    assert_eq!(a_str, "Box<Any>");
+    assert_eq!(b_str, "Box<Any>");
+
+    static EIGHT: usize = 8us;
+    static TEST: Test = Test;
+    let a = &EIGHT as &Any;
+    let b = &TEST as &Any;
+    let s = format!("{:?}", a);
+    assert_eq!(s, "&Any");
+    let s = format!("{:?}", b);
+    assert_eq!(s, "&Any");
+}
+
+#[test]
+fn deref() {
+    fn homura<T: Deref<Target=i32>>(_: T) { }
+    homura(Box::new(765i32));
+}
diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs
index 47715fe9e5d..231ef6e7e74 100644
--- a/src/liballoc/lib.rs
+++ b/src/liballoc/lib.rs
@@ -93,6 +93,8 @@ pub mod heap;
 
 #[cfg(not(test))]
 pub mod boxed;
+#[cfg(test)]
+mod boxed_test;
 pub mod arc;
 pub mod rc;