Skip to content

Commit efea645

Browse files
committed
rollup merge of rust-lang#21446: stepancheg/boxed-test
Conflicts: src/liballoc/boxed.rs
2 parents 907db6c + ace2f09 commit efea645

File tree

3 files changed

+77
-54
lines changed

3 files changed

+77
-54
lines changed

src/liballoc/boxed.rs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -201,57 +201,3 @@ impl<'a, T> Iterator for Box<Iterator<Item=T> + 'a> {
201201
(**self).size_hint()
202202
}
203203
}
204-
205-
#[cfg(test)]
206-
mod test {
207-
#[test]
208-
fn test_owned_clone() {
209-
let a = Box::new(5i);
210-
let b: Box<int> = a.clone();
211-
assert!(a == b);
212-
}
213-
214-
#[test]
215-
fn any_move() {
216-
let a = Box::new(8u) as Box<Any>;
217-
let b = Box::new(Test) as Box<Any>;
218-
219-
match a.downcast::<uint>() {
220-
Ok(a) => { assert!(a == Box::new(8u)); }
221-
Err(..) => panic!()
222-
}
223-
match b.downcast::<Test>() {
224-
Ok(a) => { assert!(a == Box::new(Test)); }
225-
Err(..) => panic!()
226-
}
227-
228-
let a = Box::new(8u) as Box<Any>;
229-
let b = Box::new(Test) as Box<Any>;
230-
231-
assert!(a.downcast::<Box<Test>>().is_err());
232-
assert!(b.downcast::<Box<uint>>().is_err());
233-
}
234-
235-
#[test]
236-
fn test_show() {
237-
let a = Box::new(8u) as Box<Any>;
238-
let b = Box::new(Test) as Box<Any>;
239-
let a_str = a.to_str();
240-
let b_str = b.to_str();
241-
assert_eq!(a_str, "Box<Any>");
242-
assert_eq!(b_str, "Box<Any>");
243-
244-
let a = &8u as &Any;
245-
let b = &Test as &Any;
246-
let s = format!("{}", a);
247-
assert_eq!(s, "&Any");
248-
let s = format!("{}", b);
249-
assert_eq!(s, "&Any");
250-
}
251-
252-
#[test]
253-
fn deref() {
254-
fn homura<T: Deref<Target=i32>>(_: T) { }
255-
homura(Box::new(765i32));
256-
}
257-
}

src/liballoc/boxed_test.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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.
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+
//! Test for `boxed` mod.
12+
13+
use core::any::Any;
14+
use core::ops::Deref;
15+
use core::result::Result::{Ok, Err};
16+
use core::clone::Clone;
17+
18+
use std::boxed::Box;
19+
use std::boxed::BoxAny;
20+
21+
#[test]
22+
fn test_owned_clone() {
23+
let a = Box::new(5i);
24+
let b: Box<int> = a.clone();
25+
assert!(a == b);
26+
}
27+
28+
#[derive(PartialEq, Eq)]
29+
struct Test;
30+
31+
#[test]
32+
fn any_move() {
33+
let a = Box::new(8u) as Box<Any>;
34+
let b = Box::new(Test) as Box<Any>;
35+
36+
match a.downcast::<uint>() {
37+
Ok(a) => { assert!(a == Box::new(8u)); }
38+
Err(..) => panic!()
39+
}
40+
match b.downcast::<Test>() {
41+
Ok(a) => { assert!(a == Box::new(Test)); }
42+
Err(..) => panic!()
43+
}
44+
45+
let a = Box::new(8u) as Box<Any>;
46+
let b = Box::new(Test) as Box<Any>;
47+
48+
assert!(a.downcast::<Box<Test>>().is_err());
49+
assert!(b.downcast::<Box<uint>>().is_err());
50+
}
51+
52+
#[test]
53+
fn test_show() {
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>");
60+
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");
69+
}
70+
71+
#[test]
72+
fn deref() {
73+
fn homura<T: Deref<Target=i32>>(_: T) { }
74+
homura(Box::new(765i32));
75+
}

src/liballoc/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ pub mod heap;
9393

9494
#[cfg(not(test))]
9595
pub mod boxed;
96+
#[cfg(test)]
97+
mod boxed_test;
9698
pub mod arc;
9799
pub mod rc;
98100

0 commit comments

Comments
 (0)