Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 38 additions & 34 deletions src/libcore/at_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,45 +277,49 @@ pub mod raw {
pub unsafe fn reserve_at_least<T>(v: &mut @[T], n: uint) {
reserve(v, uint::next_power_of_two(n));
}

}

#[test]
pub fn test() {
// 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);
#[cfg(test)]
mod test {
use super::*;
use prelude::*;

#[test]
fn test() {
// 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]);
}

#[test]
pub fn append_test() {
assert!(@[1,2,3] + @[4,5,6] == @[1,2,3,4,5,6]);
}
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]);
}

#[test]
pub fn test_from_owned() {
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]
fn append_test() {
assert!(@[1,2,3] + @[4,5,6] == @[1,2,3,4,5,6]);
}

#[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_owned() {
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]
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]]);
}
}
10 changes: 5 additions & 5 deletions src/libcore/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,16 @@ pub unsafe fn copy_lifetime_vec<'a,S,T>(_ptr: &'a [S], ptr: &T) -> &'a T {
****************************************************************************/

#[cfg(test)]
pub mod tests {
mod tests {
use cast::{bump_box_refcount, reinterpret_cast, transmute};

#[test]
pub fn test_reinterpret_cast() {
fn test_reinterpret_cast() {
assert!(1u == unsafe { reinterpret_cast(&1) });
}

#[test]
pub fn test_bump_box_refcount() {
fn test_bump_box_refcount() {
unsafe {
let box = @~"box box box"; // refcount 1
bump_box_refcount(box); // refcount 2
Expand All @@ -135,7 +135,7 @@ pub mod tests {
}

#[test]
pub fn test_transmute() {
fn test_transmute() {
use managed::raw::BoxRepr;
unsafe {
let x = @100u8;
Expand All @@ -146,7 +146,7 @@ pub mod tests {
}

#[test]
pub fn test_transmute2() {
fn test_transmute2() {
unsafe {
assert!(~[76u8, 0u8] == transmute(~"L"));
}
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,12 @@ pub fn try_send_one<T: Owned>(chan: ChanOne<T>, data: T)
}

#[cfg(test)]
pub mod test {
mod test {
use either::Right;
use super::{Chan, Port, oneshot, recv_one, stream};

#[test]
pub fn test_select2() {
fn test_select2() {
let (p1, c1) = stream();
let (p2, c2) = stream();

Expand All @@ -446,7 +446,7 @@ pub mod test {
}

#[test]
pub fn test_oneshot() {
fn test_oneshot() {
let (c, p) = oneshot::init();

oneshot::client::send(c, ());
Expand Down
Loading