From 1ed646eaf7d09455a086afa11bcd83a7d2a6b0f4 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sat, 28 Jun 2014 13:57:36 -0700 Subject: Extract tests from libcore to a separate crate Libcore's test infrastructure is complicated by the fact that many lang items are defined in the crate. The current approach (realcore/realstd imports) is hacky and hard to work with (tests inside of core::cmp haven't been run for months!). Moving tests to a separate crate does mean that they can only test the public API of libcore, but I don't feel that that is too much of an issue. The only tests that I had to get rid of were some checking the various numeric formatters, but those are also exercised through normal format! calls in other tests. --- src/liballoc/owned.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'src/liballoc') diff --git a/src/liballoc/owned.rs b/src/liballoc/owned.rs index 589adbd41d0..33afa806f4e 100644 --- a/src/liballoc/owned.rs +++ b/src/liballoc/owned.rs @@ -146,3 +146,51 @@ impl fmt::Show for Box { f.pad("Box") } } + +#[cfg(test)] +mod test { + #[test] + fn test_owned_clone() { + let a = box 5i; + let b: Box = a.clone(); + assert!(a == b); + } + + #[test] + fn any_move() { + let a = box 8u as Box; + let b = box Test as Box; + + match a.move::() { + Ok(a) => { assert!(a == box 8u); } + Err(..) => fail!() + } + match b.move::() { + Ok(a) => { assert!(a == box Test); } + Err(..) => fail!() + } + + let a = box 8u as Box; + let b = box Test as Box; + + assert!(a.move::>().is_err()); + assert!(b.move::>().is_err()); + } + + #[test] + fn test_show() { + let a = box 8u as Box; + let b = box Test as Box; + let a_str = a.to_str(); + let b_str = b.to_str(); + assert_eq!(a_str.as_slice(), "Box"); + assert_eq!(b_str.as_slice(), "Box"); + + let a = &8u as &Any; + let b = &Test as &Any; + let s = format!("{}", a); + assert_eq!(s.as_slice(), "&Any"); + let s = format!("{}", b); + assert_eq!(s.as_slice(), "&Any"); + } +} -- cgit 1.4.1-3-g733a5