1 // Copyright 2012-2015 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.
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.
11 //! Test for `boxed` mod.
15 use core::result::Result::{Ok, Err};
16 use core::clone::Clone;
19 use std::boxed::BoxAny;
22 fn test_owned_clone() {
24 let b: Box<int> = a.clone();
28 #[derive(PartialEq, Eq)]
33 let a = Box::new(8u) as Box<Any>;
34 let b = Box::new(Test) as Box<Any>;
36 match a.downcast::<uint>() {
37 Ok(a) => { assert!(a == Box::new(8u)); }
40 match b.downcast::<Test>() {
41 Ok(a) => { assert!(a == Box::new(Test)); }
45 let a = Box::new(8u) as Box<Any>;
46 let b = Box::new(Test) as Box<Any>;
48 assert!(a.downcast::<Box<Test>>().is_err());
49 assert!(b.downcast::<Box<uint>>().is_err());
54 let a = Box::new(8u) as Box<Any>;
55 let b = Box::new(Test) as Box<Any>;
56 let a_str = format!("{:?}", a);
57 let b_str = format!("{:?}", b);
58 assert_eq!(a_str, "Box<Any>");
59 assert_eq!(b_str, "Box<Any>");
61 static EIGHT: usize = 8us;
62 static TEST: Test = Test;
63 let a = &EIGHT as &Any;
64 let b = &TEST as &Any;
65 let s = format!("{:?}", a);
66 assert_eq!(s, "&Any");
67 let s = format!("{:?}", b);
68 assert_eq!(s, "&Any");
73 fn homura<T: Deref<Target=i32>>(_: T) { }
74 homura(Box::new(765i32));