core: Get coretest working

This mostly involved frobbing imports between realstd, realcore, and the core
being test. Some of the imports are a little counterintuitive, but it mainly
focuses around libcore's types not implementing Show while libstd's types
implement Show.
This commit is contained in:
Alex Crichton
2014-05-01 18:06:59 -07:00
parent f62c121eb0
commit 104e285eb8
33 changed files with 247 additions and 86 deletions

View File

@@ -150,6 +150,7 @@ mod tests {
use super::*; use super::*;
use owned::Box; use owned::Box;
use str::StrSlice; use str::StrSlice;
use realstd::str::StrAllocating;
#[deriving(Eq, Show)] #[deriving(Eq, Show)]
struct Test; struct Test;
@@ -274,13 +275,20 @@ mod tests {
#[test] #[test]
fn test_show() { fn test_show() {
<<<<<<< HEAD
let a = box 8u as Box<Any>; let a = box 8u as Box<Any>;
let b = box Test as Box<Any>; let b = box Test as Box<Any>;
assert_eq!(format!("{}", a), "Box<Any>".to_owned()); assert_eq!(format!("{}", a), "Box<Any>".to_owned());
assert_eq!(format!("{}", b), "Box<Any>".to_owned()); assert_eq!(format!("{}", b), "Box<Any>".to_owned());
=======
let a = ~8u as ~::realcore::any::Any;
let b = ~Test as ~::realcore::any::Any;
assert_eq!(format!("{}", a), "~Any".to_owned());
assert_eq!(format!("{}", b), "~Any".to_owned());
>>>>>>> core: Get coretest working
let a = &8u as &Any; let a = &8u as &::realcore::any::Any;
let b = &Test as &Any; let b = &Test as &::realcore::any::Any;
assert_eq!(format!("{}", a), "&Any".to_owned()); assert_eq!(format!("{}", a), "&Any".to_owned());
assert_eq!(format!("{}", b), "&Any".to_owned()); assert_eq!(format!("{}", b), "&Any".to_owned());
} }

View File

@@ -175,9 +175,8 @@ impl Default for bool {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use prelude::*; use realstd::prelude::*;
use super::to_bit; use super::to_bit;
use str::StrSlice;
#[test] #[test]
fn test_to_bit() { fn test_to_bit() {

View File

@@ -108,7 +108,7 @@ pub unsafe fn copy_lifetime_vec<'a,S,T>(_ptr: &'a [S], ptr: &T) -> &'a T {
mod tests { mod tests {
use cast::{bump_box_refcount, transmute}; use cast::{bump_box_refcount, transmute};
use raw; use raw;
use str::StrSlice; use realstd::str::StrAllocating;
#[test] #[test]
fn test_transmute_copy() { fn test_transmute_copy() {

View File

@@ -221,22 +221,22 @@ mod test {
#[test] #[test]
fn smoketest_cell() { fn smoketest_cell() {
let x = Cell::new(10); let x = Cell::new(10);
assert_eq!(x, Cell::new(10)); assert!(x == Cell::new(10));
assert_eq!(x.get(), 10); assert!(x.get() == 10);
x.set(20); x.set(20);
assert_eq!(x, Cell::new(20)); assert!(x == Cell::new(20));
assert_eq!(x.get(), 20); assert!(x.get() == 20);
let y = Cell::new((30, 40)); let y = Cell::new((30, 40));
assert_eq!(y, Cell::new((30, 40))); assert!(y == Cell::new((30, 40)));
assert_eq!(y.get(), (30, 40)); assert!(y.get() == (30, 40));
} }
#[test] #[test]
fn cell_has_sensible_show() { fn cell_has_sensible_show() {
use str::StrSlice; use str::StrSlice;
let x = Cell::new("foo bar"); let x = ::realcore::cell::Cell::new("foo bar");
assert!(format!("{}", x).contains(x.get())); assert!(format!("{}", x).contains(x.get()));
x.set("baz qux"); x.set("baz qux");

View File

@@ -29,10 +29,6 @@ use option::{None, Option, Some};
use iter::{Iterator, range_step}; use iter::{Iterator, range_step};
use unicode::{derived_property, property, general_category, decompose, conversions}; use unicode::{derived_property, property, general_category, decompose, conversions};
#[cfg(test)] use str::Str;
#[cfg(test)] use strbuf::StrBuf;
#[cfg(test)] use slice::ImmutableVector;
#[cfg(not(test))] use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering}; #[cfg(not(test))] use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering};
#[cfg(not(test))] use default::Default; #[cfg(not(test))] use default::Default;
@@ -682,6 +678,14 @@ impl Default for char {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::{escape_unicode, escape_default};
use realcore::char::Char;
use slice::ImmutableVector;
use realstd::option::{Some, None};
use realstd::strbuf::StrBuf;
use realstd::str::StrAllocating;
#[test] #[test]
fn test_is_lowercase() { fn test_is_lowercase() {
assert!('a'.is_lowercase()); assert!('a'.is_lowercase());
@@ -822,7 +826,7 @@ mod test {
#[test] #[test]
fn test_to_str() { fn test_to_str() {
use to_str::ToStr; use realstd::to_str::ToStr;
let s = 't'.to_str(); let s = 't'.to_str();
assert_eq!(s, "t".to_owned()); assert_eq!(s, "t".to_owned());
} }

View File

@@ -128,6 +128,8 @@ extern_fn_clone!(A, B, C, D, E, F, G, H)
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use prelude::*;
#[test] #[test]
fn test_owned_clone() { fn test_owned_clone() {
let a = box 5i; let a = box 5i;

View File

@@ -12,6 +12,7 @@
#![allow(dead_code)] #![allow(dead_code)]
#[cfg(not(test))]
use str::raw::c_str_to_static_slice; use str::raw::c_str_to_static_slice;
// FIXME: Once std::fmt is in libcore, all of these functions should delegate // FIXME: Once std::fmt is in libcore, all of these functions should delegate

View File

@@ -34,8 +34,6 @@ use std::unstable::finally::Finally;
use ops::Drop; use ops::Drop;
#[cfg(test)] use task::failing;
/// A trait for executing a destructor unconditionally after a block of code, /// A trait for executing a destructor unconditionally after a block of code,
/// regardless of whether the blocked fails. /// regardless of whether the blocked fails.
pub trait Finally<T> { pub trait Finally<T> {
@@ -119,6 +117,9 @@ impl<'a,A> Drop for Finallyalizer<'a,A> {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::{try_finally, Finally};
use realstd::task::failing;
#[test] #[test]
fn test_success() { fn test_success() {
let mut i = 0; let mut i = 0;

View File

@@ -46,7 +46,7 @@ A quick refresher on memory ordering:
// This is needed to prevent duplicate lang item definitions. // This is needed to prevent duplicate lang item definitions.
#[cfg(test)] #[cfg(test)]
pub use realstd::intrinsics::{TyDesc, Opaque, TyVisitor, TypeId}; pub use realcore::intrinsics::{TyDesc, Opaque, TyVisitor, TypeId};
pub type GlueFn = extern "Rust" fn(*i8); pub type GlueFn = extern "Rust" fn(*i8);

View File

@@ -1090,7 +1090,7 @@ impl<A, T: Clone + RandomAccessIterator<A>> RandomAccessIterator<A> for Cycle<T>
pub struct Chain<T, U> { pub struct Chain<T, U> {
a: T, a: T,
b: U, b: U,
flag: bool flag: bool,
} }
impl<A, T: Iterator<A>, U: Iterator<A>> Iterator<A> for Chain<T, U> { impl<A, T: Iterator<A>, U: Iterator<A>> Iterator<A> for Chain<T, U> {
@@ -2329,13 +2329,13 @@ pub mod order {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use realstd::prelude::*;
use prelude::*; use realstd::iter::*;
use realstd::num;
use cmp; use cmp;
use owned::Box; use owned::Box;
use uint; use uint;
use num;
#[test] #[test]
fn test_counter_from_iter() { fn test_counter_from_iter() {

View File

@@ -18,9 +18,21 @@
html_root_url = "http://static.rust-lang.org/doc/master")] html_root_url = "http://static.rust-lang.org/doc/master")]
#![no_std] #![no_std]
#![feature(globs, macro_rules, managed_boxes)] #![feature(globs, macro_rules, managed_boxes, phase)]
#![deny(missing_doc)] #![deny(missing_doc)]
#[cfg(test)] extern crate realcore = "core";
#[cfg(test)] extern crate libc;
#[cfg(test)] extern crate native;
#[phase(syntax, link)] #[cfg(test)] extern crate realstd = "std";
#[phase(syntax, link)] #[cfg(test)] extern crate log;
#[cfg(test)] pub use kinds = realcore::kinds;
#[cfg(test)] pub use cmp = realcore::cmp;
#[cfg(test)] pub use ops = realcore::ops;
#[cfg(test)] pub use ty = realcore::ty;
#[cfg(not(test))]
mod macros; mod macros;
#[path = "num/float_macros.rs"] mod float_macros; #[path = "num/float_macros.rs"] mod float_macros;
@@ -44,6 +56,10 @@ mod macros;
pub mod num; pub mod num;
/* The libcore prelude, not as all-encompassing as the libstd prelude */
pub mod prelude;
/* Core modules for ownership management */ /* Core modules for ownership management */
pub mod cast; pub mod cast;
@@ -53,10 +69,10 @@ pub mod ptr;
/* Core language traits */ /* Core language traits */
pub mod cmp; #[cfg(not(test))] pub mod kinds;
pub mod kinds; #[cfg(not(test))] pub mod ops;
pub mod ops; #[cfg(not(test))] pub mod ty;
pub mod ty; #[cfg(not(test))] pub mod cmp;
pub mod clone; pub mod clone;
pub mod default; pub mod default;
pub mod container; pub mod container;
@@ -88,4 +104,9 @@ mod should_not_exist;
mod std { mod std {
pub use clone; pub use clone;
pub use cmp; pub use cmp;
#[cfg(test)] pub use realstd::fmt; // needed for fail!()
#[cfg(test)] pub use realstd::rt; // needed for fail!()
#[cfg(test)] pub use realstd::option; // needed for assert!()
#[cfg(test)] pub use realstd::os; // needed for tests
} }

View File

@@ -293,7 +293,7 @@ pub fn drop<T>(_x: T) { }
mod tests { mod tests {
use mem::*; use mem::*;
use option::{Some,None}; use option::{Some,None};
use str::StrSlice; use realstd::str::StrAllocating;
#[test] #[test]
fn size_of_basic() { fn size_of_basic() {

View File

@@ -10,11 +10,12 @@
//! Operations and constants for 32-bits floats (`f32` type) //! Operations and constants for 32-bits floats (`f32` type)
use cmp::{Eq, Ord};
use default::Default; use default::Default;
use intrinsics; use intrinsics;
use num::{Zero, One, Bounded, Signed, Num, Primitive}; use num::{Zero, One, Bounded, Signed, Num, Primitive};
use ops::{Add, Sub, Mul, Div, Rem, Neg};
#[cfg(not(test))] use cmp::{Eq, Ord};
#[cfg(not(test))] use ops::{Add, Sub, Mul, Div, Rem, Neg};
pub static RADIX: uint = 2u; pub static RADIX: uint = 2u;
@@ -100,6 +101,7 @@ pub mod consts {
pub static LN_10: f32 = 2.30258509299404568401799145468436421_f32; pub static LN_10: f32 = 2.30258509299404568401799145468436421_f32;
} }
#[cfg(not(test))]
impl Ord for f32 { impl Ord for f32 {
#[inline] #[inline]
fn lt(&self, other: &f32) -> bool { (*self) < (*other) } fn lt(&self, other: &f32) -> bool { (*self) < (*other) }
@@ -110,6 +112,7 @@ impl Ord for f32 {
#[inline] #[inline]
fn gt(&self, other: &f32) -> bool { (*self) > (*other) } fn gt(&self, other: &f32) -> bool { (*self) > (*other) }
} }
#[cfg(not(test))]
impl Eq for f32 { impl Eq for f32 {
#[inline] #[inline]
fn eq(&self, other: &f32) -> bool { (*self) == (*other) } fn eq(&self, other: &f32) -> bool { (*self) == (*other) }

View File

@@ -10,11 +10,12 @@
//! Operations and constants for 64-bits floats (`f64` type) //! Operations and constants for 64-bits floats (`f64` type)
use cmp::{Eq, Ord};
use default::Default; use default::Default;
use intrinsics; use intrinsics;
use num::{Zero, One, Bounded, Signed, Num, Primitive}; use num::{Zero, One, Bounded, Signed, Num, Primitive};
use ops::{Add, Sub, Mul, Div, Rem, Neg};
#[cfg(not(test))] use cmp::{Eq, Ord};
#[cfg(not(test))] use ops::{Add, Sub, Mul, Div, Rem, Neg};
// FIXME(#5527): These constants should be deprecated once associated // FIXME(#5527): These constants should be deprecated once associated
// constants are implemented in favour of referencing the respective // constants are implemented in favour of referencing the respective
@@ -106,6 +107,7 @@ pub mod consts {
pub static LN_10: f64 = 2.30258509299404568401799145468436421_f64; pub static LN_10: f64 = 2.30258509299404568401799145468436421_f64;
} }
#[cfg(not(test))]
impl Ord for f64 { impl Ord for f64 {
#[inline] #[inline]
fn lt(&self, other: &f64) -> bool { (*self) < (*other) } fn lt(&self, other: &f64) -> bool { (*self) < (*other) }
@@ -116,6 +118,7 @@ impl Ord for f64 {
#[inline] #[inline]
fn gt(&self, other: &f64) -> bool { (*self) > (*other) } fn gt(&self, other: &f64) -> bool { (*self) > (*other) }
} }
#[cfg(not(test))]
impl Eq for f64 { impl Eq for f64 {
#[inline] #[inline]
fn eq(&self, other: &f64) -> bool { (*self) == (*other) } fn eq(&self, other: &f64) -> bool { (*self) == (*other) }

View File

@@ -10,15 +10,19 @@
//! Operations and constants for signed 16-bits integers (`i16` type) //! Operations and constants for signed 16-bits integers (`i16` type)
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
use default::Default; use default::Default;
use intrinsics; use intrinsics;
use num::{Bitwise, Bounded, Zero, One, Signed, Num, Primitive, Int}; use num::{Bitwise, Bounded, Zero, One, Signed, Num, Primitive, Int};
use num::{CheckedDiv, CheckedAdd, CheckedSub, CheckedMul}; use num::{CheckedDiv, CheckedAdd, CheckedSub, CheckedMul};
use ops::{Add, Sub, Mul, Div, Rem, Neg, BitOr, BitAnd, BitXor};
use ops::{Shl, Shr, Not};
use option::{Option, Some, None}; use option::{Option, Some, None};
#[cfg(not(test))]
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
#[cfg(not(test))]
use ops::{Add, Sub, Mul, Div, Rem, Neg, BitOr, BitAnd, BitXor};
#[cfg(not(test))]
use ops::{Shl, Shr, Not};
int_module!(i16, 16) int_module!(i16, 16)
impl Bitwise for i16 { impl Bitwise for i16 {

View File

@@ -10,15 +10,19 @@
//! Operations and constants for signed 32-bits integers (`i32` type) //! Operations and constants for signed 32-bits integers (`i32` type)
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
use default::Default; use default::Default;
use intrinsics; use intrinsics;
use num::{Bitwise, Bounded, Zero, One, Signed, Num, Primitive, Int}; use num::{Bitwise, Bounded, Zero, One, Signed, Num, Primitive, Int};
use num::{CheckedDiv, CheckedAdd, CheckedSub, CheckedMul}; use num::{CheckedDiv, CheckedAdd, CheckedSub, CheckedMul};
use ops::{Add, Sub, Mul, Div, Rem, Neg, BitOr, BitAnd, BitXor};
use ops::{Shl, Shr, Not};
use option::{Option, Some, None}; use option::{Option, Some, None};
#[cfg(not(test))]
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
#[cfg(not(test))]
use ops::{Add, Sub, Mul, Div, Rem, Neg, BitOr, BitAnd, BitXor};
#[cfg(not(test))]
use ops::{Shl, Shr, Not};
int_module!(i32, 32) int_module!(i32, 32)
impl Bitwise for i32 { impl Bitwise for i32 {

View File

@@ -10,15 +10,19 @@
//! Operations and constants for signed 64-bits integers (`i64` type) //! Operations and constants for signed 64-bits integers (`i64` type)
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
use default::Default; use default::Default;
use intrinsics; use intrinsics;
use num::{Bitwise, Bounded, Zero, One, Signed, Num, Primitive, Int}; use num::{Bitwise, Bounded, Zero, One, Signed, Num, Primitive, Int};
use num::{CheckedDiv, CheckedAdd, CheckedSub, CheckedMul}; use num::{CheckedDiv, CheckedAdd, CheckedSub, CheckedMul};
use ops::{Add, Sub, Mul, Div, Rem, Neg, BitOr, BitAnd, BitXor};
use ops::{Shl, Shr, Not};
use option::{Option, Some, None}; use option::{Option, Some, None};
#[cfg(not(test))]
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
#[cfg(not(test))]
use ops::{Add, Sub, Mul, Div, Rem, Neg, BitOr, BitAnd, BitXor};
#[cfg(not(test))]
use ops::{Shl, Shr, Not};
int_module!(i64, 64) int_module!(i64, 64)
impl Bitwise for i64 { impl Bitwise for i64 {

View File

@@ -10,15 +10,19 @@
//! Operations and constants for signed 8-bits integers (`i8` type) //! Operations and constants for signed 8-bits integers (`i8` type)
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
use default::Default; use default::Default;
use intrinsics; use intrinsics;
use num::{Bitwise, Bounded, Zero, One, Signed, Num, Primitive, Int}; use num::{Bitwise, Bounded, Zero, One, Signed, Num, Primitive, Int};
use num::{CheckedDiv, CheckedAdd, CheckedSub, CheckedMul}; use num::{CheckedDiv, CheckedAdd, CheckedSub, CheckedMul};
use ops::{Add, Sub, Mul, Div, Rem, Neg, BitOr, BitAnd, BitXor};
use ops::{Shl, Shr, Not};
use option::{Option, Some, None}; use option::{Option, Some, None};
#[cfg(not(test))]
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
#[cfg(not(test))]
use ops::{Add, Sub, Mul, Div, Rem, Neg, BitOr, BitAnd, BitXor};
#[cfg(not(test))]
use ops::{Shl, Shr, Not};
int_module!(i8, 8) int_module!(i8, 8)
impl Bitwise for i8 { impl Bitwise for i8 {

View File

@@ -10,15 +10,19 @@
//! Operations and constants for architecture-sized signed integers (`int` type) //! Operations and constants for architecture-sized signed integers (`int` type)
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
use default::Default; use default::Default;
use intrinsics; use intrinsics;
use num::{Bitwise, Bounded, Zero, One, Signed, Num, Primitive, Int}; use num::{Bitwise, Bounded, Zero, One, Signed, Num, Primitive, Int};
use num::{CheckedDiv, CheckedAdd, CheckedSub, CheckedMul}; use num::{CheckedDiv, CheckedAdd, CheckedSub, CheckedMul};
use ops::{Add, Sub, Mul, Div, Rem, Neg, BitOr, BitAnd, BitXor};
use ops::{Shl, Shr, Not};
use option::{Option, Some, None}; use option::{Option, Some, None};
#[cfg(not(test))]
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
#[cfg(not(test))]
use ops::{Add, Sub, Mul, Div, Rem, Neg, BitOr, BitAnd, BitXor};
#[cfg(not(test))]
use ops::{Shl, Shr, Not};
#[cfg(target_word_size = "32")] int_module!(int, 32) #[cfg(target_word_size = "32")] int_module!(int, 32)
#[cfg(target_word_size = "64")] int_module!(int, 64) #[cfg(target_word_size = "64")] int_module!(int, 64)

View File

@@ -28,15 +28,19 @@ pub static MIN: $T = (-1 as $T) << (BITS - 1);
// calling the `Bounded::max_value` function. // calling the `Bounded::max_value` function.
pub static MAX: $T = !MIN; pub static MAX: $T = !MIN;
#[cfg(not(test))]
impl Ord for $T { impl Ord for $T {
#[inline] #[inline]
fn lt(&self, other: &$T) -> bool { *self < *other } fn lt(&self, other: &$T) -> bool { *self < *other }
} }
#[cfg(not(test))]
impl TotalEq for $T {} impl TotalEq for $T {}
#[cfg(not(test))]
impl Eq for $T { impl Eq for $T {
#[inline] #[inline]
fn eq(&self, other: &$T) -> bool { *self == *other } fn eq(&self, other: &$T) -> bool { *self == *other }
} }
#[cfg(not(test))]
impl TotalOrd for $T { impl TotalOrd for $T {
#[inline] #[inline]
fn cmp(&self, other: &$T) -> Ordering { fn cmp(&self, other: &$T) -> Ordering {
@@ -221,7 +225,7 @@ impl Bounded for $T {
impl CheckedDiv for $T { impl CheckedDiv for $T {
#[inline] #[inline]
fn checked_div(&self, v: &$T) -> Option<$T> { fn checked_div(&self, v: &$T) -> Option<$T> {
if *v == 0 { if *v == 0 || (*self == MIN && *v == -1) {
None None
} else { } else {
Some(self / *v) Some(self / *v)
@@ -244,12 +248,9 @@ mod tests {
use super::*; use super::*;
use int; use int;
use i32;
use num; use num;
use num::Bitwise; use num::Bitwise;
use num::CheckedDiv; use num::CheckedDiv;
use num::ToStrRadix;
use str::StrSlice;
#[test] #[test]
fn test_overflows() { fn test_overflows() {

View File

@@ -858,3 +858,19 @@ pub trait CheckedDiv: Div<Self, Self> {
/// `None` is returned. /// `None` is returned.
fn checked_div(&self, v: &Self) -> Option<Self>; fn checked_div(&self, v: &Self) -> Option<Self>;
} }
/// Helper function for testing numeric operations
#[cfg(test)]
pub fn test_num<T:Num + NumCast + ::std::fmt::Show>(ten: T, two: T) {
assert_eq!(ten.add(&two), cast(12).unwrap());
assert_eq!(ten.sub(&two), cast(8).unwrap());
assert_eq!(ten.mul(&two), cast(20).unwrap());
assert_eq!(ten.div(&two), cast(5).unwrap());
assert_eq!(ten.rem(&two), cast(0).unwrap());
assert_eq!(ten.add(&two), ten + two);
assert_eq!(ten.sub(&two), ten - two);
assert_eq!(ten.mul(&two), ten * two);
assert_eq!(ten.div(&two), ten / two);
assert_eq!(ten.rem(&two), ten % two);
}

View File

@@ -10,15 +10,19 @@
//! Operations and constants for unsigned 16-bits integers (`u16` type) //! Operations and constants for unsigned 16-bits integers (`u16` type)
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
use default::Default; use default::Default;
use intrinsics; use intrinsics;
use num::{Bitwise, Bounded, Zero, One, Unsigned, Num, Int, Primitive}; use num::{Bitwise, Bounded, Zero, One, Unsigned, Num, Int, Primitive};
use num::{CheckedAdd, CheckedSub, CheckedMul, CheckedDiv}; use num::{CheckedAdd, CheckedSub, CheckedMul, CheckedDiv};
use ops::{Add, Sub, Mul, Div, Rem, Neg, BitAnd, BitOr, BitXor};
use ops::{Shl, Shr, Not};
use option::{Some, None, Option}; use option::{Some, None, Option};
#[cfg(not(test))]
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
#[cfg(not(test))]
use ops::{Add, Sub, Mul, Div, Rem, Neg, BitAnd, BitOr, BitXor};
#[cfg(not(test))]
use ops::{Shl, Shr, Not};
uint_module!(u16, i16, 16) uint_module!(u16, i16, 16)
impl CheckedAdd for u16 { impl CheckedAdd for u16 {

View File

@@ -10,15 +10,19 @@
//! Operations and constants for unsigned 32-bits integers (`u32` type) //! Operations and constants for unsigned 32-bits integers (`u32` type)
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
use default::Default; use default::Default;
use intrinsics; use intrinsics;
use num::{Bitwise, Bounded, Zero, One, Unsigned, Num, Int, Primitive}; use num::{Bitwise, Bounded, Zero, One, Unsigned, Num, Int, Primitive};
use num::{CheckedAdd, CheckedSub, CheckedMul, CheckedDiv}; use num::{CheckedAdd, CheckedSub, CheckedMul, CheckedDiv};
use ops::{Add, Sub, Mul, Div, Rem, Neg, BitAnd, BitOr, BitXor};
use ops::{Shl, Shr, Not};
use option::{Some, None, Option}; use option::{Some, None, Option};
#[cfg(not(test))]
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
#[cfg(not(test))]
use ops::{Add, Sub, Mul, Div, Rem, Neg, BitAnd, BitOr, BitXor};
#[cfg(not(test))]
use ops::{Shl, Shr, Not};
uint_module!(u32, i32, 32) uint_module!(u32, i32, 32)
impl CheckedAdd for u32 { impl CheckedAdd for u32 {

View File

@@ -10,15 +10,19 @@
//! Operations and constants for unsigned 64-bits integer (`u64` type) //! Operations and constants for unsigned 64-bits integer (`u64` type)
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
use default::Default; use default::Default;
use intrinsics; use intrinsics;
use num::{Bitwise, Bounded, Zero, One, Unsigned, Num, Int, Primitive}; use num::{Bitwise, Bounded, Zero, One, Unsigned, Num, Int, Primitive};
use num::{CheckedAdd, CheckedSub, CheckedMul, CheckedDiv}; use num::{CheckedAdd, CheckedSub, CheckedMul, CheckedDiv};
use ops::{Add, Sub, Mul, Div, Rem, Neg, BitAnd, BitOr, BitXor};
use ops::{Shl, Shr, Not};
use option::{Some, None, Option}; use option::{Some, None, Option};
#[cfg(not(test))]
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
#[cfg(not(test))]
use ops::{Add, Sub, Mul, Div, Rem, Neg, BitAnd, BitOr, BitXor};
#[cfg(not(test))]
use ops::{Shl, Shr, Not};
uint_module!(u64, i64, 64) uint_module!(u64, i64, 64)
impl CheckedAdd for u64 { impl CheckedAdd for u64 {

View File

@@ -10,15 +10,19 @@
//! Operations and constants for unsigned 8-bits integers (`u8` type) //! Operations and constants for unsigned 8-bits integers (`u8` type)
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
use default::Default; use default::Default;
use intrinsics; use intrinsics;
use num::{Bitwise, Bounded, Zero, One, Unsigned, Num, Int, Primitive}; use num::{Bitwise, Bounded, Zero, One, Unsigned, Num, Int, Primitive};
use num::{CheckedAdd, CheckedSub, CheckedMul, CheckedDiv}; use num::{CheckedAdd, CheckedSub, CheckedMul, CheckedDiv};
use ops::{Add, Sub, Mul, Div, Rem, Neg, BitAnd, BitOr, BitXor};
use ops::{Shl, Shr, Not};
use option::{Some, None, Option}; use option::{Some, None, Option};
#[cfg(not(test))]
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
#[cfg(not(test))]
use ops::{Add, Sub, Mul, Div, Rem, Neg, BitAnd, BitOr, BitXor};
#[cfg(not(test))]
use ops::{Shl, Shr, Not};
uint_module!(u8, i8, 8) uint_module!(u8, i8, 8)
impl CheckedAdd for u8 { impl CheckedAdd for u8 {

View File

@@ -10,15 +10,19 @@
//! Operations and constants for architecture-sized unsigned integers (`uint` type) //! Operations and constants for architecture-sized unsigned integers (`uint` type)
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
use default::Default; use default::Default;
use intrinsics; use intrinsics;
use num::{Bitwise, Bounded, Zero, One, Unsigned, Num, Int, Primitive}; use num::{Bitwise, Bounded, Zero, One, Unsigned, Num, Int, Primitive};
use num::{CheckedAdd, CheckedSub, CheckedMul, CheckedDiv}; use num::{CheckedAdd, CheckedSub, CheckedMul, CheckedDiv};
use ops::{Add, Sub, Mul, Div, Rem, Neg, BitAnd, BitOr, BitXor};
use ops::{Shl, Shr, Not};
use option::{Some, None, Option}; use option::{Some, None, Option};
#[cfg(not(test))]
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
#[cfg(not(test))]
use ops::{Add, Sub, Mul, Div, Rem, Neg, BitAnd, BitOr, BitXor};
#[cfg(not(test))]
use ops::{Shl, Shr, Not};
uint_module!(uint, int, ::int::BITS) uint_module!(uint, int, ::int::BITS)
#[cfg(target_word_size = "32")] #[cfg(target_word_size = "32")]

View File

@@ -19,15 +19,19 @@ pub static BYTES : uint = ($bits / 8);
pub static MIN: $T = 0 as $T; pub static MIN: $T = 0 as $T;
pub static MAX: $T = 0 as $T - 1 as $T; pub static MAX: $T = 0 as $T - 1 as $T;
#[cfg(not(test))]
impl Ord for $T { impl Ord for $T {
#[inline] #[inline]
fn lt(&self, other: &$T) -> bool { *self < *other } fn lt(&self, other: &$T) -> bool { *self < *other }
} }
#[cfg(not(test))]
impl TotalEq for $T {} impl TotalEq for $T {}
#[cfg(not(test))]
impl Eq for $T { impl Eq for $T {
#[inline] #[inline]
fn eq(&self, other: &$T) -> bool { *self == *other } fn eq(&self, other: &$T) -> bool { *self == *other }
} }
#[cfg(not(test))]
impl TotalOrd for $T { impl TotalOrd for $T {
#[inline] #[inline]
fn cmp(&self, other: &$T) -> Ordering { fn cmp(&self, other: &$T) -> Ordering {
@@ -184,9 +188,6 @@ mod tests {
use num; use num;
use num::CheckedDiv; use num::CheckedDiv;
use num::Bitwise; use num::Bitwise;
use num::ToStrRadix;
use str::StrSlice;
use u16;
#[test] #[test]
fn test_overflows() { fn test_overflows() {

View File

@@ -236,6 +236,7 @@ impl<T> Option<T> {
/// ///
/// Fails if the value is a `None` with a custom failure message provided by `msg`. /// Fails if the value is a `None` with a custom failure message provided by `msg`.
#[inline] #[inline]
#[cfg(not(test))]
pub fn expect(self, msg: &str) -> T { pub fn expect(self, msg: &str) -> T {
match self { match self {
Some(val) => val, Some(val) => val,
@@ -243,6 +244,16 @@ impl<T> Option<T> {
} }
} }
// FIXME: once std::fmt is in libcore, this extra variant should not be
// necessary.
#[cfg(test)]
pub fn expect(self, msg: &str) -> T {
match self {
Some(val) => val,
None => fail!("{}", msg),
}
}
/// Moves a value out of an option type and returns it, consuming the `Option`. /// Moves a value out of an option type and returns it, consuming the `Option`.
/// ///
/// # Failure /// # Failure
@@ -605,10 +616,10 @@ pub fn collect<T, Iter: Iterator<Option<T>>, V: FromIterator<T>>(iter: Iter) ->
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use realstd::option::collect;
use prelude::*; use realstd::prelude::*;
use realstd::iter::range;
use iter::range;
use str::StrSlice; use str::StrSlice;
use kinds::marker; use kinds::marker;
use slice::ImmutableVector; use slice::ImmutableVector;
@@ -637,7 +648,7 @@ mod tests {
#[test] #[test]
fn test_get_resource() { fn test_get_resource() {
use rc::Rc; use realstd::rc::Rc;
use cell::RefCell; use cell::RefCell;
struct R { struct R {

47
src/libcore/prelude.rs Normal file
View File

@@ -0,0 +1,47 @@
// Copyright 2014 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.
//! The core prelude
//!
//! For more information, see std::prelude.
// Reexported core operators
pub use kinds::{Copy, Send, Sized, Share};
pub use ops::{Add, Sub, Mul, Div, Rem, Neg, Not};
pub use ops::{BitAnd, BitOr, BitXor};
pub use ops::{Drop, Deref, DerefMut};
pub use ops::{Shl, Shr, Index};
pub use option::{Option, Some, None};
pub use result::{Result, Ok, Err};
// Reexported functions
pub use iter::range;
pub use mem::drop;
// Reexported types and traits
pub use char::Char;
pub use clone::Clone;
pub use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater, Equiv};
pub use container::{Container, Mutable, Map, MutableMap, Set, MutableSet};
pub use iter::{FromIterator, Extendable};
pub use iter::{Iterator, DoubleEndedIterator, RandomAccessIterator, CloneableIterator};
pub use iter::{OrdIterator, MutableDoubleEndedIterator, ExactSize};
pub use num::{Num, NumCast, CheckedAdd, CheckedSub, CheckedMul};
pub use num::{Signed, Unsigned};
pub use num::{Primitive, Int, ToPrimitive, FromPrimitive};
pub use ptr::RawPtr;
pub use str::{Str, StrSlice};
pub use tuple::{Tuple1, Tuple2, Tuple3, Tuple4};
pub use tuple::{Tuple5, Tuple6, Tuple7, Tuple8};
pub use tuple::{Tuple9, Tuple10, Tuple11, Tuple12};
pub use slice::{ImmutableEqVector, ImmutableTotalOrdVector};
pub use slice::{MutableVector};
pub use slice::{Vector, ImmutableVector};

View File

@@ -480,12 +480,12 @@ impl<T> Ord for *mut T {
#[cfg(test)] #[cfg(test)]
pub mod ptr_tests { pub mod ptr_tests {
use super::*; use super::*;
use prelude::*; use realstd::prelude::*;
use c_str::ToCStr; use realstd::c_str::ToCStr;
use cast; use cast;
use libc; use libc;
use str; use realstd::str;
use slice::{ImmutableVector, MutableVector}; use slice::{ImmutableVector, MutableVector};
#[test] #[test]

View File

@@ -592,11 +592,9 @@ pub fn fold_<T,E,Iter:Iterator<Result<T,E>>>(iterator: Iter) -> Result<(),E> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use realstd::result::{collect, fold, fold_};
use prelude::*; use realstd::prelude::*;
use str::StrSlice; use realstd::iter::range;
use iter::range;
pub fn op1() -> Result<int, ~str> { Ok(666) } pub fn op1() -> Result<int, ~str> { Ok(666) }
pub fn op2() -> Result<int, ~str> { Err("sadface".to_owned()) } pub fn op2() -> Result<int, ~str> { Err("sadface".to_owned()) }

View File

@@ -17,14 +17,16 @@ use intrinsics;
use iter::{Iterator, FromIterator}; use iter::{Iterator, FromIterator};
use mem; use mem;
use num::{CheckedMul, CheckedAdd}; use num::{CheckedMul, CheckedAdd};
use ops::Add;
use option::{Some, None}; use option::{Some, None};
use ptr::RawPtr; use ptr::RawPtr;
use ptr; use ptr;
use raw::Vec; use raw::Vec;
use slice::{ImmutableVector, Vector}; use slice::ImmutableVector;
use str::StrSlice; use str::StrSlice;
#[cfg(not(test))] use ops::Add;
#[cfg(not(test))] use slice::Vector;
#[allow(ctypes)] #[allow(ctypes)]
extern { extern {
fn malloc(size: uint) -> *u8; fn malloc(size: uint) -> *u8;
@@ -118,6 +120,7 @@ impl FromIterator<char> for ~str {
} }
} }
#[cfg(not(test))]
impl<'a> Add<&'a str,~str> for &'a str { impl<'a> Add<&'a str,~str> for &'a str {
#[inline] #[inline]
fn add(&self, rhs: & &'a str) -> ~str { fn add(&self, rhs: & &'a str) -> ~str {
@@ -181,6 +184,7 @@ impl<A> FromIterator<A> for ~[A] {
} }
} }
#[cfg(not(test))]
impl<'a,T:Clone, V: Vector<T>> Add<V, ~[T]> for &'a [T] { impl<'a,T:Clone, V: Vector<T>> Add<V, ~[T]> for &'a [T] {
#[inline] #[inline]
fn add(&self, rhs: &V) -> ~[T] { fn add(&self, rhs: &V) -> ~[T] {
@@ -189,6 +193,7 @@ impl<'a,T:Clone, V: Vector<T>> Add<V, ~[T]> for &'a [T] {
} }
} }
#[cfg(not(test))]
impl<T:Clone, V: Vector<T>> Add<V, ~[T]> for ~[T] { impl<T:Clone, V: Vector<T>> Add<V, ~[T]> for ~[T] {
#[inline] #[inline]
fn add(&self, rhs: &V) -> ~[T] { fn add(&self, rhs: &V) -> ~[T] {

View File

@@ -246,7 +246,7 @@ mod tests {
use super::*; use super::*;
use clone::Clone; use clone::Clone;
use cmp::*; use cmp::*;
use str::StrSlice; use realstd::str::StrAllocating;
#[test] #[test]
fn test_clone() { fn test_clone() {