From d3be98e9f5e721b53dccd0a43c2ff58ddd32ac47 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Tue, 16 Apr 2013 01:08:52 +1000 Subject: [PATCH 1/3] libcore,std,syntax,rustc: move tests into `mod tests`, make them private (no pub mod or pub fn). --- src/libcore/at_vec.rs | 71 +++--- src/libcore/cast.rs | 10 +- src/libcore/comm.rs | 6 +- src/libcore/hash.rs | 310 ++++++++++++------------ src/libcore/hashmap.rs | 28 +-- src/libcore/num/float.rs | 395 ++++++++++++++++--------------- src/libcore/num/int-template.rs | 317 +++++++++++++------------ src/libcore/num/uint-template.rs | 316 +++++++++++++------------ src/libcore/pipes.rs | 6 +- src/libcore/ptr.rs | 202 ++++++++-------- src/libcore/rand.rs | 40 ++-- src/libcore/run.rs | 16 +- src/libcore/sys.rs | 18 +- src/libcore/task/mod.rs | 2 +- src/libcore/unstable.rs | 6 +- src/librustc/back/rpath.rs | 34 +-- src/librustc/driver/driver.rs | 6 +- src/librustc/driver/session.rs | 20 +- src/libstd/arc.rs | 24 +- src/libstd/base64.rs | 4 +- src/libstd/bitv.rs | 64 ++--- src/libstd/dlist.rs | 76 +++--- src/libstd/future.rs | 18 +- src/libstd/getopts.rs | 104 ++++---- src/libstd/list.rs | 20 +- src/libstd/net_tcp.rs | 8 +- src/libstd/net_url.rs | 46 ++-- src/libstd/sha1.rs | 2 +- src/libstd/sort.rs | 18 +- src/libstd/sync.rs | 72 +++--- src/libstd/test.rs | 8 +- src/libstd/time.rs | 22 +- src/libstd/timer.rs | 10 +- src/libstd/uv_ll.rs | 12 +- src/libsyntax/parse/lexer.rs | 2 +- src/libsyntax/print/pprust.rs | 2 +- src/libsyntax/util/interner.rs | 80 ++++--- 37 files changed, 1211 insertions(+), 1184 deletions(-) diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index 38a663dc24504..337b0722ce7ab 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -277,45 +277,48 @@ pub mod raw { pub unsafe fn reserve_at_least(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::*; + + #[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::(~[]) == @[]); - 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::([]) == @[]); - 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::(~[]) == @[]); + 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::([]) == @[]); + 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]]); + } +} \ No newline at end of file diff --git a/src/libcore/cast.rs b/src/libcore/cast.rs index 42464c848efb3..1d214f402f5ac 100644 --- a/src/libcore/cast.rs +++ b/src/libcore/cast.rs @@ -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 @@ -135,7 +135,7 @@ pub mod tests { } #[test] - pub fn test_transmute() { + fn test_transmute() { use managed::raw::BoxRepr; unsafe { let x = @100u8; @@ -146,7 +146,7 @@ pub mod tests { } #[test] - pub fn test_transmute2() { + fn test_transmute2() { unsafe { assert!(~[76u8, 0u8] == transmute(~"L")); } diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index d665bf311f362..f8b046e5b8c4f 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -426,12 +426,12 @@ pub fn try_send_one(chan: ChanOne, 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(); @@ -446,7 +446,7 @@ pub mod test { } #[test] - pub fn test_oneshot() { + fn test_oneshot() { let (c, p) = oneshot::init(); oneshot::client::send(c, ()); diff --git a/src/libcore/hash.rs b/src/libcore/hash.rs index c229bc17311c9..ba1f8cebdb01c 100644 --- a/src/libcore/hash.rs +++ b/src/libcore/hash.rs @@ -357,170 +357,176 @@ impl Streaming for SipState { } } -#[test] -pub fn test_siphash() { - let vecs : [[u8, ..8], ..64] = [ - [ 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72, ], - [ 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; - let k1 = 0x_0f_0e_0d_0c_0b_0a_09_08_u64; - let mut buf : ~[u8] = ~[]; - 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); +#[cfg(test)] +mod tests { + use super::*; + use prelude::*; + + #[test] + fn test_siphash() { + let vecs : [[u8, ..8], ..64] = [ + [ 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72, ], + [ 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; + let k1 = 0x_0f_0e_0d_0c_0b_0a_09_08_u64; + let mut buf : ~[u8] = ~[]; + 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 } - 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); + 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); + 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); + assert!(f == i && f == v); - buf += ~[t as u8]; - stream_inc.input(~[t as u8]); + buf += ~[t as u8]; + stream_inc.input(~[t as u8]); - t += 1; + t += 1; + } } -} -#[test] #[cfg(target_arch = "arm")] -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_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] #[cfg(target_arch = "arm")] + 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_64")] + 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")] + 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] + 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] + 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] -pub fn test_hash_no_bytes_dropped_32() { - let val = 0xdeadbeef_u32; + #[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()); + 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)) + fn zero_byte(val: u32, byte: uint) -> u32 { + assert!(byte < 4); + val & !(0xff << (byte * 8)) + } } -} +} \ No newline at end of file diff --git a/src/libcore/hashmap.rs b/src/libcore/hashmap.rs index 2869c198ca2fc..3efe21fc42cdb 100644 --- a/src/libcore/hashmap.rs +++ b/src/libcore/hashmap.rs @@ -847,7 +847,7 @@ mod test_map { use uint; #[test] - pub fn test_insert() { + fn test_insert() { let mut m = HashMap::new(); assert!(m.insert(1, 2)); assert!(m.insert(2, 4)); @@ -869,7 +869,7 @@ mod test_map { } #[test] - pub fn test_insert_overwrite() { + fn test_insert_overwrite() { let mut m = HashMap::new(); assert!(m.insert(1, 2)); assert!(*m.get(&1) == 2); @@ -878,7 +878,7 @@ mod test_map { } #[test] - pub fn test_insert_conflicts() { + fn test_insert_conflicts() { let mut m = linear_map_with_capacity(4); assert!(m.insert(1, 2)); assert!(m.insert(5, 3)); @@ -889,7 +889,7 @@ mod test_map { } #[test] - pub fn test_conflict_remove() { + fn test_conflict_remove() { let mut m = linear_map_with_capacity(4); assert!(m.insert(1, 2)); assert!(m.insert(5, 3)); @@ -900,7 +900,7 @@ mod test_map { } #[test] - pub fn test_is_empty() { + fn test_is_empty() { let mut m = linear_map_with_capacity(4); assert!(m.insert(1, 2)); assert!(!m.is_empty()); @@ -909,7 +909,7 @@ mod test_map { } #[test] - pub fn test_pop() { + fn test_pop() { let mut m = HashMap::new(); m.insert(1, 2); assert!(m.pop(&1) == Some(2)); @@ -917,7 +917,7 @@ mod test_map { } #[test] - pub fn test_swap() { + fn test_swap() { let mut m = HashMap::new(); assert!(m.swap(1, 2) == None); assert!(m.swap(1, 3) == Some(2)); @@ -925,21 +925,21 @@ mod test_map { } #[test] - pub fn test_find_or_insert() { + fn test_find_or_insert() { let mut m = HashMap::new::(); assert!(m.find_or_insert(1, 2) == &2); assert!(m.find_or_insert(1, 3) == &2); } #[test] - pub fn test_find_or_insert_with() { + fn test_find_or_insert_with() { let mut m = HashMap::new::(); assert!(m.find_or_insert_with(1, |_| 2) == &2); assert!(m.find_or_insert_with(1, |_| 3) == &2); } #[test] - pub fn test_consume() { + fn test_consume() { let mut m = HashMap::new(); assert!(m.insert(1, 2)); assert!(m.insert(2, 3)); @@ -954,7 +954,7 @@ mod test_map { } #[test] - pub fn test_iterate() { + fn test_iterate() { let mut m = linear_map_with_capacity(4); for uint::range(0, 32) |i| { assert!(m.insert(i, i*2)); @@ -968,7 +968,7 @@ mod test_map { } #[test] - pub fn test_find() { + fn test_find() { let mut m = HashMap::new(); assert!(m.find(&1).is_none()); m.insert(1, 2); @@ -979,7 +979,7 @@ mod test_map { } #[test] - pub fn test_eq() { + fn test_eq() { let mut m1 = HashMap::new(); m1.insert(1, 2); m1.insert(2, 3); @@ -997,7 +997,7 @@ mod test_map { } #[test] - pub fn test_expand() { + fn test_expand() { let mut m = HashMap::new(); assert!(m.len() == 0); diff --git a/src/libcore/num/float.rs b/src/libcore/num/float.rs index 87d04b05087c2..488756787b5cd 100644 --- a/src/libcore/num/float.rs +++ b/src/libcore/num/float.rs @@ -29,7 +29,6 @@ use from_str; #[cfg(notest)] use cmp::{Eq, Ord}; #[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::logarithm; @@ -142,7 +141,7 @@ pub fn to_str_radix(num: float, radix: uint) -> ~str { let (r, special) = strconv::to_str_common( &num, radix, true, strconv::SignNeg, strconv::DigAll); 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 } @@ -177,12 +176,6 @@ pub fn to_str_exact(num: float, digits: uint) -> ~str { 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 * significant digits @@ -474,195 +467,205 @@ impl ops::Neg for float { fn neg(&self) -> float { -*self } } -#[test] -pub fn test_from_str() { - assert!(from_str(~"3") == Some(3.)); - assert!(from_str(~"3.14") == Some(3.14)); - assert!(from_str(~"+3.14") == Some(3.14)); - assert!(from_str(~"-3.14") == Some(-3.14)); - assert!(from_str(~"2.5E10") == Some(25000000000.)); - assert!(from_str(~"2.5e10") == Some(25000000000.)); - 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()); - 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); -} +#[cfg(test)] +mod tests { + use super::*; + use prelude::*; + #[test] + pub fn test_to_str_exact_do_decimal() { + let s = to_str_exact(5.0, 4u); + assert!(s == ~"5.0000"); + } + + #[test] + pub fn test_from_str() { + assert!(from_str(~"3") == Some(3.)); + assert!(from_str(~"3.14") == Some(3.14)); + assert!(from_str(~"+3.14") == Some(3.14)); + assert!(from_str(~"-3.14") == Some(-3.14)); + assert!(from_str(~"2.5E10") == Some(25000000000.)); + assert!(from_str(~"2.5e10") == Some(25000000000.)); + 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()); + 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); + } +} // // Local Variables: diff --git a/src/libcore/num/int-template.rs b/src/libcore/num/int-template.rs index 6fbe44737d184..b495f9e7088fe 100644 --- a/src/libcore/num/int-template.rs +++ b/src/libcore/num/int-template.rs @@ -277,181 +277,188 @@ impl ToStrRadix for T { } } -#[test] -fn test_from_str() { - assert!(from_str(~"0") == Some(0 as T)); - 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)); - - assert!(from_str(~"-1") == Some(-1 as T)); - 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)); - - assert!(from_str(~" ").is_none()); - assert!(from_str(~"x").is_none()); -} +#[cfg(test)] +mod tests { + use super::*; + use super::inst::T; + use prelude::*; + + #[test] + fn test_from_str() { + assert!(from_str(~"0") == Some(0 as T)); + 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)); + + assert!(from_str(~"-1") == Some(-1 as T)); + 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)); + + assert!(from_str(~" ").is_none()); + assert!(from_str(~"x").is_none()); + } -#[test] -fn test_parse_bytes() { - 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_parse_bytes() { + 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_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")); + #[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")); + 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")); + 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")); + 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")); + 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")); + 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")); + 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")); -} + 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())); + #[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())); + 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())); + 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())); + 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())); + 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())); + 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())); + 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())); -} + 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 = ~[]; + #[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"); + 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| {} -} + #[test] + #[should_fail] + #[ignore(cfg(windows))] + fn test_range_step_zero_step() { + for range_step(0,10,0) |_i| {} + } +} \ No newline at end of file diff --git a/src/libcore/num/uint-template.rs b/src/libcore/num/uint-template.rs index 1cbdabafdab96..af6557e9881f2 100644 --- a/src/libcore/num/uint-template.rs +++ b/src/libcore/num/uint-template.rs @@ -242,184 +242,190 @@ impl ToStrRadix for T { } } -#[test] -pub 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(2 as T, 10u) == ~"2"); - assert!(to_str_radix(11 as T, 10u) == ~"11"); - assert!(to_str_radix(11 as T, 16u) == ~"b"); - assert!(to_str_radix(255 as T, 16u) == ~"ff"); - assert!(to_str_radix(0xff as T, 10u) == ~"255"); -} +#[cfg(test)] +mod tests { + use super::*; + use super::inst::T; + use prelude::*; + #[test] + pub 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(2 as T, 10u) == ~"2"); + assert!(to_str_radix(11 as T, 10u) == ~"11"); + assert!(to_str_radix(11 as T, 16u) == ~"b"); + assert!(to_str_radix(255 as T, 16u) == ~"ff"); + assert!(to_str_radix(0xff as T, 10u) == ~"255"); + } -#[test] -pub fn test_from_str() { - assert!(from_str(~"0") == Some(0u as T)); - 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_from_str() { + assert!(from_str(~"0") == Some(0u as T)); + 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] + 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")); + #[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")); + 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")); + 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")); + 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")); + 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")); + 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")); + 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")); -} + 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())); + #[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())); + 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())); + 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())); + 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())); + 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())); + 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())); + 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())); -} + 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_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] + #[should_fail] + #[ignore(cfg(windows))] + pub fn to_str_radix37() { + uint::to_str_radix(100u, 37u); + } -#[test] -pub fn test_ranges() { - let mut l = ~[]; + #[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); - } + 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"); + 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"); + } } - for range_step(10,0,1) |_i| { - fail!(~"unreachable"); + + #[test] + #[should_fail] + #[ignore(cfg(windows))] + fn test_range_step_zero_step_up() { + for range_step(0,10,0) |_i| {} } - for range_step(0,1,-10) |_i| { - fail!(~"unreachable"); + #[test] + #[should_fail] + #[ignore(cfg(windows))] + fn test_range_step_zero_step_down() { + for range_step(0,-10,0) |_i| {} } -} - -#[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| {} -} +} \ No newline at end of file diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 18f8030d5b84e..fddb2af558709 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -957,13 +957,13 @@ pub mod rt { } #[cfg(test)] -pub mod test { +mod test { use either::Right; use comm::{Chan, Port, oneshot, recv_one, stream, Select2, GenericChan, Peekable}; #[test] - pub fn test_select2() { + fn test_select2() { let (p1, c1) = stream(); let (p2, c2) = stream(); @@ -978,7 +978,7 @@ pub mod test { } #[test] - pub fn test_oneshot() { + fn test_oneshot() { let (c, p) = oneshot::init(); oneshot::client::send(c, ()); diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 14e17de4fbda0..ebde37e77b42f 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -15,8 +15,6 @@ use libc; use libc::{c_void, size_t}; use sys; -#[cfg(test)] use vec; -#[cfg(test)] use str; #[cfg(notest)] use cmp::{Eq, Ord}; use uint; @@ -341,101 +339,101 @@ impl<'self,T:Ord> Ord for &'self const T { } } -#[test] -pub fn test() { - unsafe { - 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));; - - *pptr = Pair {fst: 50, snd: 60}; - assert!((*iptr == 50)); - assert!((p.fst == 50)); - assert!((p.snd == 60)); - - let mut v0 = ~[32000u16, 32001u16, 32002u16]; - let mut v1 = ~[0u16, 0u16, 0u16]; - - copy_memory(mut_offset(vec::raw::to_mut_ptr(v1), 1u), - offset(vec::raw::to_ptr(v0), 1u), 1u); - assert!((v1[0] == 0u16 && v1[1] == 32001u16 && v1[2] == 0u16)); - copy_memory(vec::raw::to_mut_ptr(v1), - offset(vec::raw::to_ptr(v0), 2u), 1u); - assert!((v1[0] == 32002u16 && v1[1] == 32001u16 && - v1[2] == 0u16)); - 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)); +#[cfg(test)] +pub mod ptr_tests { + use super::*; + use prelude::*; + + #[test] + fn test() { + unsafe { + 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));; + + *pptr = Pair {fst: 50, snd: 60}; + assert!((*iptr == 50)); + assert!((p.fst == 50)); + assert!((p.snd == 60)); + + let mut v0 = ~[32000u16, 32001u16, 32002u16]; + let mut v1 = ~[0u16, 0u16, 0u16]; + + copy_memory(mut_offset(vec::raw::to_mut_ptr(v1), 1u), + offset(vec::raw::to_ptr(v0), 1u), 1u); + assert!((v1[0] == 0u16 && v1[1] == 32001u16 && v1[2] == 0u16)); + copy_memory(vec::raw::to_mut_ptr(v1), + offset(vec::raw::to_ptr(v0), 2u), 1u); + assert!((v1[0] == 32002u16 && v1[1] == 32001u16 && + v1[2] == 0u16)); + 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] -pub fn test_position() { - use str::as_c_str; - use libc::c_char; + #[test] + fn test_position() { + use str::as_c_str; + use libc::c_char; - let s = ~"hello"; - unsafe { - assert!(2u == as_c_str(s, |p| position(p, - |c| *c == 'l' as c_char))); - assert!(4u == as_c_str(s, |p| position(p, - |c| *c == 'o' as c_char))); - assert!(5u == as_c_str(s, |p| position(p, - |c| *c == 0 as c_char))); + let s = ~"hello"; + unsafe { + assert!(2u == as_c_str(s, |p| position(p, + |c| *c == 'l' as c_char))); + assert!(4u == as_c_str(s, |p| position(p, + |c| *c == 'o' as c_char))); + assert!(5u == as_c_str(s, |p| position(p, + |c| *c == 0 as c_char))); + } } -} -#[test] -pub fn test_buf_len() { - let s0 = ~"hello"; - let s1 = ~"there"; - let s2 = ~"thing"; - do str::as_c_str(s0) |p0| { - do str::as_c_str(s1) |p1| { - do str::as_c_str(s2) |p2| { - let v = ~[p0, p1, p2, null()]; - do vec::as_imm_buf(v) |vp, len| { - assert!(unsafe { buf_len(vp) } == 3u); - assert!(len == 4u); + #[test] + fn test_buf_len() { + let s0 = ~"hello"; + let s1 = ~"there"; + let s2 = ~"thing"; + do str::as_c_str(s0) |p0| { + do str::as_c_str(s1) |p1| { + do str::as_c_str(s2) |p2| { + let v = ~[p0, p1, p2, null()]; + do vec::as_imm_buf(v) |vp, len| { + assert!(unsafe { buf_len(vp) } == 3u); + 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()); + #[test] + 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()); + } - 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] - pub fn test_ptr_array_each_with_len() { + fn test_ptr_array_each_with_len() { unsafe { let one = ~"oneOne"; let two = ~"twoTwo"; @@ -451,22 +449,22 @@ pub mod ptr_tests { let arr_ptr = &arr[0]; let mut ctr = 0; let mut iteration_count = 0; - ptr::array_each_with_len(arr_ptr, vec::len(arr), - |e| { - let actual = str::raw::from_c_str(e); - let expected = copy expected_arr[ctr]; - debug!( - "test_ptr_array_each e: %s, a: %s", - expected, actual); - assert!(actual == expected); - ctr += 1; - iteration_count += 1; - }); + array_each_with_len(arr_ptr, vec::len(arr), + |e| { + let actual = str::raw::from_c_str(e); + let expected = copy expected_arr[ctr]; + debug!( + "test_ptr_array_each e: %s, a: %s", + expected, actual); + assert!(actual == expected); + ctr += 1; + iteration_count += 1; + }); assert!(iteration_count == 3u); } } #[test] - pub fn test_ptr_array_each() { + fn test_ptr_array_each() { unsafe { let one = ~"oneOne"; let two = ~"twoTwo"; @@ -484,12 +482,12 @@ pub mod ptr_tests { let arr_ptr = &arr[0]; let mut ctr = 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 expected = copy expected_arr[ctr]; debug!( "test_ptr_array_each e: %s, a: %s", - expected, actual); + expected, actual); assert!(actual == expected); ctr += 1; iteration_count += 1; @@ -500,9 +498,9 @@ pub mod ptr_tests { #[test] #[should_fail] #[ignore(cfg(windows))] - pub fn test_ptr_array_each_with_len_null_ptr() { + fn test_ptr_array_each_with_len_null_ptr() { 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); }); } @@ -510,9 +508,9 @@ pub mod ptr_tests { #[test] #[should_fail] #[ignore(cfg(windows))] - pub fn test_ptr_array_each_null_ptr() { + fn test_ptr_array_each_null_ptr() { unsafe { - ptr::array_each(0 as **libc::c_char, |e| { + array_each(0 as **libc::c_char, |e| { str::raw::from_c_str(e); }); } diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs index c6400ccded8a6..0a93a651a8572 100644 --- a/src/libcore/rand.rs +++ b/src/libcore/rand.rs @@ -747,12 +747,12 @@ pub fn random() -> uint { #[cfg(test)] -pub mod tests { +mod tests { use option::{Option, Some}; use rand; #[test] - pub fn rng_seeded() { + fn rng_seeded() { let seed = rand::seed(); let ra = rand::seeded_rng(seed); let rb = rand::seeded_rng(seed); @@ -760,7 +760,7 @@ pub mod tests { } #[test] - pub fn rng_seeded_custom_seed() { + fn rng_seeded_custom_seed() { // much shorter than generated seeds which are 1024 bytes let seed = [2u8, 32u8, 4u8, 32u8, 51u8]; let ra = rand::seeded_rng(seed); @@ -769,7 +769,7 @@ pub mod tests { } #[test] - pub fn rng_seeded_custom_seed2() { + fn rng_seeded_custom_seed2() { let seed = [2u8, 32u8, 4u8, 32u8, 51u8]; let ra = rand::seeded_rng(seed); // Regression test that isaac is actually using the above vector @@ -780,7 +780,7 @@ pub mod tests { } #[test] - pub fn gen_int_range() { + fn gen_int_range() { let r = rand::Rng(); let a = r.gen_int_range(-3, 42); assert!(a >= -3 && a < 42); @@ -791,12 +791,12 @@ pub mod tests { #[test] #[should_fail] #[ignore(cfg(windows))] - pub fn gen_int_from_fail() { + fn gen_int_from_fail() { rand::Rng().gen_int_range(5, -2); } #[test] - pub fn gen_uint_range() { + fn gen_uint_range() { let r = rand::Rng(); let a = r.gen_uint_range(3u, 42u); assert!(a >= 3u && a < 42u); @@ -807,12 +807,12 @@ pub mod tests { #[test] #[should_fail] #[ignore(cfg(windows))] - pub fn gen_uint_range_fail() { + fn gen_uint_range_fail() { rand::Rng().gen_uint_range(5u, 2u); } #[test] - pub fn gen_float() { + fn gen_float() { let r = rand::Rng(); let a = r.gen_float(); let b = r.gen_float(); @@ -820,14 +820,14 @@ pub mod tests { } #[test] - pub fn gen_weighted_bool() { + fn gen_weighted_bool() { let r = rand::Rng(); assert!(r.gen_weighted_bool(0u) == true); assert!(r.gen_weighted_bool(1u) == true); } #[test] - pub fn gen_str() { + fn gen_str() { let r = rand::Rng(); debug!(r.gen_str(10u)); debug!(r.gen_str(10u)); @@ -838,7 +838,7 @@ pub mod tests { } #[test] - pub fn gen_bytes() { + fn gen_bytes() { let r = rand::Rng(); assert!(r.gen_bytes(0u).len() == 0u); assert!(r.gen_bytes(10u).len() == 10u); @@ -846,13 +846,13 @@ pub mod tests { } #[test] - pub fn choose() { + fn choose() { let r = rand::Rng(); assert!(r.choose([1, 1, 1]) == 1); } #[test] - pub fn choose_option() { + fn choose_option() { let r = rand::Rng(); let x: Option = r.choose_option([]); assert!(x.is_none()); @@ -860,7 +860,7 @@ pub mod tests { } #[test] - pub fn choose_weighted() { + fn choose_weighted() { let r = rand::Rng(); assert!(r.choose_weighted(~[ rand::Weighted { weight: 1u, item: 42 }, @@ -872,7 +872,7 @@ pub mod tests { } #[test] - pub fn choose_weighted_option() { + fn choose_weighted_option() { let r = rand::Rng(); assert!(r.choose_weighted_option(~[ rand::Weighted { weight: 1u, item: 42 }, @@ -886,7 +886,7 @@ pub mod tests { } #[test] - pub fn weighted_vec() { + fn weighted_vec() { let r = rand::Rng(); let empty: ~[int] = ~[]; assert!(r.weighted_vec(~[]) == empty); @@ -898,7 +898,7 @@ pub mod tests { } #[test] - pub fn shuffle() { + fn shuffle() { let r = rand::Rng(); let empty: ~[int] = ~[]; assert!(r.shuffle(~[]) == empty); @@ -906,7 +906,7 @@ pub mod tests { } #[test] - pub fn task_rng() { + fn task_rng() { let r = rand::task_rng(); r.gen_int(); assert!(r.shuffle(~[1, 1, 1]) == ~[1, 1, 1]); @@ -914,7 +914,7 @@ pub mod tests { } #[test] - pub fn random() { + fn random() { // not sure how to test this aside from just getting a number let _n : uint = rand::random(); } diff --git a/src/libcore/run.rs b/src/libcore/run.rs index 49df2938afd40..8e247a25012f1 100644 --- a/src/libcore/run.rs +++ b/src/libcore/run.rs @@ -521,7 +521,7 @@ mod tests { // Regression test for memory leaks #[ignore(cfg(windows))] // FIXME (#2626) - pub fn test_leaks() { + fn test_leaks() { run::run_program("echo", []); run::start_program("echo", []); run::program_output("echo", []); @@ -529,7 +529,7 @@ mod tests { #[test] #[allow(non_implicitly_copyable_typarams)] - pub fn test_pipes() { + fn test_pipes() { let pipe_in = os::pipe(); let pipe_out = os::pipe(); let pipe_err = os::pipe(); @@ -555,7 +555,7 @@ mod tests { } #[test] - pub fn waitpid() { + fn waitpid() { let pid = run::spawn_process("false", [], &None, &None, 0i32, 0i32, 0i32); @@ -564,20 +564,20 @@ mod tests { } #[test] - pub fn test_destroy_once() { + fn test_destroy_once() { let mut p = run::start_program("echo", []); p.destroy(); // this shouldn't crash (and nor should the destructor) } #[test] - pub fn test_destroy_twice() { + fn test_destroy_twice() { let mut p = run::start_program("echo", []); p.destroy(); // this shouldnt crash... p.destroy(); // ...and nor should this (and nor should the destructor) } #[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)); os::remove_file(&path); @@ -598,13 +598,13 @@ mod tests { #[test] #[cfg(unix)] - pub fn test_unforced_destroy_actually_kills() { + fn test_unforced_destroy_actually_kills() { test_destroy_actually_kills(false); } #[test] #[cfg(unix)] - pub fn test_forced_destroy_actually_kills() { + fn test_forced_destroy_actually_kills() { test_destroy_actually_kills(true); } } diff --git a/src/libcore/sys.rs b/src/libcore/sys.rs index 678005ce06f96..04f96f5eb229e 100644 --- a/src/libcore/sys.rs +++ b/src/libcore/sys.rs @@ -160,12 +160,12 @@ pub fn fail_assert(msg: &str, file: &str, line: uint) -> ! { } #[cfg(test)] -pub mod tests { +mod tests { use cast; use sys::{Closure, pref_align_of, size_of, nonzero_size_of}; #[test] - pub fn size_of_basic() { + fn size_of_basic() { assert!(size_of::() == 1u); assert!(size_of::() == 2u); assert!(size_of::() == 4u); @@ -176,20 +176,20 @@ pub mod tests { #[cfg(target_arch = "x86")] #[cfg(target_arch = "arm")] #[cfg(target_arch = "mips")] - pub fn size_of_32() { + fn size_of_32() { assert!(size_of::() == 4u); assert!(size_of::<*uint>() == 4u); } #[test] #[cfg(target_arch = "x86_64")] - pub fn size_of_64() { + fn size_of_64() { assert!(size_of::() == 8u); assert!(size_of::<*uint>() == 8u); } #[test] - pub fn nonzero_size_of_basic() { + fn nonzero_size_of_basic() { type Z = [i8, ..0]; assert!(size_of::() == 0u); assert!(nonzero_size_of::() == 1u); @@ -197,7 +197,7 @@ pub mod tests { } #[test] - pub fn align_of_basic() { + fn align_of_basic() { assert!(pref_align_of::() == 1u); assert!(pref_align_of::() == 2u); assert!(pref_align_of::() == 4u); @@ -207,20 +207,20 @@ pub mod tests { #[cfg(target_arch = "x86")] #[cfg(target_arch = "arm")] #[cfg(target_arch = "mips")] - pub fn align_of_32() { + fn align_of_32() { assert!(pref_align_of::() == 4u); assert!(pref_align_of::<*uint>() == 4u); } #[test] #[cfg(target_arch = "x86_64")] - pub fn align_of_64() { + fn align_of_64() { assert!(pref_align_of::() == 8u); assert!(pref_align_of::<*uint>() == 8u); } #[test] - pub fn synthesize_closure() { + fn synthesize_closure() { unsafe { let x = 10; let f: &fn(int) -> int = |y| x + y; diff --git a/src/libcore/task/mod.rs b/src/libcore/task/mod.rs index d712bf8f98f44..a6c4b6c526862 100644 --- a/src/libcore/task/mod.rs +++ b/src/libcore/task/mod.rs @@ -925,7 +925,7 @@ fn test_spawn_sched_childs_on_default_sched() { } #[cfg(test)] -pub mod testrt { +mod testrt { use libc; #[nolink] diff --git a/src/libcore/unstable.rs b/src/libcore/unstable.rs index e43d321dc4d05..c057fce0abd8c 100644 --- a/src/libcore/unstable.rs +++ b/src/libcore/unstable.rs @@ -286,14 +286,14 @@ pub impl Exclusive { } #[cfg(test)] -pub mod tests { +mod tests { use comm; use super::exclusive; use task; use uint; #[test] - pub fn exclusive_arc() { + fn exclusive_arc() { let mut futures = ~[]; let num_tasks = 10; @@ -324,7 +324,7 @@ pub mod tests { } #[test] #[should_fail] #[ignore(cfg(windows))] - pub fn exclusive_poison() { + fn exclusive_poison() { // Tests that if one task fails inside of an exclusive, subsequent // accesses will also fail. let x = exclusive(1); diff --git a/src/librustc/back/rpath.rs b/src/librustc/back/rpath.rs index cc1168bd79ddd..49935eea0e13d 100644 --- a/src/librustc/back/rpath.rs +++ b/src/librustc/back/rpath.rs @@ -212,14 +212,14 @@ mod test { use driver::session; #[test] - pub fn test_rpaths_to_flags() { + fn test_rpaths_to_flags() { let flags = rpaths_to_flags(~[Path("path1"), Path("path2")]); assert!(flags == ~[~"-Wl,-rpath,path1", ~"-Wl,-rpath,path2"]); } #[test] - pub fn test_prefix_rpath() { + fn test_prefix_rpath() { let res = get_install_prefix_rpath("triple"); let d = Path(env!("CFG_PREFIX")) .push_rel(&Path("lib/rustc/triple/lib")); @@ -230,13 +230,13 @@ mod test { } #[test] - pub fn test_prefix_rpath_abs() { + fn test_prefix_rpath_abs() { let res = get_install_prefix_rpath("triple"); assert!(res.is_absolute); } #[test] - pub fn test_minimize1() { + fn test_minimize1() { let res = minimize_rpaths([Path("rpath1"), Path("rpath2"), Path("rpath1")]); @@ -244,7 +244,7 @@ mod test { } #[test] - pub fn test_minimize2() { + fn test_minimize2() { let res = minimize_rpaths(~[Path("1a"), Path("2"), Path("2"), Path("1a"), Path("4a"),Path("1a"), Path("2"), Path("3"), Path("4a"), @@ -253,7 +253,7 @@ mod test { } #[test] - pub fn test_relative_to1() { + fn test_relative_to1() { let p1 = Path("/usr/bin/rustc"); let p2 = Path("/usr/lib/mylib"); let res = get_relative_to(&p1, &p2); @@ -261,7 +261,7 @@ mod test { } #[test] - pub fn test_relative_to2() { + fn test_relative_to2() { let p1 = Path("/usr/bin/rustc"); let p2 = Path("/usr/bin/../lib/mylib"); let res = get_relative_to(&p1, &p2); @@ -269,7 +269,7 @@ mod test { } #[test] - pub fn test_relative_to3() { + fn test_relative_to3() { let p1 = Path("/usr/bin/whatever/rustc"); let p2 = Path("/usr/lib/whatever/mylib"); let res = get_relative_to(&p1, &p2); @@ -277,7 +277,7 @@ mod test { } #[test] - pub fn test_relative_to4() { + fn test_relative_to4() { let p1 = Path("/usr/bin/whatever/../rustc"); let p2 = Path("/usr/lib/whatever/mylib"); let res = get_relative_to(&p1, &p2); @@ -285,7 +285,7 @@ mod test { } #[test] - pub fn test_relative_to5() { + fn test_relative_to5() { let p1 = Path("/usr/bin/whatever/../rustc"); let p2 = Path("/usr/lib/whatever/../mylib"); let res = get_relative_to(&p1, &p2); @@ -293,7 +293,7 @@ mod test { } #[test] - pub fn test_relative_to6() { + fn test_relative_to6() { let p1 = Path("/1"); let p2 = Path("/2/3"); let res = get_relative_to(&p1, &p2); @@ -301,7 +301,7 @@ mod test { } #[test] - pub fn test_relative_to7() { + fn test_relative_to7() { let p1 = Path("/1/2"); let p2 = Path("/3"); let res = get_relative_to(&p1, &p2); @@ -309,7 +309,7 @@ mod test { } #[test] - pub fn test_relative_to8() { + fn test_relative_to8() { let p1 = Path("/home/brian/Dev/rust/build/").push_rel( &Path("stage2/lib/rustc/i686-unknown-linux-gnu/lib/librustc.so")); let p2 = Path("/home/brian/Dev/rust/build/stage2/bin/..").push_rel( @@ -324,7 +324,7 @@ mod test { #[test] #[cfg(target_os = "linux")] #[cfg(target_os = "andorid")] - pub fn test_rpath_relative() { + fn test_rpath_relative() { let o = session::os_linux; let res = get_rpath_relative_to_output(o, &Path("bin/rustc"), &Path("lib/libstd.so")); @@ -333,7 +333,7 @@ mod test { #[test] #[cfg(target_os = "freebsd")] - pub fn test_rpath_relative() { + fn test_rpath_relative() { let o = session::os_freebsd; let res = get_rpath_relative_to_output(o, &Path("bin/rustc"), &Path("lib/libstd.so")); @@ -342,7 +342,7 @@ mod test { #[test] #[cfg(target_os = "macos")] - pub fn test_rpath_relative() { + fn test_rpath_relative() { // this is why refinements would be nice let o = session::os_macos; let res = get_rpath_relative_to_output(o, @@ -352,7 +352,7 @@ mod test { } #[test] - pub fn test_get_absolute_rpath() { + fn test_get_absolute_rpath() { let res = get_absolute_rpath(&Path("lib/libstd.so")); debug!("test_get_absolute_rpath: %s vs. %s", res.to_str(), diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index d725b70003754..a804469ac6511 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -876,7 +876,7 @@ pub fn list_metadata(sess: Session, path: &Path, out: @io::Writer) { } #[cfg(test)] -pub mod test { +mod test { use core::prelude::*; 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 #[test] - pub fn test_switch_implies_cfg_test() { + fn test_switch_implies_cfg_test() { let matches = &match getopts(~[~"--test"], optgroups()) { Ok(copy m) => m, @@ -907,7 +907,7 @@ pub mod test { // When the user supplies --test and --cfg test, don't implicitly add // another --cfg test #[test] - pub fn test_switch_implies_cfg_test_unless_cfg_test() { + fn test_switch_implies_cfg_test_unless_cfg_test() { let matches = &match getopts(~[~"--test", ~"--cfg=test"], optgroups()) { Ok(copy m) => m, diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index 226905bbab728..aee5e01e09108 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -354,14 +354,14 @@ pub fn sess_os_to_meta_os(os: os) -> metadata::loader::os { } #[cfg(test)] -pub mod test { +mod test { use driver::session::{bin_crate, building_library, lib_crate}; use driver::session::{unknown_crate}; use syntax::ast; 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_ { style: ast::attr_outer, 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 = ~[]; if with_bin { attrs += ~[make_crate_type_attr(~"bin")]; } if with_lib { attrs += ~[make_crate_type_attr(~"lib")]; } @@ -385,43 +385,43 @@ pub mod 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); assert!(!building_library(unknown_crate, crate, false)); } #[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); assert!(building_library(unknown_crate, crate, false)); } #[test] - pub fn bin_option_overrides_lib_crate_type() { + fn bin_option_overrides_lib_crate_type() { let crate = make_crate(false, true); assert!(!building_library(bin_crate, crate, false)); } #[test] - pub fn lib_option_overrides_bin_crate_type() { + fn lib_option_overrides_bin_crate_type() { let crate = make_crate(true, false); assert!(building_library(lib_crate, crate, false)); } #[test] - pub fn bin_crate_type_is_default() { + fn bin_crate_type_is_default() { let crate = make_crate(false, false); assert!(!building_library(unknown_crate, crate, false)); } #[test] - pub fn test_option_overrides_lib_crate_type() { + fn test_option_overrides_lib_crate_type() { let crate = make_crate(false, true); assert!(!building_library(unknown_crate, crate, true)); } #[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); assert!(building_library(lib_crate, crate, true)); } diff --git a/src/libstd/arc.rs b/src/libstd/arc.rs index 585ce2dc81500..da1e4688939cc 100644 --- a/src/libstd/arc.rs +++ b/src/libstd/arc.rs @@ -492,7 +492,7 @@ mod tests { use core::vec; #[test] - pub fn manually_share_arc() { + fn manually_share_arc() { let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; let arc_v = arc::ARC(v); @@ -517,7 +517,7 @@ mod tests { } #[test] - pub fn test_mutex_arc_condvar() { + fn test_mutex_arc_condvar() { let arc = ~MutexARC(false); let arc2 = ~arc.clone(); let (p,c) = comm::oneshot(); @@ -539,7 +539,7 @@ mod tests { } } #[test] #[should_fail] #[ignore(cfg(windows))] - pub fn test_arc_condvar_poison() { + fn test_arc_condvar_poison() { let arc = ~MutexARC(1); let arc2 = ~arc.clone(); let (p, c) = comm::stream(); @@ -561,7 +561,7 @@ mod tests { } } #[test] #[should_fail] #[ignore(cfg(windows))] - pub fn test_mutex_arc_poison() { + fn test_mutex_arc_poison() { let arc = ~MutexARC(1); let arc2 = ~arc.clone(); do task::try || { @@ -574,7 +574,7 @@ mod tests { } } #[test] #[should_fail] #[ignore(cfg(windows))] - pub fn test_rw_arc_poison_wr() { + fn test_rw_arc_poison_wr() { let arc = ~RWARC(1); let arc2 = (*arc).clone(); do task::try || { @@ -587,7 +587,7 @@ mod tests { } } #[test] #[should_fail] #[ignore(cfg(windows))] - pub fn test_rw_arc_poison_ww() { + fn test_rw_arc_poison_ww() { let arc = ~RWARC(1); let arc2 = (*arc).clone(); do task::try || { @@ -600,7 +600,7 @@ mod tests { } } #[test] #[should_fail] #[ignore(cfg(windows))] - pub fn test_rw_arc_poison_dw() { + fn test_rw_arc_poison_dw() { let arc = ~RWARC(1); let arc2 = (*arc).clone(); do task::try || { @@ -615,7 +615,7 @@ mod tests { } } #[test] #[ignore(cfg(windows))] - pub fn test_rw_arc_no_poison_rr() { + fn test_rw_arc_no_poison_rr() { let arc = ~RWARC(1); let arc2 = (*arc).clone(); do task::try || { @@ -628,7 +628,7 @@ mod tests { } } #[test] #[ignore(cfg(windows))] - pub fn test_rw_arc_no_poison_rw() { + fn test_rw_arc_no_poison_rw() { let arc = ~RWARC(1); let arc2 = (*arc).clone(); do task::try || { @@ -641,7 +641,7 @@ mod tests { } } #[test] #[ignore(cfg(windows))] - pub fn test_rw_arc_no_poison_dr() { + fn test_rw_arc_no_poison_dr() { let arc = ~RWARC(1); let arc2 = (*arc).clone(); do task::try || { @@ -657,7 +657,7 @@ mod tests { } } #[test] - pub fn test_rw_arc() { + fn test_rw_arc() { let arc = ~RWARC(0); let arc2 = (*arc).clone(); let (p,c) = comm::stream(); @@ -694,7 +694,7 @@ mod tests { do arc.read |num| { assert!(*num == 10); } } #[test] - pub fn test_rw_downgrade() { + fn test_rw_downgrade() { // (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. // (3) Downgrader wakes, sets state to 31337. diff --git a/src/libstd/base64.rs b/src/libstd/base64.rs index 781a720b1a4db..c960c7186e3d2 100644 --- a/src/libstd/base64.rs +++ b/src/libstd/base64.rs @@ -154,7 +154,7 @@ mod tests { use core::str; #[test] - pub fn test_to_base64() { + fn test_to_base64() { assert!((~"").to_base64() == ~""); assert!((~"f").to_base64() == ~"Zg=="); assert!((~"fo").to_base64() == ~"Zm8="); @@ -165,7 +165,7 @@ mod tests { } #[test] - pub fn test_from_base64() { + fn test_from_base64() { assert!((~"").from_base64() == str::to_bytes(~"")); assert!((~"Zg==").from_base64() == str::to_bytes(~"f")); assert!((~"Zm8=").from_base64() == str::to_bytes(~"fo")); diff --git a/src/libstd/bitv.rs b/src/libstd/bitv.rs index 632a38e8ca2d8..d89ce4232b175 100644 --- a/src/libstd/bitv.rs +++ b/src/libstd/bitv.rs @@ -880,7 +880,7 @@ mod tests { static bench_bits : uint = 1 << 14; #[test] - pub fn test_to_str() { + fn test_to_str() { let zerolen = Bitv::new(0u, false); assert!(zerolen.to_str() == ~""); @@ -889,7 +889,7 @@ mod tests { } #[test] - pub fn test_0_elements() { + fn test_0_elements() { let mut act; let mut exp; act = Bitv::new(0u, false); @@ -898,7 +898,7 @@ mod tests { } #[test] - pub fn test_1_element() { + fn test_1_element() { let mut act; act = Bitv::new(1u, false); assert!(act.eq_vec(~[0u])); @@ -907,7 +907,7 @@ mod tests { } #[test] - pub fn test_2_elements() { + fn test_2_elements() { let mut b = bitv::Bitv::new(2, false); b.set(0, true); b.set(1, false); @@ -915,7 +915,7 @@ mod tests { } #[test] - pub fn test_10_elements() { + fn test_10_elements() { let mut act; // all 0 @@ -954,7 +954,7 @@ mod tests { } #[test] - pub fn test_31_elements() { + fn test_31_elements() { let mut act; // all 0 @@ -1027,7 +1027,7 @@ mod tests { } #[test] - pub fn test_32_elements() { + fn test_32_elements() { let mut act; // all 0 @@ -1102,7 +1102,7 @@ mod tests { } #[test] - pub fn test_33_elements() { + fn test_33_elements() { let mut act; // all 0 @@ -1178,21 +1178,21 @@ mod tests { } #[test] - pub fn test_equal_differing_sizes() { + fn test_equal_differing_sizes() { let v0 = Bitv::new(10u, false); let v1 = Bitv::new(11u, false); assert!(!v0.equal(&v1)); } #[test] - pub fn test_equal_greatly_differing_sizes() { + fn test_equal_greatly_differing_sizes() { let v0 = Bitv::new(10u, false); let v1 = Bitv::new(110u, false); assert!(!v0.equal(&v1)); } #[test] - pub fn test_equal_sneaky_small() { + fn test_equal_sneaky_small() { let mut a = bitv::Bitv::new(1, false); a.set(0, true); @@ -1203,7 +1203,7 @@ mod tests { } #[test] - pub fn test_equal_sneaky_big() { + fn test_equal_sneaky_big() { let mut a = bitv::Bitv::new(100, false); for uint::range(0, 100) |i| { a.set(i, true); @@ -1218,14 +1218,14 @@ mod tests { } #[test] - pub fn test_from_bytes() { + fn test_from_bytes() { let bitv = from_bytes([0b10110110, 0b00000000, 0b11111111]); let str = ~"10110110" + ~"00000000" + ~"11111111"; assert!(bitv.to_str() == str); } #[test] - pub fn test_to_bytes() { + fn test_to_bytes() { let mut bv = Bitv::new(3, true); bv.set(1, false); assert!(bv.to_bytes() == ~[0b10100000]); @@ -1237,19 +1237,19 @@ mod tests { } #[test] - pub fn test_from_bools() { + fn test_from_bools() { assert!(from_bools([true, false, true, true]).to_str() == ~"1011"); } #[test] - pub fn test_to_bools() { + fn test_to_bools() { let bools = ~[false, false, true, false, false, true, true, false]; assert!(from_bytes([0b00100110]).to_bools() == bools); } #[test] - pub fn test_small_difference() { + fn test_small_difference() { let mut b1 = Bitv::new(3, false); let mut b2 = Bitv::new(3, false); b1.set(0, true); @@ -1263,7 +1263,7 @@ mod tests { } #[test] - pub fn test_big_difference() { + fn test_big_difference() { let mut b1 = Bitv::new(100, false); let mut b2 = Bitv::new(100, false); b1.set(0, true); @@ -1277,7 +1277,7 @@ mod tests { } #[test] - pub fn test_small_clear() { + fn test_small_clear() { let mut b = Bitv::new(14, true); b.clear(); for b.ones |i| { @@ -1286,7 +1286,7 @@ mod tests { } #[test] - pub fn test_big_clear() { + fn test_big_clear() { let mut b = Bitv::new(140, true); b.clear(); for b.ones |i| { @@ -1295,7 +1295,7 @@ mod tests { } #[test] - pub fn test_bitv_set_basic() { + fn test_bitv_set_basic() { let mut b = BitvSet::new(); assert!(b.insert(3)); assert!(!b.insert(3)); @@ -1382,7 +1382,7 @@ mod tests { } #[test] - pub fn test_bitv_set_union() { + fn test_bitv_set_union() { let mut a = BitvSet::new(); let mut b = BitvSet::new(); assert!(a.insert(1)); @@ -1410,7 +1410,7 @@ mod tests { } #[test] - pub fn test_bitv_remove() { + fn test_bitv_remove() { let mut a = BitvSet::new(); assert!(a.insert(1)); @@ -1430,7 +1430,7 @@ mod tests { } #[bench] - pub fn bench_uint_small(b: &mut BenchHarness) { + fn bench_uint_small(b: &mut BenchHarness) { let r = rng(); let mut bitv = 0 as uint; do b.iter { @@ -1439,7 +1439,7 @@ mod tests { } #[bench] - pub fn bench_small_bitv_small(b: &mut BenchHarness) { + fn bench_small_bitv_small(b: &mut BenchHarness) { let r = rng(); let mut bitv = SmallBitv::new(uint::bits); do b.iter { @@ -1448,7 +1448,7 @@ mod tests { } #[bench] - pub fn bench_big_bitv_small(b: &mut BenchHarness) { + fn bench_big_bitv_small(b: &mut BenchHarness) { let r = rng(); let mut bitv = BigBitv::new(~[0]); do b.iter { @@ -1457,7 +1457,7 @@ mod tests { } #[bench] - pub fn bench_big_bitv_big(b: &mut BenchHarness) { + fn bench_big_bitv_big(b: &mut BenchHarness) { let r = rng(); let mut storage = ~[]; storage.grow(bench_bits / uint::bits, &0); @@ -1468,7 +1468,7 @@ mod tests { } #[bench] - pub fn bench_bitv_big(b: &mut BenchHarness) { + fn bench_bitv_big(b: &mut BenchHarness) { let r = rng(); let mut bitv = Bitv::new(bench_bits, false); do b.iter { @@ -1477,7 +1477,7 @@ mod tests { } #[bench] - pub fn bench_bitv_small(b: &mut BenchHarness) { + fn bench_bitv_small(b: &mut BenchHarness) { let r = rng(); let mut bitv = Bitv::new(uint::bits, false); do b.iter { @@ -1486,7 +1486,7 @@ mod tests { } #[bench] - pub fn bench_bitv_set_small(b: &mut BenchHarness) { + fn bench_bitv_set_small(b: &mut BenchHarness) { let r = rng(); let mut bitv = BitvSet::new(); do b.iter { @@ -1495,7 +1495,7 @@ mod tests { } #[bench] - pub fn bench_bitv_set_big(b: &mut BenchHarness) { + fn bench_bitv_set_big(b: &mut BenchHarness) { let r = rng(); let mut bitv = BitvSet::new(); do b.iter { @@ -1504,7 +1504,7 @@ mod tests { } #[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 b2 = Bitv::new(bench_bits, false); do b.iter { diff --git a/src/libstd/dlist.rs b/src/libstd/dlist.rs index a490065b835c1..f9de2e0f58ad0 100644 --- a/src/libstd/dlist.rs +++ b/src/libstd/dlist.rs @@ -537,7 +537,7 @@ mod tests { use core::prelude::*; #[test] - pub fn test_dlist_concat() { + fn test_dlist_concat() { let a = from_vec(~[1,2]); let b = from_vec(~[3,4]); let c = from_vec(~[5,6]); @@ -557,7 +557,7 @@ mod tests { abcd.assert_consistent(); assert!(abcd.is_empty()); } #[test] - pub fn test_dlist_append() { + fn test_dlist_append() { let a = from_vec(~[1,2,3]); let b = from_vec(~[4,5,6]); a.append(b); @@ -573,7 +573,7 @@ mod tests { a.assert_consistent(); assert!(a.is_empty()); } #[test] - pub fn test_dlist_append_empty() { + fn test_dlist_append_empty() { let a = from_vec(~[1,2,3]); let b = DList::(); a.append(b); @@ -586,7 +586,7 @@ mod tests { a.assert_consistent(); assert!(a.is_empty()); } #[test] - pub fn test_dlist_append_to_empty() { + fn test_dlist_append_to_empty() { let a = DList::(); let b = from_vec(~[4,5,6]); a.append(b); @@ -599,7 +599,7 @@ mod tests { a.assert_consistent(); assert!(a.is_empty()); } #[test] - pub fn test_dlist_append_two_empty() { + fn test_dlist_append_two_empty() { let a = DList::(); let b = DList::(); a.append(b); @@ -611,19 +611,19 @@ mod tests { #[test] #[ignore(cfg(windows))] #[should_fail] - pub fn test_dlist_append_self() { + fn test_dlist_append_self() { let a = DList::(); a.append(a); } #[test] #[ignore(cfg(windows))] #[should_fail] - pub fn test_dlist_prepend_self() { + fn test_dlist_prepend_self() { let a = DList::(); a.prepend(a); } #[test] - pub fn test_dlist_prepend() { + fn test_dlist_prepend() { let a = from_vec(~[1,2,3]); let b = from_vec(~[4,5,6]); b.prepend(a); @@ -639,7 +639,7 @@ mod tests { b.assert_consistent(); assert!(b.is_empty()); } #[test] - pub fn test_dlist_reverse() { + fn test_dlist_reverse() { let a = from_vec(~[5,4,3,2,1]); a.reverse(); assert_eq!(a.len(), 5); @@ -651,14 +651,14 @@ mod tests { a.assert_consistent(); assert!(a.is_empty()); } #[test] - pub fn test_dlist_reverse_empty() { + fn test_dlist_reverse_empty() { let a = DList::(); a.reverse(); assert_eq!(a.len(), 0); a.assert_consistent(); } #[test] - pub fn test_dlist_each_node() { + fn test_dlist_each_node() { let a = from_vec(~[1,2,4,5]); for a.each_node |nobe| { if nobe.data > 3 { @@ -675,28 +675,28 @@ mod tests { a.assert_consistent(); assert!(a.is_empty()); } #[test] - pub fn test_dlist_clear() { + fn test_dlist_clear() { let a = from_vec(~[5,4,3,2,1]); a.clear(); assert_eq!(a.len(), 0); a.assert_consistent(); } #[test] - pub fn test_dlist_is_empty() { + fn test_dlist_is_empty() { let empty = DList::(); let full1 = from_vec(~[1,2,3]); assert!(empty.is_empty()); assert!(!full1.is_empty()); } #[test] - pub fn test_dlist_head_tail() { + fn test_dlist_head_tail() { let l = from_vec(~[1,2,3]); assert_eq!(l.head(), 1); assert_eq!(l.tail(), 3); assert_eq!(l.len(), 3); } #[test] - pub fn test_dlist_pop() { + fn test_dlist_pop() { let l = from_vec(~[1,2,3]); assert_eq!(l.pop().get(), 1); assert_eq!(l.tail(), 3); @@ -709,7 +709,7 @@ mod tests { assert!(l.pop().is_none()); } #[test] - pub fn test_dlist_pop_tail() { + fn test_dlist_pop_tail() { let l = from_vec(~[1,2,3]); assert_eq!(l.pop_tail().get(), 3); assert_eq!(l.tail(), 2); @@ -722,7 +722,7 @@ mod tests { assert!(l.pop_tail().is_none()); } #[test] - pub fn test_dlist_push() { + fn test_dlist_push() { let l = DList::(); l.push(1); assert_eq!(l.head(), 1); @@ -736,7 +736,7 @@ mod tests { assert_eq!(l.len(), 3); } #[test] - pub fn test_dlist_push_head() { + fn test_dlist_push_head() { let l = DList::(); l.push_head(3); assert_eq!(l.head(), 3); @@ -750,12 +750,12 @@ mod tests { assert_eq!(l.len(), 3); } #[test] - pub fn test_dlist_foldl() { + fn test_dlist_foldl() { let l = from_vec(vec::from_fn(101, |x|x)); assert_eq!(iter::foldl(&l, 0, |accum,elem| *accum+*elem), 5050); } #[test] - pub fn test_dlist_break_early() { + fn test_dlist_break_early() { let l = from_vec(~[1,2,3,4,5]); let mut x = 0; for l.each |i| { @@ -765,7 +765,7 @@ mod tests { assert_eq!(x, 3); } #[test] - pub fn test_dlist_remove_head() { + fn test_dlist_remove_head() { let l = DList::(); l.assert_consistent(); let one = l.push_n(1); l.assert_consistent(); let _two = l.push_n(2); @@ -780,7 +780,7 @@ mod tests { l.assert_consistent(); assert!(l.is_empty()); } #[test] - pub fn test_dlist_remove_mid() { + fn test_dlist_remove_mid() { let l = DList::(); l.assert_consistent(); let _one = l.push_n(1); l.assert_consistent(); let two = l.push_n(2); @@ -795,7 +795,7 @@ mod tests { l.assert_consistent(); assert!(l.is_empty()); } #[test] - pub fn test_dlist_remove_tail() { + fn test_dlist_remove_tail() { let l = DList::(); l.assert_consistent(); let _one = l.push_n(1); l.assert_consistent(); let _two = l.push_n(2); @@ -810,7 +810,7 @@ mod tests { l.assert_consistent(); assert!(l.is_empty()); } #[test] - pub fn test_dlist_remove_one_two() { + fn test_dlist_remove_one_two() { let l = DList::(); l.assert_consistent(); let one = l.push_n(1); l.assert_consistent(); let two = l.push_n(2); @@ -826,7 +826,7 @@ mod tests { l.assert_consistent(); assert!(l.is_empty()); } #[test] - pub fn test_dlist_remove_one_three() { + fn test_dlist_remove_one_three() { let l = DList::(); l.assert_consistent(); let one = l.push_n(1); l.assert_consistent(); let _two = l.push_n(2); @@ -841,7 +841,7 @@ mod tests { l.assert_consistent(); assert!(l.is_empty()); } #[test] - pub fn test_dlist_remove_two_three() { + fn test_dlist_remove_two_three() { let l = DList::(); l.assert_consistent(); let _one = l.push_n(1); l.assert_consistent(); let two = l.push_n(2); @@ -856,7 +856,7 @@ mod tests { l.assert_consistent(); assert!(l.is_empty()); } #[test] - pub fn test_dlist_remove_all() { + fn test_dlist_remove_all() { let l = DList::(); l.assert_consistent(); let one = l.push_n(1); l.assert_consistent(); let two = l.push_n(2); @@ -869,7 +869,7 @@ mod tests { l.assert_consistent(); assert!(l.is_empty()); } #[test] - pub fn test_dlist_insert_n_before() { + fn test_dlist_insert_n_before() { let l = DList::(); l.assert_consistent(); let _one = l.push_n(1); l.assert_consistent(); let two = l.push_n(2); @@ -885,7 +885,7 @@ mod tests { l.assert_consistent(); assert!(l.is_empty()); } #[test] - pub fn test_dlist_insert_n_after() { + fn test_dlist_insert_n_after() { let l = DList::(); l.assert_consistent(); let one = l.push_n(1); l.assert_consistent(); let _two = l.push_n(2); @@ -901,7 +901,7 @@ mod tests { l.assert_consistent(); assert!(l.is_empty()); } #[test] - pub fn test_dlist_insert_before_head() { + fn test_dlist_insert_before_head() { let l = DList::(); l.assert_consistent(); let one = l.push_n(1); l.assert_consistent(); let _two = l.push_n(2); @@ -916,7 +916,7 @@ mod tests { l.assert_consistent(); assert!(l.is_empty()); } #[test] - pub fn test_dlist_insert_after_tail() { + fn test_dlist_insert_after_tail() { let l = DList::(); l.assert_consistent(); let _one = l.push_n(1); l.assert_consistent(); let two = l.push_n(2); @@ -931,7 +931,7 @@ mod tests { l.assert_consistent(); assert!(l.is_empty()); } #[test] #[should_fail] #[ignore(cfg(windows))] - pub fn test_dlist_asymmetric_link() { + fn test_dlist_asymmetric_link() { let l = DList::(); let _one = l.push_n(1); let two = l.push_n(2); @@ -939,7 +939,7 @@ mod tests { l.assert_consistent(); } #[test] #[should_fail] #[ignore(cfg(windows))] - pub fn test_dlist_cyclic_list() { + fn test_dlist_cyclic_list() { let l = DList::(); let one = l.push_n(1); let _two = l.push_n(2); @@ -949,32 +949,32 @@ mod tests { l.assert_consistent(); } #[test] #[should_fail] #[ignore(cfg(windows))] - pub fn test_dlist_headless() { + fn test_dlist_headless() { DList::().head(); } #[test] #[should_fail] #[ignore(cfg(windows))] - pub fn test_dlist_insert_already_present_before() { + fn test_dlist_insert_already_present_before() { let l = DList::(); let one = l.push_n(1); let two = l.push_n(2); l.insert_n_before(two, one); } #[test] #[should_fail] #[ignore(cfg(windows))] - pub fn test_dlist_insert_already_present_after() { + fn test_dlist_insert_already_present_after() { let l = DList::(); let one = l.push_n(1); let two = l.push_n(2); l.insert_n_after(one, two); } #[test] #[should_fail] #[ignore(cfg(windows))] - pub fn test_dlist_insert_before_orphan() { + fn test_dlist_insert_before_orphan() { let l = DList::(); let one = new_dlist_node(1); let two = new_dlist_node(2); l.insert_n_before(one, two); } #[test] #[should_fail] #[ignore(cfg(windows))] - pub fn test_dlist_insert_after_orphan() { + fn test_dlist_insert_after_orphan() { let l = DList::(); let one = new_dlist_node(1); let two = new_dlist_node(2); diff --git a/src/libstd/future.rs b/src/libstd/future.rs index feea8fb4fcda7..a36f67fc95a00 100644 --- a/src/libstd/future.rs +++ b/src/libstd/future.rs @@ -172,7 +172,7 @@ pub fn spawn(blk: ~fn() -> A) -> Future { #[allow(non_implicitly_copyable_typarams)] #[cfg(test)] -pub mod test { +mod test { use core::prelude::*; use future::*; @@ -181,13 +181,13 @@ pub mod test { use core::task; #[test] - pub fn test_from_value() { + fn test_from_value() { let f = from_value(~"snail"); assert!(f.get() == ~"snail"); } #[test] - pub fn test_from_port() { + fn test_from_port() { let (ch, po) = oneshot::init(); send_one(ch, ~"whale"); let f = from_port(po); @@ -195,25 +195,25 @@ pub mod test { } #[test] - pub fn test_from_fn() { + fn test_from_fn() { let f = from_fn(|| ~"brail"); assert!(f.get() == ~"brail"); } #[test] - pub fn test_interface_get() { + fn test_interface_get() { let f = from_value(~"fail"); assert!(f.get() == ~"fail"); } #[test] - pub fn test_get_ref_method() { + fn test_get_ref_method() { let f = from_value(22); assert!(*f.get_ref() == 22); } #[test] - pub fn test_spawn() { + fn test_spawn() { let f = spawn(|| ~"bale"); assert!(f.get() == ~"bale"); } @@ -221,13 +221,13 @@ pub mod test { #[test] #[should_fail] #[ignore(cfg(target_os = "win32"))] - pub fn test_futurefail() { + fn test_futurefail() { let f = spawn(|| fail!()); let _x: ~str = f.get(); } #[test] - pub fn test_sendable_future() { + fn test_sendable_future() { let expected = ~"schlorf"; let f = do spawn { copy expected }; do task::spawn || { diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index b1e80718d8f74..d710a7b873548 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -662,7 +662,7 @@ mod tests { use core::result::{Err, Ok}; use core::result; - pub fn check_fail_type(f: Fail_, ft: FailType) { + fn check_fail_type(f: Fail_, ft: FailType) { match f { ArgumentMissing(_) => assert!(ft == ArgumentMissing_), UnrecognizedOption(_) => assert!(ft == UnrecognizedOption_), @@ -675,7 +675,7 @@ mod tests { // Tests for reqopt #[test] - pub fn test_reqopt_long() { + fn test_reqopt_long() { let args = ~[~"--test=20"]; let opts = ~[reqopt(~"test")]; let rs = getopts(args, opts); @@ -689,7 +689,7 @@ mod tests { } #[test] - pub fn test_reqopt_long_missing() { + fn test_reqopt_long_missing() { let args = ~[~"blah"]; let opts = ~[reqopt(~"test")]; let rs = getopts(args, opts); @@ -700,7 +700,7 @@ mod tests { } #[test] - pub fn test_reqopt_long_no_arg() { + fn test_reqopt_long_no_arg() { let args = ~[~"--test"]; let opts = ~[reqopt(~"test")]; let rs = getopts(args, opts); @@ -711,7 +711,7 @@ mod tests { } #[test] - pub fn test_reqopt_long_multi() { + fn test_reqopt_long_multi() { let args = ~[~"--test=20", ~"--test=30"]; let opts = ~[reqopt(~"test")]; let rs = getopts(args, opts); @@ -722,7 +722,7 @@ mod tests { } #[test] - pub fn test_reqopt_short() { + fn test_reqopt_short() { let args = ~[~"-t", ~"20"]; let opts = ~[reqopt(~"t")]; let rs = getopts(args, opts); @@ -736,7 +736,7 @@ mod tests { } #[test] - pub fn test_reqopt_short_missing() { + fn test_reqopt_short_missing() { let args = ~[~"blah"]; let opts = ~[reqopt(~"t")]; let rs = getopts(args, opts); @@ -747,7 +747,7 @@ mod tests { } #[test] - pub fn test_reqopt_short_no_arg() { + fn test_reqopt_short_no_arg() { let args = ~[~"-t"]; let opts = ~[reqopt(~"t")]; let rs = getopts(args, opts); @@ -758,7 +758,7 @@ mod tests { } #[test] - pub fn test_reqopt_short_multi() { + fn test_reqopt_short_multi() { let args = ~[~"-t", ~"20", ~"-t", ~"30"]; let opts = ~[reqopt(~"t")]; let rs = getopts(args, opts); @@ -771,7 +771,7 @@ mod tests { // Tests for optopt #[test] - pub fn test_optopt_long() { + fn test_optopt_long() { let args = ~[~"--test=20"]; let opts = ~[optopt(~"test")]; let rs = getopts(args, opts); @@ -785,7 +785,7 @@ mod tests { } #[test] - pub fn test_optopt_long_missing() { + fn test_optopt_long_missing() { let args = ~[~"blah"]; let opts = ~[optopt(~"test")]; let rs = getopts(args, opts); @@ -796,7 +796,7 @@ mod tests { } #[test] - pub fn test_optopt_long_no_arg() { + fn test_optopt_long_no_arg() { let args = ~[~"--test"]; let opts = ~[optopt(~"test")]; let rs = getopts(args, opts); @@ -807,7 +807,7 @@ mod tests { } #[test] - pub fn test_optopt_long_multi() { + fn test_optopt_long_multi() { let args = ~[~"--test=20", ~"--test=30"]; let opts = ~[optopt(~"test")]; let rs = getopts(args, opts); @@ -818,7 +818,7 @@ mod tests { } #[test] - pub fn test_optopt_short() { + fn test_optopt_short() { let args = ~[~"-t", ~"20"]; let opts = ~[optopt(~"t")]; let rs = getopts(args, opts); @@ -832,7 +832,7 @@ mod tests { } #[test] - pub fn test_optopt_short_missing() { + fn test_optopt_short_missing() { let args = ~[~"blah"]; let opts = ~[optopt(~"t")]; let rs = getopts(args, opts); @@ -843,7 +843,7 @@ mod tests { } #[test] - pub fn test_optopt_short_no_arg() { + fn test_optopt_short_no_arg() { let args = ~[~"-t"]; let opts = ~[optopt(~"t")]; let rs = getopts(args, opts); @@ -854,7 +854,7 @@ mod tests { } #[test] - pub fn test_optopt_short_multi() { + fn test_optopt_short_multi() { let args = ~[~"-t", ~"20", ~"-t", ~"30"]; let opts = ~[optopt(~"t")]; let rs = getopts(args, opts); @@ -867,7 +867,7 @@ mod tests { // Tests for optflag #[test] - pub fn test_optflag_long() { + fn test_optflag_long() { let args = ~[~"--test"]; let opts = ~[optflag(~"test")]; let rs = getopts(args, opts); @@ -878,7 +878,7 @@ mod tests { } #[test] - pub fn test_optflag_long_missing() { + fn test_optflag_long_missing() { let args = ~[~"blah"]; let opts = ~[optflag(~"test")]; let rs = getopts(args, opts); @@ -889,7 +889,7 @@ mod tests { } #[test] - pub fn test_optflag_long_arg() { + fn test_optflag_long_arg() { let args = ~[~"--test=20"]; let opts = ~[optflag(~"test")]; let rs = getopts(args, opts); @@ -903,7 +903,7 @@ mod tests { } #[test] - pub fn test_optflag_long_multi() { + fn test_optflag_long_multi() { let args = ~[~"--test", ~"--test"]; let opts = ~[optflag(~"test")]; let rs = getopts(args, opts); @@ -914,7 +914,7 @@ mod tests { } #[test] - pub fn test_optflag_short() { + fn test_optflag_short() { let args = ~[~"-t"]; let opts = ~[optflag(~"t")]; let rs = getopts(args, opts); @@ -925,7 +925,7 @@ mod tests { } #[test] - pub fn test_optflag_short_missing() { + fn test_optflag_short_missing() { let args = ~[~"blah"]; let opts = ~[optflag(~"t")]; let rs = getopts(args, opts); @@ -936,7 +936,7 @@ mod tests { } #[test] - pub fn test_optflag_short_arg() { + fn test_optflag_short_arg() { let args = ~[~"-t", ~"20"]; let opts = ~[optflag(~"t")]; let rs = getopts(args, opts); @@ -951,7 +951,7 @@ mod tests { } #[test] - pub fn test_optflag_short_multi() { + fn test_optflag_short_multi() { let args = ~[~"-t", ~"-t"]; let opts = ~[optflag(~"t")]; let rs = getopts(args, opts); @@ -963,7 +963,7 @@ mod tests { // Tests for optflagmulti #[test] - pub fn test_optflagmulti_short1() { + fn test_optflagmulti_short1() { let args = ~[~"-v"]; let opts = ~[optflagmulti(~"v")]; let rs = getopts(args, opts); @@ -976,7 +976,7 @@ mod tests { } #[test] - pub fn test_optflagmulti_short2a() { + fn test_optflagmulti_short2a() { let args = ~[~"-v", ~"-v"]; let opts = ~[optflagmulti(~"v")]; let rs = getopts(args, opts); @@ -989,7 +989,7 @@ mod tests { } #[test] - pub fn test_optflagmulti_short2b() { + fn test_optflagmulti_short2b() { let args = ~[~"-vv"]; let opts = ~[optflagmulti(~"v")]; let rs = getopts(args, opts); @@ -1002,7 +1002,7 @@ mod tests { } #[test] - pub fn test_optflagmulti_long1() { + fn test_optflagmulti_long1() { let args = ~[~"--verbose"]; let opts = ~[optflagmulti(~"verbose")]; let rs = getopts(args, opts); @@ -1015,7 +1015,7 @@ mod tests { } #[test] - pub fn test_optflagmulti_long2() { + fn test_optflagmulti_long2() { let args = ~[~"--verbose", ~"--verbose"]; let opts = ~[optflagmulti(~"verbose")]; let rs = getopts(args, opts); @@ -1029,7 +1029,7 @@ mod tests { // Tests for optmulti #[test] - pub fn test_optmulti_long() { + fn test_optmulti_long() { let args = ~[~"--test=20"]; let opts = ~[optmulti(~"test")]; let rs = getopts(args, opts); @@ -1043,7 +1043,7 @@ mod tests { } #[test] - pub fn test_optmulti_long_missing() { + fn test_optmulti_long_missing() { let args = ~[~"blah"]; let opts = ~[optmulti(~"test")]; let rs = getopts(args, opts); @@ -1054,7 +1054,7 @@ mod tests { } #[test] - pub fn test_optmulti_long_no_arg() { + fn test_optmulti_long_no_arg() { let args = ~[~"--test"]; let opts = ~[optmulti(~"test")]; let rs = getopts(args, opts); @@ -1065,7 +1065,7 @@ mod tests { } #[test] - pub fn test_optmulti_long_multi() { + fn test_optmulti_long_multi() { let args = ~[~"--test=20", ~"--test=30"]; let opts = ~[optmulti(~"test")]; let rs = getopts(args, opts); @@ -1082,7 +1082,7 @@ mod tests { } #[test] - pub fn test_optmulti_short() { + fn test_optmulti_short() { let args = ~[~"-t", ~"20"]; let opts = ~[optmulti(~"t")]; let rs = getopts(args, opts); @@ -1096,7 +1096,7 @@ mod tests { } #[test] - pub fn test_optmulti_short_missing() { + fn test_optmulti_short_missing() { let args = ~[~"blah"]; let opts = ~[optmulti(~"t")]; let rs = getopts(args, opts); @@ -1107,7 +1107,7 @@ mod tests { } #[test] - pub fn test_optmulti_short_no_arg() { + fn test_optmulti_short_no_arg() { let args = ~[~"-t"]; let opts = ~[optmulti(~"t")]; let rs = getopts(args, opts); @@ -1118,7 +1118,7 @@ mod tests { } #[test] - pub fn test_optmulti_short_multi() { + fn test_optmulti_short_multi() { let args = ~[~"-t", ~"20", ~"-t", ~"30"]; let opts = ~[optmulti(~"t")]; let rs = getopts(args, opts); @@ -1135,7 +1135,7 @@ mod tests { } #[test] - pub fn test_unrecognized_option_long() { + fn test_unrecognized_option_long() { let args = ~[~"--untest"]; let opts = ~[optmulti(~"t")]; let rs = getopts(args, opts); @@ -1146,7 +1146,7 @@ mod tests { } #[test] - pub fn test_unrecognized_option_short() { + fn test_unrecognized_option_short() { let args = ~[~"-t"]; let opts = ~[optmulti(~"test")]; let rs = getopts(args, opts); @@ -1157,7 +1157,7 @@ mod tests { } #[test] - pub fn test_combined() { + fn test_combined() { let args = ~[~"prog", ~"free1", ~"-s", ~"20", ~"free2", ~"--flag", ~"--long=30", ~"-f", ~"-m", ~"40", @@ -1189,7 +1189,7 @@ mod tests { } #[test] - pub fn test_multi() { + fn test_multi() { let args = ~[~"-e", ~"foo", ~"--encrypt", ~"foo"]; let opts = ~[optopt(~"e"), optopt(~"encrypt"), optopt(~"f")]; let matches = &match getopts(args, opts) { @@ -1211,7 +1211,7 @@ mod tests { } #[test] - pub fn test_nospace() { + fn test_nospace() { let args = ~[~"-Lfoo", ~"-M."]; let opts = ~[optmulti(~"L"), optmulti(~"M")]; let matches = &match getopts(args, opts) { @@ -1226,7 +1226,7 @@ mod tests { } #[test] - pub fn test_groups_reqopt() { + fn test_groups_reqopt() { let opt = groups::reqopt(~"b", ~"banana", ~"some bananas", ~"VAL"); assert!(opt == OptGroup { short_name: ~"b", long_name: ~"banana", @@ -1237,7 +1237,7 @@ mod tests { } #[test] - pub fn test_groups_optopt() { + fn test_groups_optopt() { let opt = groups::optopt(~"a", ~"apple", ~"some apples", ~"VAL"); assert!(opt == OptGroup { short_name: ~"a", long_name: ~"apple", @@ -1248,7 +1248,7 @@ mod tests { } #[test] - pub fn test_groups_optflag() { + fn test_groups_optflag() { let opt = groups::optflag(~"k", ~"kiwi", ~"some kiwis"); assert!(opt == OptGroup { short_name: ~"k", long_name: ~"kiwi", @@ -1259,7 +1259,7 @@ mod tests { } #[test] - pub fn test_groups_optflagopt() { + fn test_groups_optflagopt() { let opt = groups::optflagopt(~"p", ~"pineapple", ~"some pineapples", ~"VAL"); assert!(opt == OptGroup { short_name: ~"p", @@ -1271,7 +1271,7 @@ mod tests { } #[test] - pub fn test_groups_optmulti() { + fn test_groups_optmulti() { let opt = groups::optmulti(~"l", ~"lime", ~"some limes", ~"VAL"); assert!(opt == OptGroup { short_name: ~"l", @@ -1283,7 +1283,7 @@ mod tests { } #[test] - pub fn test_groups_long_to_short() { + fn test_groups_long_to_short() { let short = ~[reqopt(~"b"), reqopt(~"banana")]; let verbose = groups::reqopt(~"b", ~"banana", ~"some bananas", ~"VAL"); @@ -1292,7 +1292,7 @@ mod tests { } #[test] - pub fn test_groups_getopts() { + fn test_groups_getopts() { let short = ~[ reqopt(~"b"), reqopt(~"banana"), optopt(~"a"), optopt(~"apple"), @@ -1318,7 +1318,7 @@ mod tests { } #[test] - pub fn test_groups_usage() { + fn test_groups_usage() { let optgroups = ~[ groups::reqopt(~"b", ~"banana", ~"Desc", ~"VAL"), groups::optopt(~"a", ~"012345678901234567890123456789", @@ -1349,7 +1349,7 @@ Options: } #[test] - pub fn test_groups_usage_description_wrapping() { + fn test_groups_usage_description_wrapping() { // indentation should be 24 spaces // lines wrap after 78: or rather descriptions wrap after 54 diff --git a/src/libstd/list.rs b/src/libstd/list.rs index 63d461ed4d3bf..8e173ff8a9c6a 100644 --- a/src/libstd/list.rs +++ b/src/libstd/list.rs @@ -160,7 +160,7 @@ mod tests { use core::option; #[test] - pub fn test_is_empty() { + fn test_is_empty() { let empty : @list::List = from_vec(~[]); let full1 = from_vec(~[1]); let full2 = from_vec(~['r', 'u']); @@ -171,7 +171,7 @@ mod tests { } #[test] - pub fn test_from_vec() { + fn test_from_vec() { let l = from_vec(~[0, 1, 2]); assert!((head(l) == 0)); @@ -184,13 +184,13 @@ mod tests { } #[test] - pub fn test_from_vec_empty() { + fn test_from_vec_empty() { let empty : @list::List = from_vec(~[]); assert!((empty == @list::Nil::)); } #[test] - pub fn test_foldl() { + fn test_foldl() { fn add(a: &uint, b: &int) -> uint { return *a + (*b as uint); } let l = from_vec(~[0, 1, 2, 3, 4]); let empty = @list::Nil::; @@ -199,7 +199,7 @@ mod tests { } #[test] - pub fn test_foldl2() { + fn test_foldl2() { fn sub(a: &int, b: &int) -> int { *a - *b } @@ -208,14 +208,14 @@ mod tests { } #[test] - pub fn test_find_success() { + fn test_find_success() { fn match_(i: &int) -> bool { return *i == 2; } let l = from_vec(~[0, 1, 2]); assert!((list::find(l, match_) == option::Some(2))); } #[test] - pub fn test_find_fail() { + fn test_find_fail() { fn match_(_i: &int) -> bool { return false; } let l = from_vec(~[0, 1, 2]); let empty = @list::Nil::; @@ -224,7 +224,7 @@ mod tests { } #[test] - pub fn test_has() { + fn test_has() { let l = from_vec(~[5, 8, 6]); let empty = @list::Nil::; assert!((list::has(l, 5))); @@ -234,7 +234,7 @@ mod tests { } #[test] - pub fn test_len() { + fn test_len() { let l = from_vec(~[0, 1, 2]); let empty = @list::Nil::; assert!((list::len(l) == 3u)); @@ -242,7 +242,7 @@ mod tests { } #[test] - pub fn test_append() { + fn test_append() { assert!(from_vec(~[1,2,3,4]) == list::append(list::from_vec(~[1,2]), list::from_vec(~[3,4]))); } diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index a8b2723bcfbc4..b32df75063d97 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -1426,7 +1426,7 @@ struct TcpBufferedSocketData { } #[cfg(test)] -pub mod test { +mod test { use net::ip; use net::tcp::{GenericListenErr, TcpConnectErrData, TcpListenErrData}; use net::tcp::{connect, accept, read, listen, TcpSocket, socket_buf}; @@ -1447,9 +1447,9 @@ pub mod test { #[cfg(target_os="darwin")] #[cfg(target_os="linux")] #[cfg(target_os="android")] - pub mod tcp_ipv4_server_and_client_test { + mod tcp_ipv4_server_and_client_test { #[cfg(target_arch="x86_64")] - pub mod impl64 { + mod impl64 { use net::tcp::test::*; #[test] @@ -1497,7 +1497,7 @@ pub mod test { #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] #[cfg(target_arch="mips")] - pub mod impl32 { + mod impl32 { use net::tcp::test::*; #[test] diff --git a/src/libstd/net_url.rs b/src/libstd/net_url.rs index 9b8b0f9be0bcd..4cb9a98036b19 100644 --- a/src/libstd/net_url.rs +++ b/src/libstd/net_url.rs @@ -810,7 +810,7 @@ mod tests { use core::hashmap::HashMap; #[test] - pub fn test_url_parse() { + fn test_url_parse() { let url = ~"http://user:pass@rust-lang.org/doc?s=v#something"; let up = from_str(url); @@ -826,7 +826,7 @@ mod tests { } #[test] - pub fn test_url_parse_host_slash() { + fn test_url_parse_host_slash() { let urlstr = ~"http://0.42.42.42/"; let url = from_str(urlstr).unwrap(); assert!(url.host == ~"0.42.42.42"); @@ -834,87 +834,87 @@ mod tests { } #[test] - pub fn test_url_with_underscores() { + fn test_url_with_underscores() { let urlstr = ~"http://dotcom.com/file_name.html"; let url = from_str(urlstr).unwrap(); assert!(url.path == ~"/file_name.html"); } #[test] - pub fn test_url_with_dashes() { + fn test_url_with_dashes() { let urlstr = ~"http://dotcom.com/file-name.html"; let url = from_str(urlstr).unwrap(); assert!(url.path == ~"/file-name.html"); } #[test] - pub fn test_no_scheme() { + fn test_no_scheme() { assert!(get_scheme("noschemehere.html").is_err()); } #[test] - pub fn test_invalid_scheme_errors() { + fn test_invalid_scheme_errors() { assert!(from_str("99://something").is_err()); assert!(from_str("://something").is_err()); } #[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"; assert!(from_str(url).unwrap().to_str() == url); } #[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"; assert!(from_str(url).unwrap().to_str() == url); } #[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"; assert!(from_str(url).unwrap().to_str() == url); } #[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 should_be = ~"http://user:pass@rust-lang.org/doc#something"; assert!(from_str(url).unwrap().to_str() == should_be); } #[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"; assert!(from_str(url).unwrap().to_str() == url); } #[test] - pub fn test_minimal_url_parse_and_format() { + fn test_minimal_url_parse_and_format() { let url = ~"http://rust-lang.org/doc"; assert!(from_str(url).unwrap().to_str() == url); } #[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"; assert!(from_str(url).unwrap().to_str() == url); } #[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"; assert!(from_str(url).unwrap().to_str() == url); } #[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"; assert!(from_str(url).unwrap().to_str() == url); } #[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 u = from_str(url).unwrap(); assert!(u.path == ~"/doc uments"); @@ -922,13 +922,13 @@ mod tests { } #[test] - pub fn test_url_without_authority() { + fn test_url_without_authority() { let url = ~"mailto:test@email.com"; assert!(from_str(url).unwrap().to_str() == url); } #[test] - pub fn test_encode() { + fn test_encode() { assert!(encode("") == ~""); assert!(encode("http://example.com") == ~"http://example.com"); assert!(encode("foo bar% baz") == ~"foo%20bar%25%20baz"); @@ -956,7 +956,7 @@ mod tests { } #[test] - pub fn test_encode_component() { + fn test_encode_component() { assert!(encode_component("") == ~""); assert!(encode_component("http://example.com") == ~"http%3A%2F%2Fexample.com"); @@ -985,7 +985,7 @@ mod tests { } #[test] - pub fn test_decode() { + fn test_decode() { assert!(decode("") == ~""); assert!(decode("abc/def 123") == ~"abc/def 123"); assert!(decode("abc%2Fdef%20123") == ~"abc%2Fdef 123"); @@ -1013,7 +1013,7 @@ mod tests { } #[test] - pub fn test_decode_component() { + fn test_decode_component() { assert!(decode_component("") == ~""); assert!(decode_component("abc/def 123") == ~"abc/def 123"); assert!(decode_component("abc%2Fdef%20123") == ~"abc/def 123"); @@ -1041,7 +1041,7 @@ mod tests { } #[test] - pub fn test_encode_form_urlencoded() { + fn test_encode_form_urlencoded() { let mut m = HashMap::new(); assert!(encode_form_urlencoded(&m) == ~""); @@ -1060,7 +1060,7 @@ mod tests { } #[test] - pub fn test_decode_form_urlencoded() { + fn test_decode_form_urlencoded() { // FIXME #4449: Commented out because this causes an ICE, but only // on FreeBSD /* diff --git a/src/libstd/sha1.rs b/src/libstd/sha1.rs index f5f7f5e326a79..6aa4d1c54bc9e 100644 --- a/src/libstd/sha1.rs +++ b/src/libstd/sha1.rs @@ -282,7 +282,7 @@ mod tests { use core::vec; #[test] - pub fn test() { + fn test() { struct Test { input: ~str, output: ~[u8], diff --git a/src/libstd/sort.rs b/src/libstd/sort.rs index 39ca9bb5ba66f..72a888fcc917b 100644 --- a/src/libstd/sort.rs +++ b/src/libstd/sort.rs @@ -733,7 +733,7 @@ mod test_qsort3 { 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::(v1); quick_sort3::(v1); let mut i = 0; @@ -745,7 +745,7 @@ mod test_qsort3 { } #[test] - pub fn test() { + fn test() { { let mut v1 = ~[3, 7, 4, 5, 2, 9, 5, 8]; let mut v2 = ~[2, 3, 4, 5, 5, 7, 8, 9]; @@ -777,7 +777,7 @@ mod test_qsort { use core::int; 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::(v1); fn leual(a: &int, b: &int) -> bool { *a <= *b } quick_sort::(v1, leual); @@ -790,7 +790,7 @@ mod test_qsort { } #[test] - pub fn test() { + fn test() { { let mut v1 = ~[3, 7, 4, 5, 2, 9, 5, 8]; let mut v2 = ~[2, 3, 4, 5, 5, 7, 8, 9]; @@ -816,7 +816,7 @@ mod test_qsort { // Regression test for #750 #[test] - pub fn test_simple() { + fn test_simple() { let mut names = ~[2, 1, 3]; let expected = ~[1, 2, 3]; @@ -842,7 +842,7 @@ mod tests { use core::vec; - pub fn check_sort(v1: &[int], v2: &[int]) { + fn check_sort(v1: &[int], v2: &[int]) { let len = vec::len::(v1); pub fn le(a: &int, b: &int) -> bool { *a <= *b } let f = le; @@ -856,7 +856,7 @@ mod tests { } #[test] - pub fn test() { + fn test() { { let v1 = ~[3, 7, 4, 5, 2, 9, 5, 8]; let v2 = ~[2, 3, 4, 5, 5, 7, 8, 9]; @@ -873,7 +873,7 @@ mod tests { } #[test] - pub fn test_merge_sort_mutable() { + fn test_merge_sort_mutable() { pub fn le(a: &int, b: &int) -> bool { *a <= *b } let mut v1 = ~[3, 2, 1]; let v2 = merge_sort(v1, le); @@ -881,7 +881,7 @@ mod tests { } #[test] - pub fn test_merge_sort_stability() { + fn test_merge_sort_stability() { // tjc: funny that we have to use parens fn ile(x: &(&'static str), y: &(&'static str)) -> bool { diff --git a/src/libstd/sync.rs b/src/libstd/sync.rs index f2de8213a1b9e..971bb51f7e9f4 100644 --- a/src/libstd/sync.rs +++ b/src/libstd/sync.rs @@ -728,19 +728,19 @@ mod tests { * Semaphore tests ************************************************************************/ #[test] - pub fn test_sem_acquire_release() { + fn test_sem_acquire_release() { let s = ~semaphore(1); s.acquire(); s.release(); s.acquire(); } #[test] - pub fn test_sem_basic() { + fn test_sem_basic() { let s = ~semaphore(1); do s.access { } } #[test] - pub fn test_sem_as_mutex() { + fn test_sem_as_mutex() { let s = ~semaphore(1); let s2 = ~s.clone(); do task::spawn || { @@ -753,7 +753,7 @@ mod tests { } } #[test] - pub fn test_sem_as_cvar() { + fn test_sem_as_cvar() { /* Child waits and parent signals */ let (p,c) = comm::stream(); let s = ~semaphore(0); @@ -779,7 +779,7 @@ mod tests { c.send(()); } #[test] - pub fn test_sem_multi_resource() { + fn test_sem_multi_resource() { // Parent and child both get in the critical section at the same // time, and shake hands. let s = ~semaphore(2); @@ -798,7 +798,7 @@ mod tests { } } #[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. // When one blocks, it should schedule the other one. do task::spawn_sched(task::ManualThreads(1)) { @@ -823,7 +823,7 @@ mod tests { * Mutex tests ************************************************************************/ #[test] - pub fn test_mutex_lock() { + fn test_mutex_lock() { // Unsafely achieve shared state, and do the textbook // "load tmp = move ptr; inc tmp; store ptr <- tmp" dance. let (p,c) = comm::stream(); @@ -854,7 +854,7 @@ mod tests { } } #[test] - pub fn test_mutex_cond_wait() { + fn test_mutex_cond_wait() { let m = ~Mutex(); // Child wakes up parent @@ -886,7 +886,7 @@ mod tests { let _ = port.recv(); // Wait until child wakes up } #[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 mut ports = ~[]; @@ -913,15 +913,15 @@ mod tests { for ports.each |port| { let _ = port.recv(); } } #[test] - pub fn test_mutex_cond_broadcast() { + fn test_mutex_cond_broadcast() { test_mutex_cond_broadcast_helper(12); } #[test] - pub fn test_mutex_cond_broadcast_none() { + fn test_mutex_cond_broadcast_none() { test_mutex_cond_broadcast_helper(0); } #[test] - pub fn test_mutex_cond_no_waiter() { + fn test_mutex_cond_no_waiter() { let m = ~Mutex(); let m2 = ~m.clone(); do task::try || { @@ -932,7 +932,7 @@ mod tests { } } #[test] #[ignore(cfg(windows))] - pub fn test_mutex_killed_simple() { + fn test_mutex_killed_simple() { // Mutex must get automatically unlocked if failed/killed within. let m = ~Mutex(); let m2 = ~m.clone(); @@ -947,7 +947,7 @@ mod tests { do m.lock { } } #[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 // unwinding (e.g. double unlock). let m = ~Mutex(); @@ -973,7 +973,7 @@ mod tests { } } #[test] #[ignore(cfg(windows))] - pub fn test_mutex_killed_broadcast() { + fn test_mutex_killed_broadcast() { let m = ~Mutex(); let m2 = ~m.clone(); let (p,c) = comm::stream(); @@ -1026,7 +1026,7 @@ mod tests { } } #[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(). let m = ~Mutex(); do m.lock_cond |cond| { @@ -1040,7 +1040,7 @@ mod tests { } } #[test] #[ignore(cfg(windows))] - pub fn test_mutex_different_conds() { + fn test_mutex_different_conds() { let result = do task::try { let m = ~mutex_with_condvars(2); let m2 = ~m.clone(); @@ -1061,7 +1061,7 @@ mod tests { assert!(result.is_err()); } #[test] #[ignore(cfg(windows))] - pub fn test_mutex_no_condvars() { + fn test_mutex_no_condvars() { let result = do task::try { let m = ~mutex_with_condvars(0); do m.lock_cond |cond| { cond.wait(); } @@ -1084,7 +1084,7 @@ mod tests { #[cfg(test)] pub enum RWlockMode { Read, Write, Downgrade, DowngradeRead } #[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 { Read => x.read(blk), Write => x.write(blk), @@ -1100,7 +1100,7 @@ mod tests { } } #[cfg(test)] - pub fn test_rwlock_exclusion(x: ~RWlock, + fn test_rwlock_exclusion(x: ~RWlock, mode1: RWlockMode, mode2: RWlockMode) { // Test mutual exclusion between readers and writers. Just like the @@ -1132,21 +1132,21 @@ mod tests { } } #[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(), Write, Read); test_rwlock_exclusion(~RWlock(), Read, Downgrade); test_rwlock_exclusion(~RWlock(), Downgrade, Read); } #[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, Downgrade); test_rwlock_exclusion(~RWlock(), Downgrade, Write); test_rwlock_exclusion(~RWlock(), Downgrade, Downgrade); } #[cfg(test)] - pub fn test_rwlock_handshake(x: ~RWlock, + fn test_rwlock_handshake(x: ~RWlock, mode1: RWlockMode, mode2: RWlockMode, make_mode2_go_first: bool) { @@ -1178,7 +1178,7 @@ mod tests { } } #[test] - pub fn test_rwlock_readers_and_readers() { + fn test_rwlock_readers_and_readers() { test_rwlock_handshake(~RWlock(), Read, Read, false); // The downgrader needs to get in before the reader gets in, otherwise // 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. } #[test] - pub fn test_rwlock_downgrade_unlock() { + fn test_rwlock_downgrade_unlock() { // Tests that downgrade can unlock the lock in both modes let x = ~RWlock(); do lock_rwlock_in_mode(x, Downgrade) { } @@ -1197,12 +1197,12 @@ mod tests { test_rwlock_exclusion(y, Write, Write); } #[test] - pub fn test_rwlock_read_recursive() { + fn test_rwlock_read_recursive() { let x = ~RWlock(); do x.read { do x.read { } } } #[test] - pub fn test_rwlock_cond_wait() { + fn test_rwlock_cond_wait() { // As test_mutex_cond_wait above. let x = ~RWlock(); @@ -1237,7 +1237,7 @@ mod tests { do x.read { } // Just for good measure } #[cfg(test)] - pub fn test_rwlock_cond_broadcast_helper(num_waiters: uint, + fn test_rwlock_cond_broadcast_helper(num_waiters: uint, dg1: bool, dg2: bool) { // Much like the mutex broadcast test. Downgrade-enabled. @@ -1276,7 +1276,7 @@ mod tests { for ports.each |port| { let _ = port.recv(); } } #[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, false); test_rwlock_cond_broadcast_helper(0, false, true); @@ -1287,7 +1287,7 @@ mod tests { test_rwlock_cond_broadcast_helper(12, false, false); } #[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. let x = ~RWlock(); let x2 = (*x).clone(); @@ -1302,23 +1302,23 @@ mod tests { do lock_rwlock_in_mode(x, mode2) { } } #[test] #[ignore(cfg(windows))] - pub fn test_rwlock_reader_killed_writer() { + fn test_rwlock_reader_killed_writer() { rwlock_kill_helper(Read, Write); } #[test] #[ignore(cfg(windows))] - pub fn test_rwlock_writer_killed_reader() { + fn test_rwlock_writer_killed_reader() { rwlock_kill_helper(Write,Read ); } #[test] #[ignore(cfg(windows))] - pub fn test_rwlock_reader_killed_reader() { + fn test_rwlock_reader_killed_reader() { rwlock_kill_helper(Read, Read ); } #[test] #[ignore(cfg(windows))] - pub fn test_rwlock_writer_killed_writer() { + fn test_rwlock_writer_killed_writer() { rwlock_kill_helper(Write,Write); } #[test] #[ignore(cfg(windows))] - pub fn test_rwlock_kill_downgrader() { + fn test_rwlock_kill_downgrader() { rwlock_kill_helper(Downgrade, Read); rwlock_kill_helper(Read, Downgrade); rwlock_kill_helper(Downgrade, Write); @@ -1333,7 +1333,7 @@ mod tests { rwlock_kill_helper(Downgrade, DowngradeRead); } #[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. let x = ~RWlock(); let y = ~RWlock(); diff --git a/src/libstd/test.rs b/src/libstd/test.rs index 04fa319b25530..ee83a0c9bd652 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -823,7 +823,7 @@ mod tests { #[test] #[ignore(cfg(windows))] - pub fn test_should_fail() { + fn test_should_fail() { fn f() { fail!(); } let desc = TestDescAndFn { desc: TestDesc { @@ -841,7 +841,7 @@ mod tests { } #[test] - pub fn test_should_fail_but_succeeds() { + fn test_should_fail_but_succeeds() { fn f() { } let desc = TestDescAndFn { desc: TestDesc { @@ -859,7 +859,7 @@ mod tests { } #[test] - pub fn first_free_arg_should_be_a_filter() { + fn first_free_arg_should_be_a_filter() { let args = ~[~"progname", ~"filter"]; let opts = match parse_opts(args) { either::Left(copy o) => o, @@ -869,7 +869,7 @@ mod tests { } #[test] - pub fn parse_ignored_flag() { + fn parse_ignored_flag() { let args = ~[~"progname", ~"filter", ~"--ignored"]; let opts = match parse_opts(args) { either::Left(copy o) => o, diff --git a/src/libstd/time.rs b/src/libstd/time.rs index adfa12594aac1..70dc4d8cfebbf 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -872,7 +872,7 @@ mod tests { use core::str; 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_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 ns1 = precise_time_ns(); @@ -910,7 +910,7 @@ mod tests { assert!(ns2 >= ns1); } - pub fn test_at_utc() { + fn test_at_utc() { os::setenv(~"TZ", ~"America/Los_Angeles"); tzset(); @@ -931,7 +931,7 @@ mod tests { assert!(utc.tm_nsec == 54321_i32); } - pub fn test_at() { + fn test_at() { os::setenv(~"TZ", ~"America/Los_Angeles"); tzset(); @@ -959,7 +959,7 @@ mod tests { assert!(local.tm_nsec == 54321_i32); } - pub fn test_to_timespec() { + fn test_to_timespec() { os::setenv(~"TZ", ~"America/Los_Angeles"); tzset(); @@ -970,7 +970,7 @@ mod tests { assert!(utc.to_local().to_timespec() == time); } - pub fn test_conversions() { + fn test_conversions() { os::setenv(~"TZ", ~"America/Los_Angeles"); tzset(); @@ -986,7 +986,7 @@ mod tests { assert!(utc.to_local().to_utc() == utc); } - pub fn test_strptime() { + fn test_strptime() { os::setenv(~"TZ", ~"America/Los_Angeles"); tzset(); @@ -1144,7 +1144,7 @@ mod tests { assert!(test(~"%", ~"%%")); } - pub fn test_ctime() { + fn test_ctime() { os::setenv(~"TZ", ~"America/Los_Angeles"); tzset(); @@ -1158,7 +1158,7 @@ mod tests { assert!(local.ctime() == ~"Fri Feb 13 15:31:30 2009"); } - pub fn test_strftime() { + fn test_strftime() { os::setenv(~"TZ", ~"America/Los_Angeles"); tzset(); @@ -1231,7 +1231,7 @@ mod tests { 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}; let a = &Timespec::new(-2, 1); @@ -1265,7 +1265,7 @@ mod tests { } #[test] - pub fn run_tests() { + fn run_tests() { // The tests race on tzset. So instead of having many independent // tests, we will just call the functions now. test_get_time(); diff --git a/src/libstd/timer.rs b/src/libstd/timer.rs index 99e772b0c95a3..c229e72ae5d4a 100644 --- a/src/libstd/timer.rs +++ b/src/libstd/timer.rs @@ -183,13 +183,13 @@ mod test { use core::pipes::{stream, SharedChan}; #[test] - pub fn test_gl_timer_simple_sleep_test() { + fn test_gl_timer_simple_sleep_test() { let hl_loop = &uv::global_loop::get(); sleep(hl_loop, 1u); } #[test] - pub fn test_gl_timer_sleep_stress1() { + fn test_gl_timer_sleep_stress1() { let hl_loop = &uv::global_loop::get(); for iter::repeat(50u) { sleep(hl_loop, 1u); @@ -197,7 +197,7 @@ mod test { } #[test] - pub fn test_gl_timer_sleep_stress2() { + fn test_gl_timer_sleep_stress2() { let (po, ch) = stream(); let ch = SharedChan(ch); let hl_loop = &uv::global_loop::get(); @@ -241,7 +241,7 @@ mod test { #[test] #[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 mut successes = 0; let mut failures = 0; @@ -270,7 +270,7 @@ mod 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 mut successes = 0; let mut failures = 0; diff --git a/src/libstd/uv_ll.rs b/src/libstd/uv_ll.rs index 3bf297027d4d6..740ecec001f83 100644 --- a/src/libstd/uv_ll.rs +++ b/src/libstd/uv_ll.rs @@ -1225,7 +1225,7 @@ pub unsafe fn addrinfo_as_sockaddr_in6(input: *addrinfo) -> *sockaddr_in6 { } #[cfg(test)] -pub mod test { +mod test { use core::prelude::*; use core::comm::{SharedChan, stream, GenericChan, GenericPort}; use super::*; @@ -1759,11 +1759,11 @@ pub mod test { #[cfg(target_os="darwin")] #[cfg(target_os="linux")] #[cfg(target_os="android")] - pub mod tcp_and_server_client_test { + mod tcp_and_server_client_test { #[cfg(target_arch="x86_64")] - pub mod impl64 { + mod impl64 { #[test] - pub fn test_uv_ll_tcp_server_and_request() { + fn test_uv_ll_tcp_server_and_request() { unsafe { super::super::impl_uv_tcp_server_and_request(); } @@ -1772,10 +1772,10 @@ pub mod test { #[cfg(target_arch="x86")] #[cfg(target_arch="arm")] #[cfg(target_arch="mips")] - pub mod impl32 { + mod impl32 { #[test] #[ignore(cfg(target_os = "linux"))] - pub fn test_uv_ll_tcp_server_and_request() { + fn test_uv_ll_tcp_server_and_request() { unsafe { super::super::impl_uv_tcp_server_and_request(); } diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 59e4dddc73be9..bc930515a5d89 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -781,7 +781,7 @@ fn consume_whitespace(rdr: @mut StringReader) { } #[cfg(test)] -pub mod test { +mod test { use super::*; use ast; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index cf29f170f4061..88ecabe28f526 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2248,7 +2248,7 @@ pub fn print_onceness(s: @ps, o: ast::Onceness) { } #[cfg(test)] -pub mod test { +mod test { use super::*; use ast; diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index 4108871d0089c..1133fd850d84b 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -66,43 +66,47 @@ pub impl Interner { fn len(&self) -> uint { let vect = &*self.vect; vect.len() } } -#[test] -#[should_fail] -pub fn i1 () { - let i : Interner<@~str> = Interner::new(); - i.get(13); -} +#[cfg(test)] +mod tests { + use super::*; + #[test] + #[should_fail] + fn i1 () { + let i : Interner<@~str> = Interner::new(); + i.get(13); + } -#[test] -pub fn i2 () { - let i : Interner<@~str> = Interner::new(); - // first one is zero: - assert_eq!(i.intern (@~"dog"), 0); - // re-use gets the same entry: - assert_eq!(i.intern (@~"dog"), 0); - // different string gets a different #: - assert_eq!(i.intern (@~"cat"), 1); - assert_eq!(i.intern (@~"cat"), 1); - // dog is still at zero - assert_eq!(i.intern (@~"dog"), 0); - // gensym gets 3 - assert_eq!(i.gensym (@~"zebra" ), 2); - // gensym of same string gets new number : - assert_eq!(i.gensym (@~"zebra" ), 3); - // gensym of *existing* string gets new number: - assert_eq!(i.gensym (@~"dog"), 4); - assert_eq!(i.get(0), @~"dog"); - assert_eq!(i.get(1), @~"cat"); - assert_eq!(i.get(2), @~"zebra"); - assert_eq!(i.get(3), @~"zebra"); - assert_eq!(i.get(4), @~"dog"); -} + #[test] + fn i2 () { + let i : Interner<@~str> = Interner::new(); + // first one is zero: + assert_eq!(i.intern (@~"dog"), 0); + // re-use gets the same entry: + assert_eq!(i.intern (@~"dog"), 0); + // different string gets a different #: + assert_eq!(i.intern (@~"cat"), 1); + assert_eq!(i.intern (@~"cat"), 1); + // dog is still at zero + assert_eq!(i.intern (@~"dog"), 0); + // gensym gets 3 + assert_eq!(i.gensym (@~"zebra" ), 2); + // gensym of same string gets new number : + assert_eq!(i.gensym (@~"zebra" ), 3); + // gensym of *existing* string gets new number: + assert_eq!(i.gensym (@~"dog"), 4); + assert_eq!(i.get(0), @~"dog"); + assert_eq!(i.get(1), @~"cat"); + assert_eq!(i.get(2), @~"zebra"); + assert_eq!(i.get(3), @~"zebra"); + assert_eq!(i.get(4), @~"dog"); + } -#[test] -pub fn i3 () { - let i : Interner<@~str> = Interner::prefill([@~"Alan",@~"Bob",@~"Carol"]); - assert_eq!(i.get(0), @~"Alan"); - assert_eq!(i.get(1), @~"Bob"); - assert_eq!(i.get(2), @~"Carol"); - assert_eq!(i.intern(@~"Bob"), 1); -} + #[test] + fn i3 () { + let i : Interner<@~str> = Interner::prefill([@~"Alan",@~"Bob",@~"Carol"]); + assert_eq!(i.get(0), @~"Alan"); + assert_eq!(i.get(1), @~"Bob"); + assert_eq!(i.get(2), @~"Carol"); + assert_eq!(i.intern(@~"Bob"), 1); + } +} \ No newline at end of file From ef3a8ebb9bbc55bea4e0b62a1dcb6abb5512b223 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Tue, 16 Apr 2013 01:09:55 +1000 Subject: [PATCH 2/3] librustdoc: move tests into dedicated tests module. --- src/librustdoc/attr_parser.rs | 177 +++-- src/librustdoc/attr_pass.rs | 213 +++--- src/librustdoc/config.rs | 238 +++---- src/librustdoc/desc_to_brief_pass.rs | 163 ++--- src/librustdoc/extract.rs | 132 ++-- src/librustdoc/markdown_index_pass.rs | 216 +++--- src/librustdoc/markdown_pass.rs | 918 +++++++++++++------------- src/librustdoc/markdown_writer.rs | 123 ++-- src/librustdoc/page_pass.rs | 47 +- src/librustdoc/prune_hidden_pass.rs | 20 +- src/librustdoc/prune_private_pass.rs | 176 ++--- src/librustdoc/sectionalize_pass.rs | 177 ++--- src/librustdoc/text_pass.rs | 310 ++++----- src/librustdoc/trim_pass.rs | 22 +- src/librustdoc/tystr_pass.rs | 311 ++++----- 15 files changed, 1624 insertions(+), 1619 deletions(-) diff --git a/src/librustdoc/attr_parser.rs b/src/librustdoc/attr_parser.rs index 213198e6f2158..efd061209a503 100644 --- a/src/librustdoc/attr_parser.rs +++ b/src/librustdoc/attr_parser.rs @@ -25,26 +25,6 @@ pub struct CrateAttrs { name: Option<~str> } -#[cfg(test)] -mod test { - use syntax::ast; - use syntax; - - use core::option::None; - - pub fn parse_attributes(source: ~str) -> ~[ast::attribute] { - use syntax::parse; - use syntax::parse::attr::parser_attr; - use syntax::codemap; - - let parse_sess = syntax::parse::new_parse_sess(None); - let parser = parse::new_parser_from_source_str( - parse_sess, ~[], ~"-", codemap::FssNone, @source); - - parser.parse_outer_attributes() - } -} - fn doc_metas( attrs: ~[ast::attribute] ) -> ~[@ast::meta_item] { @@ -66,30 +46,6 @@ pub fn parse_crate(attrs: ~[ast::attribute]) -> CrateAttrs { } } -#[test] -fn should_extract_crate_name_from_link_attribute() { - let source = ~"#[link(name = \"snuggles\")]"; - let attrs = test::parse_attributes(source); - let attrs = parse_crate(attrs); - assert!(attrs.name == Some(~"snuggles")); -} - -#[test] -fn should_not_extract_crate_name_if_no_link_attribute() { - let source = ~""; - let attrs = test::parse_attributes(source); - let attrs = parse_crate(attrs); - assert!(attrs.name == None); -} - -#[test] -fn should_not_extract_crate_name_if_no_name_value_in_link_attribute() { - let source = ~"#[link(whatever)]"; - let attrs = test::parse_attributes(source); - let attrs = parse_crate(attrs); - assert!(attrs.name == None); -} - pub fn parse_desc(attrs: ~[ast::attribute]) -> Option<~str> { let doc_strs = do doc_metas(attrs).filter_mapped |meta| { attr::get_meta_item_value_str(*meta).map(|s| copy **s) @@ -101,60 +57,103 @@ pub fn parse_desc(attrs: ~[ast::attribute]) -> Option<~str> { } } -#[test] -fn parse_desc_should_handle_undocumented_mods() { - let source = ~""; - let attrs = test::parse_attributes(source); - let attrs = parse_desc(attrs); - assert!(attrs == None); -} - -#[test] -fn parse_desc_should_parse_simple_doc_attributes() { - let source = ~"#[doc = \"basic\"]"; - let attrs = test::parse_attributes(source); - let attrs = parse_desc(attrs); - assert!(attrs == Some(~"basic")); -} - pub fn parse_hidden(attrs: ~[ast::attribute]) -> bool { do doc_metas(attrs).find |meta| { match attr::get_meta_item_list(*meta) { - Some(metas) => { - let hiddens = attr::find_meta_items_by_name(metas, ~"hidden"); - !hiddens.is_empty() - } - None => false + Some(metas) => { + let hiddens = attr::find_meta_items_by_name(metas, ~"hidden"); + !hiddens.is_empty() + } + None => false } }.is_some() } -#[test] -fn should_parse_hidden_attribute() { - let source = ~"#[doc(hidden)]"; - let attrs = test::parse_attributes(source); - assert!(parse_hidden(attrs) == true); -} +#[cfg(test)] +mod test { + use syntax::ast; + use syntax; + use super::{parse_hidden, parse_crate, parse_desc}; + use core::prelude::*; -#[test] -fn should_parse_hidden_attribute_with_other_docs() { - let source = ~"#[doc = \"foo\"] #[doc(hidden)] #[doc = \"foo\"]"; - let attrs = test::parse_attributes(source); - assert!(parse_hidden(attrs) == true); -} + fn parse_attributes(source: ~str) -> ~[ast::attribute] { + use syntax::parse; + use syntax::parse::attr::parser_attr; + use syntax::codemap; -#[test] -fn should_not_parse_non_hidden_attribute() { - let source = ~"#[doc = \"\"]"; - let attrs = test::parse_attributes(source); - assert!(parse_hidden(attrs) == false); -} + let parse_sess = syntax::parse::new_parse_sess(None); + let parser = parse::new_parser_from_source_str( + parse_sess, ~[], ~"-", codemap::FssNone, @source); + + parser.parse_outer_attributes() + } -#[test] -fn should_concatenate_multiple_doc_comments() { - let source = ~"/// foo\n/// bar"; - let desc = parse_desc(test::parse_attributes(source)); - assert!(desc == Some(~"foo\nbar")); -} + #[test] + fn should_extract_crate_name_from_link_attribute() { + let source = ~"#[link(name = \"snuggles\")]"; + let attrs = parse_attributes(source); + let attrs = parse_crate(attrs); + assert!(attrs.name == Some(~"snuggles")); + } + #[test] + fn should_not_extract_crate_name_if_no_link_attribute() { + let source = ~""; + let attrs = parse_attributes(source); + let attrs = parse_crate(attrs); + assert!(attrs.name == None); + } + + #[test] + fn should_not_extract_crate_name_if_no_name_value_in_link_attribute() { + let source = ~"#[link(whatever)]"; + let attrs = parse_attributes(source); + let attrs = parse_crate(attrs); + assert!(attrs.name == None); + } + + #[test] + fn parse_desc_should_handle_undocumented_mods() { + let source = ~""; + let attrs = parse_attributes(source); + let attrs = parse_desc(attrs); + assert!(attrs == None); + } + + #[test] + fn parse_desc_should_parse_simple_doc_attributes() { + let source = ~"#[doc = \"basic\"]"; + let attrs = parse_attributes(source); + let attrs = parse_desc(attrs); + assert!(attrs == Some(~"basic")); + } + + #[test] + fn should_parse_hidden_attribute() { + let source = ~"#[doc(hidden)]"; + let attrs = parse_attributes(source); + assert!(parse_hidden(attrs) == true); + } + + #[test] + fn should_parse_hidden_attribute_with_other_docs() { + let source = ~"#[doc = \"foo\"] #[doc(hidden)] #[doc = \"foo\"]"; + let attrs = parse_attributes(source); + assert!(parse_hidden(attrs) == true); + } + + #[test] + fn should_not_parse_non_hidden_attribute() { + let source = ~"#[doc = \"\"]"; + let attrs = parse_attributes(source); + assert!(parse_hidden(attrs) == false); + } + + #[test] + fn should_concatenate_multiple_doc_comments() { + let source = ~"/// foo\n/// bar"; + let desc = parse_desc(parse_attributes(source)); + assert!(desc == Some(~"foo\nbar")); + } +} diff --git a/src/librustdoc/attr_pass.rs b/src/librustdoc/attr_pass.rs index b550155140f0b..a666bff18c97c 100644 --- a/src/librustdoc/attr_pass.rs +++ b/src/librustdoc/attr_pass.rs @@ -78,12 +78,6 @@ fn fold_crate( } } -#[test] -fn should_replace_top_module_name_with_crate_name() { - let doc = test::mk_doc(~"#[link(name = \"bond\")];"); - assert!(doc.cratemod().name() == ~"bond"); -} - fn fold_item( fold: &fold::Fold, doc: doc::ItemDoc @@ -113,38 +107,14 @@ fn parse_item_attrs( parse_attrs: ~fn(a: ~[ast::attribute]) -> T) -> T { do astsrv::exec(srv) |ctxt| { let attrs = match *ctxt.ast_map.get(&id) { - ast_map::node_item(item, _) => copy item.attrs, - ast_map::node_foreign_item(item, _, _, _) => copy item.attrs, - _ => fail!(~"parse_item_attrs: not an item") + ast_map::node_item(item, _) => copy item.attrs, + ast_map::node_foreign_item(item, _, _, _) => copy item.attrs, + _ => fail!(~"parse_item_attrs: not an item") }; parse_attrs(attrs) } } -#[test] -fn should_should_extract_mod_attributes() { - let doc = test::mk_doc(~"#[doc = \"test\"] mod a { }"); - assert!(doc.cratemod().mods()[0].desc() == Some(~"test")); -} - -#[test] -fn should_extract_top_mod_attributes() { - let doc = test::mk_doc(~"#[doc = \"test\"];"); - assert!(doc.cratemod().desc() == Some(~"test")); -} - -#[test] -fn should_extract_foreign_fn_attributes() { - let doc = test::mk_doc(~"extern { #[doc = \"test\"] fn a(); }"); - assert!(doc.cratemod().nmods()[0].fns[0].desc() == Some(~"test")); -} - -#[test] -fn should_extract_fn_attributes() { - let doc = test::mk_doc(~"#[doc = \"test\"] fn a() -> int { }"); - assert!(doc.cratemod().fns()[0].desc() == Some(~"test")); -} - fn fold_enum( fold: &fold::Fold, doc: doc::EnumDoc @@ -174,8 +144,8 @@ fn fold_enum( } _ => { fail!(fmt!("Enum variant %s has id that's \ - not bound to an enum item", - variant.name)) + not bound to an enum item", + variant.name)) } } } @@ -190,19 +160,6 @@ fn fold_enum( } } -#[test] -fn should_extract_enum_docs() { - let doc = test::mk_doc(~"#[doc = \"b\"]\ - enum a { v }"); - assert!(doc.cratemod().enums()[0].desc() == Some(~"b")); -} - -#[test] -fn should_extract_variant_docs() { - let doc = test::mk_doc(~"enum a { #[doc = \"c\"] v }"); - assert!(doc.cratemod().enums()[0].variants[0].desc == Some(~"c")); -} - fn fold_trait( fold: &fold::Fold, doc: doc::TraitDoc @@ -225,30 +182,30 @@ fn merge_method_attrs( // Create an assoc list from method name to attributes let attrs: ~[(~str, Option<~str>)] = do astsrv::exec(srv) |ctxt| { match *ctxt.ast_map.get(&item_id) { - ast_map::node_item(@ast::item { - node: ast::item_trait(_, _, ref methods), _ - }, _) => { - vec::map(*methods, |method| { - match copy *method { - ast::required(ty_m) => { - (to_str(ty_m.ident), - attr_parser::parse_desc(copy ty_m.attrs)) - } - ast::provided(m) => { - (to_str(m.ident), attr_parser::parse_desc(copy m.attrs)) - } - } - }) - } - ast_map::node_item(@ast::item { - node: ast::item_impl(_, _, _, ref methods), _ - }, _) => { - vec::map(*methods, |method| { - (to_str(method.ident), - attr_parser::parse_desc(copy method.attrs)) - }) - } - _ => fail!(~"unexpected item") + ast_map::node_item(@ast::item { + node: ast::item_trait(_, _, ref methods), _ + }, _) => { + vec::map(*methods, |method| { + match copy *method { + ast::required(ty_m) => { + (to_str(ty_m.ident), + attr_parser::parse_desc(copy ty_m.attrs)) + } + ast::provided(m) => { + (to_str(m.ident), attr_parser::parse_desc(copy m.attrs)) + } + } + }) + } + ast_map::node_item(@ast::item { + node: ast::item_impl(_, _, _, ref methods), _ + }, _) => { + vec::map(*methods, |method| { + (to_str(method.ident), + attr_parser::parse_desc(copy method.attrs)) + }) + } + _ => fail!(~"unexpected item") } }; @@ -263,22 +220,6 @@ fn merge_method_attrs( } } -#[test] -fn should_extract_trait_docs() { - let doc = test::mk_doc(~"#[doc = \"whatever\"] trait i { fn a(); }"); - assert!(doc.cratemod().traits()[0].desc() == Some(~"whatever")); -} - -#[test] -fn should_extract_trait_method_docs() { - let doc = test::mk_doc( - ~"trait i {\ - #[doc = \"desc\"]\ - fn f(a: bool) -> bool;\ - }"); - assert!(doc.cratemod().traits()[0].methods[0].desc == Some(~"desc")); -} - fn fold_impl( fold: &fold::Fold, @@ -293,34 +234,94 @@ fn fold_impl( } } -#[test] -fn should_extract_impl_docs() { - let doc = test::mk_doc( - ~"#[doc = \"whatever\"] impl int { fn a() { } }"); - assert!(doc.cratemod().impls()[0].desc() == Some(~"whatever")); -} - -#[test] -fn should_extract_impl_method_docs() { - let doc = test::mk_doc( - ~"impl int {\ - #[doc = \"desc\"]\ - fn f(a: bool) -> bool { }\ - }"); - assert!(doc.cratemod().impls()[0].methods[0].desc == Some(~"desc")); -} - #[cfg(test)] mod test { use astsrv; use attr_pass::run; use doc; use extract; + use core::prelude::*; - pub fn mk_doc(source: ~str) -> doc::Doc { + fn mk_doc(source: ~str) -> doc::Doc { do astsrv::from_str(copy source) |srv| { let doc = extract::from_srv(srv.clone(), ~""); run(srv.clone(), doc) } } + + #[test] + fn should_replace_top_module_name_with_crate_name() { + let doc = mk_doc(~"#[link(name = \"bond\")];"); + assert!(doc.cratemod().name() == ~"bond"); + } + + #[test] + fn should_should_extract_mod_attributes() { + let doc = mk_doc(~"#[doc = \"test\"] mod a { }"); + assert!(doc.cratemod().mods()[0].desc() == Some(~"test")); + } + + #[test] + fn should_extract_top_mod_attributes() { + let doc = mk_doc(~"#[doc = \"test\"];"); + assert!(doc.cratemod().desc() == Some(~"test")); + } + + #[test] + fn should_extract_foreign_fn_attributes() { + let doc = mk_doc(~"extern { #[doc = \"test\"] fn a(); }"); + assert!(doc.cratemod().nmods()[0].fns[0].desc() == Some(~"test")); + } + + #[test] + fn should_extract_fn_attributes() { + let doc = mk_doc(~"#[doc = \"test\"] fn a() -> int { }"); + assert!(doc.cratemod().fns()[0].desc() == Some(~"test")); + } + + #[test] + fn should_extract_enum_docs() { + let doc = mk_doc(~"#[doc = \"b\"]\ + enum a { v }"); + assert!(doc.cratemod().enums()[0].desc() == Some(~"b")); + } + + #[test] + fn should_extract_variant_docs() { + let doc = mk_doc(~"enum a { #[doc = \"c\"] v }"); + assert!(doc.cratemod().enums()[0].variants[0].desc == Some(~"c")); + } + + #[test] + fn should_extract_trait_docs() { + let doc = mk_doc(~"#[doc = \"whatever\"] trait i { fn a(); }"); + assert!(doc.cratemod().traits()[0].desc() == Some(~"whatever")); + } + + #[test] + fn should_extract_trait_method_docs() { + let doc = mk_doc( + ~"trait i {\ + #[doc = \"desc\"]\ + fn f(a: bool) -> bool;\ + }"); + assert!(doc.cratemod().traits()[0].methods[0].desc == Some(~"desc")); + } + + #[test] + fn should_extract_impl_docs() { + let doc = mk_doc( + ~"#[doc = \"whatever\"] impl int { fn a() { } }"); + assert!(doc.cratemod().impls()[0].desc() == Some(~"whatever")); + } + + #[test] + fn should_extract_impl_method_docs() { + let doc = mk_doc( + ~"impl int {\ + #[doc = \"desc\"]\ + fn f(a: bool) -> bool { }\ + }"); + assert!(doc.cratemod().impls()[0].methods[0].desc == Some(~"desc")); + } } diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 62ddec7a1199c..ed1a54c49a731 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -209,7 +209,7 @@ fn parse_output_style(output_style: &str) -> Result { } } -fn maybe_find_pandoc( +pub fn maybe_find_pandoc( config: &Config, maybe_pandoc_cmd: Option<~str>, program_output: Process @@ -243,140 +243,140 @@ fn maybe_find_pandoc( } } -#[test] -fn should_find_pandoc() { - let config = Config { - output_format: PandocHtml, - .. default_config(&Path("test")) - }; - let mock_program_output: ~fn(&str, &[~str]) -> ProgramOutput = |_, _| { - ProgramOutput { status: 0, out: ~"pandoc 1.8.2.1", err: ~"" } - }; - let result = maybe_find_pandoc(&config, None, mock_program_output); - assert!(result == result::Ok(Some(~"pandoc"))); -} - -#[test] -fn should_error_with_no_pandoc() { - let config = Config { - output_format: PandocHtml, - .. default_config(&Path("test")) - }; - let mock_program_output: ~fn(&str, &[~str]) -> ProgramOutput = |_, _| { - ProgramOutput { status: 1, out: ~"", err: ~"" } - }; - let result = maybe_find_pandoc(&config, None, mock_program_output); - assert!(result == result::Err(~"couldn't find pandoc")); -} - #[cfg(test)] mod test { - use config::{Config, mock_program_output, parse_config_}; - - use core::result::Result; + use config::*; + use core::prelude::*; + use core::run::ProgramOutput; - pub fn parse_config(args: &[~str]) -> Result { + fn parse_config(args: &[~str]) -> Result { parse_config_(args, mock_program_output) } -} -#[test] -fn should_error_with_no_crates() { - let config = test::parse_config(~[~"rustdoc"]); - assert!(config.get_err() == ~"no crates specified"); -} + #[test] + fn should_find_pandoc() { + let config = Config { + output_format: PandocHtml, + .. default_config(&Path("test")) + }; + let mock_program_output: ~fn(&str, &[~str]) -> ProgramOutput = |_, _| { + ProgramOutput { status: 0, out: ~"pandoc 1.8.2.1", err: ~"" } + }; + let result = maybe_find_pandoc(&config, None, mock_program_output); + assert!(result == result::Ok(Some(~"pandoc"))); + } -#[test] -fn should_error_with_multiple_crates() { - let config = - test::parse_config(~[~"rustdoc", ~"crate1.rc", ~"crate2.rc"]); - assert!(config.get_err() == ~"multiple crates specified"); -} + #[test] + fn should_error_with_no_pandoc() { + let config = Config { + output_format: PandocHtml, + .. default_config(&Path("test")) + }; + let mock_program_output: ~fn(&str, &[~str]) -> ProgramOutput = |_, _| { + ProgramOutput { status: 1, out: ~"", err: ~"" } + }; + let result = maybe_find_pandoc(&config, None, mock_program_output); + assert!(result == result::Err(~"couldn't find pandoc")); + } -#[test] -fn should_set_output_dir_to_cwd_if_not_provided() { - let config = test::parse_config(~[~"rustdoc", ~"crate.rc"]); - assert!(config.get().output_dir == Path(".")); -} + #[test] + fn should_error_with_no_crates() { + let config = parse_config(~[~"rustdoc"]); + assert!(config.get_err() == ~"no crates specified"); + } -#[test] -fn should_set_output_dir_if_provided() { - let config = test::parse_config(~[ - ~"rustdoc", ~"crate.rc", ~"--output-dir", ~"snuggles" - ]); - assert!(config.get().output_dir == Path("snuggles")); -} + #[test] + fn should_error_with_multiple_crates() { + let config = + parse_config(~[~"rustdoc", ~"crate1.rc", ~"crate2.rc"]); + assert!(config.get_err() == ~"multiple crates specified"); + } -#[test] -fn should_set_output_format_to_pandoc_html_if_not_provided() { - let config = test::parse_config(~[~"rustdoc", ~"crate.rc"]); - assert!(config.get().output_format == PandocHtml); -} + #[test] + fn should_set_output_dir_to_cwd_if_not_provided() { + let config = parse_config(~[~"rustdoc", ~"crate.rc"]); + assert!(config.get().output_dir == Path(".")); + } -#[test] -fn should_set_output_format_to_markdown_if_requested() { - let config = test::parse_config(~[ - ~"rustdoc", ~"crate.rc", ~"--output-format", ~"markdown" - ]); - assert!(config.get().output_format == Markdown); -} + #[test] + fn should_set_output_dir_if_provided() { + let config = parse_config(~[ + ~"rustdoc", ~"crate.rc", ~"--output-dir", ~"snuggles" + ]); + assert!(config.get().output_dir == Path("snuggles")); + } -#[test] -fn should_set_output_format_to_pandoc_html_if_requested() { - let config = test::parse_config(~[ - ~"rustdoc", ~"crate.rc", ~"--output-format", ~"html" - ]); - assert!(config.get().output_format == PandocHtml); -} + #[test] + fn should_set_output_format_to_pandoc_html_if_not_provided() { + let config = parse_config(~[~"rustdoc", ~"crate.rc"]); + assert!(config.get().output_format == PandocHtml); + } -#[test] -fn should_error_on_bogus_format() { - let config = test::parse_config(~[ - ~"rustdoc", ~"crate.rc", ~"--output-format", ~"bogus" - ]); - assert!(config.get_err() == ~"unknown output format 'bogus'"); -} + #[test] + fn should_set_output_format_to_markdown_if_requested() { + let config = parse_config(~[ + ~"rustdoc", ~"crate.rc", ~"--output-format", ~"markdown" + ]); + assert!(config.get().output_format == Markdown); + } -#[test] -fn should_set_output_style_to_doc_per_mod_by_default() { - let config = test::parse_config(~[~"rustdoc", ~"crate.rc"]); - assert!(config.get().output_style == DocPerMod); -} + #[test] + fn should_set_output_format_to_pandoc_html_if_requested() { + let config = parse_config(~[ + ~"rustdoc", ~"crate.rc", ~"--output-format", ~"html" + ]); + assert!(config.get().output_format == PandocHtml); + } -#[test] -fn should_set_output_style_to_one_doc_if_requested() { - let config = test::parse_config(~[ - ~"rustdoc", ~"crate.rc", ~"--output-style", ~"doc-per-crate" - ]); - assert!(config.get().output_style == DocPerCrate); -} + #[test] + fn should_error_on_bogus_format() { + let config = parse_config(~[ + ~"rustdoc", ~"crate.rc", ~"--output-format", ~"bogus" + ]); + assert!(config.get_err() == ~"unknown output format 'bogus'"); + } -#[test] -fn should_set_output_style_to_doc_per_mod_if_requested() { - let config = test::parse_config(~[ - ~"rustdoc", ~"crate.rc", ~"--output-style", ~"doc-per-mod" - ]); - assert!(config.get().output_style == DocPerMod); -} + #[test] + fn should_set_output_style_to_doc_per_mod_by_default() { + let config = parse_config(~[~"rustdoc", ~"crate.rc"]); + assert!(config.get().output_style == DocPerMod); + } -#[test] -fn should_error_on_bogus_output_style() { - let config = test::parse_config(~[ - ~"rustdoc", ~"crate.rc", ~"--output-style", ~"bogus" - ]); - assert!(config.get_err() == ~"unknown output style 'bogus'"); -} + #[test] + fn should_set_output_style_to_one_doc_if_requested() { + let config = parse_config(~[ + ~"rustdoc", ~"crate.rc", ~"--output-style", ~"doc-per-crate" + ]); + assert!(config.get().output_style == DocPerCrate); + } -#[test] -fn should_set_pandoc_command_if_requested() { - let config = test::parse_config(~[ - ~"rustdoc", ~"crate.rc", ~"--pandoc-cmd", ~"panda-bear-doc" - ]); - assert!(config.get().pandoc_cmd == Some(~"panda-bear-doc")); -} + #[test] + fn should_set_output_style_to_doc_per_mod_if_requested() { + let config = parse_config(~[ + ~"rustdoc", ~"crate.rc", ~"--output-style", ~"doc-per-mod" + ]); + assert!(config.get().output_style == DocPerMod); + } -#[test] -fn should_set_pandoc_command_when_using_pandoc() { - let config = test::parse_config(~[~"rustdoc", ~"crate.rc"]); - assert!(config.get().pandoc_cmd == Some(~"pandoc")); -} + #[test] + fn should_error_on_bogus_output_style() { + let config = parse_config(~[ + ~"rustdoc", ~"crate.rc", ~"--output-style", ~"bogus" + ]); + assert!(config.get_err() == ~"unknown output style 'bogus'"); + } + + #[test] + fn should_set_pandoc_command_if_requested() { + let config = parse_config(~[ + ~"rustdoc", ~"crate.rc", ~"--pandoc-cmd", ~"panda-bear-doc" + ]); + assert!(config.get().pandoc_cmd == Some(~"panda-bear-doc")); + } + + #[test] + fn should_set_pandoc_command_when_using_pandoc() { + let config = parse_config(~[~"rustdoc", ~"crate.rc"]); + assert!(config.get().pandoc_cmd == Some(~"pandoc")); + } +} \ No newline at end of file diff --git a/src/librustdoc/desc_to_brief_pass.rs b/src/librustdoc/desc_to_brief_pass.rs index 7c50af40f337a..5027b24435599 100644 --- a/src/librustdoc/desc_to_brief_pass.rs +++ b/src/librustdoc/desc_to_brief_pass.rs @@ -81,44 +81,7 @@ fn fold_impl(fold: &fold::Fold<()>, doc: doc::ImplDoc) -> doc::ImplDoc { } } -#[test] -fn should_promote_desc() { - let doc = test::mk_doc(~"#[doc = \"desc\"] mod m { }"); - assert!(doc.cratemod().mods()[0].brief() == Some(~"desc")); -} - -#[test] -fn should_promote_trait_method_desc() { - let doc = test::mk_doc(~"trait i { #[doc = \"desc\"] fn a(); }"); - assert!(doc.cratemod().traits()[0].methods[0].brief == - Some(~"desc")); -} - -#[test] -fn should_promote_impl_method_desc() { - let doc = test::mk_doc( - ~"impl int { #[doc = \"desc\"] fn a() { } }"); - assert!(doc.cratemod().impls()[0].methods[0].brief == Some(~"desc")); -} - -#[cfg(test)] -pub mod test { - use astsrv; - use attr_pass; - use desc_to_brief_pass::run; - use doc; - use extract; - - pub fn mk_doc(source: ~str) -> doc::Doc { - do astsrv::from_str(copy source) |srv| { - let doc = extract::from_srv(srv.clone(), ~""); - let doc = (attr_pass::mk_pass().f)(srv.clone(), doc); - run(srv.clone(), doc) - } - } -} - -fn extract(desc: Option<~str>) -> Option<~str> { +pub fn extract(desc: Option<~str>) -> Option<~str> { if desc.is_none() { return None } @@ -182,7 +145,7 @@ fn first_sentence_(s: &str) -> ~str { } } -fn paragraphs(s: &str) -> ~[~str] { +pub fn paragraphs(s: &str) -> ~[~str] { let mut lines = ~[]; for str::each_line_any(s) |line| { lines.push(line.to_owned()); } let mut whitespace_lines = 0; @@ -219,28 +182,65 @@ fn paragraphs(s: &str) -> ~[~str] { } } -#[test] -fn test_paragraphs_1() { - let paras = paragraphs(~"1\n\n2"); - assert!(paras == ~[~"1", ~"2"]); -} +#[cfg(test)] +mod test { + use astsrv; + use attr_pass; + use super::{extract, paragraphs, run}; + use doc; + use extract; + use core::prelude::*; -#[test] -fn test_paragraphs_2() { - let paras = paragraphs(~"\n\n1\n1\n\n2\n\n"); - assert!(paras == ~[~"1\n1", ~"2"]); -} + fn mk_doc(source: ~str) -> doc::Doc { + do astsrv::from_str(copy source) |srv| { + let doc = extract::from_srv(srv.clone(), ~""); + let doc = (attr_pass::mk_pass().f)(srv.clone(), doc); + run(srv.clone(), doc) + } + } -#[test] -fn should_promote_short_descs() { - let desc = Some(~"desc"); - let brief = extract(copy desc); - assert!(brief == desc); -} + #[test] + fn should_promote_desc() { + let doc = mk_doc(~"#[doc = \"desc\"] mod m { }"); + assert!(doc.cratemod().mods()[0].brief() == Some(~"desc")); + } + + #[test] + fn should_promote_trait_method_desc() { + let doc = mk_doc(~"trait i { #[doc = \"desc\"] fn a(); }"); + assert!(doc.cratemod().traits()[0].methods[0].brief == + Some(~"desc")); + } + + #[test] + fn should_promote_impl_method_desc() { + let doc = mk_doc( + ~"impl int { #[doc = \"desc\"] fn a() { } }"); + assert!(doc.cratemod().impls()[0].methods[0].brief == Some(~"desc")); + } -#[test] -fn should_not_promote_long_descs() { - let desc = Some(~"Warkworth Castle is a ruined medieval building + #[test] + fn test_paragraphs_1() { + let paras = paragraphs(~"1\n\n2"); + assert!(paras == ~[~"1", ~"2"]); + } + + #[test] + fn test_paragraphs_2() { + let paras = paragraphs(~"\n\n1\n1\n\n2\n\n"); + assert!(paras == ~[~"1\n1", ~"2"]); + } + + #[test] + fn should_promote_short_descs() { + let desc = Some(~"desc"); + let brief = extract(copy desc); + assert!(brief == desc); + } + + #[test] + fn should_not_promote_long_descs() { + let desc = Some(~"Warkworth Castle is a ruined medieval building in the town of the same name in the English county of Northumberland, and the town and castle occupy a loop of the River Coquet, less than a mile from England's north-east coast. When the castle was founded is uncertain, @@ -248,13 +248,13 @@ but traditionally its construction has been ascribed to Prince Henry of Scotland in the mid 12th century, although it may have been built by King Henry II of England when he took control of England'snorthern counties."); - let brief = extract(desc); - assert!(brief == None); -} + let brief = extract(desc); + assert!(brief == None); + } -#[test] -fn should_promote_first_sentence() { - let desc = Some(~"Warkworth Castle is a ruined medieval building + #[test] + fn should_promote_first_sentence() { + let desc = Some(~"Warkworth Castle is a ruined medieval building in the town. of the same name in the English county of Northumberland, and the town and castle occupy a loop of the River Coquet, less than a mile from England's north-east coast. When the castle was founded is uncertain, @@ -262,14 +262,14 @@ but traditionally its construction has been ascribed to Prince Henry of Scotland in the mid 12th century, although it may have been built by King Henry II of England when he took control of England'snorthern counties."); - let brief = extract(desc); - assert!(brief == Some( - ~"Warkworth Castle is a ruined medieval building in the town")); -} + let brief = extract(desc); + assert!(brief == Some( + ~"Warkworth Castle is a ruined medieval building in the town")); + } -#[test] -fn should_not_consider_double_period_to_end_sentence() { - let desc = Some(~"Warkworth..Castle is a ruined medieval building + #[test] + fn should_not_consider_double_period_to_end_sentence() { + let desc = Some(~"Warkworth..Castle is a ruined medieval building in the town. of the same name in the English county of Northumberland, and the town and castle occupy a loop of the River Coquet, less than a mile from England's north-east coast. When the castle was founded is uncertain, @@ -277,14 +277,14 @@ but traditionally its construction has been ascribed to Prince Henry of Scotland in the mid 12th century, although it may have been built by King Henry II of England when he took control of England'snorthern counties."); - let brief = extract(desc); - assert!(brief == Some( - ~"Warkworth..Castle is a ruined medieval building in the town")); -} + let brief = extract(desc); + assert!(brief == Some( + ~"Warkworth..Castle is a ruined medieval building in the town")); + } -#[test] -fn should_not_consider_triple_period_to_end_sentence() { - let desc = Some(~"Warkworth... Castle is a ruined medieval building + #[test] + fn should_not_consider_triple_period_to_end_sentence() { + let desc = Some(~"Warkworth... Castle is a ruined medieval building in the town. of the same name in the English county of Northumberland, and the town and castle occupy a loop of the River Coquet, less than a mile from England's north-east coast. When the castle was founded is uncertain, @@ -292,7 +292,8 @@ but traditionally its construction has been ascribed to Prince Henry of Scotland in the mid 12th century, although it may have been built by King Henry II of England when he took control of England'snorthern counties."); - let brief = extract(desc); - assert!(brief == Some( - ~"Warkworth... Castle is a ruined medieval building in the town")); + let brief = extract(desc); + assert!(brief == Some( + ~"Warkworth... Castle is a ruined medieval building in the town")); + } } diff --git a/src/librustdoc/extract.rs b/src/librustdoc/extract.rs index 1d6d569e1c29d..fa3f7d6432489 100644 --- a/src/librustdoc/extract.rs +++ b/src/librustdoc/extract.rs @@ -182,13 +182,6 @@ fn constdoc_from_const(itemdoc: doc::ItemDoc) -> doc::ConstDoc { } } -#[test] -fn should_extract_const_name_and_id() { - let doc = test::mk_doc(~"static a: int = 0;"); - assert!(doc.cratemod().consts()[0].id() != 0); - assert!(doc.cratemod().consts()[0].name() == ~"a"); -} - fn enumdoc_from_enum( itemdoc: doc::ItemDoc, variants: ~[ast::variant] @@ -213,19 +206,6 @@ fn variantdoc_from_variant(variant: &ast::variant) -> doc::VariantDoc { } } -#[test] -fn should_extract_enums() { - let doc = test::mk_doc(~"enum e { v }"); - assert!(doc.cratemod().enums()[0].id() != 0); - assert!(doc.cratemod().enums()[0].name() == ~"e"); -} - -#[test] -fn should_extract_enum_variants() { - let doc = test::mk_doc(~"enum e { v }"); - assert!(doc.cratemod().enums()[0].variants[0].name == ~"v"); -} - fn traitdoc_from_trait( itemdoc: doc::ItemDoc, methods: ~[ast::trait_method] @@ -259,18 +239,6 @@ fn traitdoc_from_trait( } } -#[test] -fn should_extract_traits() { - let doc = test::mk_doc(~"trait i { fn f(); }"); - assert!(doc.cratemod().traits()[0].name() == ~"i"); -} - -#[test] -fn should_extract_trait_methods() { - let doc = test::mk_doc(~"trait i { fn f(); }"); - assert!(doc.cratemod().traits()[0].methods[0].name == ~"f"); -} - fn impldoc_from_impl( itemdoc: doc::ItemDoc, methods: ~[@ast::method] @@ -293,12 +261,6 @@ fn impldoc_from_impl( } } -#[test] -fn should_extract_impl_methods() { - let doc = test::mk_doc(~"impl int { fn f() { } }"); - assert!(doc.cratemod().impls()[0].methods[0].name == ~"f"); -} - fn tydoc_from_ty( itemdoc: doc::ItemDoc ) -> doc::TyDoc { @@ -308,12 +270,6 @@ fn tydoc_from_ty( } } -#[test] -fn should_extract_tys() { - let doc = test::mk_doc(~"type a = int;"); - assert!(doc.cratemod().types()[0].name() == ~"a"); -} - fn structdoc_from_struct( itemdoc: doc::ItemDoc, struct_def: @ast::struct_def @@ -330,18 +286,6 @@ fn structdoc_from_struct( } } -#[test] -fn should_extract_structs() { - let doc = test::mk_doc(~"struct Foo { field: () }"); - assert!(doc.cratemod().structs()[0].name() == ~"Foo"); -} - -#[test] -fn should_extract_struct_fields() { - let doc = test::mk_doc(~"struct Foo { field: () }"); - assert!(doc.cratemod().structs()[0].fields[0] == ~"field"); -} - #[cfg(test)] mod test { use astsrv; @@ -351,20 +295,20 @@ mod test { use core::vec; - pub fn mk_doc(source: ~str) -> doc::Doc { + fn mk_doc(source: ~str) -> doc::Doc { let ast = parse::from_str(source); extract(ast, ~"") } #[test] - pub fn extract_empty_crate() { + fn extract_empty_crate() { let doc = mk_doc(~""); assert!(vec::is_empty(doc.cratemod().mods())); assert!(vec::is_empty(doc.cratemod().fns())); } #[test] - pub fn extract_mods() { + fn extract_mods() { let doc = mk_doc(~"mod a { mod b { } mod c { } }"); assert!(doc.cratemod().mods()[0].name() == ~"a"); assert!(doc.cratemod().mods()[0].mods()[0].name() == ~"b"); @@ -372,26 +316,26 @@ mod test { } #[test] - pub fn extract_fns_from_foreign_mods() { + fn extract_fns_from_foreign_mods() { let doc = mk_doc(~"extern { fn a(); }"); assert!(doc.cratemod().nmods()[0].fns[0].name() == ~"a"); } #[test] - pub fn extract_mods_deep() { + fn extract_mods_deep() { let doc = mk_doc(~"mod a { mod b { mod c { } } }"); assert!(doc.cratemod().mods()[0].mods()[0].mods()[0].name() == ~"c"); } #[test] - pub fn extract_should_set_mod_ast_id() { + fn extract_should_set_mod_ast_id() { let doc = mk_doc(~"mod a { }"); assert!(doc.cratemod().mods()[0].id() != 0); } #[test] - pub fn extract_fns() { + fn extract_fns() { let doc = mk_doc( ~"fn a() { } \ mod b { fn c() { @@ -401,13 +345,13 @@ mod test { } #[test] - pub fn extract_should_set_fn_ast_id() { + fn extract_should_set_fn_ast_id() { let doc = mk_doc(~"fn a() { }"); assert!(doc.cratemod().fns()[0].id() != 0); } #[test] - pub fn extract_should_use_default_crate_name() { + fn extract_should_use_default_crate_name() { let source = ~""; let ast = parse::from_str(source); let doc = extract(ast, ~"burp"); @@ -415,11 +359,67 @@ mod test { } #[test] - pub fn extract_from_seq_srv() { + fn extract_from_seq_srv() { let source = ~""; do astsrv::from_str(source) |srv| { let doc = from_srv(srv, ~"name"); assert!(doc.cratemod().name() == ~"name"); } } + + #[test] + fn should_extract_const_name_and_id() { + let doc = mk_doc(~"static a: int = 0;"); + assert!(doc.cratemod().consts()[0].id() != 0); + assert!(doc.cratemod().consts()[0].name() == ~"a"); + } + + #[test] + fn should_extract_enums() { + let doc = mk_doc(~"enum e { v }"); + assert!(doc.cratemod().enums()[0].id() != 0); + assert!(doc.cratemod().enums()[0].name() == ~"e"); + } + + #[test] + fn should_extract_enum_variants() { + let doc = mk_doc(~"enum e { v }"); + assert!(doc.cratemod().enums()[0].variants[0].name == ~"v"); + } + + #[test] + fn should_extract_traits() { + let doc = mk_doc(~"trait i { fn f(); }"); + assert!(doc.cratemod().traits()[0].name() == ~"i"); + } + + #[test] + fn should_extract_trait_methods() { + let doc = mk_doc(~"trait i { fn f(); }"); + assert!(doc.cratemod().traits()[0].methods[0].name == ~"f"); + } + + #[test] + fn should_extract_impl_methods() { + let doc = mk_doc(~"impl int { fn f() { } }"); + assert!(doc.cratemod().impls()[0].methods[0].name == ~"f"); + } + + #[test] + fn should_extract_tys() { + let doc = mk_doc(~"type a = int;"); + assert!(doc.cratemod().types()[0].name() == ~"a"); + } + + #[test] + fn should_extract_structs() { + let doc = mk_doc(~"struct Foo { field: () }"); + assert!(doc.cratemod().structs()[0].name() == ~"Foo"); + } + + #[test] + fn should_extract_struct_fields() { + let doc = mk_doc(~"struct Foo { field: () }"); + assert!(doc.cratemod().structs()[0].fields[0] == ~"field"); + } } diff --git a/src/librustdoc/markdown_index_pass.rs b/src/librustdoc/markdown_index_pass.rs index 55901b4904aa3..866fbba2be87a 100644 --- a/src/librustdoc/markdown_index_pass.rs +++ b/src/librustdoc/markdown_index_pass.rs @@ -115,7 +115,7 @@ fn item_to_entry( } } -fn pandoc_header_id(header: &str) -> ~str { +pub fn pandoc_header_id(header: &str) -> ~str { // http://johnmacfarlane.net/pandoc/README.html#headers @@ -162,110 +162,6 @@ fn pandoc_header_id(header: &str) -> ~str { fn maybe_use_section_id(s: &str) -> ~str { s.to_str() } } -#[test] -fn should_remove_punctuation_from_headers() { - assert!(pandoc_header_id(~"impl foo of bar") == - ~"impl-foo-of-bara"); - assert!(pandoc_header_id(~"impl of num::num for int") - == ~"impl-of-numnum-for-int"); - assert!(pandoc_header_id(~"impl of num::num for int/&") - == ~"impl-of-numnum-for-int"); - assert!(pandoc_header_id(~"impl of num::num for ^int") - == ~"impl-of-numnum-for-int"); - assert!(pandoc_header_id(~"impl for & condvar") - == ~"impl-for-condvar"); - assert!(pandoc_header_id(~"impl of Select for (Left, Right)") - == ~"impl-of-selectt-u-for-left-right"); - assert!(pandoc_header_id(~"impl of Condition<'self, T, U>") - == ~"impl-of-conditionself-t-u"); - assert!(pandoc_header_id(~"impl of Condition") - == ~"impl-of-conditiont-copy-clone"); -} - -#[test] -fn should_trim_whitespace_after_removing_punctuation() { - assert!(pandoc_header_id("impl foo for ()") == ~"impl-foo-for"); -} - -#[test] -fn should_index_mod_contents() { - let doc = test::mk_doc( - config::DocPerCrate, - ~"mod a { } fn b() { }" - ); - assert!((&doc.cratemod().index).get().entries[0] == doc::IndexEntry { - kind: ~"Module", - name: ~"a", - brief: None, - link: ~"#module-a" - }); - assert!((&doc.cratemod().index).get().entries[1] == doc::IndexEntry { - kind: ~"Function", - name: ~"b", - brief: None, - link: ~"#function-b" - }); -} - -#[test] -fn should_index_mod_contents_multi_page() { - let doc = test::mk_doc( - config::DocPerMod, - ~"mod a { } fn b() { }" - ); - assert!((&doc.cratemod().index).get().entries[0] == doc::IndexEntry { - kind: ~"Module", - name: ~"a", - brief: None, - link: ~"a.html" - }); - assert!((&doc.cratemod().index).get().entries[1] == doc::IndexEntry { - kind: ~"Function", - name: ~"b", - brief: None, - link: ~"#function-b" - }); -} - -#[test] -fn should_index_foreign_mod_pages() { - let doc = test::mk_doc( - config::DocPerMod, - ~"extern mod a { }" - ); - assert!((&doc.cratemod().index).get().entries[0] == doc::IndexEntry { - kind: ~"Foreign module", - name: ~"a", - brief: None, - link: ~"a.html" - }); -} - -#[test] -fn should_add_brief_desc_to_index() { - let doc = test::mk_doc( - config::DocPerMod, - ~"#[doc = \"test\"] mod a { }" - ); - assert!((&doc.cratemod().index).get().entries[0].brief - == Some(~"test")); -} - -#[test] -fn should_index_foreign_mod_contents() { - let doc = test::mk_doc( - config::DocPerCrate, - ~"extern mod a { fn b(); }" - ); - assert!((&doc.cratemod().nmods()[0].index).get().entries[0] - == doc::IndexEntry { - kind: ~"Function", - name: ~"b", - brief: None, - link: ~"#function-b" - }); -} - #[cfg(test)] mod test { use astsrv; @@ -276,10 +172,10 @@ mod test { use extract; use markdown_index_pass::run; use path_pass; + use super::pandoc_header_id; + use core::prelude::*; - use core::path::Path; - - pub fn mk_doc(output_style: config::OutputStyle, source: ~str) + fn mk_doc(output_style: config::OutputStyle, source: ~str) -> doc::Doc { do astsrv::from_str(source) |srv| { let config = config::Config { @@ -293,4 +189,108 @@ mod test { run(srv.clone(), doc, config) } } + + #[test] + fn should_remove_punctuation_from_headers() { + assert!(pandoc_header_id(~"impl foo of bar") == + ~"impl-foo-of-bara"); + assert!(pandoc_header_id(~"impl of num::num for int") + == ~"impl-of-numnum-for-int"); + assert!(pandoc_header_id(~"impl of num::num for int/&") + == ~"impl-of-numnum-for-int"); + assert!(pandoc_header_id(~"impl of num::num for ^int") + == ~"impl-of-numnum-for-int"); + assert!(pandoc_header_id(~"impl for & condvar") + == ~"impl-for-condvar"); + assert!(pandoc_header_id(~"impl of Select for (Left, Right)") + == ~"impl-of-selectt-u-for-left-right"); + assert!(pandoc_header_id(~"impl of Condition<'self, T, U>") + == ~"impl-of-conditionself-t-u"); + assert!(pandoc_header_id(~"impl of Condition") + == ~"impl-of-conditiont-copy-clone"); + } + + #[test] + fn should_trim_whitespace_after_removing_punctuation() { + assert!(pandoc_header_id("impl foo for ()") == ~"impl-foo-for"); + } + + #[test] + fn should_index_mod_contents() { + let doc = mk_doc( + config::DocPerCrate, + ~"mod a { } fn b() { }" + ); + assert!((&doc.cratemod().index).get().entries[0] == doc::IndexEntry { + kind: ~"Module", + name: ~"a", + brief: None, + link: ~"#module-a" + }); + assert!((&doc.cratemod().index).get().entries[1] == doc::IndexEntry { + kind: ~"Function", + name: ~"b", + brief: None, + link: ~"#function-b" + }); + } + + #[test] + fn should_index_mod_contents_multi_page() { + let doc = mk_doc( + config::DocPerMod, + ~"mod a { } fn b() { }" + ); + assert!((&doc.cratemod().index).get().entries[0] == doc::IndexEntry { + kind: ~"Module", + name: ~"a", + brief: None, + link: ~"a.html" + }); + assert!((&doc.cratemod().index).get().entries[1] == doc::IndexEntry { + kind: ~"Function", + name: ~"b", + brief: None, + link: ~"#function-b" + }); + } + + #[test] + fn should_index_foreign_mod_pages() { + let doc = mk_doc( + config::DocPerMod, + ~"extern mod a { }" + ); + assert!((&doc.cratemod().index).get().entries[0] == doc::IndexEntry { + kind: ~"Foreign module", + name: ~"a", + brief: None, + link: ~"a.html" + }); + } + + #[test] + fn should_add_brief_desc_to_index() { + let doc = mk_doc( + config::DocPerMod, + ~"#[doc = \"test\"] mod a { }" + ); + assert!((&doc.cratemod().index).get().entries[0].brief + == Some(~"test")); + } + + #[test] + fn should_index_foreign_mod_contents() { + let doc = mk_doc( + config::DocPerCrate, + ~"extern mod a { fn b(); }" + ); + assert!((&doc.cratemod().nmods()[0].index).get().entries[0] + == doc::IndexEntry { + kind: ~"Function", + name: ~"b", + brief: None, + link: ~"#function-b" + }); + } } diff --git a/src/librustdoc/markdown_pass.rs b/src/librustdoc/markdown_pass.rs index 8c4cd26bb7c11..2dfc04e8ec709 100644 --- a/src/librustdoc/markdown_pass.rs +++ b/src/librustdoc/markdown_pass.rs @@ -22,10 +22,6 @@ use markdown_writer::WriterFactory; use pass::Pass; use sort_pass; -#[cfg(test)] use config; -#[cfg(test)] use markdown_writer; -#[cfg(test)] use page_pass; - use core::cell::Cell; use core::str; use core::vec; @@ -48,8 +44,8 @@ fn run( fn mods_last(item1: &doc::ItemTag, item2: &doc::ItemTag) -> bool { fn is_mod(item: &doc::ItemTag) -> bool { match *item { - doc::ModTag(_) => true, - _ => false + doc::ModTag(_) => true, + _ => false } } @@ -69,33 +65,6 @@ fn run( return doc; } -#[test] -fn should_write_modules_last() { - /* - Because the markdown pass writes all modules at the same level of - indentation (it doesn't 'nest' them), we need to make sure that we - write all of the modules contained in each module after all other - types of items, or else the header nesting will end up wrong, with - modules appearing to contain items that they do not. - */ - let markdown = test::render( - ~"mod a { }\ - fn b() { }\ - mod c { - }\ - fn d() { }" - ); - - let idx_a = str::find_str(markdown, ~"# Module `a`").get(); - let idx_b = str::find_str(markdown, ~"## Function `b`").get(); - let idx_c = str::find_str(markdown, ~"# Module `c`").get(); - let idx_d = str::find_str(markdown, ~"## Function `d`").get(); - - assert!(idx_b < idx_d); - assert!(idx_d < idx_a); - assert!(idx_a < idx_c); -} - struct Ctxt { w: Writer } @@ -118,33 +87,18 @@ pub fn write_markdown( fn write_page(ctxt: &Ctxt, page: &doc::Page) { write_title(ctxt, copy *page); match copy *page { - doc::CratePage(doc) => { - write_crate(ctxt, doc); - } - doc::ItemPage(doc) => { - // We don't write a header for item's pages because their - // header in the html output is created by the page title - write_item_no_header(ctxt, doc); - } + doc::CratePage(doc) => { + write_crate(ctxt, doc); + } + doc::ItemPage(doc) => { + // We don't write a header for item's pages because their + // header in the html output is created by the page title + write_item_no_header(ctxt, doc); + } } ctxt.w.put_done(); } -#[test] -fn should_request_new_writer_for_each_page() { - // This port will send us a (page, str) pair for every writer - // that was created - let (writer_factory, po) = markdown_writer::future_writer_factory(); - let (srv, doc) = test::create_doc_srv(~"mod a { }"); - // Split the document up into pages - let doc = (page_pass::mk_pass(config::DocPerMod).f)(srv, doc); - write_markdown(doc, writer_factory); - // We expect two pages to have been written - for iter::repeat(2) { - po.recv(); - } -} - fn write_title(ctxt: &Ctxt, page: doc::Page) { ctxt.w.put_line(fmt!("%% %s", make_title(page))); ctxt.w.put_line(~""); @@ -152,38 +106,18 @@ fn write_title(ctxt: &Ctxt, page: doc::Page) { fn make_title(page: doc::Page) -> ~str { let item = match page { - doc::CratePage(CrateDoc) => { - doc::ModTag(copy CrateDoc.topmod) - } - doc::ItemPage(ItemTag) => { - ItemTag - } + doc::CratePage(CrateDoc) => { + doc::ModTag(copy CrateDoc.topmod) + } + doc::ItemPage(ItemTag) => { + ItemTag + } }; let title = markdown_pass::header_text(item); let title = str::replace(title, ~"`", ~""); return title; } -#[test] -fn should_write_title_for_each_page() { - let (writer_factory, po) = markdown_writer::future_writer_factory(); - let (srv, doc) = test::create_doc_srv( - ~"#[link(name = \"core\")]; mod a { }"); - let doc = (page_pass::mk_pass(config::DocPerMod).f)(srv, doc); - write_markdown(doc, writer_factory); - for iter::repeat(2) { - let (page, markdown) = po.recv(); - match page { - doc::CratePage(_) => { - assert!(str::contains(markdown, ~"% Crate core")); - } - doc::ItemPage(_) => { - assert!(str::contains(markdown, ~"% Module a")); - } - } - } -} - enum Hlvl { H1 = 1, H2 = 2, @@ -204,94 +138,94 @@ fn write_header_(ctxt: &Ctxt, lvl: Hlvl, title: ~str) { pub fn header_kind(doc: doc::ItemTag) -> ~str { match doc { - doc::ModTag(_) => { - if doc.id() == syntax::ast::crate_node_id { - ~"Crate" - } else { - ~"Module" + doc::ModTag(_) => { + if doc.id() == syntax::ast::crate_node_id { + ~"Crate" + } else { + ~"Module" + } + } + doc::NmodTag(_) => { + ~"Foreign module" + } + doc::FnTag(_) => { + ~"Function" + } + doc::ConstTag(_) => { + ~"Const" + } + doc::EnumTag(_) => { + ~"Enum" + } + doc::TraitTag(_) => { + ~"Trait" + } + doc::ImplTag(_) => { + ~"Implementation" + } + doc::TyTag(_) => { + ~"Type" + } + doc::StructTag(_) => { + ~"Struct" } - } - doc::NmodTag(_) => { - ~"Foreign module" - } - doc::FnTag(_) => { - ~"Function" - } - doc::ConstTag(_) => { - ~"Const" - } - doc::EnumTag(_) => { - ~"Enum" - } - doc::TraitTag(_) => { - ~"Trait" - } - doc::ImplTag(_) => { - ~"Implementation" - } - doc::TyTag(_) => { - ~"Type" - } - doc::StructTag(_) => { - ~"Struct" - } } } pub fn header_name(doc: doc::ItemTag) -> ~str { let fullpath = str::connect(doc.path() + ~[doc.name()], ~"::"); match &doc { - &doc::ModTag(_) if doc.id() != syntax::ast::crate_node_id => { - fullpath - } - &doc::NmodTag(_) => { - fullpath - } - &doc::ImplTag(ref doc) => { - assert!(doc.self_ty.is_some()); - let bounds = if (&doc.bounds_str).is_some() { - fmt!(" where %s", (&doc.bounds_str).get()) - } else { - ~"" - }; - let self_ty = (&doc.self_ty).get(); - let mut trait_part = ~""; - for doc.trait_types.eachi |i, trait_type| { - if i == 0 { - trait_part += ~" of "; + &doc::ModTag(_) if doc.id() != syntax::ast::crate_node_id => { + fullpath + } + &doc::NmodTag(_) => { + fullpath + } + &doc::ImplTag(ref doc) => { + assert!(doc.self_ty.is_some()); + let bounds = if (&doc.bounds_str).is_some() { + fmt!(" where %s", (&doc.bounds_str).get()) } else { - trait_part += ~", "; + ~"" + }; + let self_ty = (&doc.self_ty).get(); + let mut trait_part = ~""; + for doc.trait_types.eachi |i, trait_type| { + if i == 0 { + trait_part += ~" of "; + } else { + trait_part += ~", "; + } + trait_part += *trait_type; } - trait_part += *trait_type; + fmt!("%s for %s%s", trait_part, self_ty, bounds) + } + _ => { + doc.name() } - fmt!("%s for %s%s", trait_part, self_ty, bounds) - } - _ => { - doc.name() - } } } pub fn header_text(doc: doc::ItemTag) -> ~str { match &doc { - &doc::ImplTag(ref ImplDoc) => { - let header_kind = header_kind(copy doc); - let bounds = if (&ImplDoc.bounds_str).is_some() { - fmt!(" where `%s`", (&ImplDoc.bounds_str).get()) - } else { - ~"" - }; - let desc = if ImplDoc.trait_types.is_empty() { - fmt!("for `%s`%s", (&ImplDoc.self_ty).get(), bounds) - } else { - fmt!("of `%s` for `%s`%s", - ImplDoc.trait_types[0], - (&ImplDoc.self_ty).get(), - bounds) - }; - return fmt!("%s %s", header_kind, desc); - } - _ => {} + &doc::ImplTag(ref ImplDoc) => { + let header_kind = header_kind(copy doc); + let bounds = if (&ImplDoc.bounds_str).is_some() { + fmt!(" where `%s`", (&ImplDoc.bounds_str).get()) + } else { + ~"" + }; + let desc = if ImplDoc.trait_types.is_empty() { + fmt!("for `%s`%s", (&ImplDoc.self_ty).get(), bounds) + } else { + fmt!("of `%s` for `%s`%s", + ImplDoc.trait_types[0], + (&ImplDoc.self_ty).get(), + bounds) + }; + return fmt!("%s %s", header_kind, desc); + } + _ => {} } header_text_(header_kind(copy doc), @@ -323,12 +257,6 @@ fn write_mod( write_mod_contents(ctxt, ModDoc); } -#[test] -fn should_write_full_path_to_mod() { - let markdown = test::render(~"mod a { mod b { mod c { } } }"); - assert!(str::contains(markdown, ~"# Module `a::b::c`")); -} - fn write_common( ctxt: &Ctxt, desc: Option<~str>, @@ -363,17 +291,6 @@ fn write_section(ctxt: &Ctxt, section: doc::Section) { ctxt.w.put_line(~""); } -#[test] -fn should_write_sections() { - let markdown = test::render( - ~"#[doc = \"\ - # Header\n\ - Body\"]\ - mod a { - }"); - assert!(str::contains(markdown, ~"#### Header\n\nBody\n\n")); -} - fn write_mod_contents( ctxt: &Ctxt, doc: doc::ModDoc @@ -402,15 +319,15 @@ fn write_item_(ctxt: &Ctxt, doc: doc::ItemTag, write_header: bool) { } match doc { - doc::ModTag(ModDoc) => write_mod(ctxt, ModDoc), - doc::NmodTag(nModDoc) => write_nmod(ctxt, nModDoc), - doc::FnTag(FnDoc) => write_fn(ctxt, FnDoc), - doc::ConstTag(ConstDoc) => write_const(ctxt, ConstDoc), - doc::EnumTag(EnumDoc) => write_enum(ctxt, EnumDoc), - doc::TraitTag(TraitDoc) => write_trait(ctxt, TraitDoc), - doc::ImplTag(ImplDoc) => write_impl(ctxt, ImplDoc), - doc::TyTag(TyDoc) => write_type(ctxt, TyDoc), - doc::StructTag(StructDoc) => put_struct(ctxt, StructDoc), + doc::ModTag(ModDoc) => write_mod(ctxt, ModDoc), + doc::NmodTag(nModDoc) => write_nmod(ctxt, nModDoc), + doc::FnTag(FnDoc) => write_fn(ctxt, FnDoc), + doc::ConstTag(ConstDoc) => write_const(ctxt, ConstDoc), + doc::EnumTag(EnumDoc) => write_enum(ctxt, EnumDoc), + doc::TraitTag(TraitDoc) => write_trait(ctxt, TraitDoc), + doc::ImplTag(ImplDoc) => write_impl(ctxt, ImplDoc), + doc::TyTag(TyDoc) => write_type(ctxt, TyDoc), + doc::StructTag(StructDoc) => put_struct(ctxt, StructDoc), } } @@ -420,17 +337,11 @@ fn write_item_header(ctxt: &Ctxt, doc: doc::ItemTag) { fn item_header_lvl(doc: &doc::ItemTag) -> Hlvl { match doc { - &doc::ModTag(_) | &doc::NmodTag(_) => H1, - _ => H2 + &doc::ModTag(_) | &doc::NmodTag(_) => H1, + _ => H2 } } -#[test] -fn should_write_crate_description() { - let markdown = test::render(~"#[doc = \"this is the crate\"];"); - assert!(str::contains(markdown, ~"this is the crate")); -} - fn write_index(ctxt: &Ctxt, index: doc::Index) { if vec::is_empty(index.entries) { return; @@ -444,7 +355,7 @@ fn write_index(ctxt: &Ctxt, index: doc::Index) { let id = copy entry.link; if entry.brief.is_some() { ctxt.w.put_line(fmt!("* [%s](%s) - %s", - header, id, (&entry.brief).get())); + header, id, (&entry.brief).get())); } else { ctxt.w.put_line(fmt!("* [%s](%s)", header, id)); } @@ -454,37 +365,6 @@ fn write_index(ctxt: &Ctxt, index: doc::Index) { ctxt.w.put_line(~""); } -#[test] -fn should_write_index() { - let markdown = test::render(~"mod a { } mod b { }"); - assert!(str::contains( - markdown, - ~"\n\n* [Module `a`](#module-a)\n\ - * [Module `b`](#module-b)\n\n" - )); -} - -#[test] -fn should_write_index_brief() { - let markdown = test::render(~"#[doc = \"test\"] mod a { }"); - assert!(str::contains(markdown, ~"(#module-a) - test\n")); -} - -#[test] -fn should_not_write_index_if_no_entries() { - let markdown = test::render(~""); - assert!(!str::contains(markdown, ~"\n\n\n")); -} - -#[test] -fn should_write_index_for_foreign_mods() { - let markdown = test::render(~"extern mod a { fn a(); }"); - assert!(str::contains( - markdown, - ~"\n\n* [Function `a`](#function-a)\n\n" - )); -} - fn write_nmod(ctxt: &Ctxt, doc: doc::NmodDoc) { write_common(ctxt, doc.desc(), doc.sections()); if doc.index.is_some() { @@ -497,27 +377,6 @@ fn write_nmod(ctxt: &Ctxt, doc: doc::NmodDoc) { } } -#[test] -fn should_write_foreign_mods() { - let markdown = test::render(~"#[doc = \"test\"] extern mod a { }"); - assert!(str::contains(markdown, ~"Foreign module `a`")); - assert!(str::contains(markdown, ~"test")); -} - -#[test] -fn should_write_foreign_fns() { - let markdown = test::render( - ~"extern mod a { #[doc = \"test\"] fn a(); }"); - assert!(str::contains(markdown, ~"test")); -} - -#[test] -fn should_write_foreign_fn_headers() { - let markdown = test::render( - ~"extern mod a { #[doc = \"test\"] fn a(); }"); - assert!(str::contains(markdown, ~"## Function `a`")); -} - fn write_fn( ctxt: &Ctxt, doc: doc::FnDoc @@ -542,11 +401,11 @@ fn write_fnlike( fn write_sig(ctxt: &Ctxt, sig: Option<~str>) { match sig { - Some(sig) => { - ctxt.w.put_line(code_block_indent(sig)); - ctxt.w.put_line(~""); - } - None => fail!(~"unimplemented") + Some(sig) => { + ctxt.w.put_line(code_block_indent(sig)); + ctxt.w.put_line(~""); + } + None => fail!(~"unimplemented") } } @@ -558,51 +417,6 @@ fn code_block_indent(s: ~str) -> ~str { str::connect(indented, "\n") } -#[test] -fn write_markdown_should_write_function_header() { - let markdown = test::render(~"fn func() { }"); - assert!(str::contains(markdown, ~"## Function `func`")); -} - -#[test] -fn should_write_the_function_signature() { - let markdown = test::render(~"#[doc = \"f\"] fn a() { }"); - assert!(str::contains(markdown, ~"\n fn a()\n")); -} - -#[test] -fn should_insert_blank_line_after_fn_signature() { - let markdown = test::render(~"#[doc = \"f\"] fn a() { }"); - assert!(str::contains(markdown, ~"fn a()\n\n")); -} - -#[test] -fn should_correctly_indent_fn_signature() { - let doc = test::create_doc(~"fn a() { }"); - let doc = doc::Doc{ - pages: ~[ - doc::CratePage(doc::CrateDoc{ - topmod: doc::ModDoc{ - items: ~[doc::FnTag(doc::SimpleItemDoc{ - sig: Some(~"line 1\nline 2"), - .. copy doc.cratemod().fns()[0] - })], - .. doc.cratemod() - }, - .. doc.CrateDoc() - }) - ] - }; - let markdown = test::write_markdown_str(doc); - assert!(str::contains(markdown, ~" line 1\n line 2")); -} - -#[test] -fn should_leave_blank_line_between_fn_header_and_sig() { - let markdown = test::render(~"fn a() { }"); - assert!(str::contains(markdown, ~"Function `a`\n\n fn a()")); -} - fn write_const( ctxt: &Ctxt, doc: doc::ConstDoc @@ -611,20 +425,6 @@ fn write_const( write_common(ctxt, doc.desc(), doc.sections()); } -#[test] -fn should_write_const_header() { - let markdown = test::render(~"static a: bool = true;"); - assert!(str::contains(markdown, ~"## Const `a`\n\n")); -} - -#[test] -fn should_write_const_description() { - let markdown = test::render( - ~"#[doc = \"b\"]\ - static a: bool = true;"); - assert!(str::contains(markdown, ~"\n\nb\n\n")); -} - fn write_enum( ctxt: &Ctxt, doc: doc::EnumDoc @@ -633,19 +433,6 @@ fn write_enum( write_variants(ctxt, doc.variants); } -#[test] -fn should_write_enum_header() { - let markdown = test::render(~"enum a { b }"); - assert!(str::contains(markdown, ~"## Enum `a`\n\n")); -} - -#[test] -fn should_write_enum_description() { - let markdown = test::render( - ~"#[doc = \"b\"] enum a { b }"); - assert!(str::contains(markdown, ~"\n\nb\n\n")); -} - fn write_variants( ctxt: &Ctxt, docs: &[doc::VariantDoc] @@ -667,46 +454,13 @@ fn write_variant(ctxt: &Ctxt, doc: doc::VariantDoc) { assert!(doc.sig.is_some()); let sig = (&doc.sig).get(); match copy doc.desc { - Some(desc) => { - ctxt.w.put_line(fmt!("* `%s` - %s", sig, desc)); - } - None => { - ctxt.w.put_line(fmt!("* `%s`", sig)); - } - } -} - -#[test] -fn should_write_variant_list() { - let markdown = test::render( - ~"enum a { \ - #[doc = \"test\"] b, \ - #[doc = \"test\"] c }"); - assert!(str::contains( - markdown, - ~"\n\n#### Variants\n\ - \n* `b` - test\ - \n* `c` - test\n\n")); -} - -#[test] -fn should_write_variant_list_without_descs() { - let markdown = test::render(~"enum a { b, c }"); - assert!(str::contains( - markdown, - ~"\n\n#### Variants\n\ - \n* `b`\ - \n* `c`\n\n")); -} - -#[test] -fn should_write_variant_list_with_signatures() { - let markdown = test::render(~"enum a { b(int), #[doc = \"a\"] c(int) }"); - assert!(str::contains( - markdown, - ~"\n\n#### Variants\n\ - \n* `b(int)`\ - \n* `c(int)` - a\n\n")); + Some(desc) => { + ctxt.w.put_line(fmt!("* `%s` - %s", sig, desc)); + } + None => { + ctxt.w.put_line(fmt!("* `%s`", sig)); + } + } } fn write_trait(ctxt: &Ctxt, doc: doc::TraitDoc) { @@ -730,78 +484,11 @@ fn write_method(ctxt: &Ctxt, doc: doc::MethodDoc) { ); } -#[test] -fn should_write_trait_header() { - let markdown = test::render(~"trait i { fn a(); }"); - assert!(str::contains(markdown, ~"## Trait `i`")); -} - -#[test] -fn should_write_trait_desc() { - let markdown = test::render( - ~"#[doc = \"desc\"] trait i { fn a(); }"); - assert!(str::contains(markdown, ~"desc")); -} - -#[test] -fn should_write_trait_method_header() { - let markdown = test::render( - ~"trait i { fn a(); }"); - assert!(str::contains(markdown, ~"### Method `a`")); -} - -#[test] -fn should_write_trait_method_signature() { - let markdown = test::render( - ~"trait i { fn a(&self); }"); - assert!(str::contains(markdown, ~"\n fn a(&self)")); -} - fn write_impl(ctxt: &Ctxt, doc: doc::ImplDoc) { write_common(ctxt, doc.desc(), doc.sections()); write_methods(ctxt, doc.methods); } -#[test] -fn should_write_impl_header() { - let markdown = test::render(~"impl int { fn a() { } }"); - assert!(str::contains(markdown, ~"## Implementation for `int`")); -} - -#[test] -fn should_write_impl_header_with_bounds() { - let markdown = test::render(~"impl int { }"); - assert!(str::contains(markdown, ~"## Implementation for `int` where ``")); -} - -#[test] -fn should_write_impl_header_with_trait() { - let markdown = test::render(~"impl j for int { fn a() { } }"); - assert!(str::contains(markdown, - ~"## Implementation of `j` for `int`")); -} - -#[test] -fn should_write_impl_desc() { - let markdown = test::render( - ~"#[doc = \"desc\"] impl int { fn a() { } }"); - assert!(str::contains(markdown, ~"desc")); -} - -#[test] -fn should_write_impl_method_header() { - let markdown = test::render( - ~"impl int { fn a() { } }"); - assert!(str::contains(markdown, ~"### Method `a`")); -} - -#[test] -fn should_write_impl_method_signature() { - let markdown = test::render( - ~"impl int { fn a(&mut self) { } }"); - assert!(str::contains(markdown, ~"\n fn a(&mut self)")); -} - fn write_type( ctxt: &Ctxt, doc: doc::TyDoc @@ -810,25 +497,6 @@ fn write_type( write_common(ctxt, doc.desc(), doc.sections()); } -#[test] -fn should_write_type_header() { - let markdown = test::render(~"type t = int;"); - assert!(str::contains(markdown, ~"## Type `t`")); -} - -#[test] -fn should_write_type_desc() { - let markdown = test::render( - ~"#[doc = \"desc\"] type t = int;"); - assert!(str::contains(markdown, ~"\n\ndesc\n\n")); -} - -#[test] -fn should_write_type_signature() { - let markdown = test::render(~"type t = int;"); - assert!(str::contains(markdown, ~"\n\n type t = int\n\n")); -} - fn put_struct( ctxt: &Ctxt, doc: doc::StructDoc @@ -837,12 +505,6 @@ fn put_struct( write_common(ctxt, doc.desc(), doc.sections()); } -#[test] -fn should_put_struct_header() { - let markdown = test::render(~"struct S { field: () }"); - assert!(str::contains(markdown, ~"## Struct `S`\n\n")); -} - #[cfg(test)] mod test { use astsrv; @@ -855,22 +517,21 @@ mod test { use markdown_pass::{mk_pass, write_markdown}; use markdown_writer; use path_pass; + use page_pass; use sectionalize_pass; use trim_pass; use tystr_pass; use unindent_pass; + use core::prelude::*; - use core::path::Path; - use core::str; - - pub fn render(source: ~str) -> ~str { + fn render(source: ~str) -> ~str { let (srv, doc) = create_doc_srv(source); let markdown = write_markdown_str_srv(srv, doc); debug!("markdown: %s", markdown); markdown } - pub fn create_doc_srv(source: ~str) -> (astsrv::Srv, doc::Doc) { + fn create_doc_srv(source: ~str) -> (astsrv::Srv, doc::Doc) { do astsrv::from_str(source) |srv| { let config = config::Config { @@ -901,12 +562,12 @@ mod test { } } - pub fn create_doc(source: ~str) -> doc::Doc { + fn create_doc(source: ~str) -> doc::Doc { let (_, doc) = create_doc_srv(source); doc } - pub fn write_markdown_str( + fn write_markdown_str( doc: doc::Doc ) -> ~str { let (writer_factory, po) = markdown_writer::future_writer_factory(); @@ -914,7 +575,7 @@ mod test { return po.recv().second(); } - pub fn write_markdown_str_srv( + fn write_markdown_str_srv( srv: astsrv::Srv, doc: doc::Doc ) -> ~str { @@ -925,14 +586,349 @@ mod test { } #[test] - pub fn write_markdown_should_write_mod_headers() { + fn write_markdown_should_write_mod_headers() { let markdown = render(~"mod moo { }"); assert!(str::contains(markdown, ~"# Module `moo`")); } #[test] - pub fn should_leave_blank_line_after_header() { + fn should_leave_blank_line_after_header() { let markdown = render(~"mod morp { }"); assert!(str::contains(markdown, ~"Module `morp`\n\n")); } + + #[test] + fn should_write_modules_last() { + /* + Because the markdown pass writes all modules at the same level of + indentation (it doesn't 'nest' them), we need to make sure that we + write all of the modules contained in each module after all other + types of items, or else the header nesting will end up wrong, with + modules appearing to contain items that they do not. + */ + let markdown = render( + ~"mod a { }\ + fn b() { }\ + mod c { +}\ + fn d() { }" + ); + + let idx_a = str::find_str(markdown, ~"# Module `a`").get(); + let idx_b = str::find_str(markdown, ~"## Function `b`").get(); + let idx_c = str::find_str(markdown, ~"# Module `c`").get(); + let idx_d = str::find_str(markdown, ~"## Function `d`").get(); + + assert!(idx_b < idx_d); + assert!(idx_d < idx_a); + assert!(idx_a < idx_c); + } + + #[test] + fn should_request_new_writer_for_each_page() { + // This port will send us a (page, str) pair for every writer + // that was created + let (writer_factory, po) = markdown_writer::future_writer_factory(); + let (srv, doc) = create_doc_srv(~"mod a { }"); + // Split the document up into pages + let doc = (page_pass::mk_pass(config::DocPerMod).f)(srv, doc); + write_markdown(doc, writer_factory); + // We expect two pages to have been written + for iter::repeat(2) { + po.recv(); + } + } + + #[test] + fn should_write_title_for_each_page() { + let (writer_factory, po) = markdown_writer::future_writer_factory(); + let (srv, doc) = create_doc_srv( + ~"#[link(name = \"core\")]; mod a { }"); + let doc = (page_pass::mk_pass(config::DocPerMod).f)(srv, doc); + write_markdown(doc, writer_factory); + for iter::repeat(2) { + let (page, markdown) = po.recv(); + match page { + doc::CratePage(_) => { + assert!(str::contains(markdown, ~"% Crate core")); + } + doc::ItemPage(_) => { + assert!(str::contains(markdown, ~"% Module a")); + } + } + } + } + + #[test] + fn should_write_full_path_to_mod() { + let markdown = render(~"mod a { mod b { mod c { } } }"); + assert!(str::contains(markdown, ~"# Module `a::b::c`")); + } + + #[test] + fn should_write_sections() { + let markdown = render( + ~"#[doc = \"\ + # Header\n\ + Body\"]\ + mod a { +}"); + assert!(str::contains(markdown, ~"#### Header\n\nBody\n\n")); + } + + #[test] + fn should_write_crate_description() { + let markdown = render(~"#[doc = \"this is the crate\"];"); + assert!(str::contains(markdown, ~"this is the crate")); + } + + + #[test] + fn should_write_index() { + let markdown = render(~"mod a { } mod b { }"); + assert!(str::contains( + markdown, + ~"\n\n* [Module `a`](#module-a)\n\ + * [Module `b`](#module-b)\n\n" + )); + } + + #[test] + fn should_write_index_brief() { + let markdown = render(~"#[doc = \"test\"] mod a { }"); + assert!(str::contains(markdown, ~"(#module-a) - test\n")); + } + + #[test] + fn should_not_write_index_if_no_entries() { + let markdown = render(~""); + assert!(!str::contains(markdown, ~"\n\n\n")); + } + + #[test] + fn should_write_index_for_foreign_mods() { + let markdown = render(~"extern mod a { fn a(); }"); + assert!(str::contains( + markdown, + ~"\n\n* [Function `a`](#function-a)\n\n" + )); + } + + #[test] + fn should_write_foreign_mods() { + let markdown = render(~"#[doc = \"test\"] extern mod a { }"); + assert!(str::contains(markdown, ~"Foreign module `a`")); + assert!(str::contains(markdown, ~"test")); + } + + #[test] + fn should_write_foreign_fns() { + let markdown = render( + ~"extern mod a { #[doc = \"test\"] fn a(); }"); + assert!(str::contains(markdown, ~"test")); + } + + #[test] + fn should_write_foreign_fn_headers() { + let markdown = render( + ~"extern mod a { #[doc = \"test\"] fn a(); }"); + assert!(str::contains(markdown, ~"## Function `a`")); + } + + #[test] + fn write_markdown_should_write_function_header() { + let markdown = render(~"fn func() { }"); + assert!(str::contains(markdown, ~"## Function `func`")); + } + + #[test] + fn should_write_the_function_signature() { + let markdown = render(~"#[doc = \"f\"] fn a() { }"); + assert!(str::contains(markdown, ~"\n fn a()\n")); + } + + #[test] + fn should_insert_blank_line_after_fn_signature() { + let markdown = render(~"#[doc = \"f\"] fn a() { }"); + assert!(str::contains(markdown, ~"fn a()\n\n")); + } + + #[test] + fn should_correctly_indent_fn_signature() { + let doc = create_doc(~"fn a() { }"); + let doc = doc::Doc{ + pages: ~[ + doc::CratePage(doc::CrateDoc{ + topmod: doc::ModDoc{ + items: ~[doc::FnTag(doc::SimpleItemDoc{ + sig: Some(~"line 1\nline 2"), + .. copy doc.cratemod().fns()[0] + })], + .. doc.cratemod() + }, + .. doc.CrateDoc() + }) + ] + }; + let markdown = write_markdown_str(doc); + assert!(str::contains(markdown, ~" line 1\n line 2")); + } + + #[test] + fn should_leave_blank_line_between_fn_header_and_sig() { + let markdown = render(~"fn a() { }"); + assert!(str::contains(markdown, ~"Function `a`\n\n fn a()")); + } + + #[test] + fn should_write_const_header() { + let markdown = render(~"static a: bool = true;"); + assert!(str::contains(markdown, ~"## Const `a`\n\n")); + } + + #[test] + fn should_write_const_description() { + let markdown = render( + ~"#[doc = \"b\"]\ + static a: bool = true;"); + assert!(str::contains(markdown, ~"\n\nb\n\n")); + } + + #[test] + fn should_write_enum_header() { + let markdown = render(~"enum a { b }"); + assert!(str::contains(markdown, ~"## Enum `a`\n\n")); + } + + #[test] + fn should_write_enum_description() { + let markdown = render( + ~"#[doc = \"b\"] enum a { b }"); + assert!(str::contains(markdown, ~"\n\nb\n\n")); + } + + #[test] + fn should_write_variant_list() { + let markdown = render( + ~"enum a { \ + #[doc = \"test\"] b, \ + #[doc = \"test\"] c }"); + assert!(str::contains( + markdown, + ~"\n\n#### Variants\n\ + \n* `b` - test\ + \n* `c` - test\n\n")); + } + + #[test] + fn should_write_variant_list_without_descs() { + let markdown = render(~"enum a { b, c }"); + assert!(str::contains( + markdown, + ~"\n\n#### Variants\n\ + \n* `b`\ + \n* `c`\n\n")); + } + + #[test] + fn should_write_variant_list_with_signatures() { + let markdown = render(~"enum a { b(int), #[doc = \"a\"] c(int) }"); + assert!(str::contains( + markdown, + ~"\n\n#### Variants\n\ + \n* `b(int)`\ + \n* `c(int)` - a\n\n")); + } + + #[test] + fn should_write_trait_header() { + let markdown = render(~"trait i { fn a(); }"); + assert!(str::contains(markdown, ~"## Trait `i`")); + } + + #[test] + fn should_write_trait_desc() { + let markdown = render( + ~"#[doc = \"desc\"] trait i { fn a(); }"); + assert!(str::contains(markdown, ~"desc")); + } + + #[test] + fn should_write_trait_method_header() { + let markdown = render( + ~"trait i { fn a(); }"); + assert!(str::contains(markdown, ~"### Method `a`")); + } + + #[test] + fn should_write_trait_method_signature() { + let markdown = render( + ~"trait i { fn a(&self); }"); + assert!(str::contains(markdown, ~"\n fn a(&self)")); + } + + #[test] + fn should_write_impl_header() { + let markdown = render(~"impl int { fn a() { } }"); + assert!(str::contains(markdown, ~"## Implementation for `int`")); + } + + #[test] + fn should_write_impl_header_with_bounds() { + let markdown = render(~"impl int { }"); + assert!(str::contains(markdown, ~"## Implementation for `int` where ``")); + } + + #[test] + fn should_write_impl_header_with_trait() { + let markdown = render(~"impl j for int { fn a() { } }"); + assert!(str::contains(markdown, + ~"## Implementation of `j` for `int`")); + } + + #[test] + fn should_write_impl_desc() { + let markdown = render( + ~"#[doc = \"desc\"] impl int { fn a() { } }"); + assert!(str::contains(markdown, ~"desc")); + } + + #[test] + fn should_write_impl_method_header() { + let markdown = render( + ~"impl int { fn a() { } }"); + assert!(str::contains(markdown, ~"### Method `a`")); + } + + #[test] + fn should_write_impl_method_signature() { + let markdown = render( + ~"impl int { fn a(&mut self) { } }"); + assert!(str::contains(markdown, ~"\n fn a(&mut self)")); + } + + #[test] + fn should_write_type_header() { + let markdown = render(~"type t = int;"); + assert!(str::contains(markdown, ~"## Type `t`")); + } + + #[test] + fn should_write_type_desc() { + let markdown = render( + ~"#[doc = \"desc\"] type t = int;"); + assert!(str::contains(markdown, ~"\n\ndesc\n\n")); + } + + #[test] + fn should_write_type_signature() { + let markdown = render(~"type t = int;"); + assert!(str::contains(markdown, ~"\n\n type t = int\n\n")); + } + + #[test] + fn should_put_struct_header() { + let markdown = render(~"struct S { field: () }"); + assert!(str::contains(markdown, ~"## Struct `S`\n\n")); + } } diff --git a/src/librustdoc/markdown_writer.rs b/src/librustdoc/markdown_writer.rs index 2011649995ecd..fcf7011cbc309 100644 --- a/src/librustdoc/markdown_writer.rs +++ b/src/librustdoc/markdown_writer.rs @@ -182,7 +182,7 @@ fn generic_writer(process: ~fn(markdown: ~str)) -> Writer { result } -fn make_local_filename( +pub fn make_local_filename( config: config::Config, page: doc::Page ) -> Path { @@ -218,65 +218,6 @@ pub fn make_filename( Path(filename).with_filetype(ext) } -#[test] -fn should_use_markdown_file_name_based_off_crate() { - let config = config::Config { - output_dir: Path("output/dir"), - output_format: config::Markdown, - output_style: config::DocPerCrate, - .. config::default_config(&Path("input/test.rc")) - }; - let doc = test::mk_doc(~"test", ~""); - let page = doc::CratePage(doc.CrateDoc()); - let filename = make_local_filename(config, page); - assert!(filename.to_str() == ~"output/dir/test.md"); -} - -#[test] -fn should_name_html_crate_file_name_index_html_when_doc_per_mod() { - let config = config::Config { - output_dir: Path("output/dir"), - output_format: config::PandocHtml, - output_style: config::DocPerMod, - .. config::default_config(&Path("input/test.rc")) - }; - let doc = test::mk_doc(~"", ~""); - let page = doc::CratePage(doc.CrateDoc()); - let filename = make_local_filename(config, page); - assert!(filename.to_str() == ~"output/dir/index.html"); -} - -#[test] -fn should_name_mod_file_names_by_path() { - let config = config::Config { - output_dir: Path("output/dir"), - output_format: config::PandocHtml, - output_style: config::DocPerMod, - .. config::default_config(&Path("input/test.rc")) - }; - let doc = test::mk_doc(~"", ~"mod a { mod b { } }"); - let modb = copy doc.cratemod().mods()[0].mods()[0]; - let page = doc::ItemPage(doc::ModTag(modb)); - let filename = make_local_filename(config, page); - assert!(filename == Path("output/dir/a_b.html")); -} - -#[cfg(test)] -mod test { - use astsrv; - use doc; - use extract; - use path_pass; - - pub fn mk_doc(name: ~str, source: ~str) -> doc::Doc { - do astsrv::from_str(source) |srv| { - let doc = extract::from_srv(srv.clone(), copy name); - let doc = (path_pass::mk_pass().f)(srv.clone(), doc); - doc - } - } -} - fn write_file(path: &Path, s: ~str) { use core::io::WriterUtil; @@ -322,3 +263,65 @@ fn future_writer() -> (Writer, future::Future<~str>) { }; (writer, future) } + +#[cfg(test)] +mod test { + use astsrv; + use doc; + use extract; + use path_pass; + use config; + use super::make_local_filename; + use core::prelude::*; + + fn mk_doc(name: ~str, source: ~str) -> doc::Doc { + do astsrv::from_str(source) |srv| { + let doc = extract::from_srv(srv.clone(), copy name); + let doc = (path_pass::mk_pass().f)(srv.clone(), doc); + doc + } + } + + #[test] + fn should_use_markdown_file_name_based_off_crate() { + let config = config::Config { + output_dir: Path("output/dir"), + output_format: config::Markdown, + output_style: config::DocPerCrate, + .. config::default_config(&Path("input/test.rc")) + }; + let doc = mk_doc(~"test", ~""); + let page = doc::CratePage(doc.CrateDoc()); + let filename = make_local_filename(config, page); + assert!(filename.to_str() == ~"output/dir/test.md"); + } + + #[test] + fn should_name_html_crate_file_name_index_html_when_doc_per_mod() { + let config = config::Config { + output_dir: Path("output/dir"), + output_format: config::PandocHtml, + output_style: config::DocPerMod, + .. config::default_config(&Path("input/test.rc")) + }; + let doc = mk_doc(~"", ~""); + let page = doc::CratePage(doc.CrateDoc()); + let filename = make_local_filename(config, page); + assert!(filename.to_str() == ~"output/dir/index.html"); + } + + #[test] + fn should_name_mod_file_names_by_path() { + let config = config::Config { + output_dir: Path("output/dir"), + output_format: config::PandocHtml, + output_style: config::DocPerMod, + .. config::default_config(&Path("input/test.rc")) + }; + let doc = mk_doc(~"", ~"mod a { mod b { } }"); + let modb = copy doc.cratemod().mods()[0].mods()[0]; + let page = doc::ItemPage(doc::ModTag(modb)); + let filename = make_local_filename(config, page); + assert!(filename == Path("output/dir/a_b.html")); + } +} diff --git a/src/librustdoc/page_pass.rs b/src/librustdoc/page_pass.rs index 55f17f5c1501d..c620e20530e66 100644 --- a/src/librustdoc/page_pass.rs +++ b/src/librustdoc/page_pass.rs @@ -149,27 +149,6 @@ fn fold_nmod( return doc; } -#[test] -fn should_not_split_the_doc_into_pages_for_doc_per_crate() { - let doc = test::mk_doc_( - config::DocPerCrate, - ~"mod a { } mod b { mod c { } }" - ); - assert!(doc.pages.len() == 1u); -} - -#[test] -fn should_make_a_page_for_every_mod() { - let doc = test::mk_doc(~"mod a { }"); - assert!(doc.pages.mods()[0].name() == ~"a"); -} - -#[test] -fn should_remove_mods_from_containing_mods() { - let doc = test::mk_doc(~"mod a { }"); - assert!(vec::is_empty(doc.cratemod().mods())); -} - #[cfg(test)] mod test { use astsrv; @@ -177,8 +156,9 @@ mod test { use doc; use extract; use page_pass::run; + use core::vec; - pub fn mk_doc_( + fn mk_doc_( output_style: config::OutputStyle, source: ~str ) -> doc::Doc { @@ -188,7 +168,28 @@ mod test { } } - pub fn mk_doc(source: ~str) -> doc::Doc { + fn mk_doc(source: ~str) -> doc::Doc { mk_doc_(config::DocPerMod, copy source) } + + #[test] + fn should_not_split_the_doc_into_pages_for_doc_per_crate() { + let doc = mk_doc_( + config::DocPerCrate, + ~"mod a { } mod b { mod c { } }" + ); + assert!(doc.pages.len() == 1u); + } + + #[test] + fn should_make_a_page_for_every_mod() { + let doc = mk_doc(~"mod a { }"); + assert!(doc.pages.mods()[0].name() == ~"a"); + } + + #[test] + fn should_remove_mods_from_containing_mods() { + let doc = mk_doc(~"mod a { }"); + assert!(vec::is_empty(doc.cratemod().mods())); + } } diff --git a/src/librustdoc/prune_hidden_pass.rs b/src/librustdoc/prune_hidden_pass.rs index f46d183ffcfaf..a50f1f51765f9 100644 --- a/src/librustdoc/prune_hidden_pass.rs +++ b/src/librustdoc/prune_hidden_pass.rs @@ -61,25 +61,25 @@ fn is_hidden(srv: astsrv::Srv, doc: doc::ItemDoc) -> bool { } } -#[test] -fn should_prune_hidden_items() { - use core::vec; - - let doc = test::mk_doc(~"#[doc(hidden)] mod a { }"); - assert!(vec::is_empty(doc.cratemod().mods())) -} - #[cfg(test)] -pub mod test { +mod test { use astsrv; use doc; use extract; use prune_hidden_pass::run; - pub fn mk_doc(source: ~str) -> doc::Doc { + fn mk_doc(source: ~str) -> doc::Doc { do astsrv::from_str(copy source) |srv| { let doc = extract::from_srv(srv.clone(), ~""); run(srv.clone(), doc) } } + + #[test] + fn should_prune_hidden_items() { + use core::vec; + + let doc = mk_doc(~"#[doc(hidden)] mod a { }"); + assert!(vec::is_empty(doc.cratemod().mods())) + } } diff --git a/src/librustdoc/prune_private_pass.rs b/src/librustdoc/prune_private_pass.rs index 08008ab2bcae0..0578169e257d4 100644 --- a/src/librustdoc/prune_private_pass.rs +++ b/src/librustdoc/prune_private_pass.rs @@ -154,106 +154,106 @@ fn is_visible(srv: astsrv::Srv, doc: doc::ItemDoc) -> bool { } } -#[test] -fn should_prune_items_without_pub_modifier() { - let doc = test::mk_doc(~"mod a { }"); - assert!(vec::is_empty(doc.cratemod().mods())); -} - -#[test] -fn should_not_prune_trait_impls() { - // Impls are more complicated - let doc = test::mk_doc( - ~" \ - trait Foo { } \ - impl Foo for int { } \ - "); - assert!(!doc.cratemod().impls().is_empty()); -} - -#[test] -fn should_prune_associated_methods_without_vis_modifier_on_impls_without_vis_modifier() { - let doc = test::mk_doc( - ~"impl Foo {\ - pub fn bar() { }\ - fn baz() { }\ - }"); - assert!(doc.cratemod().impls()[0].methods.len() == 1); -} - -#[test] -fn should_prune_priv_associated_methods_on_impls_without_vis_modifier() { - let doc = test::mk_doc( - ~"impl Foo {\ - pub fn bar() { }\ - priv fn baz() { }\ - }"); - assert!(doc.cratemod().impls()[0].methods.len() == 1); -} - -#[test] -fn should_prune_priv_associated_methods_on_pub_impls() { - let doc = test::mk_doc( - ~"pub impl Foo {\ - fn bar() { }\ - priv fn baz() { }\ - }"); - assert!(doc.cratemod().impls()[0].methods.len() == 1); -} - -#[test] -fn should_prune_associated_methods_without_vis_modifier_on_priv_impls() { - let doc = test::mk_doc( - ~"priv impl Foo {\ - pub fn bar() { }\ - fn baz() { }\ - }"); - assert!(doc.cratemod().impls()[0].methods.len() == 1); -} - -#[test] -fn should_prune_priv_associated_methods_on_priv_impls() { - let doc = test::mk_doc( - ~"priv impl Foo {\ - pub fn bar() { }\ - priv fn baz() { }\ - }"); - assert!(doc.cratemod().impls()[0].methods.len() == 1); -} - -#[test] -fn should_prune_associated_impls_with_no_pub_methods() { - let doc = test::mk_doc( - ~"priv impl Foo {\ - fn baz() { }\ - }"); - assert!(doc.cratemod().impls().is_empty()); -} - -#[test] -fn should_not_prune_associated_impls_with_pub_methods() { - let doc = test::mk_doc( - ~" \ - impl Foo { pub fn bar() { } } \ - "); - assert!(!doc.cratemod().impls().is_empty()); -} - #[cfg(test)] -pub mod test { +mod test { use astsrv; use doc; use extract; use tystr_pass; use prune_private_pass::run; + use core::vec; - pub fn mk_doc(source: ~str) -> doc::Doc { + fn mk_doc(source: ~str) -> doc::Doc { do astsrv::from_str(copy source) |srv| { let doc = extract::from_srv(srv.clone(), ~""); let doc = tystr_pass::run(srv.clone(), doc); run(srv.clone(), doc) } } -} + #[test] + fn should_prune_items_without_pub_modifier() { + let doc = mk_doc(~"mod a { }"); + assert!(vec::is_empty(doc.cratemod().mods())); + } + + #[test] + fn should_not_prune_trait_impls() { + // Impls are more complicated + let doc = mk_doc( + ~" \ + trait Foo { } \ + impl Foo for int { } \ + "); + assert!(!doc.cratemod().impls().is_empty()); + } + + #[test] + fn should_prune_associated_methods_without_vis_modifier_on_impls_without_vis_modifier() { + let doc = mk_doc( + ~"impl Foo {\ + pub fn bar() { }\ + fn baz() { }\ + }"); + assert!(doc.cratemod().impls()[0].methods.len() == 1); + } + + #[test] + fn should_prune_priv_associated_methods_on_impls_without_vis_modifier() { + let doc = mk_doc( + ~"impl Foo {\ + pub fn bar() { }\ + priv fn baz() { }\ + }"); + assert!(doc.cratemod().impls()[0].methods.len() == 1); + } + + #[test] + fn should_prune_priv_associated_methods_on_pub_impls() { + let doc = mk_doc( + ~"pub impl Foo {\ + fn bar() { }\ + priv fn baz() { }\ + }"); + assert!(doc.cratemod().impls()[0].methods.len() == 1); + } + + #[test] + fn should_prune_associated_methods_without_vis_modifier_on_priv_impls() { + let doc = mk_doc( + ~"priv impl Foo {\ + pub fn bar() { }\ + fn baz() { }\ + }"); + assert!(doc.cratemod().impls()[0].methods.len() == 1); + } + + #[test] + fn should_prune_priv_associated_methods_on_priv_impls() { + let doc = mk_doc( + ~"priv impl Foo {\ + pub fn bar() { }\ + priv fn baz() { }\ + }"); + assert!(doc.cratemod().impls()[0].methods.len() == 1); + } + + #[test] + fn should_prune_associated_impls_with_no_pub_methods() { + let doc = mk_doc( + ~"priv impl Foo {\ + fn baz() { }\ + }"); + assert!(doc.cratemod().impls().is_empty()); + } + + #[test] + fn should_not_prune_associated_impls_with_pub_methods() { + let doc = mk_doc( + ~" \ + impl Foo { pub fn bar() { } } \ + "); + assert!(!doc.cratemod().impls().is_empty()); + } +} diff --git a/src/librustdoc/sectionalize_pass.rs b/src/librustdoc/sectionalize_pass.rs index 788f84b06c2e8..1cf43043004cf 100644 --- a/src/librustdoc/sectionalize_pass.rs +++ b/src/librustdoc/sectionalize_pass.rs @@ -160,106 +160,109 @@ fn parse_header(line: ~str) -> Option<~str> { } } -#[test] -fn should_create_section_headers() { - let doc = test::mk_doc( - ~"#[doc = \"\ - # Header\n\ - Body\"]\ - mod a { - }"); - assert!(str::contains( - doc.cratemod().mods()[0].item.sections[0].header, - ~"Header")); -} - -#[test] -fn should_create_section_bodies() { - let doc = test::mk_doc( - ~"#[doc = \"\ - # Header\n\ - Body\"]\ - mod a { - }"); - assert!(str::contains( - doc.cratemod().mods()[0].item.sections[0].body, - ~"Body")); -} -#[test] -fn should_not_create_sections_from_indented_headers() { - let doc = test::mk_doc( - ~"#[doc = \"\n\ - Text\n # Header\n\ - Body\"]\ - mod a { - }"); - assert!(vec::is_empty(doc.cratemod().mods()[0].item.sections)); -} - -#[test] -fn should_remove_section_text_from_main_desc() { - let doc = test::mk_doc( - ~"#[doc = \"\ - Description\n\n\ - # Header\n\ - Body\"]\ - mod a { - }"); - assert!(!str::contains( - doc.cratemod().mods()[0].desc().get(), - ~"Header")); - assert!(!str::contains( - doc.cratemod().mods()[0].desc().get(), - ~"Body")); -} - -#[test] -fn should_eliminate_desc_if_it_is_just_whitespace() { - let doc = test::mk_doc( - ~"#[doc = \"\ - # Header\n\ - Body\"]\ - mod a { - }"); - assert!(doc.cratemod().mods()[0].desc() == None); -} - -#[test] -fn should_sectionalize_trait_methods() { - let doc = test::mk_doc( - ~"trait i { - #[doc = \"\ - # Header\n\ - Body\"]\ - fn a(); }"); - assert!(doc.cratemod().traits()[0].methods[0].sections.len() == 1u); -} - -#[test] -fn should_sectionalize_impl_methods() { - let doc = test::mk_doc( - ~"impl bool { - #[doc = \"\ - # Header\n\ - Body\"]\ - fn a() { } }"); - assert!(doc.cratemod().impls()[0].methods[0].sections.len() == 1u); -} #[cfg(test)] -pub mod test { +mod test { use astsrv; use attr_pass; use doc; use extract; use sectionalize_pass::run; + use core::prelude::*; - pub fn mk_doc(source: ~str) -> doc::Doc { + fn mk_doc(source: ~str) -> doc::Doc { do astsrv::from_str(copy source) |srv| { let doc = extract::from_srv(srv.clone(), ~""); let doc = (attr_pass::mk_pass().f)(srv.clone(), doc); run(srv.clone(), doc) } } + + #[test] + fn should_create_section_headers() { + let doc = mk_doc( + ~"#[doc = \"\ + # Header\n\ + Body\"]\ + mod a { +}"); + assert!(str::contains( + doc.cratemod().mods()[0].item.sections[0].header, + ~"Header")); + } + + #[test] + fn should_create_section_bodies() { + let doc = mk_doc( + ~"#[doc = \"\ + # Header\n\ + Body\"]\ + mod a { +}"); + assert!(str::contains( + doc.cratemod().mods()[0].item.sections[0].body, + ~"Body")); + } + + #[test] + fn should_not_create_sections_from_indented_headers() { + let doc = mk_doc( + ~"#[doc = \"\n\ + Text\n # Header\n\ + Body\"]\ + mod a { +}"); + assert!(vec::is_empty(doc.cratemod().mods()[0].item.sections)); + } + + #[test] + fn should_remove_section_text_from_main_desc() { + let doc = mk_doc( + ~"#[doc = \"\ + Description\n\n\ + # Header\n\ + Body\"]\ + mod a { +}"); + assert!(!str::contains( + doc.cratemod().mods()[0].desc().get(), + ~"Header")); + assert!(!str::contains( + doc.cratemod().mods()[0].desc().get(), + ~"Body")); + } + + #[test] + fn should_eliminate_desc_if_it_is_just_whitespace() { + let doc = mk_doc( + ~"#[doc = \"\ + # Header\n\ + Body\"]\ + mod a { +}"); + assert!(doc.cratemod().mods()[0].desc() == None); + } + + #[test] + fn should_sectionalize_trait_methods() { + let doc = mk_doc( + ~"trait i { +#[doc = \"\ + # Header\n\ + Body\"]\ + fn a(); }"); + assert!(doc.cratemod().traits()[0].methods[0].sections.len() == 1u); + } + + #[test] + fn should_sectionalize_impl_methods() { + let doc = mk_doc( + ~"impl bool { +#[doc = \"\ + # Header\n\ + Body\"]\ + fn a() { } }"); + assert!(doc.cratemod().impls()[0].methods[0].sections.len() == 1u); + } } diff --git a/src/librustdoc/text_pass.rs b/src/librustdoc/text_pass.rs index b5e9b452d148b..785428f00775d 100644 --- a/src/librustdoc/text_pass.rs +++ b/src/librustdoc/text_pass.rs @@ -137,181 +137,181 @@ fn fold_impl( } } -#[test] -fn should_execute_op_on_enum_brief() { - let doc = test::mk_doc(~"#[doc = \" a \"] enum a { b }"); - assert!(doc.cratemod().enums()[0].brief() == Some(~"a")); -} +#[cfg(test)] +mod test { + use astsrv; + use attr_pass; + use desc_to_brief_pass; + use doc; + use extract; + use sectionalize_pass; + use text_pass::mk_pass; -#[test] -fn should_execute_op_on_enum_desc() { - let doc = test::mk_doc(~"#[doc = \" a \"] enum a { b }"); - assert!(doc.cratemod().enums()[0].desc() == Some(~"a")); -} + use core::prelude::*; -#[test] -fn should_execute_op_on_variant_desc() { - let doc = test::mk_doc(~"enum a { #[doc = \" a \"] b }"); - assert!(doc.cratemod().enums()[0].variants[0].desc == Some(~"a")); -} + fn mk_doc(source: ~str) -> doc::Doc { + do astsrv::from_str(copy source) |srv| { + let doc = extract::from_srv(srv.clone(), ~""); + let doc = (attr_pass::mk_pass().f)(srv.clone(), doc); + let doc = (desc_to_brief_pass::mk_pass().f)(srv.clone(), doc); + let doc = (sectionalize_pass::mk_pass().f)(srv.clone(), doc); + (mk_pass(~"", |s| str::trim(s).to_owned() ).f)(srv.clone(), doc) + } + } -#[test] -fn should_execute_op_on_trait_brief() { - let doc = test::mk_doc( - ~"#[doc = \" a \"] trait i { fn a(); }"); - assert!(doc.cratemod().traits()[0].brief() == Some(~"a")); -} + #[test] + fn should_execute_op_on_enum_brief() { + let doc = mk_doc(~"#[doc = \" a \"] enum a { b }"); + assert!(doc.cratemod().enums()[0].brief() == Some(~"a")); + } -#[test] -fn should_execute_op_on_trait_desc() { - let doc = test::mk_doc( - ~"#[doc = \" a \"] trait i { fn a(); }"); - assert!(doc.cratemod().traits()[0].desc() == Some(~"a")); -} + #[test] + fn should_execute_op_on_enum_desc() { + let doc = mk_doc(~"#[doc = \" a \"] enum a { b }"); + assert!(doc.cratemod().enums()[0].desc() == Some(~"a")); + } -#[test] -fn should_execute_op_on_trait_method_brief() { - let doc = test::mk_doc( - ~"trait i { #[doc = \" a \"] fn a(); }"); - assert!(doc.cratemod().traits()[0].methods[0].brief == Some(~"a")); -} + #[test] + fn should_execute_op_on_variant_desc() { + let doc = mk_doc(~"enum a { #[doc = \" a \"] b }"); + assert!(doc.cratemod().enums()[0].variants[0].desc == Some(~"a")); + } -#[test] -fn should_execute_op_on_trait_method_desc() { - let doc = test::mk_doc( - ~"trait i { #[doc = \" a \"] fn a(); }"); - assert!(doc.cratemod().traits()[0].methods[0].desc == Some(~"a")); -} + #[test] + fn should_execute_op_on_trait_brief() { + let doc = mk_doc( + ~"#[doc = \" a \"] trait i { fn a(); }"); + assert!(doc.cratemod().traits()[0].brief() == Some(~"a")); + } -#[test] -fn should_execute_op_on_impl_brief() { - let doc = test::mk_doc( - ~"#[doc = \" a \"] impl int { fn a() { } }"); - assert!(doc.cratemod().impls()[0].brief() == Some(~"a")); -} + #[test] + fn should_execute_op_on_trait_desc() { + let doc = mk_doc( + ~"#[doc = \" a \"] trait i { fn a(); }"); + assert!(doc.cratemod().traits()[0].desc() == Some(~"a")); + } -#[test] -fn should_execute_op_on_impl_desc() { - let doc = test::mk_doc( - ~"#[doc = \" a \"] impl int { fn a() { } }"); - assert!(doc.cratemod().impls()[0].desc() == Some(~"a")); -} + #[test] + fn should_execute_op_on_trait_method_brief() { + let doc = mk_doc( + ~"trait i { #[doc = \" a \"] fn a(); }"); + assert!(doc.cratemod().traits()[0].methods[0].brief == Some(~"a")); + } -#[test] -fn should_execute_op_on_impl_method_brief() { - let doc = test::mk_doc( - ~"impl int { #[doc = \" a \"] fn a() { } }"); - assert!(doc.cratemod().impls()[0].methods[0].brief == Some(~"a")); -} + #[test] + fn should_execute_op_on_trait_method_desc() { + let doc = mk_doc( + ~"trait i { #[doc = \" a \"] fn a(); }"); + assert!(doc.cratemod().traits()[0].methods[0].desc == Some(~"a")); + } -#[test] -fn should_execute_op_on_impl_method_desc() { - let doc = test::mk_doc( - ~"impl int { #[doc = \" a \"] fn a() { } }"); - assert!(doc.cratemod().impls()[0].methods[0].desc == Some(~"a")); -} + #[test] + fn should_execute_op_on_impl_brief() { + let doc = mk_doc( + ~"#[doc = \" a \"] impl int { fn a() { } }"); + assert!(doc.cratemod().impls()[0].brief() == Some(~"a")); + } -#[test] -fn should_execute_op_on_type_brief() { - let doc = test::mk_doc( - ~"#[doc = \" a \"] type t = int;"); - assert!(doc.cratemod().types()[0].brief() == Some(~"a")); -} + #[test] + fn should_execute_op_on_impl_desc() { + let doc = mk_doc( + ~"#[doc = \" a \"] impl int { fn a() { } }"); + assert!(doc.cratemod().impls()[0].desc() == Some(~"a")); + } -#[test] -fn should_execute_op_on_type_desc() { - let doc = test::mk_doc( - ~"#[doc = \" a \"] type t = int;"); - assert!(doc.cratemod().types()[0].desc() == Some(~"a")); -} + #[test] + fn should_execute_op_on_impl_method_brief() { + let doc = mk_doc( + ~"impl int { #[doc = \" a \"] fn a() { } }"); + assert!(doc.cratemod().impls()[0].methods[0].brief == Some(~"a")); + } -#[test] -fn should_execute_on_item_section_headers() { - let doc = test::mk_doc( - ~"#[doc = \"\ - # Header \n\ - Body\"]\ - fn a() { }"); - assert!(doc.cratemod().fns()[0].sections()[0].header == ~"Header"); -} + #[test] + fn should_execute_op_on_impl_method_desc() { + let doc = mk_doc( + ~"impl int { #[doc = \" a \"] fn a() { } }"); + assert!(doc.cratemod().impls()[0].methods[0].desc == Some(~"a")); + } -#[test] -fn should_execute_on_item_section_bodies() { - let doc = test::mk_doc( - ~"#[doc = \"\ - # Header\n\ - Body \"]\ - fn a() { }"); - assert!(doc.cratemod().fns()[0].sections()[0].body == ~"Body"); -} + #[test] + fn should_execute_op_on_type_brief() { + let doc = mk_doc( + ~"#[doc = \" a \"] type t = int;"); + assert!(doc.cratemod().types()[0].brief() == Some(~"a")); + } -#[test] -fn should_execute_on_trait_method_section_headers() { - let doc = test::mk_doc( - ~"trait i { - #[doc = \"\ - # Header \n\ - Body\"]\ - fn a(); }"); - assert!(doc.cratemod().traits()[0].methods[0].sections[0].header - == ~"Header"); -} + #[test] + fn should_execute_op_on_type_desc() { + let doc = mk_doc( + ~"#[doc = \" a \"] type t = int;"); + assert!(doc.cratemod().types()[0].desc() == Some(~"a")); + } -#[test] -fn should_execute_on_trait_method_section_bodies() { - let doc = test::mk_doc( - ~"trait i { - #[doc = \"\ - # Header\n\ - Body \"]\ - fn a(); }"); - assert!(doc.cratemod().traits()[0].methods[0].sections[0].body == - ~"Body"); -} + #[test] + fn should_execute_on_item_section_headers() { + let doc = mk_doc( + ~"#[doc = \"\ + # Header \n\ + Body\"]\ + fn a() { }"); + assert!(doc.cratemod().fns()[0].sections()[0].header == ~"Header"); + } -#[test] -fn should_execute_on_impl_method_section_headers() { - let doc = test::mk_doc( - ~"impl bool { - #[doc = \"\ - # Header \n\ - Body\"]\ - fn a() { } }"); - assert!(doc.cratemod().impls()[0].methods[0].sections[0].header - == ~"Header"); -} + #[test] + fn should_execute_on_item_section_bodies() { + let doc = mk_doc( + ~"#[doc = \"\ + # Header\n\ + Body \"]\ + fn a() { }"); + assert!(doc.cratemod().fns()[0].sections()[0].body == ~"Body"); + } -#[test] -fn should_execute_on_impl_method_section_bodies() { - let doc = test::mk_doc( - ~"impl bool { - #[doc = \"\ - # Header\n\ - Body \"]\ - fn a() { } }"); - assert!(doc.cratemod().impls()[0].methods[0].sections[0].body == - ~"Body"); -} + #[test] + fn should_execute_on_trait_method_section_headers() { + let doc = mk_doc( + ~"trait i { +#[doc = \"\ + # Header \n\ + Body\"]\ + fn a(); }"); + assert!(doc.cratemod().traits()[0].methods[0].sections[0].header + == ~"Header"); + } -#[cfg(test)] -mod test { - use astsrv; - use attr_pass; - use desc_to_brief_pass; - use doc; - use extract; - use sectionalize_pass; - use text_pass::mk_pass; + #[test] + fn should_execute_on_trait_method_section_bodies() { + let doc = mk_doc( + ~"trait i { +#[doc = \"\ + # Header\n\ + Body \"]\ + fn a(); }"); + assert!(doc.cratemod().traits()[0].methods[0].sections[0].body == + ~"Body"); + } - use core::str; + #[test] + fn should_execute_on_impl_method_section_headers() { + let doc = mk_doc( + ~"impl bool { +#[doc = \"\ + # Header \n\ + Body\"]\ + fn a() { } }"); + assert!(doc.cratemod().impls()[0].methods[0].sections[0].header + == ~"Header"); + } - pub fn mk_doc(source: ~str) -> doc::Doc { - do astsrv::from_str(copy source) |srv| { - let doc = extract::from_srv(srv.clone(), ~""); - let doc = (attr_pass::mk_pass().f)(srv.clone(), doc); - let doc = (desc_to_brief_pass::mk_pass().f)(srv.clone(), doc); - let doc = (sectionalize_pass::mk_pass().f)(srv.clone(), doc); - (mk_pass(~"", |s| str::trim(s).to_owned() ).f)(srv.clone(), doc) - } + #[test] + fn should_execute_on_impl_method_section_bodies() { + let doc = mk_doc( + ~"impl bool { +#[doc = \"\ + # Header\n\ + Body \"]\ + fn a() { } }"); + assert!(doc.cratemod().impls()[0].methods[0].sections[0].body == + ~"Body"); } } diff --git a/src/librustdoc/trim_pass.rs b/src/librustdoc/trim_pass.rs index ca543a27189dc..e56a5f18ac6f7 100644 --- a/src/librustdoc/trim_pass.rs +++ b/src/librustdoc/trim_pass.rs @@ -22,16 +22,6 @@ pub fn mk_pass() -> Pass { text_pass::mk_pass(~"trim", |s| s.trim().to_owned() ) } -#[test] -fn should_trim_text() { - use core::option::Some; - - let doc = test::mk_doc(~"#[doc = \" desc \"] \ - mod m { - }"); - assert!(doc.cratemod().mods()[0].desc() == Some(~"desc")); -} - #[cfg(test)] mod test { use astsrv; @@ -40,11 +30,21 @@ mod test { use extract; use trim_pass::mk_pass; - pub fn mk_doc(source: ~str) -> doc::Doc { + fn mk_doc(source: ~str) -> doc::Doc { do astsrv::from_str(copy source) |srv| { let doc = extract::from_srv(srv.clone(), ~""); let doc = (attr_pass::mk_pass().f)(srv.clone(), doc); (mk_pass().f)(srv.clone(), doc) } } + + #[test] + fn should_trim_text() { + use core::option::Some; + + let doc = mk_doc(~"#[doc = \" desc \"] \ + mod m { +}"); + assert!(doc.cratemod().mods()[0].desc() == Some(~"desc")); + } } diff --git a/src/librustdoc/tystr_pass.rs b/src/librustdoc/tystr_pass.rs index 6ccfb1bb8c4b9..c0562d306398a 100644 --- a/src/librustdoc/tystr_pass.rs +++ b/src/librustdoc/tystr_pass.rs @@ -67,35 +67,22 @@ fn fold_fn( fn get_fn_sig(srv: astsrv::Srv, fn_id: doc::AstId) -> Option<~str> { do astsrv::exec(srv) |ctxt| { match *ctxt.ast_map.get(&fn_id) { - ast_map::node_item(@ast::item { - ident: ident, - node: ast::item_fn(ref decl, purity, _, ref tys, _), _ - }, _) | - ast_map::node_foreign_item(@ast::foreign_item { - ident: ident, - node: ast::foreign_item_fn(ref decl, purity, ref tys), _ - }, _, _, _) => { - Some(pprust::fun_to_str(decl, purity, ident, None, tys, - extract::interner())) - } - _ => fail!(~"get_fn_sig: fn_id not bound to a fn item") + ast_map::node_item(@ast::item { + ident: ident, + node: ast::item_fn(ref decl, purity, _, ref tys, _), _ + }, _) | + ast_map::node_foreign_item(@ast::foreign_item { + ident: ident, + node: ast::foreign_item_fn(ref decl, purity, ref tys), _ + }, _, _, _) => { + Some(pprust::fun_to_str(decl, purity, ident, None, tys, + extract::interner())) + } + _ => fail!(~"get_fn_sig: fn_id not bound to a fn item") } } } -#[test] -fn should_add_fn_sig() { - let doc = test::mk_doc(~"fn a() -> int { }"); - assert!(doc.cratemod().fns()[0].sig == Some(~"fn a() -> int")); -} - -#[test] -fn should_add_foreign_fn_sig() { - let doc = test::mk_doc(~"extern mod a { fn a() -> int; }"); - assert!(doc.cratemod().nmods()[0].fns[0].sig == - Some(~"fn a() -> int")); -} - fn fold_const( fold: &fold::Fold, doc: doc::ConstDoc @@ -119,12 +106,6 @@ fn fold_const( } } -#[test] -fn should_add_const_types() { - let doc = test::mk_doc(~"static a: bool = true;"); - assert!(doc.cratemod().consts()[0].sig == Some(~"bool")); -} - fn fold_enum( fold: &fold::Fold, doc: doc::EnumDoc @@ -163,13 +144,6 @@ fn fold_enum( } } -#[test] -fn should_add_variant_sigs() { - let doc = test::mk_doc(~"enum a { b(int) }"); - assert!(doc.cratemod().enums()[0].variants[0].sig == - Some(~"b(int)")); -} - fn fold_trait( fold: &fold::Fold, doc: doc::TraitDoc @@ -200,73 +174,66 @@ fn get_method_sig( ) -> Option<~str> { do astsrv::exec(srv) |ctxt| { match *ctxt.ast_map.get(&item_id) { - ast_map::node_item(@ast::item { - node: ast::item_trait(_, _, ref methods), _ - }, _) => { - match vec::find(*methods, |method| { - match copy *method { - ast::required(ty_m) => to_str(ty_m.ident) == method_name, - ast::provided(m) => to_str(m.ident) == method_name, - } - }) { - Some(method) => { - match method { - ast::required(ty_m) => { - Some(pprust::fun_to_str( - &ty_m.decl, - ty_m.purity, - ty_m.ident, - Some(ty_m.self_ty.node), - &ty_m.generics, - extract::interner() - )) + ast_map::node_item(@ast::item { + node: ast::item_trait(_, _, ref methods), _ + }, _) => { + match vec::find(*methods, |method| { + match copy *method { + ast::required(ty_m) => to_str(ty_m.ident) == method_name, + ast::provided(m) => to_str(m.ident) == method_name, } - ast::provided(m) => { - Some(pprust::fun_to_str( - &m.decl, - m.purity, - m.ident, - Some(m.self_ty.node), - &m.generics, - extract::interner() - )) + }) { + Some(method) => { + match method { + ast::required(ty_m) => { + Some(pprust::fun_to_str( + &ty_m.decl, + ty_m.purity, + ty_m.ident, + Some(ty_m.self_ty.node), + &ty_m.generics, + extract::interner() + )) + } + ast::provided(m) => { + Some(pprust::fun_to_str( + &m.decl, + m.purity, + m.ident, + Some(m.self_ty.node), + &m.generics, + extract::interner() + )) + } + } } - } + _ => fail!(~"method not found") } - _ => fail!(~"method not found") } - } - ast_map::node_item(@ast::item { - node: ast::item_impl(_, _, _, ref methods), _ - }, _) => { - match vec::find(*methods, |method| { - to_str(method.ident) == method_name - }) { - Some(method) => { - Some(pprust::fun_to_str( - &method.decl, - method.purity, - method.ident, - Some(method.self_ty.node), - &method.generics, - extract::interner() - )) + ast_map::node_item(@ast::item { + node: ast::item_impl(_, _, _, ref methods), _ + }, _) => { + match vec::find(*methods, |method| { + to_str(method.ident) == method_name + }) { + Some(method) => { + Some(pprust::fun_to_str( + &method.decl, + method.purity, + method.ident, + Some(method.self_ty.node), + &method.generics, + extract::interner() + )) + } + None => fail!(~"method not found") } - None => fail!(~"method not found") } - } - _ => fail!(~"get_method_sig: item ID not bound to trait or impl") + _ => fail!(~"get_method_sig: item ID not bound to trait or impl") } } } -#[test] -fn should_add_trait_method_sigs() { - let doc = test::mk_doc(~"trait i { fn a(&mut self) -> int; }"); - assert!(doc.cratemod().traits()[0].methods[0].sig - == Some(~"fn a(&mut self) -> int")); -} - fn fold_impl( fold: &fold::Fold, doc: doc::ImplDoc @@ -305,37 +272,6 @@ fn fold_impl( } } -#[test] -fn should_add_impl_bounds() { - let doc = test::mk_doc(~"impl Option { }"); - assert!(doc.cratemod().impls()[0].bounds_str == Some(~"")); -} - -#[test] -fn should_add_impl_trait_types() { - let doc = test::mk_doc(~"impl j for int { fn a() { } }"); - assert!(doc.cratemod().impls()[0].trait_types[0] == ~"j"); -} - -#[test] -fn should_not_add_impl_trait_types_if_none() { - let doc = test::mk_doc(~"impl int { fn a() { } }"); - assert!(vec::len(doc.cratemod().impls()[0].trait_types) == 0); -} - -#[test] -fn should_add_impl_self_ty() { - let doc = test::mk_doc(~"impl int { fn a() { } }"); - assert!(doc.cratemod().impls()[0].self_ty == Some(~"int")); -} - -#[test] -fn should_add_impl_method_sigs() { - let doc = test::mk_doc(~"impl int { fn a(&self) -> int { fail!() } }"); - assert!(doc.cratemod().impls()[0].methods[0].sig - == Some(~"fn a(&self) -> int")); -} - fn fold_type( fold: &fold::Fold, doc: doc::TyDoc @@ -369,12 +305,6 @@ fn fold_type( } } -#[test] -fn should_add_type_signatures() { - let doc = test::mk_doc(~"type t = int;"); - assert!(doc.cratemod().types()[0].sig == Some(~"type t = int")); -} - fn fold_struct( fold: &fold::Fold, doc: doc::StructDoc @@ -422,38 +352,109 @@ fn strip_struct_extra_stuff(item: @ast::item) -> @ast::item { } } -#[test] -fn should_add_struct_defs() { - let doc = test::mk_doc(~"struct S { field: () }"); - assert!((&doc.cratemod().structs()[0].sig).get().contains( - "struct S {")); -} - -#[test] -fn should_not_serialize_struct_drop_blocks() { - // All we care about are the fields - let doc = test::mk_doc(~"struct S { field: (), drop { } }"); - assert!(!(&doc.cratemod().structs()[0].sig).get().contains("drop")); -} - -#[test] -fn should_not_serialize_struct_attrs() { - // All we care about are the fields - let doc = test::mk_doc(~"#[wut] struct S { field: () }"); - assert!(!(&doc.cratemod().structs()[0].sig).get().contains("wut")); -} - #[cfg(test)] -pub mod test { +mod test { use astsrv; use doc; use extract; use tystr_pass::run; + use core::prelude::*; - pub fn mk_doc(source: ~str) -> doc::Doc { + fn mk_doc(source: ~str) -> doc::Doc { do astsrv::from_str(copy source) |srv| { let doc = extract::from_srv(srv.clone(), ~""); run(srv.clone(), doc) } } + + #[test] + fn should_add_fn_sig() { + let doc = mk_doc(~"fn a() -> int { }"); + assert!(doc.cratemod().fns()[0].sig == Some(~"fn a() -> int")); + } + + #[test] + fn should_add_foreign_fn_sig() { + let doc = mk_doc(~"extern mod a { fn a() -> int; }"); + assert!(doc.cratemod().nmods()[0].fns[0].sig == + Some(~"fn a() -> int")); + } + + #[test] + fn should_add_const_types() { + let doc = mk_doc(~"static a: bool = true;"); + assert!(doc.cratemod().consts()[0].sig == Some(~"bool")); + } + + #[test] + fn should_add_variant_sigs() { + let doc = mk_doc(~"enum a { b(int) }"); + assert!(doc.cratemod().enums()[0].variants[0].sig == + Some(~"b(int)")); + } + + #[test] + fn should_add_trait_method_sigs() { + let doc = mk_doc(~"trait i { fn a(&mut self) -> int; }"); + assert!(doc.cratemod().traits()[0].methods[0].sig + == Some(~"fn a(&mut self) -> int")); + } + + #[test] + fn should_add_impl_bounds() { + let doc = mk_doc(~"impl Option { }"); + assert!(doc.cratemod().impls()[0].bounds_str == Some(~"")); + } + + #[test] + fn should_add_impl_trait_types() { + let doc = mk_doc(~"impl j for int { fn a() { } }"); + assert!(doc.cratemod().impls()[0].trait_types[0] == ~"j"); + } + + #[test] + fn should_not_add_impl_trait_types_if_none() { + let doc = mk_doc(~"impl int { fn a() { } }"); + assert!(vec::len(doc.cratemod().impls()[0].trait_types) == 0); + } + + #[test] + fn should_add_impl_self_ty() { + let doc = mk_doc(~"impl int { fn a() { } }"); + assert!(doc.cratemod().impls()[0].self_ty == Some(~"int")); + } + + #[test] + fn should_add_impl_method_sigs() { + let doc = mk_doc(~"impl int { fn a(&self) -> int { fail!() } }"); + assert!(doc.cratemod().impls()[0].methods[0].sig + == Some(~"fn a(&self) -> int")); + } + + #[test] + fn should_add_type_signatures() { + let doc = mk_doc(~"type t = int;"); + assert!(doc.cratemod().types()[0].sig == Some(~"type t = int")); + } + + #[test] + fn should_add_struct_defs() { + let doc = mk_doc(~"struct S { field: () }"); + assert!((&doc.cratemod().structs()[0].sig).get().contains( + "struct S {")); + } + + #[test] + fn should_not_serialize_struct_drop_blocks() { + // All we care about are the fields + let doc = mk_doc(~"struct S { field: (), drop { } }"); + assert!(!(&doc.cratemod().structs()[0].sig).get().contains("drop")); + } + + #[test] + fn should_not_serialize_struct_attrs() { + // All we care about are the fields + let doc = mk_doc(~"#[wut] struct S { field: () }"); + assert!(!(&doc.cratemod().structs()[0].sig).get().contains("wut")); + } } From 40e3577b0834794b2d44e6c527fda90d1adbc88e Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Tue, 16 Apr 2013 12:04:49 +1000 Subject: [PATCH 3/3] libcore: missed an import for a test --- src/libcore/at_vec.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index 337b0722ce7ab..532dcf6157b54 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -282,6 +282,7 @@ pub mod raw { #[cfg(test)] mod test { use super::*; + use prelude::*; #[test] fn test() {