fix an alloc test
This commit is contained in:
parent
214e65c2eb
commit
7f5338a122
@ -4,7 +4,6 @@ use core::any::Any;
|
|||||||
use core::clone::Clone;
|
use core::clone::Clone;
|
||||||
use core::convert::TryInto;
|
use core::convert::TryInto;
|
||||||
use core::ops::Deref;
|
use core::ops::Deref;
|
||||||
use core::result::Result::{Err, Ok};
|
|
||||||
|
|
||||||
use std::boxed::Box;
|
use std::boxed::Box;
|
||||||
|
|
||||||
@ -15,7 +14,7 @@ fn test_owned_clone() {
|
|||||||
assert!(a == b);
|
assert!(a == b);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
struct Test;
|
struct Test;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -23,24 +22,17 @@ fn any_move() {
|
|||||||
let a = Box::new(8) as Box<dyn Any>;
|
let a = Box::new(8) as Box<dyn Any>;
|
||||||
let b = Box::new(Test) as Box<dyn Any>;
|
let b = Box::new(Test) as Box<dyn Any>;
|
||||||
|
|
||||||
match a.downcast::<i32>() {
|
let a: Box<i32> = a.downcast::<i32>().unwrap();
|
||||||
Ok(a) => {
|
assert_eq!(*a, 8);
|
||||||
assert!(a == Box::new(8));
|
|
||||||
}
|
let b: Box<Test> = b.downcast::<Test>().unwrap();
|
||||||
Err(..) => panic!(),
|
assert_eq!(*b, Test);
|
||||||
}
|
|
||||||
match b.downcast::<Test>() {
|
|
||||||
Ok(a) => {
|
|
||||||
assert!(a == Box::new(Test));
|
|
||||||
}
|
|
||||||
Err(..) => panic!(),
|
|
||||||
}
|
|
||||||
|
|
||||||
let a = Box::new(8) as Box<dyn Any>;
|
let a = Box::new(8) as Box<dyn Any>;
|
||||||
let b = Box::new(Test) as Box<dyn Any>;
|
let b = Box::new(Test) as Box<dyn Any>;
|
||||||
|
|
||||||
assert!(a.downcast::<Box<Test>>().is_err());
|
assert!(a.downcast::<Box<i32>>().is_err());
|
||||||
assert!(b.downcast::<Box<i32>>().is_err());
|
assert!(b.downcast::<Box<Test>>().is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user