1
Fork 0

libcore,std,syntax,rustc: move tests into mod tests, make them private (no pub mod or pub fn).

This commit is contained in:
Huon Wilson 2013-04-16 01:08:52 +10:00
parent f10cf26e25
commit d3be98e9f5
37 changed files with 1254 additions and 1227 deletions

View file

@ -277,45 +277,48 @@ pub mod raw {
pub unsafe fn reserve_at_least<T>(v: &mut @[T], n: uint) { pub unsafe fn reserve_at_least<T>(v: &mut @[T], n: uint) {
reserve(v, uint::next_power_of_two(n)); reserve(v, uint::next_power_of_two(n));
} }
} }
#[test] #[cfg(test)]
pub fn test() { mod test {
// Some code that could use that, then: use super::*;
fn seq_range(lo: uint, hi: uint) -> @[uint] {
do build |push| { #[test]
for uint::range(lo, hi) |i| { fn test() {
push(i); // Some code that could use that, then:
fn seq_range(lo: uint, hi: uint) -> @[uint] {
do build |push| {
for uint::range(lo, hi) |i| {
push(i);
}
} }
} }
assert_eq!(seq_range(10, 15), @[10, 11, 12, 13, 14]);
assert!(from_fn(5, |x| x+1) == @[1, 2, 3, 4, 5]);
assert!(from_elem(5, 3.14) == @[3.14, 3.14, 3.14, 3.14, 3.14]);
} }
assert_eq!(seq_range(10, 15), @[10, 11, 12, 13, 14]); #[test]
assert!(from_fn(5, |x| x+1) == @[1, 2, 3, 4, 5]); fn append_test() {
assert!(from_elem(5, 3.14) == @[3.14, 3.14, 3.14, 3.14, 3.14]); assert!(@[1,2,3] + @[4,5,6] == @[1,2,3,4,5,6]);
} }
#[test] #[test]
pub fn append_test() { fn test_from_owned() {
assert!(@[1,2,3] + @[4,5,6] == @[1,2,3,4,5,6]); assert!(from_owned::<int>(~[]) == @[]);
} assert!(from_owned(~[true]) == @[true]);
assert!(from_owned(~[1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
#[test] assert!(from_owned(~[~"abc", ~"123"]) == @[~"abc", ~"123"]);
pub fn test_from_owned() { assert!(from_owned(~[~[42]]) == @[~[42]]);
assert!(from_owned::<int>(~[]) == @[]); }
assert!(from_owned(~[true]) == @[true]);
assert!(from_owned(~[1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
assert!(from_owned(~[~"abc", ~"123"]) == @[~"abc", ~"123"]);
assert!(from_owned(~[~[42]]) == @[~[42]]);
}
#[test]
pub fn test_from_slice() {
assert!(from_slice::<int>([]) == @[]);
assert!(from_slice([true]) == @[true]);
assert!(from_slice([1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
assert!(from_slice([@"abc", @"123"]) == @[@"abc", @"123"]);
assert!(from_slice([@[42]]) == @[@[42]]);
}
#[test]
fn test_from_slice() {
assert!(from_slice::<int>([]) == @[]);
assert!(from_slice([true]) == @[true]);
assert!(from_slice([1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
assert!(from_slice([@"abc", @"123"]) == @[@"abc", @"123"]);
assert!(from_slice([@[42]]) == @[@[42]]);
}
}

View file

@ -111,16 +111,16 @@ pub unsafe fn copy_lifetime_vec<'a,S,T>(_ptr: &'a [S], ptr: &T) -> &'a T {
****************************************************************************/ ****************************************************************************/
#[cfg(test)] #[cfg(test)]
pub mod tests { mod tests {
use cast::{bump_box_refcount, reinterpret_cast, transmute}; use cast::{bump_box_refcount, reinterpret_cast, transmute};
#[test] #[test]
pub fn test_reinterpret_cast() { fn test_reinterpret_cast() {
assert!(1u == unsafe { reinterpret_cast(&1) }); assert!(1u == unsafe { reinterpret_cast(&1) });
} }
#[test] #[test]
pub fn test_bump_box_refcount() { fn test_bump_box_refcount() {
unsafe { unsafe {
let box = @~"box box box"; // refcount 1 let box = @~"box box box"; // refcount 1
bump_box_refcount(box); // refcount 2 bump_box_refcount(box); // refcount 2
@ -135,7 +135,7 @@ pub mod tests {
} }
#[test] #[test]
pub fn test_transmute() { fn test_transmute() {
use managed::raw::BoxRepr; use managed::raw::BoxRepr;
unsafe { unsafe {
let x = @100u8; let x = @100u8;
@ -146,7 +146,7 @@ pub mod tests {
} }
#[test] #[test]
pub fn test_transmute2() { fn test_transmute2() {
unsafe { unsafe {
assert!(~[76u8, 0u8] == transmute(~"L")); assert!(~[76u8, 0u8] == transmute(~"L"));
} }

View file

@ -426,12 +426,12 @@ pub fn try_send_one<T: Owned>(chan: ChanOne<T>, data: T)
} }
#[cfg(test)] #[cfg(test)]
pub mod test { mod test {
use either::Right; use either::Right;
use super::{Chan, Port, oneshot, recv_one, stream}; use super::{Chan, Port, oneshot, recv_one, stream};
#[test] #[test]
pub fn test_select2() { fn test_select2() {
let (p1, c1) = stream(); let (p1, c1) = stream();
let (p2, c2) = stream(); let (p2, c2) = stream();
@ -446,7 +446,7 @@ pub mod test {
} }
#[test] #[test]
pub fn test_oneshot() { fn test_oneshot() {
let (c, p) = oneshot::init(); let (c, p) = oneshot::init();
oneshot::client::send(c, ()); oneshot::client::send(c, ());

View file

@ -357,170 +357,176 @@ impl Streaming for SipState {
} }
} }
#[test] #[cfg(test)]
pub fn test_siphash() { mod tests {
let vecs : [[u8, ..8], ..64] = [ use super::*;
[ 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72, ], use prelude::*;
[ 0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74, ],
[ 0x5a, 0x4f, 0xa9, 0xd9, 0x09, 0x80, 0x6c, 0x0d, ],
[ 0x2d, 0x7e, 0xfb, 0xd7, 0x96, 0x66, 0x67, 0x85, ],
[ 0xb7, 0x87, 0x71, 0x27, 0xe0, 0x94, 0x27, 0xcf, ],
[ 0x8d, 0xa6, 0x99, 0xcd, 0x64, 0x55, 0x76, 0x18, ],
[ 0xce, 0xe3, 0xfe, 0x58, 0x6e, 0x46, 0xc9, 0xcb, ],
[ 0x37, 0xd1, 0x01, 0x8b, 0xf5, 0x00, 0x02, 0xab, ],
[ 0x62, 0x24, 0x93, 0x9a, 0x79, 0xf5, 0xf5, 0x93, ],
[ 0xb0, 0xe4, 0xa9, 0x0b, 0xdf, 0x82, 0x00, 0x9e, ],
[ 0xf3, 0xb9, 0xdd, 0x94, 0xc5, 0xbb, 0x5d, 0x7a, ],
[ 0xa7, 0xad, 0x6b, 0x22, 0x46, 0x2f, 0xb3, 0xf4, ],
[ 0xfb, 0xe5, 0x0e, 0x86, 0xbc, 0x8f, 0x1e, 0x75, ],
[ 0x90, 0x3d, 0x84, 0xc0, 0x27, 0x56, 0xea, 0x14, ],
[ 0xee, 0xf2, 0x7a, 0x8e, 0x90, 0xca, 0x23, 0xf7, ],
[ 0xe5, 0x45, 0xbe, 0x49, 0x61, 0xca, 0x29, 0xa1, ],
[ 0xdb, 0x9b, 0xc2, 0x57, 0x7f, 0xcc, 0x2a, 0x3f, ],
[ 0x94, 0x47, 0xbe, 0x2c, 0xf5, 0xe9, 0x9a, 0x69, ],
[ 0x9c, 0xd3, 0x8d, 0x96, 0xf0, 0xb3, 0xc1, 0x4b, ],
[ 0xbd, 0x61, 0x79, 0xa7, 0x1d, 0xc9, 0x6d, 0xbb, ],
[ 0x98, 0xee, 0xa2, 0x1a, 0xf2, 0x5c, 0xd6, 0xbe, ],
[ 0xc7, 0x67, 0x3b, 0x2e, 0xb0, 0xcb, 0xf2, 0xd0, ],
[ 0x88, 0x3e, 0xa3, 0xe3, 0x95, 0x67, 0x53, 0x93, ],
[ 0xc8, 0xce, 0x5c, 0xcd, 0x8c, 0x03, 0x0c, 0xa8, ],
[ 0x94, 0xaf, 0x49, 0xf6, 0xc6, 0x50, 0xad, 0xb8, ],
[ 0xea, 0xb8, 0x85, 0x8a, 0xde, 0x92, 0xe1, 0xbc, ],
[ 0xf3, 0x15, 0xbb, 0x5b, 0xb8, 0x35, 0xd8, 0x17, ],
[ 0xad, 0xcf, 0x6b, 0x07, 0x63, 0x61, 0x2e, 0x2f, ],
[ 0xa5, 0xc9, 0x1d, 0xa7, 0xac, 0xaa, 0x4d, 0xde, ],
[ 0x71, 0x65, 0x95, 0x87, 0x66, 0x50, 0xa2, 0xa6, ],
[ 0x28, 0xef, 0x49, 0x5c, 0x53, 0xa3, 0x87, 0xad, ],
[ 0x42, 0xc3, 0x41, 0xd8, 0xfa, 0x92, 0xd8, 0x32, ],
[ 0xce, 0x7c, 0xf2, 0x72, 0x2f, 0x51, 0x27, 0x71, ],
[ 0xe3, 0x78, 0x59, 0xf9, 0x46, 0x23, 0xf3, 0xa7, ],
[ 0x38, 0x12, 0x05, 0xbb, 0x1a, 0xb0, 0xe0, 0x12, ],
[ 0xae, 0x97, 0xa1, 0x0f, 0xd4, 0x34, 0xe0, 0x15, ],
[ 0xb4, 0xa3, 0x15, 0x08, 0xbe, 0xff, 0x4d, 0x31, ],
[ 0x81, 0x39, 0x62, 0x29, 0xf0, 0x90, 0x79, 0x02, ],
[ 0x4d, 0x0c, 0xf4, 0x9e, 0xe5, 0xd4, 0xdc, 0xca, ],
[ 0x5c, 0x73, 0x33, 0x6a, 0x76, 0xd8, 0xbf, 0x9a, ],
[ 0xd0, 0xa7, 0x04, 0x53, 0x6b, 0xa9, 0x3e, 0x0e, ],
[ 0x92, 0x59, 0x58, 0xfc, 0xd6, 0x42, 0x0c, 0xad, ],
[ 0xa9, 0x15, 0xc2, 0x9b, 0xc8, 0x06, 0x73, 0x18, ],
[ 0x95, 0x2b, 0x79, 0xf3, 0xbc, 0x0a, 0xa6, 0xd4, ],
[ 0xf2, 0x1d, 0xf2, 0xe4, 0x1d, 0x45, 0x35, 0xf9, ],
[ 0x87, 0x57, 0x75, 0x19, 0x04, 0x8f, 0x53, 0xa9, ],
[ 0x10, 0xa5, 0x6c, 0xf5, 0xdf, 0xcd, 0x9a, 0xdb, ],
[ 0xeb, 0x75, 0x09, 0x5c, 0xcd, 0x98, 0x6c, 0xd0, ],
[ 0x51, 0xa9, 0xcb, 0x9e, 0xcb, 0xa3, 0x12, 0xe6, ],
[ 0x96, 0xaf, 0xad, 0xfc, 0x2c, 0xe6, 0x66, 0xc7, ],
[ 0x72, 0xfe, 0x52, 0x97, 0x5a, 0x43, 0x64, 0xee, ],
[ 0x5a, 0x16, 0x45, 0xb2, 0x76, 0xd5, 0x92, 0xa1, ],
[ 0xb2, 0x74, 0xcb, 0x8e, 0xbf, 0x87, 0x87, 0x0a, ],
[ 0x6f, 0x9b, 0xb4, 0x20, 0x3d, 0xe7, 0xb3, 0x81, ],
[ 0xea, 0xec, 0xb2, 0xa3, 0x0b, 0x22, 0xa8, 0x7f, ],
[ 0x99, 0x24, 0xa4, 0x3c, 0xc1, 0x31, 0x57, 0x24, ],
[ 0xbd, 0x83, 0x8d, 0x3a, 0xaf, 0xbf, 0x8d, 0xb7, ],
[ 0x0b, 0x1a, 0x2a, 0x32, 0x65, 0xd5, 0x1a, 0xea, ],
[ 0x13, 0x50, 0x79, 0xa3, 0x23, 0x1c, 0xe6, 0x60, ],
[ 0x93, 0x2b, 0x28, 0x46, 0xe4, 0xd7, 0x06, 0x66, ],
[ 0xe1, 0x91, 0x5f, 0x5c, 0xb1, 0xec, 0xa4, 0x6c, ],
[ 0xf3, 0x25, 0x96, 0x5c, 0xa1, 0x6d, 0x62, 0x9f, ],
[ 0x57, 0x5f, 0xf2, 0x8e, 0x60, 0x38, 0x1b, 0xe5, ],
[ 0x72, 0x45, 0x06, 0xeb, 0x4c, 0x32, 0x8a, 0x95, ]
];
let k0 = 0x_07_06_05_04_03_02_01_00_u64; #[test]
let k1 = 0x_0f_0e_0d_0c_0b_0a_09_08_u64; fn test_siphash() {
let mut buf : ~[u8] = ~[]; let vecs : [[u8, ..8], ..64] = [
let mut t = 0; [ 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72, ],
let stream_inc = &State(k0,k1); [ 0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74, ],
let stream_full = &State(k0,k1); [ 0x5a, 0x4f, 0xa9, 0xd9, 0x09, 0x80, 0x6c, 0x0d, ],
[ 0x2d, 0x7e, 0xfb, 0xd7, 0x96, 0x66, 0x67, 0x85, ],
[ 0xb7, 0x87, 0x71, 0x27, 0xe0, 0x94, 0x27, 0xcf, ],
[ 0x8d, 0xa6, 0x99, 0xcd, 0x64, 0x55, 0x76, 0x18, ],
[ 0xce, 0xe3, 0xfe, 0x58, 0x6e, 0x46, 0xc9, 0xcb, ],
[ 0x37, 0xd1, 0x01, 0x8b, 0xf5, 0x00, 0x02, 0xab, ],
[ 0x62, 0x24, 0x93, 0x9a, 0x79, 0xf5, 0xf5, 0x93, ],
[ 0xb0, 0xe4, 0xa9, 0x0b, 0xdf, 0x82, 0x00, 0x9e, ],
[ 0xf3, 0xb9, 0xdd, 0x94, 0xc5, 0xbb, 0x5d, 0x7a, ],
[ 0xa7, 0xad, 0x6b, 0x22, 0x46, 0x2f, 0xb3, 0xf4, ],
[ 0xfb, 0xe5, 0x0e, 0x86, 0xbc, 0x8f, 0x1e, 0x75, ],
[ 0x90, 0x3d, 0x84, 0xc0, 0x27, 0x56, 0xea, 0x14, ],
[ 0xee, 0xf2, 0x7a, 0x8e, 0x90, 0xca, 0x23, 0xf7, ],
[ 0xe5, 0x45, 0xbe, 0x49, 0x61, 0xca, 0x29, 0xa1, ],
[ 0xdb, 0x9b, 0xc2, 0x57, 0x7f, 0xcc, 0x2a, 0x3f, ],
[ 0x94, 0x47, 0xbe, 0x2c, 0xf5, 0xe9, 0x9a, 0x69, ],
[ 0x9c, 0xd3, 0x8d, 0x96, 0xf0, 0xb3, 0xc1, 0x4b, ],
[ 0xbd, 0x61, 0x79, 0xa7, 0x1d, 0xc9, 0x6d, 0xbb, ],
[ 0x98, 0xee, 0xa2, 0x1a, 0xf2, 0x5c, 0xd6, 0xbe, ],
[ 0xc7, 0x67, 0x3b, 0x2e, 0xb0, 0xcb, 0xf2, 0xd0, ],
[ 0x88, 0x3e, 0xa3, 0xe3, 0x95, 0x67, 0x53, 0x93, ],
[ 0xc8, 0xce, 0x5c, 0xcd, 0x8c, 0x03, 0x0c, 0xa8, ],
[ 0x94, 0xaf, 0x49, 0xf6, 0xc6, 0x50, 0xad, 0xb8, ],
[ 0xea, 0xb8, 0x85, 0x8a, 0xde, 0x92, 0xe1, 0xbc, ],
[ 0xf3, 0x15, 0xbb, 0x5b, 0xb8, 0x35, 0xd8, 0x17, ],
[ 0xad, 0xcf, 0x6b, 0x07, 0x63, 0x61, 0x2e, 0x2f, ],
[ 0xa5, 0xc9, 0x1d, 0xa7, 0xac, 0xaa, 0x4d, 0xde, ],
[ 0x71, 0x65, 0x95, 0x87, 0x66, 0x50, 0xa2, 0xa6, ],
[ 0x28, 0xef, 0x49, 0x5c, 0x53, 0xa3, 0x87, 0xad, ],
[ 0x42, 0xc3, 0x41, 0xd8, 0xfa, 0x92, 0xd8, 0x32, ],
[ 0xce, 0x7c, 0xf2, 0x72, 0x2f, 0x51, 0x27, 0x71, ],
[ 0xe3, 0x78, 0x59, 0xf9, 0x46, 0x23, 0xf3, 0xa7, ],
[ 0x38, 0x12, 0x05, 0xbb, 0x1a, 0xb0, 0xe0, 0x12, ],
[ 0xae, 0x97, 0xa1, 0x0f, 0xd4, 0x34, 0xe0, 0x15, ],
[ 0xb4, 0xa3, 0x15, 0x08, 0xbe, 0xff, 0x4d, 0x31, ],
[ 0x81, 0x39, 0x62, 0x29, 0xf0, 0x90, 0x79, 0x02, ],
[ 0x4d, 0x0c, 0xf4, 0x9e, 0xe5, 0xd4, 0xdc, 0xca, ],
[ 0x5c, 0x73, 0x33, 0x6a, 0x76, 0xd8, 0xbf, 0x9a, ],
[ 0xd0, 0xa7, 0x04, 0x53, 0x6b, 0xa9, 0x3e, 0x0e, ],
[ 0x92, 0x59, 0x58, 0xfc, 0xd6, 0x42, 0x0c, 0xad, ],
[ 0xa9, 0x15, 0xc2, 0x9b, 0xc8, 0x06, 0x73, 0x18, ],
[ 0x95, 0x2b, 0x79, 0xf3, 0xbc, 0x0a, 0xa6, 0xd4, ],
[ 0xf2, 0x1d, 0xf2, 0xe4, 0x1d, 0x45, 0x35, 0xf9, ],
[ 0x87, 0x57, 0x75, 0x19, 0x04, 0x8f, 0x53, 0xa9, ],
[ 0x10, 0xa5, 0x6c, 0xf5, 0xdf, 0xcd, 0x9a, 0xdb, ],
[ 0xeb, 0x75, 0x09, 0x5c, 0xcd, 0x98, 0x6c, 0xd0, ],
[ 0x51, 0xa9, 0xcb, 0x9e, 0xcb, 0xa3, 0x12, 0xe6, ],
[ 0x96, 0xaf, 0xad, 0xfc, 0x2c, 0xe6, 0x66, 0xc7, ],
[ 0x72, 0xfe, 0x52, 0x97, 0x5a, 0x43, 0x64, 0xee, ],
[ 0x5a, 0x16, 0x45, 0xb2, 0x76, 0xd5, 0x92, 0xa1, ],
[ 0xb2, 0x74, 0xcb, 0x8e, 0xbf, 0x87, 0x87, 0x0a, ],
[ 0x6f, 0x9b, 0xb4, 0x20, 0x3d, 0xe7, 0xb3, 0x81, ],
[ 0xea, 0xec, 0xb2, 0xa3, 0x0b, 0x22, 0xa8, 0x7f, ],
[ 0x99, 0x24, 0xa4, 0x3c, 0xc1, 0x31, 0x57, 0x24, ],
[ 0xbd, 0x83, 0x8d, 0x3a, 0xaf, 0xbf, 0x8d, 0xb7, ],
[ 0x0b, 0x1a, 0x2a, 0x32, 0x65, 0xd5, 0x1a, 0xea, ],
[ 0x13, 0x50, 0x79, 0xa3, 0x23, 0x1c, 0xe6, 0x60, ],
[ 0x93, 0x2b, 0x28, 0x46, 0xe4, 0xd7, 0x06, 0x66, ],
[ 0xe1, 0x91, 0x5f, 0x5c, 0xb1, 0xec, 0xa4, 0x6c, ],
[ 0xf3, 0x25, 0x96, 0x5c, 0xa1, 0x6d, 0x62, 0x9f, ],
[ 0x57, 0x5f, 0xf2, 0x8e, 0x60, 0x38, 0x1b, 0xe5, ],
[ 0x72, 0x45, 0x06, 0xeb, 0x4c, 0x32, 0x8a, 0x95, ]
];
fn to_hex_str(r: &[u8, ..8]) -> ~str { let k0 = 0x_07_06_05_04_03_02_01_00_u64;
let mut s = ~""; let k1 = 0x_0f_0e_0d_0c_0b_0a_09_08_u64;
for vec::each(*r) |b| { let mut buf : ~[u8] = ~[];
s += uint::to_str_radix(*b as uint, 16u); let mut t = 0;
let stream_inc = &State(k0,k1);
let stream_full = &State(k0,k1);
fn to_hex_str(r: &[u8, ..8]) -> ~str {
let mut s = ~"";
for vec::each(*r) |b| {
s += uint::to_str_radix(*b as uint, 16u);
}
s
}
while t < 64 {
debug!("siphash test %?", t);
let vec = u8to64_le!(vecs[t], 0);
let out = buf.hash_keyed(k0, k1);
debug!("got %?, expected %?", out, vec);
assert!(vec == out);
stream_full.reset();
stream_full.input(buf);
let f = stream_full.result_str();
let i = stream_inc.result_str();
let v = to_hex_str(&vecs[t]);
debug!("%d: (%s) => inc=%s full=%s", t, v, i, f);
assert!(f == i && f == v);
buf += ~[t as u8];
stream_inc.input(~[t as u8]);
t += 1;
} }
s
} }
while t < 64 { #[test] #[cfg(target_arch = "arm")]
debug!("siphash test %?", t); fn test_hash_uint() {
let vec = u8to64_le!(vecs[t], 0); let val = 0xdeadbeef_deadbeef_u64;
let out = buf.hash_keyed(k0, k1); assert!((val as u64).hash() != (val as uint).hash());
debug!("got %?, expected %?", out, vec); assert!((val as u32).hash() == (val as uint).hash());
assert!(vec == out);
stream_full.reset();
stream_full.input(buf);
let f = stream_full.result_str();
let i = stream_inc.result_str();
let v = to_hex_str(&vecs[t]);
debug!("%d: (%s) => inc=%s full=%s", t, v, i, f);
assert!(f == i && f == v);
buf += ~[t as u8];
stream_inc.input(~[t as u8]);
t += 1;
} }
} #[test] #[cfg(target_arch = "x86_64")]
fn test_hash_uint() {
#[test] #[cfg(target_arch = "arm")] let val = 0xdeadbeef_deadbeef_u64;
pub fn test_hash_uint() { assert!((val as u64).hash() == (val as uint).hash());
let val = 0xdeadbeef_deadbeef_u64; assert!((val as u32).hash() != (val as uint).hash());
assert!((val as u64).hash() != (val as uint).hash());
assert!((val as u32).hash() == (val as uint).hash());
}
#[test] #[cfg(target_arch = "x86_64")]
pub fn test_hash_uint() {
let val = 0xdeadbeef_deadbeef_u64;
assert!((val as u64).hash() == (val as uint).hash());
assert!((val as u32).hash() != (val as uint).hash());
}
#[test] #[cfg(target_arch = "x86")]
pub fn test_hash_uint() {
let val = 0xdeadbeef_deadbeef_u64;
assert!((val as u64).hash() != (val as uint).hash());
assert!((val as u32).hash() == (val as uint).hash());
}
#[test]
pub fn test_hash_idempotent() {
let val64 = 0xdeadbeef_deadbeef_u64;
val64.hash() == val64.hash();
let val32 = 0xdeadbeef_u32;
val32.hash() == val32.hash();
}
#[test]
pub fn test_hash_no_bytes_dropped_64() {
let val = 0xdeadbeef_deadbeef_u64;
assert!(val.hash() != zero_byte(val, 0).hash());
assert!(val.hash() != zero_byte(val, 1).hash());
assert!(val.hash() != zero_byte(val, 2).hash());
assert!(val.hash() != zero_byte(val, 3).hash());
assert!(val.hash() != zero_byte(val, 4).hash());
assert!(val.hash() != zero_byte(val, 5).hash());
assert!(val.hash() != zero_byte(val, 6).hash());
assert!(val.hash() != zero_byte(val, 7).hash());
fn zero_byte(val: u64, byte: uint) -> u64 {
assert!(byte < 8);
val & !(0xff << (byte * 8))
} }
} #[test] #[cfg(target_arch = "x86")]
fn test_hash_uint() {
#[test] let val = 0xdeadbeef_deadbeef_u64;
pub fn test_hash_no_bytes_dropped_32() { assert!((val as u64).hash() != (val as uint).hash());
let val = 0xdeadbeef_u32; assert!((val as u32).hash() == (val as uint).hash());
assert!(val.hash() != zero_byte(val, 0).hash());
assert!(val.hash() != zero_byte(val, 1).hash());
assert!(val.hash() != zero_byte(val, 2).hash());
assert!(val.hash() != zero_byte(val, 3).hash());
fn zero_byte(val: u32, byte: uint) -> u32 {
assert!(byte < 4);
val & !(0xff << (byte * 8))
} }
}
#[test]
fn test_hash_idempotent() {
let val64 = 0xdeadbeef_deadbeef_u64;
val64.hash() == val64.hash();
let val32 = 0xdeadbeef_u32;
val32.hash() == val32.hash();
}
#[test]
fn test_hash_no_bytes_dropped_64() {
let val = 0xdeadbeef_deadbeef_u64;
assert!(val.hash() != zero_byte(val, 0).hash());
assert!(val.hash() != zero_byte(val, 1).hash());
assert!(val.hash() != zero_byte(val, 2).hash());
assert!(val.hash() != zero_byte(val, 3).hash());
assert!(val.hash() != zero_byte(val, 4).hash());
assert!(val.hash() != zero_byte(val, 5).hash());
assert!(val.hash() != zero_byte(val, 6).hash());
assert!(val.hash() != zero_byte(val, 7).hash());
fn zero_byte(val: u64, byte: uint) -> u64 {
assert!(byte < 8);
val & !(0xff << (byte * 8))
}
}
#[test]
fn test_hash_no_bytes_dropped_32() {
let val = 0xdeadbeef_u32;
assert!(val.hash() != zero_byte(val, 0).hash());
assert!(val.hash() != zero_byte(val, 1).hash());
assert!(val.hash() != zero_byte(val, 2).hash());
assert!(val.hash() != zero_byte(val, 3).hash());
fn zero_byte(val: u32, byte: uint) -> u32 {
assert!(byte < 4);
val & !(0xff << (byte * 8))
}
}
}

View file

@ -847,7 +847,7 @@ mod test_map {
use uint; use uint;
#[test] #[test]
pub fn test_insert() { fn test_insert() {
let mut m = HashMap::new(); let mut m = HashMap::new();
assert!(m.insert(1, 2)); assert!(m.insert(1, 2));
assert!(m.insert(2, 4)); assert!(m.insert(2, 4));
@ -869,7 +869,7 @@ mod test_map {
} }
#[test] #[test]
pub fn test_insert_overwrite() { fn test_insert_overwrite() {
let mut m = HashMap::new(); let mut m = HashMap::new();
assert!(m.insert(1, 2)); assert!(m.insert(1, 2));
assert!(*m.get(&1) == 2); assert!(*m.get(&1) == 2);
@ -878,7 +878,7 @@ mod test_map {
} }
#[test] #[test]
pub fn test_insert_conflicts() { fn test_insert_conflicts() {
let mut m = linear_map_with_capacity(4); let mut m = linear_map_with_capacity(4);
assert!(m.insert(1, 2)); assert!(m.insert(1, 2));
assert!(m.insert(5, 3)); assert!(m.insert(5, 3));
@ -889,7 +889,7 @@ mod test_map {
} }
#[test] #[test]
pub fn test_conflict_remove() { fn test_conflict_remove() {
let mut m = linear_map_with_capacity(4); let mut m = linear_map_with_capacity(4);
assert!(m.insert(1, 2)); assert!(m.insert(1, 2));
assert!(m.insert(5, 3)); assert!(m.insert(5, 3));
@ -900,7 +900,7 @@ mod test_map {
} }
#[test] #[test]
pub fn test_is_empty() { fn test_is_empty() {
let mut m = linear_map_with_capacity(4); let mut m = linear_map_with_capacity(4);
assert!(m.insert(1, 2)); assert!(m.insert(1, 2));
assert!(!m.is_empty()); assert!(!m.is_empty());
@ -909,7 +909,7 @@ mod test_map {
} }
#[test] #[test]
pub fn test_pop() { fn test_pop() {
let mut m = HashMap::new(); let mut m = HashMap::new();
m.insert(1, 2); m.insert(1, 2);
assert!(m.pop(&1) == Some(2)); assert!(m.pop(&1) == Some(2));
@ -917,7 +917,7 @@ mod test_map {
} }
#[test] #[test]
pub fn test_swap() { fn test_swap() {
let mut m = HashMap::new(); let mut m = HashMap::new();
assert!(m.swap(1, 2) == None); assert!(m.swap(1, 2) == None);
assert!(m.swap(1, 3) == Some(2)); assert!(m.swap(1, 3) == Some(2));
@ -925,21 +925,21 @@ mod test_map {
} }
#[test] #[test]
pub fn test_find_or_insert() { fn test_find_or_insert() {
let mut m = HashMap::new::<int, int>(); let mut m = HashMap::new::<int, int>();
assert!(m.find_or_insert(1, 2) == &2); assert!(m.find_or_insert(1, 2) == &2);
assert!(m.find_or_insert(1, 3) == &2); assert!(m.find_or_insert(1, 3) == &2);
} }
#[test] #[test]
pub fn test_find_or_insert_with() { fn test_find_or_insert_with() {
let mut m = HashMap::new::<int, int>(); let mut m = HashMap::new::<int, int>();
assert!(m.find_or_insert_with(1, |_| 2) == &2); assert!(m.find_or_insert_with(1, |_| 2) == &2);
assert!(m.find_or_insert_with(1, |_| 3) == &2); assert!(m.find_or_insert_with(1, |_| 3) == &2);
} }
#[test] #[test]
pub fn test_consume() { fn test_consume() {
let mut m = HashMap::new(); let mut m = HashMap::new();
assert!(m.insert(1, 2)); assert!(m.insert(1, 2));
assert!(m.insert(2, 3)); assert!(m.insert(2, 3));
@ -954,7 +954,7 @@ mod test_map {
} }
#[test] #[test]
pub fn test_iterate() { fn test_iterate() {
let mut m = linear_map_with_capacity(4); let mut m = linear_map_with_capacity(4);
for uint::range(0, 32) |i| { for uint::range(0, 32) |i| {
assert!(m.insert(i, i*2)); assert!(m.insert(i, i*2));
@ -968,7 +968,7 @@ mod test_map {
} }
#[test] #[test]
pub fn test_find() { fn test_find() {
let mut m = HashMap::new(); let mut m = HashMap::new();
assert!(m.find(&1).is_none()); assert!(m.find(&1).is_none());
m.insert(1, 2); m.insert(1, 2);
@ -979,7 +979,7 @@ mod test_map {
} }
#[test] #[test]
pub fn test_eq() { fn test_eq() {
let mut m1 = HashMap::new(); let mut m1 = HashMap::new();
m1.insert(1, 2); m1.insert(1, 2);
m1.insert(2, 3); m1.insert(2, 3);
@ -997,7 +997,7 @@ mod test_map {
} }
#[test] #[test]
pub fn test_expand() { fn test_expand() {
let mut m = HashMap::new(); let mut m = HashMap::new();
assert!(m.len() == 0); assert!(m.len() == 0);

View file

@ -29,7 +29,6 @@ use from_str;
#[cfg(notest)] use cmp::{Eq, Ord}; #[cfg(notest)] use cmp::{Eq, Ord};
#[cfg(notest)] use ops; #[cfg(notest)] use ops;
#[cfg(test)] use option::{Some, None};
pub use f64::{add, sub, mul, div, rem, lt, le, eq, ne, ge, gt}; pub use f64::{add, sub, mul, div, rem, lt, le, eq, ne, ge, gt};
pub use f64::logarithm; pub use f64::logarithm;
@ -142,7 +141,7 @@ pub fn to_str_radix(num: float, radix: uint) -> ~str {
let (r, special) = strconv::to_str_common( let (r, special) = strconv::to_str_common(
&num, radix, true, strconv::SignNeg, strconv::DigAll); &num, radix, true, strconv::SignNeg, strconv::DigAll);
if special { fail!(~"number has a special value, \ if special { fail!(~"number has a special value, \
try to_str_radix_special() if those are expected") } try to_str_radix_special() if those are expected") }
r r
} }
@ -177,12 +176,6 @@ pub fn to_str_exact(num: float, digits: uint) -> ~str {
r r
} }
#[test]
pub fn test_to_str_exact_do_decimal() {
let s = to_str_exact(5.0, 4u);
assert!(s == ~"5.0000");
}
/** /**
* Converts a float to a string with a maximum number of * Converts a float to a string with a maximum number of
* significant digits * significant digits
@ -474,196 +467,206 @@ impl ops::Neg<float> for float {
fn neg(&self) -> float { -*self } fn neg(&self) -> float { -*self }
} }
#[test] #[cfg(test)]
pub fn test_from_str() { mod tests {
assert!(from_str(~"3") == Some(3.)); use super::*;
assert!(from_str(~"3.14") == Some(3.14)); use prelude::*;
assert!(from_str(~"+3.14") == Some(3.14)); #[test]
assert!(from_str(~"-3.14") == Some(-3.14)); pub fn test_to_str_exact_do_decimal() {
assert!(from_str(~"2.5E10") == Some(25000000000.)); let s = to_str_exact(5.0, 4u);
assert!(from_str(~"2.5e10") == Some(25000000000.)); assert!(s == ~"5.0000");
assert!(from_str(~"25000000000.E-10") == Some(2.5)); }
assert!(from_str(~".") == Some(0.));
assert!(from_str(~".e1") == Some(0.));
assert!(from_str(~".e-1") == Some(0.));
assert!(from_str(~"5.") == Some(5.));
assert!(from_str(~".5") == Some(0.5));
assert!(from_str(~"0.5") == Some(0.5));
assert!(from_str(~"-.5") == Some(-0.5));
assert!(from_str(~"-5") == Some(-5.));
assert!(from_str(~"inf") == Some(infinity));
assert!(from_str(~"+inf") == Some(infinity));
assert!(from_str(~"-inf") == Some(neg_infinity));
// note: NaN != NaN, hence this slightly complex test
match from_str(~"NaN") {
Some(f) => assert!(is_NaN(f)),
None => fail!()
}
// note: -0 == 0, hence these slightly more complex tests
match from_str(~"-0") {
Some(v) if is_zero(v) => assert!(is_negative(v)),
_ => fail!()
}
match from_str(~"0") {
Some(v) if is_zero(v) => assert!(is_positive(v)),
_ => fail!()
}
assert!(from_str(~"").is_none()); #[test]
assert!(from_str(~"x").is_none()); pub fn test_from_str() {
assert!(from_str(~" ").is_none()); assert!(from_str(~"3") == Some(3.));
assert!(from_str(~" ").is_none()); assert!(from_str(~"3.14") == Some(3.14));
assert!(from_str(~"e").is_none()); assert!(from_str(~"+3.14") == Some(3.14));
assert!(from_str(~"E").is_none()); assert!(from_str(~"-3.14") == Some(-3.14));
assert!(from_str(~"E1").is_none()); assert!(from_str(~"2.5E10") == Some(25000000000.));
assert!(from_str(~"1e1e1").is_none()); assert!(from_str(~"2.5e10") == Some(25000000000.));
assert!(from_str(~"1e1.1").is_none()); assert!(from_str(~"25000000000.E-10") == Some(2.5));
assert!(from_str(~"1e1-1").is_none()); assert!(from_str(~".") == Some(0.));
assert!(from_str(~".e1") == Some(0.));
assert!(from_str(~".e-1") == Some(0.));
assert!(from_str(~"5.") == Some(5.));
assert!(from_str(~".5") == Some(0.5));
assert!(from_str(~"0.5") == Some(0.5));
assert!(from_str(~"-.5") == Some(-0.5));
assert!(from_str(~"-5") == Some(-5.));
assert!(from_str(~"inf") == Some(infinity));
assert!(from_str(~"+inf") == Some(infinity));
assert!(from_str(~"-inf") == Some(neg_infinity));
// note: NaN != NaN, hence this slightly complex test
match from_str(~"NaN") {
Some(f) => assert!(is_NaN(f)),
None => fail!()
}
// note: -0 == 0, hence these slightly more complex tests
match from_str(~"-0") {
Some(v) if is_zero(v) => assert!(is_negative(v)),
_ => fail!()
}
match from_str(~"0") {
Some(v) if is_zero(v) => assert!(is_positive(v)),
_ => fail!()
}
assert!(from_str(~"").is_none());
assert!(from_str(~"x").is_none());
assert!(from_str(~" ").is_none());
assert!(from_str(~" ").is_none());
assert!(from_str(~"e").is_none());
assert!(from_str(~"E").is_none());
assert!(from_str(~"E1").is_none());
assert!(from_str(~"1e1e1").is_none());
assert!(from_str(~"1e1.1").is_none());
assert!(from_str(~"1e1-1").is_none());
}
#[test]
pub fn test_from_str_hex() {
assert!(from_str_hex(~"a4") == Some(164.));
assert!(from_str_hex(~"a4.fe") == Some(164.9921875));
assert!(from_str_hex(~"-a4.fe") == Some(-164.9921875));
assert!(from_str_hex(~"+a4.fe") == Some(164.9921875));
assert!(from_str_hex(~"ff0P4") == Some(0xff00 as float));
assert!(from_str_hex(~"ff0p4") == Some(0xff00 as float));
assert!(from_str_hex(~"ff0p-4") == Some(0xff as float));
assert!(from_str_hex(~".") == Some(0.));
assert!(from_str_hex(~".p1") == Some(0.));
assert!(from_str_hex(~".p-1") == Some(0.));
assert!(from_str_hex(~"f.") == Some(15.));
assert!(from_str_hex(~".f") == Some(0.9375));
assert!(from_str_hex(~"0.f") == Some(0.9375));
assert!(from_str_hex(~"-.f") == Some(-0.9375));
assert!(from_str_hex(~"-f") == Some(-15.));
assert!(from_str_hex(~"inf") == Some(infinity));
assert!(from_str_hex(~"+inf") == Some(infinity));
assert!(from_str_hex(~"-inf") == Some(neg_infinity));
// note: NaN != NaN, hence this slightly complex test
match from_str_hex(~"NaN") {
Some(f) => assert!(is_NaN(f)),
None => fail!()
}
// note: -0 == 0, hence these slightly more complex tests
match from_str_hex(~"-0") {
Some(v) if is_zero(v) => assert!(is_negative(v)),
_ => fail!()
}
match from_str_hex(~"0") {
Some(v) if is_zero(v) => assert!(is_positive(v)),
_ => fail!()
}
assert!(from_str_hex(~"e") == Some(14.));
assert!(from_str_hex(~"E") == Some(14.));
assert!(from_str_hex(~"E1") == Some(225.));
assert!(from_str_hex(~"1e1e1") == Some(123361.));
assert!(from_str_hex(~"1e1.1") == Some(481.0625));
assert!(from_str_hex(~"").is_none());
assert!(from_str_hex(~"x").is_none());
assert!(from_str_hex(~" ").is_none());
assert!(from_str_hex(~" ").is_none());
assert!(from_str_hex(~"p").is_none());
assert!(from_str_hex(~"P").is_none());
assert!(from_str_hex(~"P1").is_none());
assert!(from_str_hex(~"1p1p1").is_none());
assert!(from_str_hex(~"1p1.1").is_none());
assert!(from_str_hex(~"1p1-1").is_none());
}
#[test]
pub fn test_to_str_hex() {
assert!(to_str_hex(164.) == ~"a4");
assert!(to_str_hex(164.9921875) == ~"a4.fe");
assert!(to_str_hex(-164.9921875) == ~"-a4.fe");
assert!(to_str_hex(0xff00 as float) == ~"ff00");
assert!(to_str_hex(-(0xff00 as float)) == ~"-ff00");
assert!(to_str_hex(0.) == ~"0");
assert!(to_str_hex(15.) == ~"f");
assert!(to_str_hex(-15.) == ~"-f");
assert!(to_str_hex(0.9375) == ~"0.f");
assert!(to_str_hex(-0.9375) == ~"-0.f");
assert!(to_str_hex(infinity) == ~"inf");
assert!(to_str_hex(neg_infinity) == ~"-inf");
assert!(to_str_hex(NaN) == ~"NaN");
assert!(to_str_hex(0.) == ~"0");
assert!(to_str_hex(-0.) == ~"-0");
}
#[test]
pub fn test_to_str_radix() {
assert!(to_str_radix(36., 36u) == ~"10");
assert!(to_str_radix(8.125, 2u) == ~"1000.001");
}
#[test]
pub fn test_from_str_radix() {
assert!(from_str_radix(~"10", 36u) == Some(36.));
assert!(from_str_radix(~"1000.001", 2u) == Some(8.125));
}
#[test]
pub fn test_positive() {
assert!((is_positive(infinity)));
assert!((is_positive(1.)));
assert!((is_positive(0.)));
assert!((!is_positive(-1.)));
assert!((!is_positive(neg_infinity)));
assert!((!is_positive(1./neg_infinity)));
assert!((!is_positive(NaN)));
}
#[test]
pub fn test_negative() {
assert!((!is_negative(infinity)));
assert!((!is_negative(1.)));
assert!((!is_negative(0.)));
assert!((is_negative(-1.)));
assert!((is_negative(neg_infinity)));
assert!((is_negative(1./neg_infinity)));
assert!((!is_negative(NaN)));
}
#[test]
pub fn test_nonpositive() {
assert!((!is_nonpositive(infinity)));
assert!((!is_nonpositive(1.)));
assert!((!is_nonpositive(0.)));
assert!((is_nonpositive(-1.)));
assert!((is_nonpositive(neg_infinity)));
assert!((is_nonpositive(1./neg_infinity)));
assert!((!is_nonpositive(NaN)));
}
#[test]
pub fn test_nonnegative() {
assert!((is_nonnegative(infinity)));
assert!((is_nonnegative(1.)));
assert!((is_nonnegative(0.)));
assert!((!is_nonnegative(-1.)));
assert!((!is_nonnegative(neg_infinity)));
assert!((!is_nonnegative(1./neg_infinity)));
assert!((!is_nonnegative(NaN)));
}
#[test]
pub fn test_to_str_inf() {
assert!(to_str_digits(infinity, 10u) == ~"inf");
assert!(to_str_digits(-infinity, 10u) == ~"-inf");
}
#[test]
pub fn test_round() {
assert!(round(5.8) == 6.0);
assert!(round(5.2) == 5.0);
assert!(round(3.0) == 3.0);
assert!(round(2.5) == 3.0);
assert!(round(-3.5) == -4.0);
}
} }
#[test]
pub fn test_from_str_hex() {
assert!(from_str_hex(~"a4") == Some(164.));
assert!(from_str_hex(~"a4.fe") == Some(164.9921875));
assert!(from_str_hex(~"-a4.fe") == Some(-164.9921875));
assert!(from_str_hex(~"+a4.fe") == Some(164.9921875));
assert!(from_str_hex(~"ff0P4") == Some(0xff00 as float));
assert!(from_str_hex(~"ff0p4") == Some(0xff00 as float));
assert!(from_str_hex(~"ff0p-4") == Some(0xff as float));
assert!(from_str_hex(~".") == Some(0.));
assert!(from_str_hex(~".p1") == Some(0.));
assert!(from_str_hex(~".p-1") == Some(0.));
assert!(from_str_hex(~"f.") == Some(15.));
assert!(from_str_hex(~".f") == Some(0.9375));
assert!(from_str_hex(~"0.f") == Some(0.9375));
assert!(from_str_hex(~"-.f") == Some(-0.9375));
assert!(from_str_hex(~"-f") == Some(-15.));
assert!(from_str_hex(~"inf") == Some(infinity));
assert!(from_str_hex(~"+inf") == Some(infinity));
assert!(from_str_hex(~"-inf") == Some(neg_infinity));
// note: NaN != NaN, hence this slightly complex test
match from_str_hex(~"NaN") {
Some(f) => assert!(is_NaN(f)),
None => fail!()
}
// note: -0 == 0, hence these slightly more complex tests
match from_str_hex(~"-0") {
Some(v) if is_zero(v) => assert!(is_negative(v)),
_ => fail!()
}
match from_str_hex(~"0") {
Some(v) if is_zero(v) => assert!(is_positive(v)),
_ => fail!()
}
assert!(from_str_hex(~"e") == Some(14.));
assert!(from_str_hex(~"E") == Some(14.));
assert!(from_str_hex(~"E1") == Some(225.));
assert!(from_str_hex(~"1e1e1") == Some(123361.));
assert!(from_str_hex(~"1e1.1") == Some(481.0625));
assert!(from_str_hex(~"").is_none());
assert!(from_str_hex(~"x").is_none());
assert!(from_str_hex(~" ").is_none());
assert!(from_str_hex(~" ").is_none());
assert!(from_str_hex(~"p").is_none());
assert!(from_str_hex(~"P").is_none());
assert!(from_str_hex(~"P1").is_none());
assert!(from_str_hex(~"1p1p1").is_none());
assert!(from_str_hex(~"1p1.1").is_none());
assert!(from_str_hex(~"1p1-1").is_none());
}
#[test]
pub fn test_to_str_hex() {
assert!(to_str_hex(164.) == ~"a4");
assert!(to_str_hex(164.9921875) == ~"a4.fe");
assert!(to_str_hex(-164.9921875) == ~"-a4.fe");
assert!(to_str_hex(0xff00 as float) == ~"ff00");
assert!(to_str_hex(-(0xff00 as float)) == ~"-ff00");
assert!(to_str_hex(0.) == ~"0");
assert!(to_str_hex(15.) == ~"f");
assert!(to_str_hex(-15.) == ~"-f");
assert!(to_str_hex(0.9375) == ~"0.f");
assert!(to_str_hex(-0.9375) == ~"-0.f");
assert!(to_str_hex(infinity) == ~"inf");
assert!(to_str_hex(neg_infinity) == ~"-inf");
assert!(to_str_hex(NaN) == ~"NaN");
assert!(to_str_hex(0.) == ~"0");
assert!(to_str_hex(-0.) == ~"-0");
}
#[test]
pub fn test_to_str_radix() {
assert!(to_str_radix(36., 36u) == ~"10");
assert!(to_str_radix(8.125, 2u) == ~"1000.001");
}
#[test]
pub fn test_from_str_radix() {
assert!(from_str_radix(~"10", 36u) == Some(36.));
assert!(from_str_radix(~"1000.001", 2u) == Some(8.125));
}
#[test]
pub fn test_positive() {
assert!((is_positive(infinity)));
assert!((is_positive(1.)));
assert!((is_positive(0.)));
assert!((!is_positive(-1.)));
assert!((!is_positive(neg_infinity)));
assert!((!is_positive(1./neg_infinity)));
assert!((!is_positive(NaN)));
}
#[test]
pub fn test_negative() {
assert!((!is_negative(infinity)));
assert!((!is_negative(1.)));
assert!((!is_negative(0.)));
assert!((is_negative(-1.)));
assert!((is_negative(neg_infinity)));
assert!((is_negative(1./neg_infinity)));
assert!((!is_negative(NaN)));
}
#[test]
pub fn test_nonpositive() {
assert!((!is_nonpositive(infinity)));
assert!((!is_nonpositive(1.)));
assert!((!is_nonpositive(0.)));
assert!((is_nonpositive(-1.)));
assert!((is_nonpositive(neg_infinity)));
assert!((is_nonpositive(1./neg_infinity)));
assert!((!is_nonpositive(NaN)));
}
#[test]
pub fn test_nonnegative() {
assert!((is_nonnegative(infinity)));
assert!((is_nonnegative(1.)));
assert!((is_nonnegative(0.)));
assert!((!is_nonnegative(-1.)));
assert!((!is_nonnegative(neg_infinity)));
assert!((!is_nonnegative(1./neg_infinity)));
assert!((!is_nonnegative(NaN)));
}
#[test]
pub fn test_to_str_inf() {
assert!(to_str_digits(infinity, 10u) == ~"inf");
assert!(to_str_digits(-infinity, 10u) == ~"-inf");
}
#[test]
pub fn test_round() {
assert!(round(5.8) == 6.0);
assert!(round(5.2) == 5.0);
assert!(round(3.0) == 3.0);
assert!(round(2.5) == 3.0);
assert!(round(-3.5) == -4.0);
}
// //
// Local Variables: // Local Variables:
// mode: rust // mode: rust

View file

@ -277,181 +277,188 @@ impl ToStrRadix for T {
} }
} }
#[test] #[cfg(test)]
fn test_from_str() { mod tests {
assert!(from_str(~"0") == Some(0 as T)); use super::*;
assert!(from_str(~"3") == Some(3 as T)); use super::inst::T;
assert!(from_str(~"10") == Some(10 as T)); use prelude::*;
assert!(i32::from_str(~"123456789") == Some(123456789 as i32));
assert!(from_str(~"00100") == Some(100 as T));
assert!(from_str(~"-1") == Some(-1 as T)); #[test]
assert!(from_str(~"-3") == Some(-3 as T)); fn test_from_str() {
assert!(from_str(~"-10") == Some(-10 as T)); assert!(from_str(~"0") == Some(0 as T));
assert!(i32::from_str(~"-123456789") == Some(-123456789 as i32)); assert!(from_str(~"3") == Some(3 as T));
assert!(from_str(~"-00100") == Some(-100 as T)); assert!(from_str(~"10") == Some(10 as T));
assert!(i32::from_str(~"123456789") == Some(123456789 as i32));
assert!(from_str(~"00100") == Some(100 as T));
assert!(from_str(~" ").is_none()); assert!(from_str(~"-1") == Some(-1 as T));
assert!(from_str(~"x").is_none()); assert!(from_str(~"-3") == Some(-3 as T));
} assert!(from_str(~"-10") == Some(-10 as T));
assert!(i32::from_str(~"-123456789") == Some(-123456789 as i32));
assert!(from_str(~"-00100") == Some(-100 as T));
#[test] assert!(from_str(~" ").is_none());
fn test_parse_bytes() { assert!(from_str(~"x").is_none());
use str::to_bytes;
assert!(parse_bytes(to_bytes(~"123"), 10u) == Some(123 as T));
assert!(parse_bytes(to_bytes(~"1001"), 2u) == Some(9 as T));
assert!(parse_bytes(to_bytes(~"123"), 8u) == Some(83 as T));
assert!(i32::parse_bytes(to_bytes(~"123"), 16u) == Some(291 as i32));
assert!(i32::parse_bytes(to_bytes(~"ffff"), 16u) ==
Some(65535 as i32));
assert!(i32::parse_bytes(to_bytes(~"FFFF"), 16u) ==
Some(65535 as i32));
assert!(parse_bytes(to_bytes(~"z"), 36u) == Some(35 as T));
assert!(parse_bytes(to_bytes(~"Z"), 36u) == Some(35 as T));
assert!(parse_bytes(to_bytes(~"-123"), 10u) == Some(-123 as T));
assert!(parse_bytes(to_bytes(~"-1001"), 2u) == Some(-9 as T));
assert!(parse_bytes(to_bytes(~"-123"), 8u) == Some(-83 as T));
assert!(i32::parse_bytes(to_bytes(~"-123"), 16u) ==
Some(-291 as i32));
assert!(i32::parse_bytes(to_bytes(~"-ffff"), 16u) ==
Some(-65535 as i32));
assert!(i32::parse_bytes(to_bytes(~"-FFFF"), 16u) ==
Some(-65535 as i32));
assert!(parse_bytes(to_bytes(~"-z"), 36u) == Some(-35 as T));
assert!(parse_bytes(to_bytes(~"-Z"), 36u) == Some(-35 as T));
assert!(parse_bytes(to_bytes(~"Z"), 35u).is_none());
assert!(parse_bytes(to_bytes(~"-9"), 2u).is_none());
}
#[test]
fn test_to_str() {
assert!((to_str_radix(0 as T, 10u) == ~"0"));
assert!((to_str_radix(1 as T, 10u) == ~"1"));
assert!((to_str_radix(-1 as T, 10u) == ~"-1"));
assert!((to_str_radix(127 as T, 16u) == ~"7f"));
assert!((to_str_radix(100 as T, 10u) == ~"100"));
}
#[test]
fn test_int_to_str_overflow() {
let mut i8_val: i8 = 127_i8;
assert!((i8::to_str(i8_val) == ~"127"));
i8_val += 1 as i8;
assert!((i8::to_str(i8_val) == ~"-128"));
let mut i16_val: i16 = 32_767_i16;
assert!((i16::to_str(i16_val) == ~"32767"));
i16_val += 1 as i16;
assert!((i16::to_str(i16_val) == ~"-32768"));
let mut i32_val: i32 = 2_147_483_647_i32;
assert!((i32::to_str(i32_val) == ~"2147483647"));
i32_val += 1 as i32;
assert!((i32::to_str(i32_val) == ~"-2147483648"));
let mut i64_val: i64 = 9_223_372_036_854_775_807_i64;
assert!((i64::to_str(i64_val) == ~"9223372036854775807"));
i64_val += 1 as i64;
assert!((i64::to_str(i64_val) == ~"-9223372036854775808"));
}
#[test]
fn test_int_from_str_overflow() {
let mut i8_val: i8 = 127_i8;
assert!((i8::from_str(~"127") == Some(i8_val)));
assert!((i8::from_str(~"128").is_none()));
i8_val += 1 as i8;
assert!((i8::from_str(~"-128") == Some(i8_val)));
assert!((i8::from_str(~"-129").is_none()));
let mut i16_val: i16 = 32_767_i16;
assert!((i16::from_str(~"32767") == Some(i16_val)));
assert!((i16::from_str(~"32768").is_none()));
i16_val += 1 as i16;
assert!((i16::from_str(~"-32768") == Some(i16_val)));
assert!((i16::from_str(~"-32769").is_none()));
let mut i32_val: i32 = 2_147_483_647_i32;
assert!((i32::from_str(~"2147483647") == Some(i32_val)));
assert!((i32::from_str(~"2147483648").is_none()));
i32_val += 1 as i32;
assert!((i32::from_str(~"-2147483648") == Some(i32_val)));
assert!((i32::from_str(~"-2147483649").is_none()));
let mut i64_val: i64 = 9_223_372_036_854_775_807_i64;
assert!((i64::from_str(~"9223372036854775807") == Some(i64_val)));
assert!((i64::from_str(~"9223372036854775808").is_none()));
i64_val += 1 as i64;
assert!((i64::from_str(~"-9223372036854775808") == Some(i64_val)));
assert!((i64::from_str(~"-9223372036854775809").is_none()));
}
#[test]
pub fn test_ranges() {
let mut l = ~[];
for range(0,3) |i| {
l.push(i);
} }
for range_rev(13,10) |i| {
l.push(i);
}
for range_step(20,26,2) |i| {
l.push(i);
}
for range_step(36,30,-2) |i| {
l.push(i);
}
for range_step(max_value - 2, max_value, 2) |i| {
l.push(i);
}
for range_step(max_value - 3, max_value, 2) |i| {
l.push(i);
}
for range_step(min_value + 2, min_value, -2) |i| {
l.push(i);
}
for range_step(min_value + 3, min_value, -2) |i| {
l.push(i);
}
assert_eq!(l, ~[0,1,2,
13,12,11,
20,22,24,
36,34,32,
max_value-2,
max_value-3,max_value-1,
min_value+2,
min_value+3,min_value+1]);
// None of the `fail`s should execute. #[test]
for range(10,0) |_i| { fn test_parse_bytes() {
fail!(~"unreachable"); use str::to_bytes;
} assert!(parse_bytes(to_bytes(~"123"), 10u) == Some(123 as T));
for range_rev(0,10) |_i| { assert!(parse_bytes(to_bytes(~"1001"), 2u) == Some(9 as T));
fail!(~"unreachable"); assert!(parse_bytes(to_bytes(~"123"), 8u) == Some(83 as T));
} assert!(i32::parse_bytes(to_bytes(~"123"), 16u) == Some(291 as i32));
for range_step(10,0,1) |_i| { assert!(i32::parse_bytes(to_bytes(~"ffff"), 16u) ==
fail!(~"unreachable"); Some(65535 as i32));
} assert!(i32::parse_bytes(to_bytes(~"FFFF"), 16u) ==
for range_step(0,10,-1) |_i| { Some(65535 as i32));
fail!(~"unreachable"); assert!(parse_bytes(to_bytes(~"z"), 36u) == Some(35 as T));
} assert!(parse_bytes(to_bytes(~"Z"), 36u) == Some(35 as T));
}
#[test] assert!(parse_bytes(to_bytes(~"-123"), 10u) == Some(-123 as T));
#[should_fail] assert!(parse_bytes(to_bytes(~"-1001"), 2u) == Some(-9 as T));
#[ignore(cfg(windows))] assert!(parse_bytes(to_bytes(~"-123"), 8u) == Some(-83 as T));
fn test_range_step_zero_step() { assert!(i32::parse_bytes(to_bytes(~"-123"), 16u) ==
for range_step(0,10,0) |_i| {} Some(-291 as i32));
} assert!(i32::parse_bytes(to_bytes(~"-ffff"), 16u) ==
Some(-65535 as i32));
assert!(i32::parse_bytes(to_bytes(~"-FFFF"), 16u) ==
Some(-65535 as i32));
assert!(parse_bytes(to_bytes(~"-z"), 36u) == Some(-35 as T));
assert!(parse_bytes(to_bytes(~"-Z"), 36u) == Some(-35 as T));
assert!(parse_bytes(to_bytes(~"Z"), 35u).is_none());
assert!(parse_bytes(to_bytes(~"-9"), 2u).is_none());
}
#[test]
fn test_to_str() {
assert!((to_str_radix(0 as T, 10u) == ~"0"));
assert!((to_str_radix(1 as T, 10u) == ~"1"));
assert!((to_str_radix(-1 as T, 10u) == ~"-1"));
assert!((to_str_radix(127 as T, 16u) == ~"7f"));
assert!((to_str_radix(100 as T, 10u) == ~"100"));
}
#[test]
fn test_int_to_str_overflow() {
let mut i8_val: i8 = 127_i8;
assert!((i8::to_str(i8_val) == ~"127"));
i8_val += 1 as i8;
assert!((i8::to_str(i8_val) == ~"-128"));
let mut i16_val: i16 = 32_767_i16;
assert!((i16::to_str(i16_val) == ~"32767"));
i16_val += 1 as i16;
assert!((i16::to_str(i16_val) == ~"-32768"));
let mut i32_val: i32 = 2_147_483_647_i32;
assert!((i32::to_str(i32_val) == ~"2147483647"));
i32_val += 1 as i32;
assert!((i32::to_str(i32_val) == ~"-2147483648"));
let mut i64_val: i64 = 9_223_372_036_854_775_807_i64;
assert!((i64::to_str(i64_val) == ~"9223372036854775807"));
i64_val += 1 as i64;
assert!((i64::to_str(i64_val) == ~"-9223372036854775808"));
}
#[test]
fn test_int_from_str_overflow() {
let mut i8_val: i8 = 127_i8;
assert!((i8::from_str(~"127") == Some(i8_val)));
assert!((i8::from_str(~"128").is_none()));
i8_val += 1 as i8;
assert!((i8::from_str(~"-128") == Some(i8_val)));
assert!((i8::from_str(~"-129").is_none()));
let mut i16_val: i16 = 32_767_i16;
assert!((i16::from_str(~"32767") == Some(i16_val)));
assert!((i16::from_str(~"32768").is_none()));
i16_val += 1 as i16;
assert!((i16::from_str(~"-32768") == Some(i16_val)));
assert!((i16::from_str(~"-32769").is_none()));
let mut i32_val: i32 = 2_147_483_647_i32;
assert!((i32::from_str(~"2147483647") == Some(i32_val)));
assert!((i32::from_str(~"2147483648").is_none()));
i32_val += 1 as i32;
assert!((i32::from_str(~"-2147483648") == Some(i32_val)));
assert!((i32::from_str(~"-2147483649").is_none()));
let mut i64_val: i64 = 9_223_372_036_854_775_807_i64;
assert!((i64::from_str(~"9223372036854775807") == Some(i64_val)));
assert!((i64::from_str(~"9223372036854775808").is_none()));
i64_val += 1 as i64;
assert!((i64::from_str(~"-9223372036854775808") == Some(i64_val)));
assert!((i64::from_str(~"-9223372036854775809").is_none()));
}
#[test]
fn test_ranges() {
let mut l = ~[];
for range(0,3) |i| {
l.push(i);
}
for range_rev(13,10) |i| {
l.push(i);
}
for range_step(20,26,2) |i| {
l.push(i);
}
for range_step(36,30,-2) |i| {
l.push(i);
}
for range_step(max_value - 2, max_value, 2) |i| {
l.push(i);
}
for range_step(max_value - 3, max_value, 2) |i| {
l.push(i);
}
for range_step(min_value + 2, min_value, -2) |i| {
l.push(i);
}
for range_step(min_value + 3, min_value, -2) |i| {
l.push(i);
}
assert_eq!(l, ~[0,1,2,
13,12,11,
20,22,24,
36,34,32,
max_value-2,
max_value-3,max_value-1,
min_value+2,
min_value+3,min_value+1]);
// None of the `fail`s should execute.
for range(10,0) |_i| {
fail!(~"unreachable");
}
for range_rev(0,10) |_i| {
fail!(~"unreachable");
}
for range_step(10,0,1) |_i| {
fail!(~"unreachable");
}
for range_step(0,10,-1) |_i| {
fail!(~"unreachable");
}
}
#[test]
#[should_fail]
#[ignore(cfg(windows))]
fn test_range_step_zero_step() {
for range_step(0,10,0) |_i| {}
}
}

View file

@ -242,184 +242,190 @@ impl ToStrRadix for T {
} }
} }
#[test] #[cfg(test)]
pub fn test_to_str() { mod tests {
assert!(to_str_radix(0 as T, 10u) == ~"0"); use super::*;
assert!(to_str_radix(1 as T, 10u) == ~"1"); use super::inst::T;
assert!(to_str_radix(2 as T, 10u) == ~"2"); use prelude::*;
assert!(to_str_radix(11 as T, 10u) == ~"11"); #[test]
assert!(to_str_radix(11 as T, 16u) == ~"b"); pub fn test_to_str() {
assert!(to_str_radix(255 as T, 16u) == ~"ff"); assert!(to_str_radix(0 as T, 10u) == ~"0");
assert!(to_str_radix(0xff as T, 10u) == ~"255"); assert!(to_str_radix(1 as T, 10u) == ~"1");
} assert!(to_str_radix(2 as T, 10u) == ~"2");
assert!(to_str_radix(11 as T, 10u) == ~"11");
#[test] assert!(to_str_radix(11 as T, 16u) == ~"b");
pub fn test_from_str() { assert!(to_str_radix(255 as T, 16u) == ~"ff");
assert!(from_str(~"0") == Some(0u as T)); assert!(to_str_radix(0xff as T, 10u) == ~"255");
assert!(from_str(~"3") == Some(3u as T));
assert!(from_str(~"10") == Some(10u as T));
assert!(u32::from_str(~"123456789") == Some(123456789 as u32));
assert!(from_str(~"00100") == Some(100u as T));
assert!(from_str(~"").is_none());
assert!(from_str(~" ").is_none());
assert!(from_str(~"x").is_none());
}
#[test]
pub fn test_parse_bytes() {
use str::to_bytes;
assert!(parse_bytes(to_bytes(~"123"), 10u) == Some(123u as T));
assert!(parse_bytes(to_bytes(~"1001"), 2u) == Some(9u as T));
assert!(parse_bytes(to_bytes(~"123"), 8u) == Some(83u as T));
assert!(u16::parse_bytes(to_bytes(~"123"), 16u) ==
Some(291u as u16));
assert!(u16::parse_bytes(to_bytes(~"ffff"), 16u) ==
Some(65535u as u16));
assert!(parse_bytes(to_bytes(~"z"), 36u) == Some(35u as T));
assert!(parse_bytes(to_bytes(~"Z"), 10u).is_none());
assert!(parse_bytes(to_bytes(~"_"), 2u).is_none());
}
#[test]
fn test_uint_to_str_overflow() {
let mut u8_val: u8 = 255_u8;
assert!((u8::to_str(u8_val) == ~"255"));
u8_val += 1 as u8;
assert!((u8::to_str(u8_val) == ~"0"));
let mut u16_val: u16 = 65_535_u16;
assert!((u16::to_str(u16_val) == ~"65535"));
u16_val += 1 as u16;
assert!((u16::to_str(u16_val) == ~"0"));
let mut u32_val: u32 = 4_294_967_295_u32;
assert!((u32::to_str(u32_val) == ~"4294967295"));
u32_val += 1 as u32;
assert!((u32::to_str(u32_val) == ~"0"));
let mut u64_val: u64 = 18_446_744_073_709_551_615_u64;
assert!((u64::to_str(u64_val) == ~"18446744073709551615"));
u64_val += 1 as u64;
assert!((u64::to_str(u64_val) == ~"0"));
}
#[test]
fn test_uint_from_str_overflow() {
let mut u8_val: u8 = 255_u8;
assert!((u8::from_str(~"255") == Some(u8_val)));
assert!((u8::from_str(~"256").is_none()));
u8_val += 1 as u8;
assert!((u8::from_str(~"0") == Some(u8_val)));
assert!((u8::from_str(~"-1").is_none()));
let mut u16_val: u16 = 65_535_u16;
assert!((u16::from_str(~"65535") == Some(u16_val)));
assert!((u16::from_str(~"65536").is_none()));
u16_val += 1 as u16;
assert!((u16::from_str(~"0") == Some(u16_val)));
assert!((u16::from_str(~"-1").is_none()));
let mut u32_val: u32 = 4_294_967_295_u32;
assert!((u32::from_str(~"4294967295") == Some(u32_val)));
assert!((u32::from_str(~"4294967296").is_none()));
u32_val += 1 as u32;
assert!((u32::from_str(~"0") == Some(u32_val)));
assert!((u32::from_str(~"-1").is_none()));
let mut u64_val: u64 = 18_446_744_073_709_551_615_u64;
assert!((u64::from_str(~"18446744073709551615") == Some(u64_val)));
assert!((u64::from_str(~"18446744073709551616").is_none()));
u64_val += 1 as u64;
assert!((u64::from_str(~"0") == Some(u64_val)));
assert!((u64::from_str(~"-1").is_none()));
}
#[test]
#[should_fail]
#[ignore(cfg(windows))]
pub fn to_str_radix1() {
uint::to_str_radix(100u, 1u);
}
#[test]
#[should_fail]
#[ignore(cfg(windows))]
pub fn to_str_radix37() {
uint::to_str_radix(100u, 37u);
}
#[test]
pub fn test_ranges() {
let mut l = ~[];
for range(0,3) |i| {
l.push(i);
}
for range_rev(13,10) |i| {
l.push(i);
}
for range_step(20,26,2) |i| {
l.push(i);
}
for range_step(36,30,-2) |i| {
l.push(i);
}
for range_step(max_value - 2, max_value, 2) |i| {
l.push(i);
}
for range_step(max_value - 3, max_value, 2) |i| {
l.push(i);
}
for range_step(min_value + 2, min_value, -2) |i| {
l.push(i);
}
for range_step(min_value + 3, min_value, -2) |i| {
l.push(i);
} }
assert_eq!(l, ~[0,1,2, #[test]
13,12,11, pub fn test_from_str() {
20,22,24, assert!(from_str(~"0") == Some(0u as T));
36,34,32, assert!(from_str(~"3") == Some(3u as T));
max_value-2, assert!(from_str(~"10") == Some(10u as T));
max_value-3,max_value-1, assert!(u32::from_str(~"123456789") == Some(123456789 as u32));
min_value+2, assert!(from_str(~"00100") == Some(100u as T));
min_value+3,min_value+1]);
// None of the `fail`s should execute. assert!(from_str(~"").is_none());
for range(0,0) |_i| { assert!(from_str(~" ").is_none());
fail!(~"unreachable"); assert!(from_str(~"x").is_none());
} }
for range_rev(0,0) |_i| {
fail!(~"unreachable");
}
for range_step(10,0,1) |_i| {
fail!(~"unreachable");
}
for range_step(0,1,-10) |_i| {
fail!(~"unreachable");
}
}
#[test] #[test]
#[should_fail] pub fn test_parse_bytes() {
#[ignore(cfg(windows))] use str::to_bytes;
fn test_range_step_zero_step_up() { assert!(parse_bytes(to_bytes(~"123"), 10u) == Some(123u as T));
for range_step(0,10,0) |_i| {} assert!(parse_bytes(to_bytes(~"1001"), 2u) == Some(9u as T));
} assert!(parse_bytes(to_bytes(~"123"), 8u) == Some(83u as T));
#[test] assert!(u16::parse_bytes(to_bytes(~"123"), 16u) ==
#[should_fail] Some(291u as u16));
#[ignore(cfg(windows))] assert!(u16::parse_bytes(to_bytes(~"ffff"), 16u) ==
fn test_range_step_zero_step_down() { Some(65535u as u16));
for range_step(0,-10,0) |_i| {} assert!(parse_bytes(to_bytes(~"z"), 36u) == Some(35u as T));
}
assert!(parse_bytes(to_bytes(~"Z"), 10u).is_none());
assert!(parse_bytes(to_bytes(~"_"), 2u).is_none());
}
#[test]
fn test_uint_to_str_overflow() {
let mut u8_val: u8 = 255_u8;
assert!((u8::to_str(u8_val) == ~"255"));
u8_val += 1 as u8;
assert!((u8::to_str(u8_val) == ~"0"));
let mut u16_val: u16 = 65_535_u16;
assert!((u16::to_str(u16_val) == ~"65535"));
u16_val += 1 as u16;
assert!((u16::to_str(u16_val) == ~"0"));
let mut u32_val: u32 = 4_294_967_295_u32;
assert!((u32::to_str(u32_val) == ~"4294967295"));
u32_val += 1 as u32;
assert!((u32::to_str(u32_val) == ~"0"));
let mut u64_val: u64 = 18_446_744_073_709_551_615_u64;
assert!((u64::to_str(u64_val) == ~"18446744073709551615"));
u64_val += 1 as u64;
assert!((u64::to_str(u64_val) == ~"0"));
}
#[test]
fn test_uint_from_str_overflow() {
let mut u8_val: u8 = 255_u8;
assert!((u8::from_str(~"255") == Some(u8_val)));
assert!((u8::from_str(~"256").is_none()));
u8_val += 1 as u8;
assert!((u8::from_str(~"0") == Some(u8_val)));
assert!((u8::from_str(~"-1").is_none()));
let mut u16_val: u16 = 65_535_u16;
assert!((u16::from_str(~"65535") == Some(u16_val)));
assert!((u16::from_str(~"65536").is_none()));
u16_val += 1 as u16;
assert!((u16::from_str(~"0") == Some(u16_val)));
assert!((u16::from_str(~"-1").is_none()));
let mut u32_val: u32 = 4_294_967_295_u32;
assert!((u32::from_str(~"4294967295") == Some(u32_val)));
assert!((u32::from_str(~"4294967296").is_none()));
u32_val += 1 as u32;
assert!((u32::from_str(~"0") == Some(u32_val)));
assert!((u32::from_str(~"-1").is_none()));
let mut u64_val: u64 = 18_446_744_073_709_551_615_u64;
assert!((u64::from_str(~"18446744073709551615") == Some(u64_val)));
assert!((u64::from_str(~"18446744073709551616").is_none()));
u64_val += 1 as u64;
assert!((u64::from_str(~"0") == Some(u64_val)));
assert!((u64::from_str(~"-1").is_none()));
}
#[test]
#[should_fail]
#[ignore(cfg(windows))]
pub fn to_str_radix1() {
uint::to_str_radix(100u, 1u);
}
#[test]
#[should_fail]
#[ignore(cfg(windows))]
pub fn to_str_radix37() {
uint::to_str_radix(100u, 37u);
}
#[test]
pub fn test_ranges() {
let mut l = ~[];
for range(0,3) |i| {
l.push(i);
}
for range_rev(13,10) |i| {
l.push(i);
}
for range_step(20,26,2) |i| {
l.push(i);
}
for range_step(36,30,-2) |i| {
l.push(i);
}
for range_step(max_value - 2, max_value, 2) |i| {
l.push(i);
}
for range_step(max_value - 3, max_value, 2) |i| {
l.push(i);
}
for range_step(min_value + 2, min_value, -2) |i| {
l.push(i);
}
for range_step(min_value + 3, min_value, -2) |i| {
l.push(i);
}
assert_eq!(l, ~[0,1,2,
13,12,11,
20,22,24,
36,34,32,
max_value-2,
max_value-3,max_value-1,
min_value+2,
min_value+3,min_value+1]);
// None of the `fail`s should execute.
for range(0,0) |_i| {
fail!(~"unreachable");
}
for range_rev(0,0) |_i| {
fail!(~"unreachable");
}
for range_step(10,0,1) |_i| {
fail!(~"unreachable");
}
for range_step(0,1,-10) |_i| {
fail!(~"unreachable");
}
}
#[test]
#[should_fail]
#[ignore(cfg(windows))]
fn test_range_step_zero_step_up() {
for range_step(0,10,0) |_i| {}
}
#[test]
#[should_fail]
#[ignore(cfg(windows))]
fn test_range_step_zero_step_down() {
for range_step(0,-10,0) |_i| {}
}
}

View file

@ -957,13 +957,13 @@ pub mod rt {
} }
#[cfg(test)] #[cfg(test)]
pub mod test { mod test {
use either::Right; use either::Right;
use comm::{Chan, Port, oneshot, recv_one, stream, Select2, use comm::{Chan, Port, oneshot, recv_one, stream, Select2,
GenericChan, Peekable}; GenericChan, Peekable};
#[test] #[test]
pub fn test_select2() { fn test_select2() {
let (p1, c1) = stream(); let (p1, c1) = stream();
let (p2, c2) = stream(); let (p2, c2) = stream();
@ -978,7 +978,7 @@ pub mod test {
} }
#[test] #[test]
pub fn test_oneshot() { fn test_oneshot() {
let (c, p) = oneshot::init(); let (c, p) = oneshot::init();
oneshot::client::send(c, ()); oneshot::client::send(c, ());

View file

@ -15,8 +15,6 @@ use libc;
use libc::{c_void, size_t}; use libc::{c_void, size_t};
use sys; use sys;
#[cfg(test)] use vec;
#[cfg(test)] use str;
#[cfg(notest)] use cmp::{Eq, Ord}; #[cfg(notest)] use cmp::{Eq, Ord};
use uint; use uint;
@ -341,101 +339,101 @@ impl<'self,T:Ord> Ord for &'self const T {
} }
} }
#[test] #[cfg(test)]
pub fn test() { pub mod ptr_tests {
unsafe { use super::*;
struct Pair {mut fst: int, mut snd: int}; use prelude::*;
let mut p = Pair {fst: 10, snd: 20};
let pptr: *mut Pair = &mut p;
let iptr: *mut int = cast::reinterpret_cast(&pptr);
assert!((*iptr == 10));;
*iptr = 30;
assert!((*iptr == 30));
assert!((p.fst == 30));;
*pptr = Pair {fst: 50, snd: 60}; #[test]
assert!((*iptr == 50)); fn test() {
assert!((p.fst == 50)); unsafe {
assert!((p.snd == 60)); struct Pair {mut fst: int, mut snd: int};
let mut p = Pair {fst: 10, snd: 20};
let pptr: *mut Pair = &mut p;
let iptr: *mut int = cast::reinterpret_cast(&pptr);
assert!((*iptr == 10));;
*iptr = 30;
assert!((*iptr == 30));
assert!((p.fst == 30));;
let mut v0 = ~[32000u16, 32001u16, 32002u16]; *pptr = Pair {fst: 50, snd: 60};
let mut v1 = ~[0u16, 0u16, 0u16]; assert!((*iptr == 50));
assert!((p.fst == 50));
assert!((p.snd == 60));
copy_memory(mut_offset(vec::raw::to_mut_ptr(v1), 1u), let mut v0 = ~[32000u16, 32001u16, 32002u16];
offset(vec::raw::to_ptr(v0), 1u), 1u); let mut v1 = ~[0u16, 0u16, 0u16];
assert!((v1[0] == 0u16 && v1[1] == 32001u16 && v1[2] == 0u16));
copy_memory(vec::raw::to_mut_ptr(v1), copy_memory(mut_offset(vec::raw::to_mut_ptr(v1), 1u),
offset(vec::raw::to_ptr(v0), 2u), 1u); offset(vec::raw::to_ptr(v0), 1u), 1u);
assert!((v1[0] == 32002u16 && v1[1] == 32001u16 && assert!((v1[0] == 0u16 && v1[1] == 32001u16 && v1[2] == 0u16));
v1[2] == 0u16)); copy_memory(vec::raw::to_mut_ptr(v1),
copy_memory(mut_offset(vec::raw::to_mut_ptr(v1), 2u), offset(vec::raw::to_ptr(v0), 2u), 1u);
vec::raw::to_ptr(v0), 1u); assert!((v1[0] == 32002u16 && v1[1] == 32001u16 &&
assert!((v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 0u16));
v1[2] == 32000u16)); copy_memory(mut_offset(vec::raw::to_mut_ptr(v1), 2u),
vec::raw::to_ptr(v0), 1u);
assert!((v1[0] == 32002u16 && v1[1] == 32001u16 &&
v1[2] == 32000u16));
}
} }
}
#[test] #[test]
pub fn test_position() { fn test_position() {
use str::as_c_str; use str::as_c_str;
use libc::c_char; use libc::c_char;
let s = ~"hello"; let s = ~"hello";
unsafe { unsafe {
assert!(2u == as_c_str(s, |p| position(p, assert!(2u == as_c_str(s, |p| position(p,
|c| *c == 'l' as c_char))); |c| *c == 'l' as c_char)));
assert!(4u == as_c_str(s, |p| position(p, assert!(4u == as_c_str(s, |p| position(p,
|c| *c == 'o' as c_char))); |c| *c == 'o' as c_char)));
assert!(5u == as_c_str(s, |p| position(p, assert!(5u == as_c_str(s, |p| position(p,
|c| *c == 0 as c_char))); |c| *c == 0 as c_char)));
}
} }
}
#[test] #[test]
pub fn test_buf_len() { fn test_buf_len() {
let s0 = ~"hello"; let s0 = ~"hello";
let s1 = ~"there"; let s1 = ~"there";
let s2 = ~"thing"; let s2 = ~"thing";
do str::as_c_str(s0) |p0| { do str::as_c_str(s0) |p0| {
do str::as_c_str(s1) |p1| { do str::as_c_str(s1) |p1| {
do str::as_c_str(s2) |p2| { do str::as_c_str(s2) |p2| {
let v = ~[p0, p1, p2, null()]; let v = ~[p0, p1, p2, null()];
do vec::as_imm_buf(v) |vp, len| { do vec::as_imm_buf(v) |vp, len| {
assert!(unsafe { buf_len(vp) } == 3u); assert!(unsafe { buf_len(vp) } == 3u);
assert!(len == 4u); assert!(len == 4u);
}
} }
} }
} }
} }
}
#[test]
pub fn test_is_null() {
let p: *int = null();
assert!(p.is_null());
assert!(!p.is_not_null());
let q = offset(p, 1u);
assert!(!q.is_null());
assert!(q.is_not_null());
let mp: *mut int = mut_null();
assert!(mp.is_null());
assert!(!mp.is_not_null());
let mq = mp.offset(1u);
assert!(!mq.is_null());
assert!(mq.is_not_null());
}
#[cfg(test)]
pub mod ptr_tests {
use ptr;
use str;
use libc;
use vec;
#[test] #[test]
pub fn test_ptr_array_each_with_len() { fn test_is_null() {
let p: *int = null();
assert!(p.is_null());
assert!(!p.is_not_null());
let q = offset(p, 1u);
assert!(!q.is_null());
assert!(q.is_not_null());
let mp: *mut int = mut_null();
assert!(mp.is_null());
assert!(!mp.is_not_null());
let mq = mp.offset(1u);
assert!(!mq.is_null());
assert!(mq.is_not_null());
}
#[test]
fn test_ptr_array_each_with_len() {
unsafe { unsafe {
let one = ~"oneOne"; let one = ~"oneOne";
let two = ~"twoTwo"; let two = ~"twoTwo";
@ -451,22 +449,22 @@ pub mod ptr_tests {
let arr_ptr = &arr[0]; let arr_ptr = &arr[0];
let mut ctr = 0; let mut ctr = 0;
let mut iteration_count = 0; let mut iteration_count = 0;
ptr::array_each_with_len(arr_ptr, vec::len(arr), array_each_with_len(arr_ptr, vec::len(arr),
|e| { |e| {
let actual = str::raw::from_c_str(e); let actual = str::raw::from_c_str(e);
let expected = copy expected_arr[ctr]; let expected = copy expected_arr[ctr];
debug!( debug!(
"test_ptr_array_each e: %s, a: %s", "test_ptr_array_each e: %s, a: %s",
expected, actual); expected, actual);
assert!(actual == expected); assert!(actual == expected);
ctr += 1; ctr += 1;
iteration_count += 1; iteration_count += 1;
}); });
assert!(iteration_count == 3u); assert!(iteration_count == 3u);
} }
} }
#[test] #[test]
pub fn test_ptr_array_each() { fn test_ptr_array_each() {
unsafe { unsafe {
let one = ~"oneOne"; let one = ~"oneOne";
let two = ~"twoTwo"; let two = ~"twoTwo";
@ -484,12 +482,12 @@ pub mod ptr_tests {
let arr_ptr = &arr[0]; let arr_ptr = &arr[0];
let mut ctr = 0; let mut ctr = 0;
let mut iteration_count = 0; let mut iteration_count = 0;
ptr::array_each(arr_ptr, |e| { array_each(arr_ptr, |e| {
let actual = str::raw::from_c_str(e); let actual = str::raw::from_c_str(e);
let expected = copy expected_arr[ctr]; let expected = copy expected_arr[ctr];
debug!( debug!(
"test_ptr_array_each e: %s, a: %s", "test_ptr_array_each e: %s, a: %s",
expected, actual); expected, actual);
assert!(actual == expected); assert!(actual == expected);
ctr += 1; ctr += 1;
iteration_count += 1; iteration_count += 1;
@ -500,9 +498,9 @@ pub mod ptr_tests {
#[test] #[test]
#[should_fail] #[should_fail]
#[ignore(cfg(windows))] #[ignore(cfg(windows))]
pub fn test_ptr_array_each_with_len_null_ptr() { fn test_ptr_array_each_with_len_null_ptr() {
unsafe { unsafe {
ptr::array_each_with_len(0 as **libc::c_char, 1, |e| { array_each_with_len(0 as **libc::c_char, 1, |e| {
str::raw::from_c_str(e); str::raw::from_c_str(e);
}); });
} }
@ -510,9 +508,9 @@ pub mod ptr_tests {
#[test] #[test]
#[should_fail] #[should_fail]
#[ignore(cfg(windows))] #[ignore(cfg(windows))]
pub fn test_ptr_array_each_null_ptr() { fn test_ptr_array_each_null_ptr() {
unsafe { unsafe {
ptr::array_each(0 as **libc::c_char, |e| { array_each(0 as **libc::c_char, |e| {
str::raw::from_c_str(e); str::raw::from_c_str(e);
}); });
} }

View file

@ -747,12 +747,12 @@ pub fn random() -> uint {
#[cfg(test)] #[cfg(test)]
pub mod tests { mod tests {
use option::{Option, Some}; use option::{Option, Some};
use rand; use rand;
#[test] #[test]
pub fn rng_seeded() { fn rng_seeded() {
let seed = rand::seed(); let seed = rand::seed();
let ra = rand::seeded_rng(seed); let ra = rand::seeded_rng(seed);
let rb = rand::seeded_rng(seed); let rb = rand::seeded_rng(seed);
@ -760,7 +760,7 @@ pub mod tests {
} }
#[test] #[test]
pub fn rng_seeded_custom_seed() { fn rng_seeded_custom_seed() {
// much shorter than generated seeds which are 1024 bytes // much shorter than generated seeds which are 1024 bytes
let seed = [2u8, 32u8, 4u8, 32u8, 51u8]; let seed = [2u8, 32u8, 4u8, 32u8, 51u8];
let ra = rand::seeded_rng(seed); let ra = rand::seeded_rng(seed);
@ -769,7 +769,7 @@ pub mod tests {
} }
#[test] #[test]
pub fn rng_seeded_custom_seed2() { fn rng_seeded_custom_seed2() {
let seed = [2u8, 32u8, 4u8, 32u8, 51u8]; let seed = [2u8, 32u8, 4u8, 32u8, 51u8];
let ra = rand::seeded_rng(seed); let ra = rand::seeded_rng(seed);
// Regression test that isaac is actually using the above vector // Regression test that isaac is actually using the above vector
@ -780,7 +780,7 @@ pub mod tests {
} }
#[test] #[test]
pub fn gen_int_range() { fn gen_int_range() {
let r = rand::Rng(); let r = rand::Rng();
let a = r.gen_int_range(-3, 42); let a = r.gen_int_range(-3, 42);
assert!(a >= -3 && a < 42); assert!(a >= -3 && a < 42);
@ -791,12 +791,12 @@ pub mod tests {
#[test] #[test]
#[should_fail] #[should_fail]
#[ignore(cfg(windows))] #[ignore(cfg(windows))]
pub fn gen_int_from_fail() { fn gen_int_from_fail() {
rand::Rng().gen_int_range(5, -2); rand::Rng().gen_int_range(5, -2);
} }
#[test] #[test]
pub fn gen_uint_range() { fn gen_uint_range() {
let r = rand::Rng(); let r = rand::Rng();
let a = r.gen_uint_range(3u, 42u); let a = r.gen_uint_range(3u, 42u);
assert!(a >= 3u && a < 42u); assert!(a >= 3u && a < 42u);
@ -807,12 +807,12 @@ pub mod tests {
#[test] #[test]
#[should_fail] #[should_fail]
#[ignore(cfg(windows))] #[ignore(cfg(windows))]
pub fn gen_uint_range_fail() { fn gen_uint_range_fail() {
rand::Rng().gen_uint_range(5u, 2u); rand::Rng().gen_uint_range(5u, 2u);
} }
#[test] #[test]
pub fn gen_float() { fn gen_float() {
let r = rand::Rng(); let r = rand::Rng();
let a = r.gen_float(); let a = r.gen_float();
let b = r.gen_float(); let b = r.gen_float();
@ -820,14 +820,14 @@ pub mod tests {
} }
#[test] #[test]
pub fn gen_weighted_bool() { fn gen_weighted_bool() {
let r = rand::Rng(); let r = rand::Rng();
assert!(r.gen_weighted_bool(0u) == true); assert!(r.gen_weighted_bool(0u) == true);
assert!(r.gen_weighted_bool(1u) == true); assert!(r.gen_weighted_bool(1u) == true);
} }
#[test] #[test]
pub fn gen_str() { fn gen_str() {
let r = rand::Rng(); let r = rand::Rng();
debug!(r.gen_str(10u)); debug!(r.gen_str(10u));
debug!(r.gen_str(10u)); debug!(r.gen_str(10u));
@ -838,7 +838,7 @@ pub mod tests {
} }
#[test] #[test]
pub fn gen_bytes() { fn gen_bytes() {
let r = rand::Rng(); let r = rand::Rng();
assert!(r.gen_bytes(0u).len() == 0u); assert!(r.gen_bytes(0u).len() == 0u);
assert!(r.gen_bytes(10u).len() == 10u); assert!(r.gen_bytes(10u).len() == 10u);
@ -846,13 +846,13 @@ pub mod tests {
} }
#[test] #[test]
pub fn choose() { fn choose() {
let r = rand::Rng(); let r = rand::Rng();
assert!(r.choose([1, 1, 1]) == 1); assert!(r.choose([1, 1, 1]) == 1);
} }
#[test] #[test]
pub fn choose_option() { fn choose_option() {
let r = rand::Rng(); let r = rand::Rng();
let x: Option<int> = r.choose_option([]); let x: Option<int> = r.choose_option([]);
assert!(x.is_none()); assert!(x.is_none());
@ -860,7 +860,7 @@ pub mod tests {
} }
#[test] #[test]
pub fn choose_weighted() { fn choose_weighted() {
let r = rand::Rng(); let r = rand::Rng();
assert!(r.choose_weighted(~[ assert!(r.choose_weighted(~[
rand::Weighted { weight: 1u, item: 42 }, rand::Weighted { weight: 1u, item: 42 },
@ -872,7 +872,7 @@ pub mod tests {
} }
#[test] #[test]
pub fn choose_weighted_option() { fn choose_weighted_option() {
let r = rand::Rng(); let r = rand::Rng();
assert!(r.choose_weighted_option(~[ assert!(r.choose_weighted_option(~[
rand::Weighted { weight: 1u, item: 42 }, rand::Weighted { weight: 1u, item: 42 },
@ -886,7 +886,7 @@ pub mod tests {
} }
#[test] #[test]
pub fn weighted_vec() { fn weighted_vec() {
let r = rand::Rng(); let r = rand::Rng();
let empty: ~[int] = ~[]; let empty: ~[int] = ~[];
assert!(r.weighted_vec(~[]) == empty); assert!(r.weighted_vec(~[]) == empty);
@ -898,7 +898,7 @@ pub mod tests {
} }
#[test] #[test]
pub fn shuffle() { fn shuffle() {
let r = rand::Rng(); let r = rand::Rng();
let empty: ~[int] = ~[]; let empty: ~[int] = ~[];
assert!(r.shuffle(~[]) == empty); assert!(r.shuffle(~[]) == empty);
@ -906,7 +906,7 @@ pub mod tests {
} }
#[test] #[test]
pub fn task_rng() { fn task_rng() {
let r = rand::task_rng(); let r = rand::task_rng();
r.gen_int(); r.gen_int();
assert!(r.shuffle(~[1, 1, 1]) == ~[1, 1, 1]); assert!(r.shuffle(~[1, 1, 1]) == ~[1, 1, 1]);
@ -914,7 +914,7 @@ pub mod tests {
} }
#[test] #[test]
pub fn random() { fn random() {
// not sure how to test this aside from just getting a number // not sure how to test this aside from just getting a number
let _n : uint = rand::random(); let _n : uint = rand::random();
} }

View file

@ -521,7 +521,7 @@ mod tests {
// Regression test for memory leaks // Regression test for memory leaks
#[ignore(cfg(windows))] // FIXME (#2626) #[ignore(cfg(windows))] // FIXME (#2626)
pub fn test_leaks() { fn test_leaks() {
run::run_program("echo", []); run::run_program("echo", []);
run::start_program("echo", []); run::start_program("echo", []);
run::program_output("echo", []); run::program_output("echo", []);
@ -529,7 +529,7 @@ mod tests {
#[test] #[test]
#[allow(non_implicitly_copyable_typarams)] #[allow(non_implicitly_copyable_typarams)]
pub fn test_pipes() { fn test_pipes() {
let pipe_in = os::pipe(); let pipe_in = os::pipe();
let pipe_out = os::pipe(); let pipe_out = os::pipe();
let pipe_err = os::pipe(); let pipe_err = os::pipe();
@ -555,7 +555,7 @@ mod tests {
} }
#[test] #[test]
pub fn waitpid() { fn waitpid() {
let pid = run::spawn_process("false", [], let pid = run::spawn_process("false", [],
&None, &None, &None, &None,
0i32, 0i32, 0i32); 0i32, 0i32, 0i32);
@ -564,20 +564,20 @@ mod tests {
} }
#[test] #[test]
pub fn test_destroy_once() { fn test_destroy_once() {
let mut p = run::start_program("echo", []); let mut p = run::start_program("echo", []);
p.destroy(); // this shouldn't crash (and nor should the destructor) p.destroy(); // this shouldn't crash (and nor should the destructor)
} }
#[test] #[test]
pub fn test_destroy_twice() { fn test_destroy_twice() {
let mut p = run::start_program("echo", []); let mut p = run::start_program("echo", []);
p.destroy(); // this shouldnt crash... p.destroy(); // this shouldnt crash...
p.destroy(); // ...and nor should this (and nor should the destructor) p.destroy(); // ...and nor should this (and nor should the destructor)
} }
#[cfg(unix)] // there is no way to sleep on windows from inside libcore... #[cfg(unix)] // there is no way to sleep on windows from inside libcore...
pub fn test_destroy_actually_kills(force: bool) { fn test_destroy_actually_kills(force: bool) {
let path = Path(fmt!("test/core-run-test-destroy-actually-kills-%?.tmp", force)); let path = Path(fmt!("test/core-run-test-destroy-actually-kills-%?.tmp", force));
os::remove_file(&path); os::remove_file(&path);
@ -598,13 +598,13 @@ mod tests {
#[test] #[test]
#[cfg(unix)] #[cfg(unix)]
pub fn test_unforced_destroy_actually_kills() { fn test_unforced_destroy_actually_kills() {
test_destroy_actually_kills(false); test_destroy_actually_kills(false);
} }
#[test] #[test]
#[cfg(unix)] #[cfg(unix)]
pub fn test_forced_destroy_actually_kills() { fn test_forced_destroy_actually_kills() {
test_destroy_actually_kills(true); test_destroy_actually_kills(true);
} }
} }

View file

@ -160,12 +160,12 @@ pub fn fail_assert(msg: &str, file: &str, line: uint) -> ! {
} }
#[cfg(test)] #[cfg(test)]
pub mod tests { mod tests {
use cast; use cast;
use sys::{Closure, pref_align_of, size_of, nonzero_size_of}; use sys::{Closure, pref_align_of, size_of, nonzero_size_of};
#[test] #[test]
pub fn size_of_basic() { fn size_of_basic() {
assert!(size_of::<u8>() == 1u); assert!(size_of::<u8>() == 1u);
assert!(size_of::<u16>() == 2u); assert!(size_of::<u16>() == 2u);
assert!(size_of::<u32>() == 4u); assert!(size_of::<u32>() == 4u);
@ -176,20 +176,20 @@ pub mod tests {
#[cfg(target_arch = "x86")] #[cfg(target_arch = "x86")]
#[cfg(target_arch = "arm")] #[cfg(target_arch = "arm")]
#[cfg(target_arch = "mips")] #[cfg(target_arch = "mips")]
pub fn size_of_32() { fn size_of_32() {
assert!(size_of::<uint>() == 4u); assert!(size_of::<uint>() == 4u);
assert!(size_of::<*uint>() == 4u); assert!(size_of::<*uint>() == 4u);
} }
#[test] #[test]
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
pub fn size_of_64() { fn size_of_64() {
assert!(size_of::<uint>() == 8u); assert!(size_of::<uint>() == 8u);
assert!(size_of::<*uint>() == 8u); assert!(size_of::<*uint>() == 8u);
} }
#[test] #[test]
pub fn nonzero_size_of_basic() { fn nonzero_size_of_basic() {
type Z = [i8, ..0]; type Z = [i8, ..0];
assert!(size_of::<Z>() == 0u); assert!(size_of::<Z>() == 0u);
assert!(nonzero_size_of::<Z>() == 1u); assert!(nonzero_size_of::<Z>() == 1u);
@ -197,7 +197,7 @@ pub mod tests {
} }
#[test] #[test]
pub fn align_of_basic() { fn align_of_basic() {
assert!(pref_align_of::<u8>() == 1u); assert!(pref_align_of::<u8>() == 1u);
assert!(pref_align_of::<u16>() == 2u); assert!(pref_align_of::<u16>() == 2u);
assert!(pref_align_of::<u32>() == 4u); assert!(pref_align_of::<u32>() == 4u);
@ -207,20 +207,20 @@ pub mod tests {
#[cfg(target_arch = "x86")] #[cfg(target_arch = "x86")]
#[cfg(target_arch = "arm")] #[cfg(target_arch = "arm")]
#[cfg(target_arch = "mips")] #[cfg(target_arch = "mips")]
pub fn align_of_32() { fn align_of_32() {
assert!(pref_align_of::<uint>() == 4u); assert!(pref_align_of::<uint>() == 4u);
assert!(pref_align_of::<*uint>() == 4u); assert!(pref_align_of::<*uint>() == 4u);
} }
#[test] #[test]
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
pub fn align_of_64() { fn align_of_64() {
assert!(pref_align_of::<uint>() == 8u); assert!(pref_align_of::<uint>() == 8u);
assert!(pref_align_of::<*uint>() == 8u); assert!(pref_align_of::<*uint>() == 8u);
} }
#[test] #[test]
pub fn synthesize_closure() { fn synthesize_closure() {
unsafe { unsafe {
let x = 10; let x = 10;
let f: &fn(int) -> int = |y| x + y; let f: &fn(int) -> int = |y| x + y;

View file

@ -925,7 +925,7 @@ fn test_spawn_sched_childs_on_default_sched() {
} }
#[cfg(test)] #[cfg(test)]
pub mod testrt { mod testrt {
use libc; use libc;
#[nolink] #[nolink]

View file

@ -286,14 +286,14 @@ pub impl<T:Owned> Exclusive<T> {
} }
#[cfg(test)] #[cfg(test)]
pub mod tests { mod tests {
use comm; use comm;
use super::exclusive; use super::exclusive;
use task; use task;
use uint; use uint;
#[test] #[test]
pub fn exclusive_arc() { fn exclusive_arc() {
let mut futures = ~[]; let mut futures = ~[];
let num_tasks = 10; let num_tasks = 10;
@ -324,7 +324,7 @@ pub mod tests {
} }
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
pub fn exclusive_poison() { fn exclusive_poison() {
// Tests that if one task fails inside of an exclusive, subsequent // Tests that if one task fails inside of an exclusive, subsequent
// accesses will also fail. // accesses will also fail.
let x = exclusive(1); let x = exclusive(1);

View file

@ -212,14 +212,14 @@ mod test {
use driver::session; use driver::session;
#[test] #[test]
pub fn test_rpaths_to_flags() { fn test_rpaths_to_flags() {
let flags = rpaths_to_flags(~[Path("path1"), let flags = rpaths_to_flags(~[Path("path1"),
Path("path2")]); Path("path2")]);
assert!(flags == ~[~"-Wl,-rpath,path1", ~"-Wl,-rpath,path2"]); assert!(flags == ~[~"-Wl,-rpath,path1", ~"-Wl,-rpath,path2"]);
} }
#[test] #[test]
pub fn test_prefix_rpath() { fn test_prefix_rpath() {
let res = get_install_prefix_rpath("triple"); let res = get_install_prefix_rpath("triple");
let d = Path(env!("CFG_PREFIX")) let d = Path(env!("CFG_PREFIX"))
.push_rel(&Path("lib/rustc/triple/lib")); .push_rel(&Path("lib/rustc/triple/lib"));
@ -230,13 +230,13 @@ mod test {
} }
#[test] #[test]
pub fn test_prefix_rpath_abs() { fn test_prefix_rpath_abs() {
let res = get_install_prefix_rpath("triple"); let res = get_install_prefix_rpath("triple");
assert!(res.is_absolute); assert!(res.is_absolute);
} }
#[test] #[test]
pub fn test_minimize1() { fn test_minimize1() {
let res = minimize_rpaths([Path("rpath1"), let res = minimize_rpaths([Path("rpath1"),
Path("rpath2"), Path("rpath2"),
Path("rpath1")]); Path("rpath1")]);
@ -244,7 +244,7 @@ mod test {
} }
#[test] #[test]
pub fn test_minimize2() { fn test_minimize2() {
let res = minimize_rpaths(~[Path("1a"), Path("2"), Path("2"), let res = minimize_rpaths(~[Path("1a"), Path("2"), Path("2"),
Path("1a"), Path("4a"),Path("1a"), Path("1a"), Path("4a"),Path("1a"),
Path("2"), Path("3"), Path("4a"), Path("2"), Path("3"), Path("4a"),
@ -253,7 +253,7 @@ mod test {
} }
#[test] #[test]
pub fn test_relative_to1() { fn test_relative_to1() {
let p1 = Path("/usr/bin/rustc"); let p1 = Path("/usr/bin/rustc");
let p2 = Path("/usr/lib/mylib"); let p2 = Path("/usr/lib/mylib");
let res = get_relative_to(&p1, &p2); let res = get_relative_to(&p1, &p2);
@ -261,7 +261,7 @@ mod test {
} }
#[test] #[test]
pub fn test_relative_to2() { fn test_relative_to2() {
let p1 = Path("/usr/bin/rustc"); let p1 = Path("/usr/bin/rustc");
let p2 = Path("/usr/bin/../lib/mylib"); let p2 = Path("/usr/bin/../lib/mylib");
let res = get_relative_to(&p1, &p2); let res = get_relative_to(&p1, &p2);
@ -269,7 +269,7 @@ mod test {
} }
#[test] #[test]
pub fn test_relative_to3() { fn test_relative_to3() {
let p1 = Path("/usr/bin/whatever/rustc"); let p1 = Path("/usr/bin/whatever/rustc");
let p2 = Path("/usr/lib/whatever/mylib"); let p2 = Path("/usr/lib/whatever/mylib");
let res = get_relative_to(&p1, &p2); let res = get_relative_to(&p1, &p2);
@ -277,7 +277,7 @@ mod test {
} }
#[test] #[test]
pub fn test_relative_to4() { fn test_relative_to4() {
let p1 = Path("/usr/bin/whatever/../rustc"); let p1 = Path("/usr/bin/whatever/../rustc");
let p2 = Path("/usr/lib/whatever/mylib"); let p2 = Path("/usr/lib/whatever/mylib");
let res = get_relative_to(&p1, &p2); let res = get_relative_to(&p1, &p2);
@ -285,7 +285,7 @@ mod test {
} }
#[test] #[test]
pub fn test_relative_to5() { fn test_relative_to5() {
let p1 = Path("/usr/bin/whatever/../rustc"); let p1 = Path("/usr/bin/whatever/../rustc");
let p2 = Path("/usr/lib/whatever/../mylib"); let p2 = Path("/usr/lib/whatever/../mylib");
let res = get_relative_to(&p1, &p2); let res = get_relative_to(&p1, &p2);
@ -293,7 +293,7 @@ mod test {
} }
#[test] #[test]
pub fn test_relative_to6() { fn test_relative_to6() {
let p1 = Path("/1"); let p1 = Path("/1");
let p2 = Path("/2/3"); let p2 = Path("/2/3");
let res = get_relative_to(&p1, &p2); let res = get_relative_to(&p1, &p2);
@ -301,7 +301,7 @@ mod test {
} }
#[test] #[test]
pub fn test_relative_to7() { fn test_relative_to7() {
let p1 = Path("/1/2"); let p1 = Path("/1/2");
let p2 = Path("/3"); let p2 = Path("/3");
let res = get_relative_to(&p1, &p2); let res = get_relative_to(&p1, &p2);
@ -309,7 +309,7 @@ mod test {
} }
#[test] #[test]
pub fn test_relative_to8() { fn test_relative_to8() {
let p1 = Path("/home/brian/Dev/rust/build/").push_rel( let p1 = Path("/home/brian/Dev/rust/build/").push_rel(
&Path("stage2/lib/rustc/i686-unknown-linux-gnu/lib/librustc.so")); &Path("stage2/lib/rustc/i686-unknown-linux-gnu/lib/librustc.so"));
let p2 = Path("/home/brian/Dev/rust/build/stage2/bin/..").push_rel( let p2 = Path("/home/brian/Dev/rust/build/stage2/bin/..").push_rel(
@ -324,7 +324,7 @@ mod test {
#[test] #[test]
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
#[cfg(target_os = "andorid")] #[cfg(target_os = "andorid")]
pub fn test_rpath_relative() { fn test_rpath_relative() {
let o = session::os_linux; let o = session::os_linux;
let res = get_rpath_relative_to_output(o, let res = get_rpath_relative_to_output(o,
&Path("bin/rustc"), &Path("lib/libstd.so")); &Path("bin/rustc"), &Path("lib/libstd.so"));
@ -333,7 +333,7 @@ mod test {
#[test] #[test]
#[cfg(target_os = "freebsd")] #[cfg(target_os = "freebsd")]
pub fn test_rpath_relative() { fn test_rpath_relative() {
let o = session::os_freebsd; let o = session::os_freebsd;
let res = get_rpath_relative_to_output(o, let res = get_rpath_relative_to_output(o,
&Path("bin/rustc"), &Path("lib/libstd.so")); &Path("bin/rustc"), &Path("lib/libstd.so"));
@ -342,7 +342,7 @@ mod test {
#[test] #[test]
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
pub fn test_rpath_relative() { fn test_rpath_relative() {
// this is why refinements would be nice // this is why refinements would be nice
let o = session::os_macos; let o = session::os_macos;
let res = get_rpath_relative_to_output(o, let res = get_rpath_relative_to_output(o,
@ -352,7 +352,7 @@ mod test {
} }
#[test] #[test]
pub fn test_get_absolute_rpath() { fn test_get_absolute_rpath() {
let res = get_absolute_rpath(&Path("lib/libstd.so")); let res = get_absolute_rpath(&Path("lib/libstd.so"));
debug!("test_get_absolute_rpath: %s vs. %s", debug!("test_get_absolute_rpath: %s vs. %s",
res.to_str(), res.to_str(),

View file

@ -876,7 +876,7 @@ pub fn list_metadata(sess: Session, path: &Path, out: @io::Writer) {
} }
#[cfg(test)] #[cfg(test)]
pub mod test { mod test {
use core::prelude::*; use core::prelude::*;
use driver::driver::{build_configuration, build_session}; use driver::driver::{build_configuration, build_session};
@ -890,7 +890,7 @@ pub mod test {
// When the user supplies --test we should implicitly supply --cfg test // When the user supplies --test we should implicitly supply --cfg test
#[test] #[test]
pub fn test_switch_implies_cfg_test() { fn test_switch_implies_cfg_test() {
let matches = let matches =
&match getopts(~[~"--test"], optgroups()) { &match getopts(~[~"--test"], optgroups()) {
Ok(copy m) => m, Ok(copy m) => m,
@ -907,7 +907,7 @@ pub mod test {
// When the user supplies --test and --cfg test, don't implicitly add // When the user supplies --test and --cfg test, don't implicitly add
// another --cfg test // another --cfg test
#[test] #[test]
pub fn test_switch_implies_cfg_test_unless_cfg_test() { fn test_switch_implies_cfg_test_unless_cfg_test() {
let matches = let matches =
&match getopts(~[~"--test", ~"--cfg=test"], optgroups()) { &match getopts(~[~"--test", ~"--cfg=test"], optgroups()) {
Ok(copy m) => m, Ok(copy m) => m,

View file

@ -354,14 +354,14 @@ pub fn sess_os_to_meta_os(os: os) -> metadata::loader::os {
} }
#[cfg(test)] #[cfg(test)]
pub mod test { mod test {
use driver::session::{bin_crate, building_library, lib_crate}; use driver::session::{bin_crate, building_library, lib_crate};
use driver::session::{unknown_crate}; use driver::session::{unknown_crate};
use syntax::ast; use syntax::ast;
use syntax::codemap; use syntax::codemap;
pub fn make_crate_type_attr(+t: ~str) -> ast::attribute { fn make_crate_type_attr(+t: ~str) -> ast::attribute {
codemap::respan(codemap::dummy_sp(), ast::attribute_ { codemap::respan(codemap::dummy_sp(), ast::attribute_ {
style: ast::attr_outer, style: ast::attr_outer,
value: @codemap::respan(codemap::dummy_sp(), value: @codemap::respan(codemap::dummy_sp(),
@ -373,7 +373,7 @@ pub mod test {
}) })
} }
pub fn make_crate(with_bin: bool, with_lib: bool) -> @ast::crate { fn make_crate(with_bin: bool, with_lib: bool) -> @ast::crate {
let mut attrs = ~[]; let mut attrs = ~[];
if with_bin { attrs += ~[make_crate_type_attr(~"bin")]; } if with_bin { attrs += ~[make_crate_type_attr(~"bin")]; }
if with_lib { attrs += ~[make_crate_type_attr(~"lib")]; } if with_lib { attrs += ~[make_crate_type_attr(~"lib")]; }
@ -385,43 +385,43 @@ pub mod test {
} }
#[test] #[test]
pub fn bin_crate_type_attr_results_in_bin_output() { fn bin_crate_type_attr_results_in_bin_output() {
let crate = make_crate(true, false); let crate = make_crate(true, false);
assert!(!building_library(unknown_crate, crate, false)); assert!(!building_library(unknown_crate, crate, false));
} }
#[test] #[test]
pub fn lib_crate_type_attr_results_in_lib_output() { fn lib_crate_type_attr_results_in_lib_output() {
let crate = make_crate(false, true); let crate = make_crate(false, true);
assert!(building_library(unknown_crate, crate, false)); assert!(building_library(unknown_crate, crate, false));
} }
#[test] #[test]
pub fn bin_option_overrides_lib_crate_type() { fn bin_option_overrides_lib_crate_type() {
let crate = make_crate(false, true); let crate = make_crate(false, true);
assert!(!building_library(bin_crate, crate, false)); assert!(!building_library(bin_crate, crate, false));
} }
#[test] #[test]
pub fn lib_option_overrides_bin_crate_type() { fn lib_option_overrides_bin_crate_type() {
let crate = make_crate(true, false); let crate = make_crate(true, false);
assert!(building_library(lib_crate, crate, false)); assert!(building_library(lib_crate, crate, false));
} }
#[test] #[test]
pub fn bin_crate_type_is_default() { fn bin_crate_type_is_default() {
let crate = make_crate(false, false); let crate = make_crate(false, false);
assert!(!building_library(unknown_crate, crate, false)); assert!(!building_library(unknown_crate, crate, false));
} }
#[test] #[test]
pub fn test_option_overrides_lib_crate_type() { fn test_option_overrides_lib_crate_type() {
let crate = make_crate(false, true); let crate = make_crate(false, true);
assert!(!building_library(unknown_crate, crate, true)); assert!(!building_library(unknown_crate, crate, true));
} }
#[test] #[test]
pub fn test_option_does_not_override_requested_lib_type() { fn test_option_does_not_override_requested_lib_type() {
let crate = make_crate(false, false); let crate = make_crate(false, false);
assert!(building_library(lib_crate, crate, true)); assert!(building_library(lib_crate, crate, true));
} }

View file

@ -492,7 +492,7 @@ mod tests {
use core::vec; use core::vec;
#[test] #[test]
pub fn manually_share_arc() { fn manually_share_arc() {
let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let arc_v = arc::ARC(v); let arc_v = arc::ARC(v);
@ -517,7 +517,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_mutex_arc_condvar() { fn test_mutex_arc_condvar() {
let arc = ~MutexARC(false); let arc = ~MutexARC(false);
let arc2 = ~arc.clone(); let arc2 = ~arc.clone();
let (p,c) = comm::oneshot(); let (p,c) = comm::oneshot();
@ -539,7 +539,7 @@ mod tests {
} }
} }
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
pub fn test_arc_condvar_poison() { fn test_arc_condvar_poison() {
let arc = ~MutexARC(1); let arc = ~MutexARC(1);
let arc2 = ~arc.clone(); let arc2 = ~arc.clone();
let (p, c) = comm::stream(); let (p, c) = comm::stream();
@ -561,7 +561,7 @@ mod tests {
} }
} }
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
pub fn test_mutex_arc_poison() { fn test_mutex_arc_poison() {
let arc = ~MutexARC(1); let arc = ~MutexARC(1);
let arc2 = ~arc.clone(); let arc2 = ~arc.clone();
do task::try || { do task::try || {
@ -574,7 +574,7 @@ mod tests {
} }
} }
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
pub fn test_rw_arc_poison_wr() { fn test_rw_arc_poison_wr() {
let arc = ~RWARC(1); let arc = ~RWARC(1);
let arc2 = (*arc).clone(); let arc2 = (*arc).clone();
do task::try || { do task::try || {
@ -587,7 +587,7 @@ mod tests {
} }
} }
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
pub fn test_rw_arc_poison_ww() { fn test_rw_arc_poison_ww() {
let arc = ~RWARC(1); let arc = ~RWARC(1);
let arc2 = (*arc).clone(); let arc2 = (*arc).clone();
do task::try || { do task::try || {
@ -600,7 +600,7 @@ mod tests {
} }
} }
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
pub fn test_rw_arc_poison_dw() { fn test_rw_arc_poison_dw() {
let arc = ~RWARC(1); let arc = ~RWARC(1);
let arc2 = (*arc).clone(); let arc2 = (*arc).clone();
do task::try || { do task::try || {
@ -615,7 +615,7 @@ mod tests {
} }
} }
#[test] #[ignore(cfg(windows))] #[test] #[ignore(cfg(windows))]
pub fn test_rw_arc_no_poison_rr() { fn test_rw_arc_no_poison_rr() {
let arc = ~RWARC(1); let arc = ~RWARC(1);
let arc2 = (*arc).clone(); let arc2 = (*arc).clone();
do task::try || { do task::try || {
@ -628,7 +628,7 @@ mod tests {
} }
} }
#[test] #[ignore(cfg(windows))] #[test] #[ignore(cfg(windows))]
pub fn test_rw_arc_no_poison_rw() { fn test_rw_arc_no_poison_rw() {
let arc = ~RWARC(1); let arc = ~RWARC(1);
let arc2 = (*arc).clone(); let arc2 = (*arc).clone();
do task::try || { do task::try || {
@ -641,7 +641,7 @@ mod tests {
} }
} }
#[test] #[ignore(cfg(windows))] #[test] #[ignore(cfg(windows))]
pub fn test_rw_arc_no_poison_dr() { fn test_rw_arc_no_poison_dr() {
let arc = ~RWARC(1); let arc = ~RWARC(1);
let arc2 = (*arc).clone(); let arc2 = (*arc).clone();
do task::try || { do task::try || {
@ -657,7 +657,7 @@ mod tests {
} }
} }
#[test] #[test]
pub fn test_rw_arc() { fn test_rw_arc() {
let arc = ~RWARC(0); let arc = ~RWARC(0);
let arc2 = (*arc).clone(); let arc2 = (*arc).clone();
let (p,c) = comm::stream(); let (p,c) = comm::stream();
@ -694,7 +694,7 @@ mod tests {
do arc.read |num| { assert!(*num == 10); } do arc.read |num| { assert!(*num == 10); }
} }
#[test] #[test]
pub fn test_rw_downgrade() { fn test_rw_downgrade() {
// (1) A downgrader gets in write mode and does cond.wait. // (1) A downgrader gets in write mode and does cond.wait.
// (2) A writer gets in write mode, sets state to 42, and does signal. // (2) A writer gets in write mode, sets state to 42, and does signal.
// (3) Downgrader wakes, sets state to 31337. // (3) Downgrader wakes, sets state to 31337.

View file

@ -154,7 +154,7 @@ mod tests {
use core::str; use core::str;
#[test] #[test]
pub fn test_to_base64() { fn test_to_base64() {
assert!((~"").to_base64() == ~""); assert!((~"").to_base64() == ~"");
assert!((~"f").to_base64() == ~"Zg=="); assert!((~"f").to_base64() == ~"Zg==");
assert!((~"fo").to_base64() == ~"Zm8="); assert!((~"fo").to_base64() == ~"Zm8=");
@ -165,7 +165,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_from_base64() { fn test_from_base64() {
assert!((~"").from_base64() == str::to_bytes(~"")); assert!((~"").from_base64() == str::to_bytes(~""));
assert!((~"Zg==").from_base64() == str::to_bytes(~"f")); assert!((~"Zg==").from_base64() == str::to_bytes(~"f"));
assert!((~"Zm8=").from_base64() == str::to_bytes(~"fo")); assert!((~"Zm8=").from_base64() == str::to_bytes(~"fo"));

View file

@ -880,7 +880,7 @@ mod tests {
static bench_bits : uint = 1 << 14; static bench_bits : uint = 1 << 14;
#[test] #[test]
pub fn test_to_str() { fn test_to_str() {
let zerolen = Bitv::new(0u, false); let zerolen = Bitv::new(0u, false);
assert!(zerolen.to_str() == ~""); assert!(zerolen.to_str() == ~"");
@ -889,7 +889,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_0_elements() { fn test_0_elements() {
let mut act; let mut act;
let mut exp; let mut exp;
act = Bitv::new(0u, false); act = Bitv::new(0u, false);
@ -898,7 +898,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_1_element() { fn test_1_element() {
let mut act; let mut act;
act = Bitv::new(1u, false); act = Bitv::new(1u, false);
assert!(act.eq_vec(~[0u])); assert!(act.eq_vec(~[0u]));
@ -907,7 +907,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_2_elements() { fn test_2_elements() {
let mut b = bitv::Bitv::new(2, false); let mut b = bitv::Bitv::new(2, false);
b.set(0, true); b.set(0, true);
b.set(1, false); b.set(1, false);
@ -915,7 +915,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_10_elements() { fn test_10_elements() {
let mut act; let mut act;
// all 0 // all 0
@ -954,7 +954,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_31_elements() { fn test_31_elements() {
let mut act; let mut act;
// all 0 // all 0
@ -1027,7 +1027,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_32_elements() { fn test_32_elements() {
let mut act; let mut act;
// all 0 // all 0
@ -1102,7 +1102,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_33_elements() { fn test_33_elements() {
let mut act; let mut act;
// all 0 // all 0
@ -1178,21 +1178,21 @@ mod tests {
} }
#[test] #[test]
pub fn test_equal_differing_sizes() { fn test_equal_differing_sizes() {
let v0 = Bitv::new(10u, false); let v0 = Bitv::new(10u, false);
let v1 = Bitv::new(11u, false); let v1 = Bitv::new(11u, false);
assert!(!v0.equal(&v1)); assert!(!v0.equal(&v1));
} }
#[test] #[test]
pub fn test_equal_greatly_differing_sizes() { fn test_equal_greatly_differing_sizes() {
let v0 = Bitv::new(10u, false); let v0 = Bitv::new(10u, false);
let v1 = Bitv::new(110u, false); let v1 = Bitv::new(110u, false);
assert!(!v0.equal(&v1)); assert!(!v0.equal(&v1));
} }
#[test] #[test]
pub fn test_equal_sneaky_small() { fn test_equal_sneaky_small() {
let mut a = bitv::Bitv::new(1, false); let mut a = bitv::Bitv::new(1, false);
a.set(0, true); a.set(0, true);
@ -1203,7 +1203,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_equal_sneaky_big() { fn test_equal_sneaky_big() {
let mut a = bitv::Bitv::new(100, false); let mut a = bitv::Bitv::new(100, false);
for uint::range(0, 100) |i| { for uint::range(0, 100) |i| {
a.set(i, true); a.set(i, true);
@ -1218,14 +1218,14 @@ mod tests {
} }
#[test] #[test]
pub fn test_from_bytes() { fn test_from_bytes() {
let bitv = from_bytes([0b10110110, 0b00000000, 0b11111111]); let bitv = from_bytes([0b10110110, 0b00000000, 0b11111111]);
let str = ~"10110110" + ~"00000000" + ~"11111111"; let str = ~"10110110" + ~"00000000" + ~"11111111";
assert!(bitv.to_str() == str); assert!(bitv.to_str() == str);
} }
#[test] #[test]
pub fn test_to_bytes() { fn test_to_bytes() {
let mut bv = Bitv::new(3, true); let mut bv = Bitv::new(3, true);
bv.set(1, false); bv.set(1, false);
assert!(bv.to_bytes() == ~[0b10100000]); assert!(bv.to_bytes() == ~[0b10100000]);
@ -1237,19 +1237,19 @@ mod tests {
} }
#[test] #[test]
pub fn test_from_bools() { fn test_from_bools() {
assert!(from_bools([true, false, true, true]).to_str() == assert!(from_bools([true, false, true, true]).to_str() ==
~"1011"); ~"1011");
} }
#[test] #[test]
pub fn test_to_bools() { fn test_to_bools() {
let bools = ~[false, false, true, false, false, true, true, false]; let bools = ~[false, false, true, false, false, true, true, false];
assert!(from_bytes([0b00100110]).to_bools() == bools); assert!(from_bytes([0b00100110]).to_bools() == bools);
} }
#[test] #[test]
pub fn test_small_difference() { fn test_small_difference() {
let mut b1 = Bitv::new(3, false); let mut b1 = Bitv::new(3, false);
let mut b2 = Bitv::new(3, false); let mut b2 = Bitv::new(3, false);
b1.set(0, true); b1.set(0, true);
@ -1263,7 +1263,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_big_difference() { fn test_big_difference() {
let mut b1 = Bitv::new(100, false); let mut b1 = Bitv::new(100, false);
let mut b2 = Bitv::new(100, false); let mut b2 = Bitv::new(100, false);
b1.set(0, true); b1.set(0, true);
@ -1277,7 +1277,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_small_clear() { fn test_small_clear() {
let mut b = Bitv::new(14, true); let mut b = Bitv::new(14, true);
b.clear(); b.clear();
for b.ones |i| { for b.ones |i| {
@ -1286,7 +1286,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_big_clear() { fn test_big_clear() {
let mut b = Bitv::new(140, true); let mut b = Bitv::new(140, true);
b.clear(); b.clear();
for b.ones |i| { for b.ones |i| {
@ -1295,7 +1295,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_bitv_set_basic() { fn test_bitv_set_basic() {
let mut b = BitvSet::new(); let mut b = BitvSet::new();
assert!(b.insert(3)); assert!(b.insert(3));
assert!(!b.insert(3)); assert!(!b.insert(3));
@ -1382,7 +1382,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_bitv_set_union() { fn test_bitv_set_union() {
let mut a = BitvSet::new(); let mut a = BitvSet::new();
let mut b = BitvSet::new(); let mut b = BitvSet::new();
assert!(a.insert(1)); assert!(a.insert(1));
@ -1410,7 +1410,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_bitv_remove() { fn test_bitv_remove() {
let mut a = BitvSet::new(); let mut a = BitvSet::new();
assert!(a.insert(1)); assert!(a.insert(1));
@ -1430,7 +1430,7 @@ mod tests {
} }
#[bench] #[bench]
pub fn bench_uint_small(b: &mut BenchHarness) { fn bench_uint_small(b: &mut BenchHarness) {
let r = rng(); let r = rng();
let mut bitv = 0 as uint; let mut bitv = 0 as uint;
do b.iter { do b.iter {
@ -1439,7 +1439,7 @@ mod tests {
} }
#[bench] #[bench]
pub fn bench_small_bitv_small(b: &mut BenchHarness) { fn bench_small_bitv_small(b: &mut BenchHarness) {
let r = rng(); let r = rng();
let mut bitv = SmallBitv::new(uint::bits); let mut bitv = SmallBitv::new(uint::bits);
do b.iter { do b.iter {
@ -1448,7 +1448,7 @@ mod tests {
} }
#[bench] #[bench]
pub fn bench_big_bitv_small(b: &mut BenchHarness) { fn bench_big_bitv_small(b: &mut BenchHarness) {
let r = rng(); let r = rng();
let mut bitv = BigBitv::new(~[0]); let mut bitv = BigBitv::new(~[0]);
do b.iter { do b.iter {
@ -1457,7 +1457,7 @@ mod tests {
} }
#[bench] #[bench]
pub fn bench_big_bitv_big(b: &mut BenchHarness) { fn bench_big_bitv_big(b: &mut BenchHarness) {
let r = rng(); let r = rng();
let mut storage = ~[]; let mut storage = ~[];
storage.grow(bench_bits / uint::bits, &0); storage.grow(bench_bits / uint::bits, &0);
@ -1468,7 +1468,7 @@ mod tests {
} }
#[bench] #[bench]
pub fn bench_bitv_big(b: &mut BenchHarness) { fn bench_bitv_big(b: &mut BenchHarness) {
let r = rng(); let r = rng();
let mut bitv = Bitv::new(bench_bits, false); let mut bitv = Bitv::new(bench_bits, false);
do b.iter { do b.iter {
@ -1477,7 +1477,7 @@ mod tests {
} }
#[bench] #[bench]
pub fn bench_bitv_small(b: &mut BenchHarness) { fn bench_bitv_small(b: &mut BenchHarness) {
let r = rng(); let r = rng();
let mut bitv = Bitv::new(uint::bits, false); let mut bitv = Bitv::new(uint::bits, false);
do b.iter { do b.iter {
@ -1486,7 +1486,7 @@ mod tests {
} }
#[bench] #[bench]
pub fn bench_bitv_set_small(b: &mut BenchHarness) { fn bench_bitv_set_small(b: &mut BenchHarness) {
let r = rng(); let r = rng();
let mut bitv = BitvSet::new(); let mut bitv = BitvSet::new();
do b.iter { do b.iter {
@ -1495,7 +1495,7 @@ mod tests {
} }
#[bench] #[bench]
pub fn bench_bitv_set_big(b: &mut BenchHarness) { fn bench_bitv_set_big(b: &mut BenchHarness) {
let r = rng(); let r = rng();
let mut bitv = BitvSet::new(); let mut bitv = BitvSet::new();
do b.iter { do b.iter {
@ -1504,7 +1504,7 @@ mod tests {
} }
#[bench] #[bench]
pub fn bench_bitv_big_union(b: &mut BenchHarness) { fn bench_bitv_big_union(b: &mut BenchHarness) {
let mut b1 = Bitv::new(bench_bits, false); let mut b1 = Bitv::new(bench_bits, false);
let mut b2 = Bitv::new(bench_bits, false); let mut b2 = Bitv::new(bench_bits, false);
do b.iter { do b.iter {

View file

@ -537,7 +537,7 @@ mod tests {
use core::prelude::*; use core::prelude::*;
#[test] #[test]
pub fn test_dlist_concat() { fn test_dlist_concat() {
let a = from_vec(~[1,2]); let a = from_vec(~[1,2]);
let b = from_vec(~[3,4]); let b = from_vec(~[3,4]);
let c = from_vec(~[5,6]); let c = from_vec(~[5,6]);
@ -557,7 +557,7 @@ mod tests {
abcd.assert_consistent(); assert!(abcd.is_empty()); abcd.assert_consistent(); assert!(abcd.is_empty());
} }
#[test] #[test]
pub fn test_dlist_append() { fn test_dlist_append() {
let a = from_vec(~[1,2,3]); let a = from_vec(~[1,2,3]);
let b = from_vec(~[4,5,6]); let b = from_vec(~[4,5,6]);
a.append(b); a.append(b);
@ -573,7 +573,7 @@ mod tests {
a.assert_consistent(); assert!(a.is_empty()); a.assert_consistent(); assert!(a.is_empty());
} }
#[test] #[test]
pub fn test_dlist_append_empty() { fn test_dlist_append_empty() {
let a = from_vec(~[1,2,3]); let a = from_vec(~[1,2,3]);
let b = DList::<int>(); let b = DList::<int>();
a.append(b); a.append(b);
@ -586,7 +586,7 @@ mod tests {
a.assert_consistent(); assert!(a.is_empty()); a.assert_consistent(); assert!(a.is_empty());
} }
#[test] #[test]
pub fn test_dlist_append_to_empty() { fn test_dlist_append_to_empty() {
let a = DList::<int>(); let a = DList::<int>();
let b = from_vec(~[4,5,6]); let b = from_vec(~[4,5,6]);
a.append(b); a.append(b);
@ -599,7 +599,7 @@ mod tests {
a.assert_consistent(); assert!(a.is_empty()); a.assert_consistent(); assert!(a.is_empty());
} }
#[test] #[test]
pub fn test_dlist_append_two_empty() { fn test_dlist_append_two_empty() {
let a = DList::<int>(); let a = DList::<int>();
let b = DList::<int>(); let b = DList::<int>();
a.append(b); a.append(b);
@ -611,19 +611,19 @@ mod tests {
#[test] #[test]
#[ignore(cfg(windows))] #[ignore(cfg(windows))]
#[should_fail] #[should_fail]
pub fn test_dlist_append_self() { fn test_dlist_append_self() {
let a = DList::<int>(); let a = DList::<int>();
a.append(a); a.append(a);
} }
#[test] #[test]
#[ignore(cfg(windows))] #[ignore(cfg(windows))]
#[should_fail] #[should_fail]
pub fn test_dlist_prepend_self() { fn test_dlist_prepend_self() {
let a = DList::<int>(); let a = DList::<int>();
a.prepend(a); a.prepend(a);
} }
#[test] #[test]
pub fn test_dlist_prepend() { fn test_dlist_prepend() {
let a = from_vec(~[1,2,3]); let a = from_vec(~[1,2,3]);
let b = from_vec(~[4,5,6]); let b = from_vec(~[4,5,6]);
b.prepend(a); b.prepend(a);
@ -639,7 +639,7 @@ mod tests {
b.assert_consistent(); assert!(b.is_empty()); b.assert_consistent(); assert!(b.is_empty());
} }
#[test] #[test]
pub fn test_dlist_reverse() { fn test_dlist_reverse() {
let a = from_vec(~[5,4,3,2,1]); let a = from_vec(~[5,4,3,2,1]);
a.reverse(); a.reverse();
assert_eq!(a.len(), 5); assert_eq!(a.len(), 5);
@ -651,14 +651,14 @@ mod tests {
a.assert_consistent(); assert!(a.is_empty()); a.assert_consistent(); assert!(a.is_empty());
} }
#[test] #[test]
pub fn test_dlist_reverse_empty() { fn test_dlist_reverse_empty() {
let a = DList::<int>(); let a = DList::<int>();
a.reverse(); a.reverse();
assert_eq!(a.len(), 0); assert_eq!(a.len(), 0);
a.assert_consistent(); a.assert_consistent();
} }
#[test] #[test]
pub fn test_dlist_each_node() { fn test_dlist_each_node() {
let a = from_vec(~[1,2,4,5]); let a = from_vec(~[1,2,4,5]);
for a.each_node |nobe| { for a.each_node |nobe| {
if nobe.data > 3 { if nobe.data > 3 {
@ -675,28 +675,28 @@ mod tests {
a.assert_consistent(); assert!(a.is_empty()); a.assert_consistent(); assert!(a.is_empty());
} }
#[test] #[test]
pub fn test_dlist_clear() { fn test_dlist_clear() {
let a = from_vec(~[5,4,3,2,1]); let a = from_vec(~[5,4,3,2,1]);
a.clear(); a.clear();
assert_eq!(a.len(), 0); assert_eq!(a.len(), 0);
a.assert_consistent(); a.assert_consistent();
} }
#[test] #[test]
pub fn test_dlist_is_empty() { fn test_dlist_is_empty() {
let empty = DList::<int>(); let empty = DList::<int>();
let full1 = from_vec(~[1,2,3]); let full1 = from_vec(~[1,2,3]);
assert!(empty.is_empty()); assert!(empty.is_empty());
assert!(!full1.is_empty()); assert!(!full1.is_empty());
} }
#[test] #[test]
pub fn test_dlist_head_tail() { fn test_dlist_head_tail() {
let l = from_vec(~[1,2,3]); let l = from_vec(~[1,2,3]);
assert_eq!(l.head(), 1); assert_eq!(l.head(), 1);
assert_eq!(l.tail(), 3); assert_eq!(l.tail(), 3);
assert_eq!(l.len(), 3); assert_eq!(l.len(), 3);
} }
#[test] #[test]
pub fn test_dlist_pop() { fn test_dlist_pop() {
let l = from_vec(~[1,2,3]); let l = from_vec(~[1,2,3]);
assert_eq!(l.pop().get(), 1); assert_eq!(l.pop().get(), 1);
assert_eq!(l.tail(), 3); assert_eq!(l.tail(), 3);
@ -709,7 +709,7 @@ mod tests {
assert!(l.pop().is_none()); assert!(l.pop().is_none());
} }
#[test] #[test]
pub fn test_dlist_pop_tail() { fn test_dlist_pop_tail() {
let l = from_vec(~[1,2,3]); let l = from_vec(~[1,2,3]);
assert_eq!(l.pop_tail().get(), 3); assert_eq!(l.pop_tail().get(), 3);
assert_eq!(l.tail(), 2); assert_eq!(l.tail(), 2);
@ -722,7 +722,7 @@ mod tests {
assert!(l.pop_tail().is_none()); assert!(l.pop_tail().is_none());
} }
#[test] #[test]
pub fn test_dlist_push() { fn test_dlist_push() {
let l = DList::<int>(); let l = DList::<int>();
l.push(1); l.push(1);
assert_eq!(l.head(), 1); assert_eq!(l.head(), 1);
@ -736,7 +736,7 @@ mod tests {
assert_eq!(l.len(), 3); assert_eq!(l.len(), 3);
} }
#[test] #[test]
pub fn test_dlist_push_head() { fn test_dlist_push_head() {
let l = DList::<int>(); let l = DList::<int>();
l.push_head(3); l.push_head(3);
assert_eq!(l.head(), 3); assert_eq!(l.head(), 3);
@ -750,12 +750,12 @@ mod tests {
assert_eq!(l.len(), 3); assert_eq!(l.len(), 3);
} }
#[test] #[test]
pub fn test_dlist_foldl() { fn test_dlist_foldl() {
let l = from_vec(vec::from_fn(101, |x|x)); let l = from_vec(vec::from_fn(101, |x|x));
assert_eq!(iter::foldl(&l, 0, |accum,elem| *accum+*elem), 5050); assert_eq!(iter::foldl(&l, 0, |accum,elem| *accum+*elem), 5050);
} }
#[test] #[test]
pub fn test_dlist_break_early() { fn test_dlist_break_early() {
let l = from_vec(~[1,2,3,4,5]); let l = from_vec(~[1,2,3,4,5]);
let mut x = 0; let mut x = 0;
for l.each |i| { for l.each |i| {
@ -765,7 +765,7 @@ mod tests {
assert_eq!(x, 3); assert_eq!(x, 3);
} }
#[test] #[test]
pub fn test_dlist_remove_head() { fn test_dlist_remove_head() {
let l = DList::<int>(); let l = DList::<int>();
l.assert_consistent(); let one = l.push_n(1); l.assert_consistent(); let one = l.push_n(1);
l.assert_consistent(); let _two = l.push_n(2); l.assert_consistent(); let _two = l.push_n(2);
@ -780,7 +780,7 @@ mod tests {
l.assert_consistent(); assert!(l.is_empty()); l.assert_consistent(); assert!(l.is_empty());
} }
#[test] #[test]
pub fn test_dlist_remove_mid() { fn test_dlist_remove_mid() {
let l = DList::<int>(); let l = DList::<int>();
l.assert_consistent(); let _one = l.push_n(1); l.assert_consistent(); let _one = l.push_n(1);
l.assert_consistent(); let two = l.push_n(2); l.assert_consistent(); let two = l.push_n(2);
@ -795,7 +795,7 @@ mod tests {
l.assert_consistent(); assert!(l.is_empty()); l.assert_consistent(); assert!(l.is_empty());
} }
#[test] #[test]
pub fn test_dlist_remove_tail() { fn test_dlist_remove_tail() {
let l = DList::<int>(); let l = DList::<int>();
l.assert_consistent(); let _one = l.push_n(1); l.assert_consistent(); let _one = l.push_n(1);
l.assert_consistent(); let _two = l.push_n(2); l.assert_consistent(); let _two = l.push_n(2);
@ -810,7 +810,7 @@ mod tests {
l.assert_consistent(); assert!(l.is_empty()); l.assert_consistent(); assert!(l.is_empty());
} }
#[test] #[test]
pub fn test_dlist_remove_one_two() { fn test_dlist_remove_one_two() {
let l = DList::<int>(); let l = DList::<int>();
l.assert_consistent(); let one = l.push_n(1); l.assert_consistent(); let one = l.push_n(1);
l.assert_consistent(); let two = l.push_n(2); l.assert_consistent(); let two = l.push_n(2);
@ -826,7 +826,7 @@ mod tests {
l.assert_consistent(); assert!(l.is_empty()); l.assert_consistent(); assert!(l.is_empty());
} }
#[test] #[test]
pub fn test_dlist_remove_one_three() { fn test_dlist_remove_one_three() {
let l = DList::<int>(); let l = DList::<int>();
l.assert_consistent(); let one = l.push_n(1); l.assert_consistent(); let one = l.push_n(1);
l.assert_consistent(); let _two = l.push_n(2); l.assert_consistent(); let _two = l.push_n(2);
@ -841,7 +841,7 @@ mod tests {
l.assert_consistent(); assert!(l.is_empty()); l.assert_consistent(); assert!(l.is_empty());
} }
#[test] #[test]
pub fn test_dlist_remove_two_three() { fn test_dlist_remove_two_three() {
let l = DList::<int>(); let l = DList::<int>();
l.assert_consistent(); let _one = l.push_n(1); l.assert_consistent(); let _one = l.push_n(1);
l.assert_consistent(); let two = l.push_n(2); l.assert_consistent(); let two = l.push_n(2);
@ -856,7 +856,7 @@ mod tests {
l.assert_consistent(); assert!(l.is_empty()); l.assert_consistent(); assert!(l.is_empty());
} }
#[test] #[test]
pub fn test_dlist_remove_all() { fn test_dlist_remove_all() {
let l = DList::<int>(); let l = DList::<int>();
l.assert_consistent(); let one = l.push_n(1); l.assert_consistent(); let one = l.push_n(1);
l.assert_consistent(); let two = l.push_n(2); l.assert_consistent(); let two = l.push_n(2);
@ -869,7 +869,7 @@ mod tests {
l.assert_consistent(); assert!(l.is_empty()); l.assert_consistent(); assert!(l.is_empty());
} }
#[test] #[test]
pub fn test_dlist_insert_n_before() { fn test_dlist_insert_n_before() {
let l = DList::<int>(); let l = DList::<int>();
l.assert_consistent(); let _one = l.push_n(1); l.assert_consistent(); let _one = l.push_n(1);
l.assert_consistent(); let two = l.push_n(2); l.assert_consistent(); let two = l.push_n(2);
@ -885,7 +885,7 @@ mod tests {
l.assert_consistent(); assert!(l.is_empty()); l.assert_consistent(); assert!(l.is_empty());
} }
#[test] #[test]
pub fn test_dlist_insert_n_after() { fn test_dlist_insert_n_after() {
let l = DList::<int>(); let l = DList::<int>();
l.assert_consistent(); let one = l.push_n(1); l.assert_consistent(); let one = l.push_n(1);
l.assert_consistent(); let _two = l.push_n(2); l.assert_consistent(); let _two = l.push_n(2);
@ -901,7 +901,7 @@ mod tests {
l.assert_consistent(); assert!(l.is_empty()); l.assert_consistent(); assert!(l.is_empty());
} }
#[test] #[test]
pub fn test_dlist_insert_before_head() { fn test_dlist_insert_before_head() {
let l = DList::<int>(); let l = DList::<int>();
l.assert_consistent(); let one = l.push_n(1); l.assert_consistent(); let one = l.push_n(1);
l.assert_consistent(); let _two = l.push_n(2); l.assert_consistent(); let _two = l.push_n(2);
@ -916,7 +916,7 @@ mod tests {
l.assert_consistent(); assert!(l.is_empty()); l.assert_consistent(); assert!(l.is_empty());
} }
#[test] #[test]
pub fn test_dlist_insert_after_tail() { fn test_dlist_insert_after_tail() {
let l = DList::<int>(); let l = DList::<int>();
l.assert_consistent(); let _one = l.push_n(1); l.assert_consistent(); let _one = l.push_n(1);
l.assert_consistent(); let two = l.push_n(2); l.assert_consistent(); let two = l.push_n(2);
@ -931,7 +931,7 @@ mod tests {
l.assert_consistent(); assert!(l.is_empty()); l.assert_consistent(); assert!(l.is_empty());
} }
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
pub fn test_dlist_asymmetric_link() { fn test_dlist_asymmetric_link() {
let l = DList::<int>(); let l = DList::<int>();
let _one = l.push_n(1); let _one = l.push_n(1);
let two = l.push_n(2); let two = l.push_n(2);
@ -939,7 +939,7 @@ mod tests {
l.assert_consistent(); l.assert_consistent();
} }
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
pub fn test_dlist_cyclic_list() { fn test_dlist_cyclic_list() {
let l = DList::<int>(); let l = DList::<int>();
let one = l.push_n(1); let one = l.push_n(1);
let _two = l.push_n(2); let _two = l.push_n(2);
@ -949,32 +949,32 @@ mod tests {
l.assert_consistent(); l.assert_consistent();
} }
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
pub fn test_dlist_headless() { fn test_dlist_headless() {
DList::<int>().head(); DList::<int>().head();
} }
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
pub fn test_dlist_insert_already_present_before() { fn test_dlist_insert_already_present_before() {
let l = DList::<int>(); let l = DList::<int>();
let one = l.push_n(1); let one = l.push_n(1);
let two = l.push_n(2); let two = l.push_n(2);
l.insert_n_before(two, one); l.insert_n_before(two, one);
} }
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
pub fn test_dlist_insert_already_present_after() { fn test_dlist_insert_already_present_after() {
let l = DList::<int>(); let l = DList::<int>();
let one = l.push_n(1); let one = l.push_n(1);
let two = l.push_n(2); let two = l.push_n(2);
l.insert_n_after(one, two); l.insert_n_after(one, two);
} }
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
pub fn test_dlist_insert_before_orphan() { fn test_dlist_insert_before_orphan() {
let l = DList::<int>(); let l = DList::<int>();
let one = new_dlist_node(1); let one = new_dlist_node(1);
let two = new_dlist_node(2); let two = new_dlist_node(2);
l.insert_n_before(one, two); l.insert_n_before(one, two);
} }
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
pub fn test_dlist_insert_after_orphan() { fn test_dlist_insert_after_orphan() {
let l = DList::<int>(); let l = DList::<int>();
let one = new_dlist_node(1); let one = new_dlist_node(1);
let two = new_dlist_node(2); let two = new_dlist_node(2);

View file

@ -172,7 +172,7 @@ pub fn spawn<A:Owned>(blk: ~fn() -> A) -> Future<A> {
#[allow(non_implicitly_copyable_typarams)] #[allow(non_implicitly_copyable_typarams)]
#[cfg(test)] #[cfg(test)]
pub mod test { mod test {
use core::prelude::*; use core::prelude::*;
use future::*; use future::*;
@ -181,13 +181,13 @@ pub mod test {
use core::task; use core::task;
#[test] #[test]
pub fn test_from_value() { fn test_from_value() {
let f = from_value(~"snail"); let f = from_value(~"snail");
assert!(f.get() == ~"snail"); assert!(f.get() == ~"snail");
} }
#[test] #[test]
pub fn test_from_port() { fn test_from_port() {
let (ch, po) = oneshot::init(); let (ch, po) = oneshot::init();
send_one(ch, ~"whale"); send_one(ch, ~"whale");
let f = from_port(po); let f = from_port(po);
@ -195,25 +195,25 @@ pub mod test {
} }
#[test] #[test]
pub fn test_from_fn() { fn test_from_fn() {
let f = from_fn(|| ~"brail"); let f = from_fn(|| ~"brail");
assert!(f.get() == ~"brail"); assert!(f.get() == ~"brail");
} }
#[test] #[test]
pub fn test_interface_get() { fn test_interface_get() {
let f = from_value(~"fail"); let f = from_value(~"fail");
assert!(f.get() == ~"fail"); assert!(f.get() == ~"fail");
} }
#[test] #[test]
pub fn test_get_ref_method() { fn test_get_ref_method() {
let f = from_value(22); let f = from_value(22);
assert!(*f.get_ref() == 22); assert!(*f.get_ref() == 22);
} }
#[test] #[test]
pub fn test_spawn() { fn test_spawn() {
let f = spawn(|| ~"bale"); let f = spawn(|| ~"bale");
assert!(f.get() == ~"bale"); assert!(f.get() == ~"bale");
} }
@ -221,13 +221,13 @@ pub mod test {
#[test] #[test]
#[should_fail] #[should_fail]
#[ignore(cfg(target_os = "win32"))] #[ignore(cfg(target_os = "win32"))]
pub fn test_futurefail() { fn test_futurefail() {
let f = spawn(|| fail!()); let f = spawn(|| fail!());
let _x: ~str = f.get(); let _x: ~str = f.get();
} }
#[test] #[test]
pub fn test_sendable_future() { fn test_sendable_future() {
let expected = ~"schlorf"; let expected = ~"schlorf";
let f = do spawn { copy expected }; let f = do spawn { copy expected };
do task::spawn || { do task::spawn || {

View file

@ -662,7 +662,7 @@ mod tests {
use core::result::{Err, Ok}; use core::result::{Err, Ok};
use core::result; use core::result;
pub fn check_fail_type(f: Fail_, ft: FailType) { fn check_fail_type(f: Fail_, ft: FailType) {
match f { match f {
ArgumentMissing(_) => assert!(ft == ArgumentMissing_), ArgumentMissing(_) => assert!(ft == ArgumentMissing_),
UnrecognizedOption(_) => assert!(ft == UnrecognizedOption_), UnrecognizedOption(_) => assert!(ft == UnrecognizedOption_),
@ -675,7 +675,7 @@ mod tests {
// Tests for reqopt // Tests for reqopt
#[test] #[test]
pub fn test_reqopt_long() { fn test_reqopt_long() {
let args = ~[~"--test=20"]; let args = ~[~"--test=20"];
let opts = ~[reqopt(~"test")]; let opts = ~[reqopt(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -689,7 +689,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_reqopt_long_missing() { fn test_reqopt_long_missing() {
let args = ~[~"blah"]; let args = ~[~"blah"];
let opts = ~[reqopt(~"test")]; let opts = ~[reqopt(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -700,7 +700,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_reqopt_long_no_arg() { fn test_reqopt_long_no_arg() {
let args = ~[~"--test"]; let args = ~[~"--test"];
let opts = ~[reqopt(~"test")]; let opts = ~[reqopt(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -711,7 +711,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_reqopt_long_multi() { fn test_reqopt_long_multi() {
let args = ~[~"--test=20", ~"--test=30"]; let args = ~[~"--test=20", ~"--test=30"];
let opts = ~[reqopt(~"test")]; let opts = ~[reqopt(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -722,7 +722,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_reqopt_short() { fn test_reqopt_short() {
let args = ~[~"-t", ~"20"]; let args = ~[~"-t", ~"20"];
let opts = ~[reqopt(~"t")]; let opts = ~[reqopt(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -736,7 +736,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_reqopt_short_missing() { fn test_reqopt_short_missing() {
let args = ~[~"blah"]; let args = ~[~"blah"];
let opts = ~[reqopt(~"t")]; let opts = ~[reqopt(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -747,7 +747,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_reqopt_short_no_arg() { fn test_reqopt_short_no_arg() {
let args = ~[~"-t"]; let args = ~[~"-t"];
let opts = ~[reqopt(~"t")]; let opts = ~[reqopt(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -758,7 +758,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_reqopt_short_multi() { fn test_reqopt_short_multi() {
let args = ~[~"-t", ~"20", ~"-t", ~"30"]; let args = ~[~"-t", ~"20", ~"-t", ~"30"];
let opts = ~[reqopt(~"t")]; let opts = ~[reqopt(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -771,7 +771,7 @@ mod tests {
// Tests for optopt // Tests for optopt
#[test] #[test]
pub fn test_optopt_long() { fn test_optopt_long() {
let args = ~[~"--test=20"]; let args = ~[~"--test=20"];
let opts = ~[optopt(~"test")]; let opts = ~[optopt(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -785,7 +785,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optopt_long_missing() { fn test_optopt_long_missing() {
let args = ~[~"blah"]; let args = ~[~"blah"];
let opts = ~[optopt(~"test")]; let opts = ~[optopt(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -796,7 +796,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optopt_long_no_arg() { fn test_optopt_long_no_arg() {
let args = ~[~"--test"]; let args = ~[~"--test"];
let opts = ~[optopt(~"test")]; let opts = ~[optopt(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -807,7 +807,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optopt_long_multi() { fn test_optopt_long_multi() {
let args = ~[~"--test=20", ~"--test=30"]; let args = ~[~"--test=20", ~"--test=30"];
let opts = ~[optopt(~"test")]; let opts = ~[optopt(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -818,7 +818,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optopt_short() { fn test_optopt_short() {
let args = ~[~"-t", ~"20"]; let args = ~[~"-t", ~"20"];
let opts = ~[optopt(~"t")]; let opts = ~[optopt(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -832,7 +832,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optopt_short_missing() { fn test_optopt_short_missing() {
let args = ~[~"blah"]; let args = ~[~"blah"];
let opts = ~[optopt(~"t")]; let opts = ~[optopt(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -843,7 +843,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optopt_short_no_arg() { fn test_optopt_short_no_arg() {
let args = ~[~"-t"]; let args = ~[~"-t"];
let opts = ~[optopt(~"t")]; let opts = ~[optopt(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -854,7 +854,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optopt_short_multi() { fn test_optopt_short_multi() {
let args = ~[~"-t", ~"20", ~"-t", ~"30"]; let args = ~[~"-t", ~"20", ~"-t", ~"30"];
let opts = ~[optopt(~"t")]; let opts = ~[optopt(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -867,7 +867,7 @@ mod tests {
// Tests for optflag // Tests for optflag
#[test] #[test]
pub fn test_optflag_long() { fn test_optflag_long() {
let args = ~[~"--test"]; let args = ~[~"--test"];
let opts = ~[optflag(~"test")]; let opts = ~[optflag(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -878,7 +878,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optflag_long_missing() { fn test_optflag_long_missing() {
let args = ~[~"blah"]; let args = ~[~"blah"];
let opts = ~[optflag(~"test")]; let opts = ~[optflag(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -889,7 +889,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optflag_long_arg() { fn test_optflag_long_arg() {
let args = ~[~"--test=20"]; let args = ~[~"--test=20"];
let opts = ~[optflag(~"test")]; let opts = ~[optflag(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -903,7 +903,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optflag_long_multi() { fn test_optflag_long_multi() {
let args = ~[~"--test", ~"--test"]; let args = ~[~"--test", ~"--test"];
let opts = ~[optflag(~"test")]; let opts = ~[optflag(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -914,7 +914,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optflag_short() { fn test_optflag_short() {
let args = ~[~"-t"]; let args = ~[~"-t"];
let opts = ~[optflag(~"t")]; let opts = ~[optflag(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -925,7 +925,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optflag_short_missing() { fn test_optflag_short_missing() {
let args = ~[~"blah"]; let args = ~[~"blah"];
let opts = ~[optflag(~"t")]; let opts = ~[optflag(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -936,7 +936,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optflag_short_arg() { fn test_optflag_short_arg() {
let args = ~[~"-t", ~"20"]; let args = ~[~"-t", ~"20"];
let opts = ~[optflag(~"t")]; let opts = ~[optflag(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -951,7 +951,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optflag_short_multi() { fn test_optflag_short_multi() {
let args = ~[~"-t", ~"-t"]; let args = ~[~"-t", ~"-t"];
let opts = ~[optflag(~"t")]; let opts = ~[optflag(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -963,7 +963,7 @@ mod tests {
// Tests for optflagmulti // Tests for optflagmulti
#[test] #[test]
pub fn test_optflagmulti_short1() { fn test_optflagmulti_short1() {
let args = ~[~"-v"]; let args = ~[~"-v"];
let opts = ~[optflagmulti(~"v")]; let opts = ~[optflagmulti(~"v")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -976,7 +976,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optflagmulti_short2a() { fn test_optflagmulti_short2a() {
let args = ~[~"-v", ~"-v"]; let args = ~[~"-v", ~"-v"];
let opts = ~[optflagmulti(~"v")]; let opts = ~[optflagmulti(~"v")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -989,7 +989,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optflagmulti_short2b() { fn test_optflagmulti_short2b() {
let args = ~[~"-vv"]; let args = ~[~"-vv"];
let opts = ~[optflagmulti(~"v")]; let opts = ~[optflagmulti(~"v")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -1002,7 +1002,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optflagmulti_long1() { fn test_optflagmulti_long1() {
let args = ~[~"--verbose"]; let args = ~[~"--verbose"];
let opts = ~[optflagmulti(~"verbose")]; let opts = ~[optflagmulti(~"verbose")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -1015,7 +1015,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optflagmulti_long2() { fn test_optflagmulti_long2() {
let args = ~[~"--verbose", ~"--verbose"]; let args = ~[~"--verbose", ~"--verbose"];
let opts = ~[optflagmulti(~"verbose")]; let opts = ~[optflagmulti(~"verbose")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -1029,7 +1029,7 @@ mod tests {
// Tests for optmulti // Tests for optmulti
#[test] #[test]
pub fn test_optmulti_long() { fn test_optmulti_long() {
let args = ~[~"--test=20"]; let args = ~[~"--test=20"];
let opts = ~[optmulti(~"test")]; let opts = ~[optmulti(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -1043,7 +1043,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optmulti_long_missing() { fn test_optmulti_long_missing() {
let args = ~[~"blah"]; let args = ~[~"blah"];
let opts = ~[optmulti(~"test")]; let opts = ~[optmulti(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -1054,7 +1054,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optmulti_long_no_arg() { fn test_optmulti_long_no_arg() {
let args = ~[~"--test"]; let args = ~[~"--test"];
let opts = ~[optmulti(~"test")]; let opts = ~[optmulti(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -1065,7 +1065,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optmulti_long_multi() { fn test_optmulti_long_multi() {
let args = ~[~"--test=20", ~"--test=30"]; let args = ~[~"--test=20", ~"--test=30"];
let opts = ~[optmulti(~"test")]; let opts = ~[optmulti(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -1082,7 +1082,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optmulti_short() { fn test_optmulti_short() {
let args = ~[~"-t", ~"20"]; let args = ~[~"-t", ~"20"];
let opts = ~[optmulti(~"t")]; let opts = ~[optmulti(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -1096,7 +1096,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optmulti_short_missing() { fn test_optmulti_short_missing() {
let args = ~[~"blah"]; let args = ~[~"blah"];
let opts = ~[optmulti(~"t")]; let opts = ~[optmulti(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -1107,7 +1107,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optmulti_short_no_arg() { fn test_optmulti_short_no_arg() {
let args = ~[~"-t"]; let args = ~[~"-t"];
let opts = ~[optmulti(~"t")]; let opts = ~[optmulti(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -1118,7 +1118,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_optmulti_short_multi() { fn test_optmulti_short_multi() {
let args = ~[~"-t", ~"20", ~"-t", ~"30"]; let args = ~[~"-t", ~"20", ~"-t", ~"30"];
let opts = ~[optmulti(~"t")]; let opts = ~[optmulti(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -1135,7 +1135,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_unrecognized_option_long() { fn test_unrecognized_option_long() {
let args = ~[~"--untest"]; let args = ~[~"--untest"];
let opts = ~[optmulti(~"t")]; let opts = ~[optmulti(~"t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -1146,7 +1146,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_unrecognized_option_short() { fn test_unrecognized_option_short() {
let args = ~[~"-t"]; let args = ~[~"-t"];
let opts = ~[optmulti(~"test")]; let opts = ~[optmulti(~"test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
@ -1157,7 +1157,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_combined() { fn test_combined() {
let args = let args =
~[~"prog", ~"free1", ~"-s", ~"20", ~"free2", ~[~"prog", ~"free1", ~"-s", ~"20", ~"free2",
~"--flag", ~"--long=30", ~"-f", ~"-m", ~"40", ~"--flag", ~"--long=30", ~"-f", ~"-m", ~"40",
@ -1189,7 +1189,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_multi() { fn test_multi() {
let args = ~[~"-e", ~"foo", ~"--encrypt", ~"foo"]; let args = ~[~"-e", ~"foo", ~"--encrypt", ~"foo"];
let opts = ~[optopt(~"e"), optopt(~"encrypt"), optopt(~"f")]; let opts = ~[optopt(~"e"), optopt(~"encrypt"), optopt(~"f")];
let matches = &match getopts(args, opts) { let matches = &match getopts(args, opts) {
@ -1211,7 +1211,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_nospace() { fn test_nospace() {
let args = ~[~"-Lfoo", ~"-M."]; let args = ~[~"-Lfoo", ~"-M."];
let opts = ~[optmulti(~"L"), optmulti(~"M")]; let opts = ~[optmulti(~"L"), optmulti(~"M")];
let matches = &match getopts(args, opts) { let matches = &match getopts(args, opts) {
@ -1226,7 +1226,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_groups_reqopt() { fn test_groups_reqopt() {
let opt = groups::reqopt(~"b", ~"banana", ~"some bananas", ~"VAL"); let opt = groups::reqopt(~"b", ~"banana", ~"some bananas", ~"VAL");
assert!(opt == OptGroup { short_name: ~"b", assert!(opt == OptGroup { short_name: ~"b",
long_name: ~"banana", long_name: ~"banana",
@ -1237,7 +1237,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_groups_optopt() { fn test_groups_optopt() {
let opt = groups::optopt(~"a", ~"apple", ~"some apples", ~"VAL"); let opt = groups::optopt(~"a", ~"apple", ~"some apples", ~"VAL");
assert!(opt == OptGroup { short_name: ~"a", assert!(opt == OptGroup { short_name: ~"a",
long_name: ~"apple", long_name: ~"apple",
@ -1248,7 +1248,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_groups_optflag() { fn test_groups_optflag() {
let opt = groups::optflag(~"k", ~"kiwi", ~"some kiwis"); let opt = groups::optflag(~"k", ~"kiwi", ~"some kiwis");
assert!(opt == OptGroup { short_name: ~"k", assert!(opt == OptGroup { short_name: ~"k",
long_name: ~"kiwi", long_name: ~"kiwi",
@ -1259,7 +1259,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_groups_optflagopt() { fn test_groups_optflagopt() {
let opt = groups::optflagopt(~"p", ~"pineapple", let opt = groups::optflagopt(~"p", ~"pineapple",
~"some pineapples", ~"VAL"); ~"some pineapples", ~"VAL");
assert!(opt == OptGroup { short_name: ~"p", assert!(opt == OptGroup { short_name: ~"p",
@ -1271,7 +1271,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_groups_optmulti() { fn test_groups_optmulti() {
let opt = groups::optmulti(~"l", ~"lime", let opt = groups::optmulti(~"l", ~"lime",
~"some limes", ~"VAL"); ~"some limes", ~"VAL");
assert!(opt == OptGroup { short_name: ~"l", assert!(opt == OptGroup { short_name: ~"l",
@ -1283,7 +1283,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_groups_long_to_short() { fn test_groups_long_to_short() {
let short = ~[reqopt(~"b"), reqopt(~"banana")]; let short = ~[reqopt(~"b"), reqopt(~"banana")];
let verbose = groups::reqopt(~"b", ~"banana", let verbose = groups::reqopt(~"b", ~"banana",
~"some bananas", ~"VAL"); ~"some bananas", ~"VAL");
@ -1292,7 +1292,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_groups_getopts() { fn test_groups_getopts() {
let short = ~[ let short = ~[
reqopt(~"b"), reqopt(~"banana"), reqopt(~"b"), reqopt(~"banana"),
optopt(~"a"), optopt(~"apple"), optopt(~"a"), optopt(~"apple"),
@ -1318,7 +1318,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_groups_usage() { fn test_groups_usage() {
let optgroups = ~[ let optgroups = ~[
groups::reqopt(~"b", ~"banana", ~"Desc", ~"VAL"), groups::reqopt(~"b", ~"banana", ~"Desc", ~"VAL"),
groups::optopt(~"a", ~"012345678901234567890123456789", groups::optopt(~"a", ~"012345678901234567890123456789",
@ -1349,7 +1349,7 @@ Options:
} }
#[test] #[test]
pub fn test_groups_usage_description_wrapping() { fn test_groups_usage_description_wrapping() {
// indentation should be 24 spaces // indentation should be 24 spaces
// lines wrap after 78: or rather descriptions wrap after 54 // lines wrap after 78: or rather descriptions wrap after 54

View file

@ -160,7 +160,7 @@ mod tests {
use core::option; use core::option;
#[test] #[test]
pub fn test_is_empty() { fn test_is_empty() {
let empty : @list::List<int> = from_vec(~[]); let empty : @list::List<int> = from_vec(~[]);
let full1 = from_vec(~[1]); let full1 = from_vec(~[1]);
let full2 = from_vec(~['r', 'u']); let full2 = from_vec(~['r', 'u']);
@ -171,7 +171,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_from_vec() { fn test_from_vec() {
let l = from_vec(~[0, 1, 2]); let l = from_vec(~[0, 1, 2]);
assert!((head(l) == 0)); assert!((head(l) == 0));
@ -184,13 +184,13 @@ mod tests {
} }
#[test] #[test]
pub fn test_from_vec_empty() { fn test_from_vec_empty() {
let empty : @list::List<int> = from_vec(~[]); let empty : @list::List<int> = from_vec(~[]);
assert!((empty == @list::Nil::<int>)); assert!((empty == @list::Nil::<int>));
} }
#[test] #[test]
pub fn test_foldl() { fn test_foldl() {
fn add(a: &uint, b: &int) -> uint { return *a + (*b as uint); } fn add(a: &uint, b: &int) -> uint { return *a + (*b as uint); }
let l = from_vec(~[0, 1, 2, 3, 4]); let l = from_vec(~[0, 1, 2, 3, 4]);
let empty = @list::Nil::<int>; let empty = @list::Nil::<int>;
@ -199,7 +199,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_foldl2() { fn test_foldl2() {
fn sub(a: &int, b: &int) -> int { fn sub(a: &int, b: &int) -> int {
*a - *b *a - *b
} }
@ -208,14 +208,14 @@ mod tests {
} }
#[test] #[test]
pub fn test_find_success() { fn test_find_success() {
fn match_(i: &int) -> bool { return *i == 2; } fn match_(i: &int) -> bool { return *i == 2; }
let l = from_vec(~[0, 1, 2]); let l = from_vec(~[0, 1, 2]);
assert!((list::find(l, match_) == option::Some(2))); assert!((list::find(l, match_) == option::Some(2)));
} }
#[test] #[test]
pub fn test_find_fail() { fn test_find_fail() {
fn match_(_i: &int) -> bool { return false; } fn match_(_i: &int) -> bool { return false; }
let l = from_vec(~[0, 1, 2]); let l = from_vec(~[0, 1, 2]);
let empty = @list::Nil::<int>; let empty = @list::Nil::<int>;
@ -224,7 +224,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_has() { fn test_has() {
let l = from_vec(~[5, 8, 6]); let l = from_vec(~[5, 8, 6]);
let empty = @list::Nil::<int>; let empty = @list::Nil::<int>;
assert!((list::has(l, 5))); assert!((list::has(l, 5)));
@ -234,7 +234,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_len() { fn test_len() {
let l = from_vec(~[0, 1, 2]); let l = from_vec(~[0, 1, 2]);
let empty = @list::Nil::<int>; let empty = @list::Nil::<int>;
assert!((list::len(l) == 3u)); assert!((list::len(l) == 3u));
@ -242,7 +242,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_append() { fn test_append() {
assert!(from_vec(~[1,2,3,4]) assert!(from_vec(~[1,2,3,4])
== list::append(list::from_vec(~[1,2]), list::from_vec(~[3,4]))); == list::append(list::from_vec(~[1,2]), list::from_vec(~[3,4])));
} }

View file

@ -1426,7 +1426,7 @@ struct TcpBufferedSocketData {
} }
#[cfg(test)] #[cfg(test)]
pub mod test { mod test {
use net::ip; use net::ip;
use net::tcp::{GenericListenErr, TcpConnectErrData, TcpListenErrData}; use net::tcp::{GenericListenErr, TcpConnectErrData, TcpListenErrData};
use net::tcp::{connect, accept, read, listen, TcpSocket, socket_buf}; use net::tcp::{connect, accept, read, listen, TcpSocket, socket_buf};
@ -1447,9 +1447,9 @@ pub mod test {
#[cfg(target_os="darwin")] #[cfg(target_os="darwin")]
#[cfg(target_os="linux")] #[cfg(target_os="linux")]
#[cfg(target_os="android")] #[cfg(target_os="android")]
pub mod tcp_ipv4_server_and_client_test { mod tcp_ipv4_server_and_client_test {
#[cfg(target_arch="x86_64")] #[cfg(target_arch="x86_64")]
pub mod impl64 { mod impl64 {
use net::tcp::test::*; use net::tcp::test::*;
#[test] #[test]
@ -1497,7 +1497,7 @@ pub mod test {
#[cfg(target_arch="x86")] #[cfg(target_arch="x86")]
#[cfg(target_arch="arm")] #[cfg(target_arch="arm")]
#[cfg(target_arch="mips")] #[cfg(target_arch="mips")]
pub mod impl32 { mod impl32 {
use net::tcp::test::*; use net::tcp::test::*;
#[test] #[test]

View file

@ -810,7 +810,7 @@ mod tests {
use core::hashmap::HashMap; use core::hashmap::HashMap;
#[test] #[test]
pub fn test_url_parse() { fn test_url_parse() {
let url = ~"http://user:pass@rust-lang.org/doc?s=v#something"; let url = ~"http://user:pass@rust-lang.org/doc?s=v#something";
let up = from_str(url); let up = from_str(url);
@ -826,7 +826,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_url_parse_host_slash() { fn test_url_parse_host_slash() {
let urlstr = ~"http://0.42.42.42/"; let urlstr = ~"http://0.42.42.42/";
let url = from_str(urlstr).unwrap(); let url = from_str(urlstr).unwrap();
assert!(url.host == ~"0.42.42.42"); assert!(url.host == ~"0.42.42.42");
@ -834,87 +834,87 @@ mod tests {
} }
#[test] #[test]
pub fn test_url_with_underscores() { fn test_url_with_underscores() {
let urlstr = ~"http://dotcom.com/file_name.html"; let urlstr = ~"http://dotcom.com/file_name.html";
let url = from_str(urlstr).unwrap(); let url = from_str(urlstr).unwrap();
assert!(url.path == ~"/file_name.html"); assert!(url.path == ~"/file_name.html");
} }
#[test] #[test]
pub fn test_url_with_dashes() { fn test_url_with_dashes() {
let urlstr = ~"http://dotcom.com/file-name.html"; let urlstr = ~"http://dotcom.com/file-name.html";
let url = from_str(urlstr).unwrap(); let url = from_str(urlstr).unwrap();
assert!(url.path == ~"/file-name.html"); assert!(url.path == ~"/file-name.html");
} }
#[test] #[test]
pub fn test_no_scheme() { fn test_no_scheme() {
assert!(get_scheme("noschemehere.html").is_err()); assert!(get_scheme("noschemehere.html").is_err());
} }
#[test] #[test]
pub fn test_invalid_scheme_errors() { fn test_invalid_scheme_errors() {
assert!(from_str("99://something").is_err()); assert!(from_str("99://something").is_err());
assert!(from_str("://something").is_err()); assert!(from_str("://something").is_err());
} }
#[test] #[test]
pub fn test_full_url_parse_and_format() { fn test_full_url_parse_and_format() {
let url = ~"http://user:pass@rust-lang.org/doc?s=v#something"; let url = ~"http://user:pass@rust-lang.org/doc?s=v#something";
assert!(from_str(url).unwrap().to_str() == url); assert!(from_str(url).unwrap().to_str() == url);
} }
#[test] #[test]
pub fn test_userless_url_parse_and_format() { fn test_userless_url_parse_and_format() {
let url = ~"http://rust-lang.org/doc?s=v#something"; let url = ~"http://rust-lang.org/doc?s=v#something";
assert!(from_str(url).unwrap().to_str() == url); assert!(from_str(url).unwrap().to_str() == url);
} }
#[test] #[test]
pub fn test_queryless_url_parse_and_format() { fn test_queryless_url_parse_and_format() {
let url = ~"http://user:pass@rust-lang.org/doc#something"; let url = ~"http://user:pass@rust-lang.org/doc#something";
assert!(from_str(url).unwrap().to_str() == url); assert!(from_str(url).unwrap().to_str() == url);
} }
#[test] #[test]
pub fn test_empty_query_url_parse_and_format() { fn test_empty_query_url_parse_and_format() {
let url = ~"http://user:pass@rust-lang.org/doc?#something"; let url = ~"http://user:pass@rust-lang.org/doc?#something";
let should_be = ~"http://user:pass@rust-lang.org/doc#something"; let should_be = ~"http://user:pass@rust-lang.org/doc#something";
assert!(from_str(url).unwrap().to_str() == should_be); assert!(from_str(url).unwrap().to_str() == should_be);
} }
#[test] #[test]
pub fn test_fragmentless_url_parse_and_format() { fn test_fragmentless_url_parse_and_format() {
let url = ~"http://user:pass@rust-lang.org/doc?q=v"; let url = ~"http://user:pass@rust-lang.org/doc?q=v";
assert!(from_str(url).unwrap().to_str() == url); assert!(from_str(url).unwrap().to_str() == url);
} }
#[test] #[test]
pub fn test_minimal_url_parse_and_format() { fn test_minimal_url_parse_and_format() {
let url = ~"http://rust-lang.org/doc"; let url = ~"http://rust-lang.org/doc";
assert!(from_str(url).unwrap().to_str() == url); assert!(from_str(url).unwrap().to_str() == url);
} }
#[test] #[test]
pub fn test_scheme_host_only_url_parse_and_format() { fn test_scheme_host_only_url_parse_and_format() {
let url = ~"http://rust-lang.org"; let url = ~"http://rust-lang.org";
assert!(from_str(url).unwrap().to_str() == url); assert!(from_str(url).unwrap().to_str() == url);
} }
#[test] #[test]
pub fn test_pathless_url_parse_and_format() { fn test_pathless_url_parse_and_format() {
let url = ~"http://user:pass@rust-lang.org?q=v#something"; let url = ~"http://user:pass@rust-lang.org?q=v#something";
assert!(from_str(url).unwrap().to_str() == url); assert!(from_str(url).unwrap().to_str() == url);
} }
#[test] #[test]
pub fn test_scheme_host_fragment_only_url_parse_and_format() { fn test_scheme_host_fragment_only_url_parse_and_format() {
let url = ~"http://rust-lang.org#something"; let url = ~"http://rust-lang.org#something";
assert!(from_str(url).unwrap().to_str() == url); assert!(from_str(url).unwrap().to_str() == url);
} }
#[test] #[test]
pub fn test_url_component_encoding() { fn test_url_component_encoding() {
let url = ~"http://rust-lang.org/doc%20uments?ba%25d%20=%23%26%2B"; let url = ~"http://rust-lang.org/doc%20uments?ba%25d%20=%23%26%2B";
let u = from_str(url).unwrap(); let u = from_str(url).unwrap();
assert!(u.path == ~"/doc uments"); assert!(u.path == ~"/doc uments");
@ -922,13 +922,13 @@ mod tests {
} }
#[test] #[test]
pub fn test_url_without_authority() { fn test_url_without_authority() {
let url = ~"mailto:test@email.com"; let url = ~"mailto:test@email.com";
assert!(from_str(url).unwrap().to_str() == url); assert!(from_str(url).unwrap().to_str() == url);
} }
#[test] #[test]
pub fn test_encode() { fn test_encode() {
assert!(encode("") == ~""); assert!(encode("") == ~"");
assert!(encode("http://example.com") == ~"http://example.com"); assert!(encode("http://example.com") == ~"http://example.com");
assert!(encode("foo bar% baz") == ~"foo%20bar%25%20baz"); assert!(encode("foo bar% baz") == ~"foo%20bar%25%20baz");
@ -956,7 +956,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_encode_component() { fn test_encode_component() {
assert!(encode_component("") == ~""); assert!(encode_component("") == ~"");
assert!(encode_component("http://example.com") == assert!(encode_component("http://example.com") ==
~"http%3A%2F%2Fexample.com"); ~"http%3A%2F%2Fexample.com");
@ -985,7 +985,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_decode() { fn test_decode() {
assert!(decode("") == ~""); assert!(decode("") == ~"");
assert!(decode("abc/def 123") == ~"abc/def 123"); assert!(decode("abc/def 123") == ~"abc/def 123");
assert!(decode("abc%2Fdef%20123") == ~"abc%2Fdef 123"); assert!(decode("abc%2Fdef%20123") == ~"abc%2Fdef 123");
@ -1013,7 +1013,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_decode_component() { fn test_decode_component() {
assert!(decode_component("") == ~""); assert!(decode_component("") == ~"");
assert!(decode_component("abc/def 123") == ~"abc/def 123"); assert!(decode_component("abc/def 123") == ~"abc/def 123");
assert!(decode_component("abc%2Fdef%20123") == ~"abc/def 123"); assert!(decode_component("abc%2Fdef%20123") == ~"abc/def 123");
@ -1041,7 +1041,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_encode_form_urlencoded() { fn test_encode_form_urlencoded() {
let mut m = HashMap::new(); let mut m = HashMap::new();
assert!(encode_form_urlencoded(&m) == ~""); assert!(encode_form_urlencoded(&m) == ~"");
@ -1060,7 +1060,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_decode_form_urlencoded() { fn test_decode_form_urlencoded() {
// FIXME #4449: Commented out because this causes an ICE, but only // FIXME #4449: Commented out because this causes an ICE, but only
// on FreeBSD // on FreeBSD
/* /*

View file

@ -282,7 +282,7 @@ mod tests {
use core::vec; use core::vec;
#[test] #[test]
pub fn test() { fn test() {
struct Test { struct Test {
input: ~str, input: ~str,
output: ~[u8], output: ~[u8],

View file

@ -733,7 +733,7 @@ mod test_qsort3 {
use core::vec; use core::vec;
pub fn check_sort(v1: &mut [int], v2: &mut [int]) { fn check_sort(v1: &mut [int], v2: &mut [int]) {
let len = vec::len::<int>(v1); let len = vec::len::<int>(v1);
quick_sort3::<int>(v1); quick_sort3::<int>(v1);
let mut i = 0; let mut i = 0;
@ -745,7 +745,7 @@ mod test_qsort3 {
} }
#[test] #[test]
pub fn test() { fn test() {
{ {
let mut v1 = ~[3, 7, 4, 5, 2, 9, 5, 8]; let mut v1 = ~[3, 7, 4, 5, 2, 9, 5, 8];
let mut v2 = ~[2, 3, 4, 5, 5, 7, 8, 9]; let mut v2 = ~[2, 3, 4, 5, 5, 7, 8, 9];
@ -777,7 +777,7 @@ mod test_qsort {
use core::int; use core::int;
use core::vec; use core::vec;
pub fn check_sort(v1: &mut [int], v2: &mut [int]) { fn check_sort(v1: &mut [int], v2: &mut [int]) {
let len = vec::len::<int>(v1); let len = vec::len::<int>(v1);
fn leual(a: &int, b: &int) -> bool { *a <= *b } fn leual(a: &int, b: &int) -> bool { *a <= *b }
quick_sort::<int>(v1, leual); quick_sort::<int>(v1, leual);
@ -790,7 +790,7 @@ mod test_qsort {
} }
#[test] #[test]
pub fn test() { fn test() {
{ {
let mut v1 = ~[3, 7, 4, 5, 2, 9, 5, 8]; let mut v1 = ~[3, 7, 4, 5, 2, 9, 5, 8];
let mut v2 = ~[2, 3, 4, 5, 5, 7, 8, 9]; let mut v2 = ~[2, 3, 4, 5, 5, 7, 8, 9];
@ -816,7 +816,7 @@ mod test_qsort {
// Regression test for #750 // Regression test for #750
#[test] #[test]
pub fn test_simple() { fn test_simple() {
let mut names = ~[2, 1, 3]; let mut names = ~[2, 1, 3];
let expected = ~[1, 2, 3]; let expected = ~[1, 2, 3];
@ -842,7 +842,7 @@ mod tests {
use core::vec; use core::vec;
pub fn check_sort(v1: &[int], v2: &[int]) { fn check_sort(v1: &[int], v2: &[int]) {
let len = vec::len::<int>(v1); let len = vec::len::<int>(v1);
pub fn le(a: &int, b: &int) -> bool { *a <= *b } pub fn le(a: &int, b: &int) -> bool { *a <= *b }
let f = le; let f = le;
@ -856,7 +856,7 @@ mod tests {
} }
#[test] #[test]
pub fn test() { fn test() {
{ {
let v1 = ~[3, 7, 4, 5, 2, 9, 5, 8]; let v1 = ~[3, 7, 4, 5, 2, 9, 5, 8];
let v2 = ~[2, 3, 4, 5, 5, 7, 8, 9]; let v2 = ~[2, 3, 4, 5, 5, 7, 8, 9];
@ -873,7 +873,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_merge_sort_mutable() { fn test_merge_sort_mutable() {
pub fn le(a: &int, b: &int) -> bool { *a <= *b } pub fn le(a: &int, b: &int) -> bool { *a <= *b }
let mut v1 = ~[3, 2, 1]; let mut v1 = ~[3, 2, 1];
let v2 = merge_sort(v1, le); let v2 = merge_sort(v1, le);
@ -881,7 +881,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_merge_sort_stability() { fn test_merge_sort_stability() {
// tjc: funny that we have to use parens // tjc: funny that we have to use parens
fn ile(x: &(&'static str), y: &(&'static str)) -> bool fn ile(x: &(&'static str), y: &(&'static str)) -> bool
{ {

View file

@ -728,19 +728,19 @@ mod tests {
* Semaphore tests * Semaphore tests
************************************************************************/ ************************************************************************/
#[test] #[test]
pub fn test_sem_acquire_release() { fn test_sem_acquire_release() {
let s = ~semaphore(1); let s = ~semaphore(1);
s.acquire(); s.acquire();
s.release(); s.release();
s.acquire(); s.acquire();
} }
#[test] #[test]
pub fn test_sem_basic() { fn test_sem_basic() {
let s = ~semaphore(1); let s = ~semaphore(1);
do s.access { } do s.access { }
} }
#[test] #[test]
pub fn test_sem_as_mutex() { fn test_sem_as_mutex() {
let s = ~semaphore(1); let s = ~semaphore(1);
let s2 = ~s.clone(); let s2 = ~s.clone();
do task::spawn || { do task::spawn || {
@ -753,7 +753,7 @@ mod tests {
} }
} }
#[test] #[test]
pub fn test_sem_as_cvar() { fn test_sem_as_cvar() {
/* Child waits and parent signals */ /* Child waits and parent signals */
let (p,c) = comm::stream(); let (p,c) = comm::stream();
let s = ~semaphore(0); let s = ~semaphore(0);
@ -779,7 +779,7 @@ mod tests {
c.send(()); c.send(());
} }
#[test] #[test]
pub fn test_sem_multi_resource() { fn test_sem_multi_resource() {
// Parent and child both get in the critical section at the same // Parent and child both get in the critical section at the same
// time, and shake hands. // time, and shake hands.
let s = ~semaphore(2); let s = ~semaphore(2);
@ -798,7 +798,7 @@ mod tests {
} }
} }
#[test] #[test]
pub fn test_sem_runtime_friendly_blocking() { fn test_sem_runtime_friendly_blocking() {
// Force the runtime to schedule two threads on the same sched_loop. // Force the runtime to schedule two threads on the same sched_loop.
// When one blocks, it should schedule the other one. // When one blocks, it should schedule the other one.
do task::spawn_sched(task::ManualThreads(1)) { do task::spawn_sched(task::ManualThreads(1)) {
@ -823,7 +823,7 @@ mod tests {
* Mutex tests * Mutex tests
************************************************************************/ ************************************************************************/
#[test] #[test]
pub fn test_mutex_lock() { fn test_mutex_lock() {
// Unsafely achieve shared state, and do the textbook // Unsafely achieve shared state, and do the textbook
// "load tmp = move ptr; inc tmp; store ptr <- tmp" dance. // "load tmp = move ptr; inc tmp; store ptr <- tmp" dance.
let (p,c) = comm::stream(); let (p,c) = comm::stream();
@ -854,7 +854,7 @@ mod tests {
} }
} }
#[test] #[test]
pub fn test_mutex_cond_wait() { fn test_mutex_cond_wait() {
let m = ~Mutex(); let m = ~Mutex();
// Child wakes up parent // Child wakes up parent
@ -886,7 +886,7 @@ mod tests {
let _ = port.recv(); // Wait until child wakes up let _ = port.recv(); // Wait until child wakes up
} }
#[cfg(test)] #[cfg(test)]
pub fn test_mutex_cond_broadcast_helper(num_waiters: uint) { fn test_mutex_cond_broadcast_helper(num_waiters: uint) {
let m = ~Mutex(); let m = ~Mutex();
let mut ports = ~[]; let mut ports = ~[];
@ -913,15 +913,15 @@ mod tests {
for ports.each |port| { let _ = port.recv(); } for ports.each |port| { let _ = port.recv(); }
} }
#[test] #[test]
pub fn test_mutex_cond_broadcast() { fn test_mutex_cond_broadcast() {
test_mutex_cond_broadcast_helper(12); test_mutex_cond_broadcast_helper(12);
} }
#[test] #[test]
pub fn test_mutex_cond_broadcast_none() { fn test_mutex_cond_broadcast_none() {
test_mutex_cond_broadcast_helper(0); test_mutex_cond_broadcast_helper(0);
} }
#[test] #[test]
pub fn test_mutex_cond_no_waiter() { fn test_mutex_cond_no_waiter() {
let m = ~Mutex(); let m = ~Mutex();
let m2 = ~m.clone(); let m2 = ~m.clone();
do task::try || { do task::try || {
@ -932,7 +932,7 @@ mod tests {
} }
} }
#[test] #[ignore(cfg(windows))] #[test] #[ignore(cfg(windows))]
pub fn test_mutex_killed_simple() { fn test_mutex_killed_simple() {
// Mutex must get automatically unlocked if failed/killed within. // Mutex must get automatically unlocked if failed/killed within.
let m = ~Mutex(); let m = ~Mutex();
let m2 = ~m.clone(); let m2 = ~m.clone();
@ -947,7 +947,7 @@ mod tests {
do m.lock { } do m.lock { }
} }
#[test] #[ignore(cfg(windows))] #[test] #[ignore(cfg(windows))]
pub fn test_mutex_killed_cond() { fn test_mutex_killed_cond() {
// Getting killed during cond wait must not corrupt the mutex while // Getting killed during cond wait must not corrupt the mutex while
// unwinding (e.g. double unlock). // unwinding (e.g. double unlock).
let m = ~Mutex(); let m = ~Mutex();
@ -973,7 +973,7 @@ mod tests {
} }
} }
#[test] #[ignore(cfg(windows))] #[test] #[ignore(cfg(windows))]
pub fn test_mutex_killed_broadcast() { fn test_mutex_killed_broadcast() {
let m = ~Mutex(); let m = ~Mutex();
let m2 = ~m.clone(); let m2 = ~m.clone();
let (p,c) = comm::stream(); let (p,c) = comm::stream();
@ -1026,7 +1026,7 @@ mod tests {
} }
} }
#[test] #[test]
pub fn test_mutex_cond_signal_on_0() { fn test_mutex_cond_signal_on_0() {
// Tests that signal_on(0) is equivalent to signal(). // Tests that signal_on(0) is equivalent to signal().
let m = ~Mutex(); let m = ~Mutex();
do m.lock_cond |cond| { do m.lock_cond |cond| {
@ -1040,7 +1040,7 @@ mod tests {
} }
} }
#[test] #[ignore(cfg(windows))] #[test] #[ignore(cfg(windows))]
pub fn test_mutex_different_conds() { fn test_mutex_different_conds() {
let result = do task::try { let result = do task::try {
let m = ~mutex_with_condvars(2); let m = ~mutex_with_condvars(2);
let m2 = ~m.clone(); let m2 = ~m.clone();
@ -1061,7 +1061,7 @@ mod tests {
assert!(result.is_err()); assert!(result.is_err());
} }
#[test] #[ignore(cfg(windows))] #[test] #[ignore(cfg(windows))]
pub fn test_mutex_no_condvars() { fn test_mutex_no_condvars() {
let result = do task::try { let result = do task::try {
let m = ~mutex_with_condvars(0); let m = ~mutex_with_condvars(0);
do m.lock_cond |cond| { cond.wait(); } do m.lock_cond |cond| { cond.wait(); }
@ -1084,7 +1084,7 @@ mod tests {
#[cfg(test)] #[cfg(test)]
pub enum RWlockMode { Read, Write, Downgrade, DowngradeRead } pub enum RWlockMode { Read, Write, Downgrade, DowngradeRead }
#[cfg(test)] #[cfg(test)]
pub fn lock_rwlock_in_mode(x: &RWlock, mode: RWlockMode, blk: &fn()) { fn lock_rwlock_in_mode(x: &RWlock, mode: RWlockMode, blk: &fn()) {
match mode { match mode {
Read => x.read(blk), Read => x.read(blk),
Write => x.write(blk), Write => x.write(blk),
@ -1100,7 +1100,7 @@ mod tests {
} }
} }
#[cfg(test)] #[cfg(test)]
pub fn test_rwlock_exclusion(x: ~RWlock, fn test_rwlock_exclusion(x: ~RWlock,
mode1: RWlockMode, mode1: RWlockMode,
mode2: RWlockMode) { mode2: RWlockMode) {
// Test mutual exclusion between readers and writers. Just like the // Test mutual exclusion between readers and writers. Just like the
@ -1132,21 +1132,21 @@ mod tests {
} }
} }
#[test] #[test]
pub fn test_rwlock_readers_wont_modify_the_data() { fn test_rwlock_readers_wont_modify_the_data() {
test_rwlock_exclusion(~RWlock(), Read, Write); test_rwlock_exclusion(~RWlock(), Read, Write);
test_rwlock_exclusion(~RWlock(), Write, Read); test_rwlock_exclusion(~RWlock(), Write, Read);
test_rwlock_exclusion(~RWlock(), Read, Downgrade); test_rwlock_exclusion(~RWlock(), Read, Downgrade);
test_rwlock_exclusion(~RWlock(), Downgrade, Read); test_rwlock_exclusion(~RWlock(), Downgrade, Read);
} }
#[test] #[test]
pub fn test_rwlock_writers_and_writers() { fn test_rwlock_writers_and_writers() {
test_rwlock_exclusion(~RWlock(), Write, Write); test_rwlock_exclusion(~RWlock(), Write, Write);
test_rwlock_exclusion(~RWlock(), Write, Downgrade); test_rwlock_exclusion(~RWlock(), Write, Downgrade);
test_rwlock_exclusion(~RWlock(), Downgrade, Write); test_rwlock_exclusion(~RWlock(), Downgrade, Write);
test_rwlock_exclusion(~RWlock(), Downgrade, Downgrade); test_rwlock_exclusion(~RWlock(), Downgrade, Downgrade);
} }
#[cfg(test)] #[cfg(test)]
pub fn test_rwlock_handshake(x: ~RWlock, fn test_rwlock_handshake(x: ~RWlock,
mode1: RWlockMode, mode1: RWlockMode,
mode2: RWlockMode, mode2: RWlockMode,
make_mode2_go_first: bool) { make_mode2_go_first: bool) {
@ -1178,7 +1178,7 @@ mod tests {
} }
} }
#[test] #[test]
pub fn test_rwlock_readers_and_readers() { fn test_rwlock_readers_and_readers() {
test_rwlock_handshake(~RWlock(), Read, Read, false); test_rwlock_handshake(~RWlock(), Read, Read, false);
// The downgrader needs to get in before the reader gets in, otherwise // The downgrader needs to get in before the reader gets in, otherwise
// they cannot end up reading at the same time. // they cannot end up reading at the same time.
@ -1187,7 +1187,7 @@ mod tests {
// Two downgrade_reads can never both end up reading at the same time. // Two downgrade_reads can never both end up reading at the same time.
} }
#[test] #[test]
pub fn test_rwlock_downgrade_unlock() { fn test_rwlock_downgrade_unlock() {
// Tests that downgrade can unlock the lock in both modes // Tests that downgrade can unlock the lock in both modes
let x = ~RWlock(); let x = ~RWlock();
do lock_rwlock_in_mode(x, Downgrade) { } do lock_rwlock_in_mode(x, Downgrade) { }
@ -1197,12 +1197,12 @@ mod tests {
test_rwlock_exclusion(y, Write, Write); test_rwlock_exclusion(y, Write, Write);
} }
#[test] #[test]
pub fn test_rwlock_read_recursive() { fn test_rwlock_read_recursive() {
let x = ~RWlock(); let x = ~RWlock();
do x.read { do x.read { } } do x.read { do x.read { } }
} }
#[test] #[test]
pub fn test_rwlock_cond_wait() { fn test_rwlock_cond_wait() {
// As test_mutex_cond_wait above. // As test_mutex_cond_wait above.
let x = ~RWlock(); let x = ~RWlock();
@ -1237,7 +1237,7 @@ mod tests {
do x.read { } // Just for good measure do x.read { } // Just for good measure
} }
#[cfg(test)] #[cfg(test)]
pub fn test_rwlock_cond_broadcast_helper(num_waiters: uint, fn test_rwlock_cond_broadcast_helper(num_waiters: uint,
dg1: bool, dg1: bool,
dg2: bool) { dg2: bool) {
// Much like the mutex broadcast test. Downgrade-enabled. // Much like the mutex broadcast test. Downgrade-enabled.
@ -1276,7 +1276,7 @@ mod tests {
for ports.each |port| { let _ = port.recv(); } for ports.each |port| { let _ = port.recv(); }
} }
#[test] #[test]
pub fn test_rwlock_cond_broadcast() { fn test_rwlock_cond_broadcast() {
test_rwlock_cond_broadcast_helper(0, true, true); test_rwlock_cond_broadcast_helper(0, true, true);
test_rwlock_cond_broadcast_helper(0, true, false); test_rwlock_cond_broadcast_helper(0, true, false);
test_rwlock_cond_broadcast_helper(0, false, true); test_rwlock_cond_broadcast_helper(0, false, true);
@ -1287,7 +1287,7 @@ mod tests {
test_rwlock_cond_broadcast_helper(12, false, false); test_rwlock_cond_broadcast_helper(12, false, false);
} }
#[cfg(test)] #[ignore(cfg(windows))] #[cfg(test)] #[ignore(cfg(windows))]
pub fn rwlock_kill_helper(mode1: RWlockMode, mode2: RWlockMode) { fn rwlock_kill_helper(mode1: RWlockMode, mode2: RWlockMode) {
// Mutex must get automatically unlocked if failed/killed within. // Mutex must get automatically unlocked if failed/killed within.
let x = ~RWlock(); let x = ~RWlock();
let x2 = (*x).clone(); let x2 = (*x).clone();
@ -1302,23 +1302,23 @@ mod tests {
do lock_rwlock_in_mode(x, mode2) { } do lock_rwlock_in_mode(x, mode2) { }
} }
#[test] #[ignore(cfg(windows))] #[test] #[ignore(cfg(windows))]
pub fn test_rwlock_reader_killed_writer() { fn test_rwlock_reader_killed_writer() {
rwlock_kill_helper(Read, Write); rwlock_kill_helper(Read, Write);
} }
#[test] #[ignore(cfg(windows))] #[test] #[ignore(cfg(windows))]
pub fn test_rwlock_writer_killed_reader() { fn test_rwlock_writer_killed_reader() {
rwlock_kill_helper(Write,Read ); rwlock_kill_helper(Write,Read );
} }
#[test] #[ignore(cfg(windows))] #[test] #[ignore(cfg(windows))]
pub fn test_rwlock_reader_killed_reader() { fn test_rwlock_reader_killed_reader() {
rwlock_kill_helper(Read, Read ); rwlock_kill_helper(Read, Read );
} }
#[test] #[ignore(cfg(windows))] #[test] #[ignore(cfg(windows))]
pub fn test_rwlock_writer_killed_writer() { fn test_rwlock_writer_killed_writer() {
rwlock_kill_helper(Write,Write); rwlock_kill_helper(Write,Write);
} }
#[test] #[ignore(cfg(windows))] #[test] #[ignore(cfg(windows))]
pub fn test_rwlock_kill_downgrader() { fn test_rwlock_kill_downgrader() {
rwlock_kill_helper(Downgrade, Read); rwlock_kill_helper(Downgrade, Read);
rwlock_kill_helper(Read, Downgrade); rwlock_kill_helper(Read, Downgrade);
rwlock_kill_helper(Downgrade, Write); rwlock_kill_helper(Downgrade, Write);
@ -1333,7 +1333,7 @@ mod tests {
rwlock_kill_helper(Downgrade, DowngradeRead); rwlock_kill_helper(Downgrade, DowngradeRead);
} }
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
pub fn test_rwlock_downgrade_cant_swap() { fn test_rwlock_downgrade_cant_swap() {
// Tests that you can't downgrade with a different rwlock's token. // Tests that you can't downgrade with a different rwlock's token.
let x = ~RWlock(); let x = ~RWlock();
let y = ~RWlock(); let y = ~RWlock();

View file

@ -823,7 +823,7 @@ mod tests {
#[test] #[test]
#[ignore(cfg(windows))] #[ignore(cfg(windows))]
pub fn test_should_fail() { fn test_should_fail() {
fn f() { fail!(); } fn f() { fail!(); }
let desc = TestDescAndFn { let desc = TestDescAndFn {
desc: TestDesc { desc: TestDesc {
@ -841,7 +841,7 @@ mod tests {
} }
#[test] #[test]
pub fn test_should_fail_but_succeeds() { fn test_should_fail_but_succeeds() {
fn f() { } fn f() { }
let desc = TestDescAndFn { let desc = TestDescAndFn {
desc: TestDesc { desc: TestDesc {
@ -859,7 +859,7 @@ mod tests {
} }
#[test] #[test]
pub fn first_free_arg_should_be_a_filter() { fn first_free_arg_should_be_a_filter() {
let args = ~[~"progname", ~"filter"]; let args = ~[~"progname", ~"filter"];
let opts = match parse_opts(args) { let opts = match parse_opts(args) {
either::Left(copy o) => o, either::Left(copy o) => o,
@ -869,7 +869,7 @@ mod tests {
} }
#[test] #[test]
pub fn parse_ignored_flag() { fn parse_ignored_flag() {
let args = ~[~"progname", ~"filter", ~"--ignored"]; let args = ~[~"progname", ~"filter", ~"--ignored"];
let opts = match parse_opts(args) { let opts = match parse_opts(args) {
either::Left(copy o) => o, either::Left(copy o) => o,

View file

@ -872,7 +872,7 @@ mod tests {
use core::str; use core::str;
use core::vec; use core::vec;
pub fn test_get_time() { fn test_get_time() {
static some_recent_date: i64 = 1325376000i64; // 2012-01-01T00:00:00Z static some_recent_date: i64 = 1325376000i64; // 2012-01-01T00:00:00Z
static some_future_date: i64 = 1577836800i64; // 2020-01-01T00:00:00Z static some_future_date: i64 = 1577836800i64; // 2020-01-01T00:00:00Z
@ -893,7 +893,7 @@ mod tests {
} }
} }
pub fn test_precise_time() { fn test_precise_time() {
let s0 = precise_time_s(); let s0 = precise_time_s();
let ns1 = precise_time_ns(); let ns1 = precise_time_ns();
@ -910,7 +910,7 @@ mod tests {
assert!(ns2 >= ns1); assert!(ns2 >= ns1);
} }
pub fn test_at_utc() { fn test_at_utc() {
os::setenv(~"TZ", ~"America/Los_Angeles"); os::setenv(~"TZ", ~"America/Los_Angeles");
tzset(); tzset();
@ -931,7 +931,7 @@ mod tests {
assert!(utc.tm_nsec == 54321_i32); assert!(utc.tm_nsec == 54321_i32);
} }
pub fn test_at() { fn test_at() {
os::setenv(~"TZ", ~"America/Los_Angeles"); os::setenv(~"TZ", ~"America/Los_Angeles");
tzset(); tzset();
@ -959,7 +959,7 @@ mod tests {
assert!(local.tm_nsec == 54321_i32); assert!(local.tm_nsec == 54321_i32);
} }
pub fn test_to_timespec() { fn test_to_timespec() {
os::setenv(~"TZ", ~"America/Los_Angeles"); os::setenv(~"TZ", ~"America/Los_Angeles");
tzset(); tzset();
@ -970,7 +970,7 @@ mod tests {
assert!(utc.to_local().to_timespec() == time); assert!(utc.to_local().to_timespec() == time);
} }
pub fn test_conversions() { fn test_conversions() {
os::setenv(~"TZ", ~"America/Los_Angeles"); os::setenv(~"TZ", ~"America/Los_Angeles");
tzset(); tzset();
@ -986,7 +986,7 @@ mod tests {
assert!(utc.to_local().to_utc() == utc); assert!(utc.to_local().to_utc() == utc);
} }
pub fn test_strptime() { fn test_strptime() {
os::setenv(~"TZ", ~"America/Los_Angeles"); os::setenv(~"TZ", ~"America/Los_Angeles");
tzset(); tzset();
@ -1144,7 +1144,7 @@ mod tests {
assert!(test(~"%", ~"%%")); assert!(test(~"%", ~"%%"));
} }
pub fn test_ctime() { fn test_ctime() {
os::setenv(~"TZ", ~"America/Los_Angeles"); os::setenv(~"TZ", ~"America/Los_Angeles");
tzset(); tzset();
@ -1158,7 +1158,7 @@ mod tests {
assert!(local.ctime() == ~"Fri Feb 13 15:31:30 2009"); assert!(local.ctime() == ~"Fri Feb 13 15:31:30 2009");
} }
pub fn test_strftime() { fn test_strftime() {
os::setenv(~"TZ", ~"America/Los_Angeles"); os::setenv(~"TZ", ~"America/Los_Angeles");
tzset(); tzset();
@ -1231,7 +1231,7 @@ mod tests {
assert!(utc.rfc3339() == ~"2009-02-13T23:31:30Z"); assert!(utc.rfc3339() == ~"2009-02-13T23:31:30Z");
} }
pub fn test_timespec_eq_ord() { fn test_timespec_eq_ord() {
use core::cmp::{eq, ge, gt, le, lt, ne}; use core::cmp::{eq, ge, gt, le, lt, ne};
let a = &Timespec::new(-2, 1); let a = &Timespec::new(-2, 1);
@ -1265,7 +1265,7 @@ mod tests {
} }
#[test] #[test]
pub fn run_tests() { fn run_tests() {
// The tests race on tzset. So instead of having many independent // The tests race on tzset. So instead of having many independent
// tests, we will just call the functions now. // tests, we will just call the functions now.
test_get_time(); test_get_time();

View file

@ -183,13 +183,13 @@ mod test {
use core::pipes::{stream, SharedChan}; use core::pipes::{stream, SharedChan};
#[test] #[test]
pub fn test_gl_timer_simple_sleep_test() { fn test_gl_timer_simple_sleep_test() {
let hl_loop = &uv::global_loop::get(); let hl_loop = &uv::global_loop::get();
sleep(hl_loop, 1u); sleep(hl_loop, 1u);
} }
#[test] #[test]
pub fn test_gl_timer_sleep_stress1() { fn test_gl_timer_sleep_stress1() {
let hl_loop = &uv::global_loop::get(); let hl_loop = &uv::global_loop::get();
for iter::repeat(50u) { for iter::repeat(50u) {
sleep(hl_loop, 1u); sleep(hl_loop, 1u);
@ -197,7 +197,7 @@ mod test {
} }
#[test] #[test]
pub fn test_gl_timer_sleep_stress2() { fn test_gl_timer_sleep_stress2() {
let (po, ch) = stream(); let (po, ch) = stream();
let ch = SharedChan(ch); let ch = SharedChan(ch);
let hl_loop = &uv::global_loop::get(); let hl_loop = &uv::global_loop::get();
@ -241,7 +241,7 @@ mod test {
#[test] #[test]
#[cfg(ignore)] #[cfg(ignore)]
pub fn test_gl_timer_recv_timeout_before_time_passes() { fn test_gl_timer_recv_timeout_before_time_passes() {
let times = 100; let times = 100;
let mut successes = 0; let mut successes = 0;
let mut failures = 0; let mut failures = 0;
@ -270,7 +270,7 @@ mod test {
} }
#[test] #[test]
pub fn test_gl_timer_recv_timeout_after_time_passes() { fn test_gl_timer_recv_timeout_after_time_passes() {
let times = 100; let times = 100;
let mut successes = 0; let mut successes = 0;
let mut failures = 0; let mut failures = 0;

View file

@ -1225,7 +1225,7 @@ pub unsafe fn addrinfo_as_sockaddr_in6(input: *addrinfo) -> *sockaddr_in6 {
} }
#[cfg(test)] #[cfg(test)]
pub mod test { mod test {
use core::prelude::*; use core::prelude::*;
use core::comm::{SharedChan, stream, GenericChan, GenericPort}; use core::comm::{SharedChan, stream, GenericChan, GenericPort};
use super::*; use super::*;
@ -1759,11 +1759,11 @@ pub mod test {
#[cfg(target_os="darwin")] #[cfg(target_os="darwin")]
#[cfg(target_os="linux")] #[cfg(target_os="linux")]
#[cfg(target_os="android")] #[cfg(target_os="android")]
pub mod tcp_and_server_client_test { mod tcp_and_server_client_test {
#[cfg(target_arch="x86_64")] #[cfg(target_arch="x86_64")]
pub mod impl64 { mod impl64 {
#[test] #[test]
pub fn test_uv_ll_tcp_server_and_request() { fn test_uv_ll_tcp_server_and_request() {
unsafe { unsafe {
super::super::impl_uv_tcp_server_and_request(); super::super::impl_uv_tcp_server_and_request();
} }
@ -1772,10 +1772,10 @@ pub mod test {
#[cfg(target_arch="x86")] #[cfg(target_arch="x86")]
#[cfg(target_arch="arm")] #[cfg(target_arch="arm")]
#[cfg(target_arch="mips")] #[cfg(target_arch="mips")]
pub mod impl32 { mod impl32 {
#[test] #[test]
#[ignore(cfg(target_os = "linux"))] #[ignore(cfg(target_os = "linux"))]
pub fn test_uv_ll_tcp_server_and_request() { fn test_uv_ll_tcp_server_and_request() {
unsafe { unsafe {
super::super::impl_uv_tcp_server_and_request(); super::super::impl_uv_tcp_server_and_request();
} }

View file

@ -781,7 +781,7 @@ fn consume_whitespace(rdr: @mut StringReader) {
} }
#[cfg(test)] #[cfg(test)]
pub mod test { mod test {
use super::*; use super::*;
use ast; use ast;

View file

@ -2248,7 +2248,7 @@ pub fn print_onceness(s: @ps, o: ast::Onceness) {
} }
#[cfg(test)] #[cfg(test)]
pub mod test { mod test {
use super::*; use super::*;
use ast; use ast;

View file

@ -66,43 +66,47 @@ pub impl<T:Eq + IterBytes + Hash + Const + Copy> Interner<T> {
fn len(&self) -> uint { let vect = &*self.vect; vect.len() } fn len(&self) -> uint { let vect = &*self.vect; vect.len() }
} }
#[test] #[cfg(test)]
#[should_fail] mod tests {
pub fn i1 () { use super::*;
let i : Interner<@~str> = Interner::new(); #[test]
i.get(13); #[should_fail]
} fn i1 () {
let i : Interner<@~str> = Interner::new();
i.get(13);
}
#[test] #[test]
pub fn i2 () { fn i2 () {
let i : Interner<@~str> = Interner::new(); let i : Interner<@~str> = Interner::new();
// first one is zero: // first one is zero:
assert_eq!(i.intern (@~"dog"), 0); assert_eq!(i.intern (@~"dog"), 0);
// re-use gets the same entry: // re-use gets the same entry:
assert_eq!(i.intern (@~"dog"), 0); assert_eq!(i.intern (@~"dog"), 0);
// different string gets a different #: // different string gets a different #:
assert_eq!(i.intern (@~"cat"), 1); assert_eq!(i.intern (@~"cat"), 1);
assert_eq!(i.intern (@~"cat"), 1); assert_eq!(i.intern (@~"cat"), 1);
// dog is still at zero // dog is still at zero
assert_eq!(i.intern (@~"dog"), 0); assert_eq!(i.intern (@~"dog"), 0);
// gensym gets 3 // gensym gets 3
assert_eq!(i.gensym (@~"zebra" ), 2); assert_eq!(i.gensym (@~"zebra" ), 2);
// gensym of same string gets new number : // gensym of same string gets new number :
assert_eq!(i.gensym (@~"zebra" ), 3); assert_eq!(i.gensym (@~"zebra" ), 3);
// gensym of *existing* string gets new number: // gensym of *existing* string gets new number:
assert_eq!(i.gensym (@~"dog"), 4); assert_eq!(i.gensym (@~"dog"), 4);
assert_eq!(i.get(0), @~"dog"); assert_eq!(i.get(0), @~"dog");
assert_eq!(i.get(1), @~"cat"); assert_eq!(i.get(1), @~"cat");
assert_eq!(i.get(2), @~"zebra"); assert_eq!(i.get(2), @~"zebra");
assert_eq!(i.get(3), @~"zebra"); assert_eq!(i.get(3), @~"zebra");
assert_eq!(i.get(4), @~"dog"); assert_eq!(i.get(4), @~"dog");
} }
#[test] #[test]
pub fn i3 () { fn i3 () {
let i : Interner<@~str> = Interner::prefill([@~"Alan",@~"Bob",@~"Carol"]); let i : Interner<@~str> = Interner::prefill([@~"Alan",@~"Bob",@~"Carol"]);
assert_eq!(i.get(0), @~"Alan"); assert_eq!(i.get(0), @~"Alan");
assert_eq!(i.get(1), @~"Bob"); assert_eq!(i.get(1), @~"Bob");
assert_eq!(i.get(2), @~"Carol"); assert_eq!(i.get(2), @~"Carol");
assert_eq!(i.intern(@~"Bob"), 1); assert_eq!(i.intern(@~"Bob"), 1);
} }
}