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:
parent
f62c121eb0
commit
104e285eb8
@ -150,6 +150,7 @@ mod tests {
|
||||
use super::*;
|
||||
use owned::Box;
|
||||
use str::StrSlice;
|
||||
use realstd::str::StrAllocating;
|
||||
|
||||
#[deriving(Eq, Show)]
|
||||
struct Test;
|
||||
@ -274,13 +275,20 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_show() {
|
||||
<<<<<<< HEAD
|
||||
let a = box 8u as Box<Any>;
|
||||
let b = box Test as Box<Any>;
|
||||
assert_eq!(format!("{}", a), "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 b = &Test as &Any;
|
||||
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());
|
||||
}
|
||||
|
@ -175,9 +175,8 @@ impl Default for bool {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use prelude::*;
|
||||
use realstd::prelude::*;
|
||||
use super::to_bit;
|
||||
use str::StrSlice;
|
||||
|
||||
#[test]
|
||||
fn test_to_bit() {
|
||||
|
@ -108,7 +108,7 @@ pub unsafe fn copy_lifetime_vec<'a,S,T>(_ptr: &'a [S], ptr: &T) -> &'a T {
|
||||
mod tests {
|
||||
use cast::{bump_box_refcount, transmute};
|
||||
use raw;
|
||||
use str::StrSlice;
|
||||
use realstd::str::StrAllocating;
|
||||
|
||||
#[test]
|
||||
fn test_transmute_copy() {
|
||||
|
@ -221,22 +221,22 @@ mod test {
|
||||
#[test]
|
||||
fn smoketest_cell() {
|
||||
let x = Cell::new(10);
|
||||
assert_eq!(x, Cell::new(10));
|
||||
assert_eq!(x.get(), 10);
|
||||
assert!(x == Cell::new(10));
|
||||
assert!(x.get() == 10);
|
||||
x.set(20);
|
||||
assert_eq!(x, Cell::new(20));
|
||||
assert_eq!(x.get(), 20);
|
||||
assert!(x == Cell::new(20));
|
||||
assert!(x.get() == 20);
|
||||
|
||||
let y = Cell::new((30, 40));
|
||||
assert_eq!(y, Cell::new((30, 40)));
|
||||
assert_eq!(y.get(), (30, 40));
|
||||
assert!(y == Cell::new((30, 40)));
|
||||
assert!(y.get() == (30, 40));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cell_has_sensible_show() {
|
||||
use str::StrSlice;
|
||||
|
||||
let x = Cell::new("foo bar");
|
||||
let x = ::realcore::cell::Cell::new("foo bar");
|
||||
assert!(format!("{}", x).contains(x.get()));
|
||||
|
||||
x.set("baz qux");
|
||||
|
@ -29,10 +29,6 @@ use option::{None, Option, Some};
|
||||
use iter::{Iterator, range_step};
|
||||
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 default::Default;
|
||||
|
||||
@ -682,6 +678,14 @@ impl Default for char {
|
||||
|
||||
#[cfg(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]
|
||||
fn test_is_lowercase() {
|
||||
assert!('a'.is_lowercase());
|
||||
@ -822,7 +826,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_to_str() {
|
||||
use to_str::ToStr;
|
||||
use realstd::to_str::ToStr;
|
||||
let s = 't'.to_str();
|
||||
assert_eq!(s, "t".to_owned());
|
||||
}
|
||||
|
@ -128,6 +128,8 @@ extern_fn_clone!(A, B, C, D, E, F, G, H)
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use prelude::*;
|
||||
|
||||
#[test]
|
||||
fn test_owned_clone() {
|
||||
let a = box 5i;
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
#[cfg(not(test))]
|
||||
use str::raw::c_str_to_static_slice;
|
||||
|
||||
// FIXME: Once std::fmt is in libcore, all of these functions should delegate
|
||||
|
@ -34,8 +34,6 @@ use std::unstable::finally::Finally;
|
||||
|
||||
use ops::Drop;
|
||||
|
||||
#[cfg(test)] use task::failing;
|
||||
|
||||
/// A trait for executing a destructor unconditionally after a block of code,
|
||||
/// regardless of whether the blocked fails.
|
||||
pub trait Finally<T> {
|
||||
@ -119,6 +117,9 @@ impl<'a,A> Drop for Finallyalizer<'a,A> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::{try_finally, Finally};
|
||||
use realstd::task::failing;
|
||||
|
||||
#[test]
|
||||
fn test_success() {
|
||||
let mut i = 0;
|
||||
|
@ -46,7 +46,7 @@ A quick refresher on memory ordering:
|
||||
|
||||
// This is needed to prevent duplicate lang item definitions.
|
||||
#[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);
|
||||
|
||||
|
@ -1090,7 +1090,7 @@ impl<A, T: Clone + RandomAccessIterator<A>> RandomAccessIterator<A> for Cycle<T>
|
||||
pub struct Chain<T, U> {
|
||||
a: T,
|
||||
b: U,
|
||||
flag: bool
|
||||
flag: bool,
|
||||
}
|
||||
|
||||
impl<A, T: Iterator<A>, U: Iterator<A>> Iterator<A> for Chain<T, U> {
|
||||
@ -2329,13 +2329,13 @@ pub mod order {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use prelude::*;
|
||||
use realstd::prelude::*;
|
||||
use realstd::iter::*;
|
||||
use realstd::num;
|
||||
|
||||
use cmp;
|
||||
use owned::Box;
|
||||
use uint;
|
||||
use num;
|
||||
|
||||
#[test]
|
||||
fn test_counter_from_iter() {
|
||||
|
@ -18,9 +18,21 @@
|
||||
html_root_url = "http://static.rust-lang.org/doc/master")]
|
||||
|
||||
#![no_std]
|
||||
#![feature(globs, macro_rules, managed_boxes)]
|
||||
#![feature(globs, macro_rules, managed_boxes, phase)]
|
||||
#![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;
|
||||
|
||||
#[path = "num/float_macros.rs"] mod float_macros;
|
||||
@ -44,6 +56,10 @@ mod macros;
|
||||
|
||||
pub mod num;
|
||||
|
||||
/* The libcore prelude, not as all-encompassing as the libstd prelude */
|
||||
|
||||
pub mod prelude;
|
||||
|
||||
/* Core modules for ownership management */
|
||||
|
||||
pub mod cast;
|
||||
@ -53,10 +69,10 @@ pub mod ptr;
|
||||
|
||||
/* Core language traits */
|
||||
|
||||
pub mod cmp;
|
||||
pub mod kinds;
|
||||
pub mod ops;
|
||||
pub mod ty;
|
||||
#[cfg(not(test))] pub mod kinds;
|
||||
#[cfg(not(test))] pub mod ops;
|
||||
#[cfg(not(test))] pub mod ty;
|
||||
#[cfg(not(test))] pub mod cmp;
|
||||
pub mod clone;
|
||||
pub mod default;
|
||||
pub mod container;
|
||||
@ -88,4 +104,9 @@ mod should_not_exist;
|
||||
mod std {
|
||||
pub use clone;
|
||||
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
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ pub fn drop<T>(_x: T) { }
|
||||
mod tests {
|
||||
use mem::*;
|
||||
use option::{Some,None};
|
||||
use str::StrSlice;
|
||||
use realstd::str::StrAllocating;
|
||||
|
||||
#[test]
|
||||
fn size_of_basic() {
|
||||
|
@ -10,11 +10,12 @@
|
||||
|
||||
//! Operations and constants for 32-bits floats (`f32` type)
|
||||
|
||||
use cmp::{Eq, Ord};
|
||||
use default::Default;
|
||||
use intrinsics;
|
||||
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;
|
||||
|
||||
@ -100,6 +101,7 @@ pub mod consts {
|
||||
pub static LN_10: f32 = 2.30258509299404568401799145468436421_f32;
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
impl Ord for f32 {
|
||||
#[inline]
|
||||
fn lt(&self, other: &f32) -> bool { (*self) < (*other) }
|
||||
@ -110,6 +112,7 @@ impl Ord for f32 {
|
||||
#[inline]
|
||||
fn gt(&self, other: &f32) -> bool { (*self) > (*other) }
|
||||
}
|
||||
#[cfg(not(test))]
|
||||
impl Eq for f32 {
|
||||
#[inline]
|
||||
fn eq(&self, other: &f32) -> bool { (*self) == (*other) }
|
||||
|
@ -10,11 +10,12 @@
|
||||
|
||||
//! Operations and constants for 64-bits floats (`f64` type)
|
||||
|
||||
use cmp::{Eq, Ord};
|
||||
use default::Default;
|
||||
use intrinsics;
|
||||
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
|
||||
// constants are implemented in favour of referencing the respective
|
||||
@ -106,6 +107,7 @@ pub mod consts {
|
||||
pub static LN_10: f64 = 2.30258509299404568401799145468436421_f64;
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
impl Ord for f64 {
|
||||
#[inline]
|
||||
fn lt(&self, other: &f64) -> bool { (*self) < (*other) }
|
||||
@ -116,6 +118,7 @@ impl Ord for f64 {
|
||||
#[inline]
|
||||
fn gt(&self, other: &f64) -> bool { (*self) > (*other) }
|
||||
}
|
||||
#[cfg(not(test))]
|
||||
impl Eq for f64 {
|
||||
#[inline]
|
||||
fn eq(&self, other: &f64) -> bool { (*self) == (*other) }
|
||||
|
@ -10,15 +10,19 @@
|
||||
|
||||
//! Operations and constants for signed 16-bits integers (`i16` type)
|
||||
|
||||
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
|
||||
use default::Default;
|
||||
use intrinsics;
|
||||
use num::{Bitwise, Bounded, Zero, One, Signed, Num, Primitive, Int};
|
||||
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};
|
||||
|
||||
#[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)
|
||||
|
||||
impl Bitwise for i16 {
|
||||
|
@ -10,15 +10,19 @@
|
||||
|
||||
//! Operations and constants for signed 32-bits integers (`i32` type)
|
||||
|
||||
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
|
||||
use default::Default;
|
||||
use intrinsics;
|
||||
use num::{Bitwise, Bounded, Zero, One, Signed, Num, Primitive, Int};
|
||||
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};
|
||||
|
||||
#[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)
|
||||
|
||||
impl Bitwise for i32 {
|
||||
|
@ -10,15 +10,19 @@
|
||||
|
||||
//! Operations and constants for signed 64-bits integers (`i64` type)
|
||||
|
||||
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
|
||||
use default::Default;
|
||||
use intrinsics;
|
||||
use num::{Bitwise, Bounded, Zero, One, Signed, Num, Primitive, Int};
|
||||
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};
|
||||
|
||||
#[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)
|
||||
|
||||
impl Bitwise for i64 {
|
||||
|
@ -10,15 +10,19 @@
|
||||
|
||||
//! Operations and constants for signed 8-bits integers (`i8` type)
|
||||
|
||||
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
|
||||
use default::Default;
|
||||
use intrinsics;
|
||||
use num::{Bitwise, Bounded, Zero, One, Signed, Num, Primitive, Int};
|
||||
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};
|
||||
|
||||
#[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)
|
||||
|
||||
impl Bitwise for i8 {
|
||||
|
@ -10,15 +10,19 @@
|
||||
|
||||
//! Operations and constants for architecture-sized signed integers (`int` type)
|
||||
|
||||
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
|
||||
use default::Default;
|
||||
use intrinsics;
|
||||
use num::{Bitwise, Bounded, Zero, One, Signed, Num, Primitive, Int};
|
||||
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};
|
||||
|
||||
#[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 = "64")] int_module!(int, 64)
|
||||
|
||||
|
@ -28,15 +28,19 @@ pub static MIN: $T = (-1 as $T) << (BITS - 1);
|
||||
// calling the `Bounded::max_value` function.
|
||||
pub static MAX: $T = !MIN;
|
||||
|
||||
#[cfg(not(test))]
|
||||
impl Ord for $T {
|
||||
#[inline]
|
||||
fn lt(&self, other: &$T) -> bool { *self < *other }
|
||||
}
|
||||
#[cfg(not(test))]
|
||||
impl TotalEq for $T {}
|
||||
#[cfg(not(test))]
|
||||
impl Eq for $T {
|
||||
#[inline]
|
||||
fn eq(&self, other: &$T) -> bool { *self == *other }
|
||||
}
|
||||
#[cfg(not(test))]
|
||||
impl TotalOrd for $T {
|
||||
#[inline]
|
||||
fn cmp(&self, other: &$T) -> Ordering {
|
||||
@ -221,7 +225,7 @@ impl Bounded for $T {
|
||||
impl CheckedDiv for $T {
|
||||
#[inline]
|
||||
fn checked_div(&self, v: &$T) -> Option<$T> {
|
||||
if *v == 0 {
|
||||
if *v == 0 || (*self == MIN && *v == -1) {
|
||||
None
|
||||
} else {
|
||||
Some(self / *v)
|
||||
@ -244,12 +248,9 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
use int;
|
||||
use i32;
|
||||
use num;
|
||||
use num::Bitwise;
|
||||
use num::CheckedDiv;
|
||||
use num::ToStrRadix;
|
||||
use str::StrSlice;
|
||||
|
||||
#[test]
|
||||
fn test_overflows() {
|
||||
|
@ -858,3 +858,19 @@ pub trait CheckedDiv: Div<Self, Self> {
|
||||
/// `None` is returned.
|
||||
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);
|
||||
}
|
||||
|
@ -10,15 +10,19 @@
|
||||
|
||||
//! Operations and constants for unsigned 16-bits integers (`u16` type)
|
||||
|
||||
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
|
||||
use default::Default;
|
||||
use intrinsics;
|
||||
use num::{Bitwise, Bounded, Zero, One, Unsigned, Num, Int, Primitive};
|
||||
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};
|
||||
|
||||
#[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)
|
||||
|
||||
impl CheckedAdd for u16 {
|
||||
|
@ -10,15 +10,19 @@
|
||||
|
||||
//! Operations and constants for unsigned 32-bits integers (`u32` type)
|
||||
|
||||
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
|
||||
use default::Default;
|
||||
use intrinsics;
|
||||
use num::{Bitwise, Bounded, Zero, One, Unsigned, Num, Int, Primitive};
|
||||
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};
|
||||
|
||||
#[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)
|
||||
|
||||
impl CheckedAdd for u32 {
|
||||
|
@ -10,15 +10,19 @@
|
||||
|
||||
//! Operations and constants for unsigned 64-bits integer (`u64` type)
|
||||
|
||||
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
|
||||
use default::Default;
|
||||
use intrinsics;
|
||||
use num::{Bitwise, Bounded, Zero, One, Unsigned, Num, Int, Primitive};
|
||||
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};
|
||||
|
||||
#[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)
|
||||
|
||||
impl CheckedAdd for u64 {
|
||||
|
@ -10,15 +10,19 @@
|
||||
|
||||
//! Operations and constants for unsigned 8-bits integers (`u8` type)
|
||||
|
||||
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
|
||||
use default::Default;
|
||||
use intrinsics;
|
||||
use num::{Bitwise, Bounded, Zero, One, Unsigned, Num, Int, Primitive};
|
||||
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};
|
||||
|
||||
#[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)
|
||||
|
||||
impl CheckedAdd for u8 {
|
||||
|
@ -10,15 +10,19 @@
|
||||
|
||||
//! Operations and constants for architecture-sized unsigned integers (`uint` type)
|
||||
|
||||
use cmp::{Eq, Ord, TotalEq, TotalOrd, Less, Greater, Equal, Ordering};
|
||||
use default::Default;
|
||||
use intrinsics;
|
||||
use num::{Bitwise, Bounded, Zero, One, Unsigned, Num, Int, Primitive};
|
||||
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};
|
||||
|
||||
#[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)
|
||||
|
||||
#[cfg(target_word_size = "32")]
|
||||
|
@ -19,15 +19,19 @@ pub static BYTES : uint = ($bits / 8);
|
||||
pub static MIN: $T = 0 as $T;
|
||||
pub static MAX: $T = 0 as $T - 1 as $T;
|
||||
|
||||
#[cfg(not(test))]
|
||||
impl Ord for $T {
|
||||
#[inline]
|
||||
fn lt(&self, other: &$T) -> bool { *self < *other }
|
||||
}
|
||||
#[cfg(not(test))]
|
||||
impl TotalEq for $T {}
|
||||
#[cfg(not(test))]
|
||||
impl Eq for $T {
|
||||
#[inline]
|
||||
fn eq(&self, other: &$T) -> bool { *self == *other }
|
||||
}
|
||||
#[cfg(not(test))]
|
||||
impl TotalOrd for $T {
|
||||
#[inline]
|
||||
fn cmp(&self, other: &$T) -> Ordering {
|
||||
@ -184,9 +188,6 @@ mod tests {
|
||||
use num;
|
||||
use num::CheckedDiv;
|
||||
use num::Bitwise;
|
||||
use num::ToStrRadix;
|
||||
use str::StrSlice;
|
||||
use u16;
|
||||
|
||||
#[test]
|
||||
fn test_overflows() {
|
||||
|
@ -236,6 +236,7 @@ impl<T> Option<T> {
|
||||
///
|
||||
/// Fails if the value is a `None` with a custom failure message provided by `msg`.
|
||||
#[inline]
|
||||
#[cfg(not(test))]
|
||||
pub fn expect(self, msg: &str) -> T {
|
||||
match self {
|
||||
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`.
|
||||
///
|
||||
/// # Failure
|
||||
@ -605,10 +616,10 @@ pub fn collect<T, Iter: Iterator<Option<T>>, V: FromIterator<T>>(iter: Iter) ->
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use prelude::*;
|
||||
use realstd::option::collect;
|
||||
use realstd::prelude::*;
|
||||
use realstd::iter::range;
|
||||
|
||||
use iter::range;
|
||||
use str::StrSlice;
|
||||
use kinds::marker;
|
||||
use slice::ImmutableVector;
|
||||
@ -637,7 +648,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_get_resource() {
|
||||
use rc::Rc;
|
||||
use realstd::rc::Rc;
|
||||
use cell::RefCell;
|
||||
|
||||
struct R {
|
||||
|
47
src/libcore/prelude.rs
Normal file
47
src/libcore/prelude.rs
Normal 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};
|
@ -480,12 +480,12 @@ impl<T> Ord for *mut T {
|
||||
#[cfg(test)]
|
||||
pub mod ptr_tests {
|
||||
use super::*;
|
||||
use prelude::*;
|
||||
use realstd::prelude::*;
|
||||
|
||||
use c_str::ToCStr;
|
||||
use realstd::c_str::ToCStr;
|
||||
use cast;
|
||||
use libc;
|
||||
use str;
|
||||
use realstd::str;
|
||||
use slice::{ImmutableVector, MutableVector};
|
||||
|
||||
#[test]
|
||||
|
@ -592,11 +592,9 @@ pub fn fold_<T,E,Iter:Iterator<Result<T,E>>>(iterator: Iter) -> Result<(),E> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use prelude::*;
|
||||
use str::StrSlice;
|
||||
|
||||
use iter::range;
|
||||
use realstd::result::{collect, fold, fold_};
|
||||
use realstd::prelude::*;
|
||||
use realstd::iter::range;
|
||||
|
||||
pub fn op1() -> Result<int, ~str> { Ok(666) }
|
||||
pub fn op2() -> Result<int, ~str> { Err("sadface".to_owned()) }
|
||||
|
@ -17,14 +17,16 @@ use intrinsics;
|
||||
use iter::{Iterator, FromIterator};
|
||||
use mem;
|
||||
use num::{CheckedMul, CheckedAdd};
|
||||
use ops::Add;
|
||||
use option::{Some, None};
|
||||
use ptr::RawPtr;
|
||||
use ptr;
|
||||
use raw::Vec;
|
||||
use slice::{ImmutableVector, Vector};
|
||||
use slice::ImmutableVector;
|
||||
use str::StrSlice;
|
||||
|
||||
#[cfg(not(test))] use ops::Add;
|
||||
#[cfg(not(test))] use slice::Vector;
|
||||
|
||||
#[allow(ctypes)]
|
||||
extern {
|
||||
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 {
|
||||
#[inline]
|
||||
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] {
|
||||
#[inline]
|
||||
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] {
|
||||
#[inline]
|
||||
fn add(&self, rhs: &V) -> ~[T] {
|
||||
|
@ -246,7 +246,7 @@ mod tests {
|
||||
use super::*;
|
||||
use clone::Clone;
|
||||
use cmp::*;
|
||||
use str::StrSlice;
|
||||
use realstd::str::StrAllocating;
|
||||
|
||||
#[test]
|
||||
fn test_clone() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user