mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Clean up rustc warnings.
compiletest: compact "linux" "macos" etc.as "unix". liballoc: remove a superfluous "use". libcollections: remove invocations of deprecated methods in favor of their suggested replacements and use "_" for a loop counter. libcoretest: remove invocations of deprecated methods; also add "allow(deprecated)" for testing a deprecated method itself. libglob: use "cfg_attr". libgraphviz: add a test for one of data constructors. libgreen: remove a superfluous "use". libnum: "allow(type_overflow)" for type cast into u8 in a test code. librustc: names of static variables should be in upper case. libserialize: v[i] instead of get(). libstd/ascii: to_lowercase() instead of to_lower(). libstd/bitflags: modify AnotherSetOfFlags to use i8 as its backend. It will serve better for testing various aspects of bitflags!. libstd/collections: "allow(deprecated)" for testing a deprecated method itself. libstd/io: remove invocations of deprecated methods and superfluous "use". Also add #[test] where it was missing. libstd/num: introduce a helper function to effectively remove invocations of a deprecated method. libstd/path and rand: remove invocations of deprecated methods and superfluous "use". libstd/task and libsync/comm: "allow(deprecated)" for testing a deprecated method itself. libsync/deque: remove superfluous "unsafe". libsync/mutex and once: names of static variables should be in upper case. libterm: introduce a helper function to effectively remove invocations of a deprecated method. We still see a few warnings about using obsoleted native::task::spawn() in the test modules for libsync. I'm not sure how I should replace them with std::task::TaksBuilder and native::task::NativeTaskBuilder (dependency to libstd?) Signed-off-by: NODA, Kai <nodakai@gmail.com>
This commit is contained in:
parent
a6e0c76ef4
commit
f27ad3d3e9
@ -947,15 +947,12 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError> ,
|
||||
String::from_chars(c.as_slice())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
#[cfg(windows)]
|
||||
fn prefix_matches( line : &str, prefix : &str ) -> bool {
|
||||
to_lower(line).as_slice().starts_with(to_lower(prefix).as_slice())
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux",
|
||||
target_os = "macos",
|
||||
target_os = "freebsd",
|
||||
target_os = "dragonfly"))]
|
||||
#[cfg(unix)]
|
||||
fn prefix_matches( line : &str, prefix : &str ) -> bool {
|
||||
line.starts_with( prefix )
|
||||
}
|
||||
@ -1356,24 +1353,21 @@ fn program_output(config: &Config, testfile: &Path, lib_path: &str, prog: String
|
||||
}
|
||||
|
||||
// Linux and mac don't require adjusting the library search path
|
||||
#[cfg(any(target_os = "linux",
|
||||
target_os = "macos",
|
||||
target_os = "freebsd",
|
||||
target_os = "dragonfly"))]
|
||||
#[cfg(unix)]
|
||||
fn make_cmdline(_libpath: &str, prog: &str, args: &[String]) -> String {
|
||||
format!("{} {}", prog, args.connect(" "))
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
#[cfg(windows)]
|
||||
fn make_cmdline(libpath: &str, prog: &str, args: &[String]) -> String {
|
||||
format!("{} {} {}", lib_path_cmd_prefix(libpath), prog, args.connect(" "))
|
||||
}
|
||||
|
||||
// Build the LD_LIBRARY_PATH variable as it would be seen on the command line
|
||||
// for diagnostic purposes
|
||||
#[cfg(target_os = "windows")]
|
||||
fn lib_path_cmd_prefix(path: &str) -> String {
|
||||
format!("{}=\"{}\"", util::lib_path_env_var(), util::make_new_path(path))
|
||||
// Build the LD_LIBRARY_PATH variable as it would be seen on the command line
|
||||
// for diagnostic purposes
|
||||
fn lib_path_cmd_prefix(path: &str) -> String {
|
||||
format!("{}=\"{}\"", util::lib_path_env_var(), util::make_new_path(path))
|
||||
}
|
||||
|
||||
format!("{} {} {}", lib_path_cmd_prefix(libpath), prog, args.connect(" "))
|
||||
}
|
||||
|
||||
fn dump_output(config: &Config, testfile: &Path, out: &str, err: &str) {
|
||||
|
@ -276,7 +276,6 @@ impl<T: Sync + Send> Drop for Weak<T> {
|
||||
#[allow(experimental)]
|
||||
mod tests {
|
||||
use std::clone::Clone;
|
||||
use std::collections::MutableSeq;
|
||||
use std::comm::channel;
|
||||
use std::mem::drop;
|
||||
use std::ops::Drop;
|
||||
|
@ -2659,7 +2659,7 @@ mod tests {
|
||||
let mut r = rng();
|
||||
let mut bitv = Bitv::with_capacity(BENCH_BITS, false);
|
||||
b.iter(|| {
|
||||
for i in range(0u, 100) {
|
||||
for _ in range(0u, 100) {
|
||||
bitv.set((r.next_u32() as uint) % BENCH_BITS, r.gen());
|
||||
}
|
||||
&bitv
|
||||
|
@ -890,13 +890,13 @@ mod tests {
|
||||
}
|
||||
|
||||
let v = vec![1i,2,3,4,5];
|
||||
let u = vec![9i,8,1,2,3,4,5];
|
||||
let mut u = vec![9i,8,1,2,3,4,5];
|
||||
let mut m = list_from(v.as_slice());
|
||||
m.prepend(list_from(u.as_slice()));
|
||||
check_links(&m);
|
||||
let sum = u.append(v.as_slice());
|
||||
assert_eq!(sum.len(), m.len());
|
||||
for elt in sum.into_iter() {
|
||||
u.extend(v.as_slice().iter().map(|&b| b));
|
||||
assert_eq!(u.len(), m.len());
|
||||
for elt in u.into_iter() {
|
||||
assert_eq!(m.pop_front(), Some(elt))
|
||||
}
|
||||
}
|
||||
|
@ -611,10 +611,10 @@ mod tests {
|
||||
assert_eq!(deq.len(), 3);
|
||||
deq.push_front(a.clone());
|
||||
assert_eq!(deq.len(), 4);
|
||||
assert_eq!((*deq.get(0)).clone(), a.clone());
|
||||
assert_eq!((*deq.get(1)).clone(), b.clone());
|
||||
assert_eq!((*deq.get(2)).clone(), c.clone());
|
||||
assert_eq!((*deq.get(3)).clone(), d.clone());
|
||||
assert_eq!(deq[0].clone(), a.clone());
|
||||
assert_eq!(deq[1].clone(), b.clone());
|
||||
assert_eq!(deq[2].clone(), c.clone());
|
||||
assert_eq!(deq[3].clone(), d.clone());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -626,7 +626,7 @@ mod tests {
|
||||
assert_eq!(deq.len(), 66);
|
||||
|
||||
for i in range(0u, 66) {
|
||||
assert_eq!(*deq.get(i), 65 - i);
|
||||
assert_eq!(deq[i], 65 - i);
|
||||
}
|
||||
|
||||
let mut deq = RingBuf::new();
|
||||
@ -635,7 +635,7 @@ mod tests {
|
||||
}
|
||||
|
||||
for i in range(0u, 66) {
|
||||
assert_eq!(*deq.get(i), i);
|
||||
assert_eq!(deq[i], i);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -883,6 +883,7 @@ mod tests {
|
||||
use std::slice::{AsSlice, ImmutableSlice};
|
||||
use string::String;
|
||||
use vec::Vec;
|
||||
use slice::CloneableVector;
|
||||
|
||||
use unicode::char::UnicodeChar;
|
||||
|
||||
@ -1504,7 +1505,7 @@ mod tests {
|
||||
fn vec_str_conversions() {
|
||||
let s1: String = String::from_str("All mimsy were the borogoves");
|
||||
|
||||
let v: Vec<u8> = Vec::from_slice(s1.as_bytes());
|
||||
let v: Vec<u8> = s1.as_bytes().to_vec();
|
||||
let s2: String = String::from_str(from_utf8(v.as_slice()).unwrap());
|
||||
let mut i: uint = 0u;
|
||||
let n1: uint = s1.len();
|
||||
|
@ -1036,6 +1036,7 @@ mod tests {
|
||||
use str::{Str, StrSlice, Owned};
|
||||
use super::{as_string, String};
|
||||
use vec::Vec;
|
||||
use slice::CloneableVector;
|
||||
|
||||
#[test]
|
||||
fn test_as_string() {
|
||||
@ -1051,15 +1052,15 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_from_utf8() {
|
||||
let xs = Vec::from_slice(b"hello");
|
||||
let xs = b"hello".to_vec();
|
||||
assert_eq!(String::from_utf8(xs), Ok(String::from_str("hello")));
|
||||
|
||||
let xs = Vec::from_slice("ศไทย中华Việt Nam".as_bytes());
|
||||
let xs = "ศไทย中华Việt Nam".as_bytes().to_vec();
|
||||
assert_eq!(String::from_utf8(xs), Ok(String::from_str("ศไทย中华Việt Nam")));
|
||||
|
||||
let xs = Vec::from_slice(b"hello\xFF");
|
||||
let xs = b"hello\xFF".to_vec();
|
||||
assert_eq!(String::from_utf8(xs),
|
||||
Err(Vec::from_slice(b"hello\xFF")));
|
||||
Err(b"hello\xFF".to_vec()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1211,7 +1212,8 @@ mod tests {
|
||||
fn test_push_bytes() {
|
||||
let mut s = String::from_str("ABC");
|
||||
unsafe {
|
||||
s.push_bytes([b'D']);
|
||||
let mv = s.as_mut_vec();
|
||||
mv.push_all([b'D']);
|
||||
}
|
||||
assert_eq!(s.as_slice(), "ABCD");
|
||||
}
|
||||
@ -1239,17 +1241,18 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pop_char() {
|
||||
fn test_pop() {
|
||||
let mut data = String::from_str("ประเทศไทย中华b¢€𤭢");
|
||||
assert_eq!(data.pop_char().unwrap(), '𤭢'); // 4 bytes
|
||||
assert_eq!(data.pop_char().unwrap(), '€'); // 3 bytes
|
||||
assert_eq!(data.pop_char().unwrap(), '¢'); // 2 bytes
|
||||
assert_eq!(data.pop_char().unwrap(), 'b'); // 1 bytes
|
||||
assert_eq!(data.pop_char().unwrap(), '华');
|
||||
assert_eq!(data.pop().unwrap(), '𤭢'); // 4 bytes
|
||||
assert_eq!(data.pop().unwrap(), '€'); // 3 bytes
|
||||
assert_eq!(data.pop().unwrap(), '¢'); // 2 bytes
|
||||
assert_eq!(data.pop().unwrap(), 'b'); // 1 bytes
|
||||
assert_eq!(data.pop().unwrap(), '华');
|
||||
assert_eq!(data.as_slice(), "ประเทศไทย中");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)] // use remove(0) instead
|
||||
fn test_shift_char() {
|
||||
let mut data = String::from_str("𤭢€¢b华ประเทศไทย中");
|
||||
assert_eq!(data.shift_char().unwrap(), '𤭢'); // 4 bytes
|
||||
|
@ -2266,8 +2266,8 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mut_slice_from() {
|
||||
let mut values = Vec::from_slice([1u8,2,3,4,5]);
|
||||
fn test_slice_from_mut() {
|
||||
let mut values = vec![1u8,2,3,4,5];
|
||||
{
|
||||
let slice = values.slice_from_mut(2);
|
||||
assert!(slice == [3, 4, 5]);
|
||||
@ -2280,8 +2280,8 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mut_slice_to() {
|
||||
let mut values = Vec::from_slice([1u8,2,3,4,5]);
|
||||
fn test_slice_to_mut() {
|
||||
let mut values = vec![1u8,2,3,4,5];
|
||||
{
|
||||
let slice = values.slice_to_mut(2);
|
||||
assert!(slice == [1, 2]);
|
||||
@ -2294,8 +2294,8 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mut_split_at() {
|
||||
let mut values = Vec::from_slice([1u8,2,3,4,5]);
|
||||
fn test_split_at_mut() {
|
||||
let mut values = vec![1u8,2,3,4,5];
|
||||
{
|
||||
let (left, right) = values.split_at_mut(2);
|
||||
{
|
||||
@ -2315,7 +2315,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
assert!(values == Vec::from_slice([2u8, 3, 5, 6, 7]));
|
||||
assert!(values == vec![2u8, 3, 5, 6, 7]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -2355,16 +2355,16 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_grow_fn() {
|
||||
let mut v = Vec::from_slice([0u, 1]);
|
||||
let mut v = vec![0u, 1];
|
||||
v.grow_fn(3, |i| i);
|
||||
assert!(v == Vec::from_slice([0u, 1, 0, 1, 2]));
|
||||
assert!(v == vec![0u, 1, 0, 1, 2]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_retain() {
|
||||
let mut vec = Vec::from_slice([1u, 2, 3, 4]);
|
||||
let mut vec = vec![1u, 2, 3, 4];
|
||||
vec.retain(|x| x%2 == 0);
|
||||
assert!(vec == Vec::from_slice([2u, 4]));
|
||||
assert!(vec == vec![2u, 4]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -2567,32 +2567,32 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_move_items() {
|
||||
let mut vec = vec!(1i, 2, 3);
|
||||
let mut vec2 : Vec<int> = vec!();
|
||||
let vec = vec![1, 2, 3];
|
||||
let mut vec2 : Vec<i32> = vec![];
|
||||
for i in vec.into_iter() {
|
||||
vec2.push(i);
|
||||
}
|
||||
assert!(vec2 == vec!(1i, 2, 3));
|
||||
assert!(vec2 == vec![1, 2, 3]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_move_items_reverse() {
|
||||
let mut vec = vec!(1i, 2, 3);
|
||||
let mut vec2 : Vec<int> = vec!();
|
||||
let vec = vec![1, 2, 3];
|
||||
let mut vec2 : Vec<i32> = vec![];
|
||||
for i in vec.into_iter().rev() {
|
||||
vec2.push(i);
|
||||
}
|
||||
assert!(vec2 == vec!(3i, 2, 1));
|
||||
assert!(vec2 == vec![3, 2, 1]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_move_items_zero_sized() {
|
||||
let mut vec = vec!((), (), ());
|
||||
let mut vec2 : Vec<()> = vec!();
|
||||
let vec = vec![(), (), ()];
|
||||
let mut vec2 : Vec<()> = vec![];
|
||||
for i in vec.into_iter() {
|
||||
vec2.push(i);
|
||||
}
|
||||
assert!(vec2 == vec!((), (), ()));
|
||||
assert!(vec2 == vec![(), (), ()]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -2707,7 +2707,7 @@ mod tests {
|
||||
b.bytes = src_len as u64;
|
||||
|
||||
b.iter(|| {
|
||||
let dst = Vec::from_slice(src.clone().as_slice());
|
||||
let dst = src.clone().as_slice().to_vec();
|
||||
assert_eq!(dst.len(), src_len);
|
||||
assert!(dst.iter().enumerate().all(|(i, x)| i == *x));
|
||||
});
|
||||
@ -2871,7 +2871,7 @@ mod tests {
|
||||
|
||||
b.iter(|| {
|
||||
let mut dst = dst.clone();
|
||||
dst.push_all_move(src.clone());
|
||||
dst.extend(src.clone().into_iter());
|
||||
assert_eq!(dst.len(), dst_len + src_len);
|
||||
assert!(dst.iter().enumerate().all(|(i, x)| i == *x));
|
||||
});
|
||||
|
@ -117,7 +117,7 @@ fn test_is_digit() {
|
||||
fn test_escape_default() {
|
||||
fn string(c: char) -> String {
|
||||
let mut result = String::new();
|
||||
escape_default(c, |c| { result.push_char(c); });
|
||||
escape_default(c, |c| { result.push(c); });
|
||||
return result;
|
||||
}
|
||||
let s = string('\n');
|
||||
@ -152,7 +152,7 @@ fn test_escape_default() {
|
||||
fn test_escape_unicode() {
|
||||
fn string(c: char) -> String {
|
||||
let mut result = String::new();
|
||||
escape_unicode(c, |c| { result.push_char(c); });
|
||||
escape_unicode(c, |c| { result.push(c); });
|
||||
return result;
|
||||
}
|
||||
let s = string('\x00');
|
||||
|
@ -868,7 +868,7 @@ fn bench_multiple_take(b: &mut Bencher) {
|
||||
let mut it = range(0u, 42).cycle();
|
||||
b.iter(|| {
|
||||
let n = it.next().unwrap();
|
||||
for m in range(0u, n) {
|
||||
for _ in range(0u, n) {
|
||||
it.take(it.next().unwrap()).all(|_| true);
|
||||
}
|
||||
});
|
||||
|
@ -109,7 +109,7 @@ fn test_transmute() {
|
||||
}
|
||||
|
||||
unsafe {
|
||||
assert!(Vec::from_slice([76u8]) == transmute("L".to_string()));
|
||||
assert!(vec![76u8] == transmute("L".to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,6 +89,7 @@ fn test_collect() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)] // we know fold_ is deprecated
|
||||
fn test_fold() {
|
||||
assert_eq!(fold_(range(0i, 0)
|
||||
.map(|_| Ok::<(), ()>(()))),
|
||||
|
@ -682,7 +682,7 @@ mod test {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore(cfg(windows))] // FIXME (#9406)
|
||||
#[cfg_attr(windows, ignore)] // FIXME (#9406)
|
||||
fn test_lots_of_files() {
|
||||
// this is a good test because it touches lots of differently named files
|
||||
glob("/*/*/*/*").skip(10000).next();
|
||||
|
@ -735,6 +735,20 @@ r#"digraph single_edge {
|
||||
"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_some_labelled() {
|
||||
let labels : Trivial = SomeNodesLabelled(vec![Some("A"), None]);
|
||||
let result = test_input(LabelledGraph::new("test_some_labelled", labels,
|
||||
vec![edge(0, 1, "A-1")]));
|
||||
assert_eq!(result.unwrap().as_slice(),
|
||||
r#"digraph test_some_labelled {
|
||||
N0[label="A"];
|
||||
N1[label="N1"];
|
||||
N0 -> N1[label="A-1"];
|
||||
}
|
||||
"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn single_cyclic_node() {
|
||||
let labels : Trivial = UnlabelledNodes(1);
|
||||
|
@ -1027,7 +1027,6 @@ mod test {
|
||||
use std::rt::task::TaskOpts;
|
||||
use std::rt::task::Task;
|
||||
use std::rt::local::Local;
|
||||
use std::time::Duration;
|
||||
|
||||
use {TaskState, PoolConfig, SchedPool};
|
||||
use basic;
|
||||
|
@ -462,6 +462,7 @@ macro_rules! impl_integer_for_uint {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(type_overflow)]
|
||||
fn test_lcm() {
|
||||
assert_eq!((1 as $T).lcm(&0), 0 as $T);
|
||||
assert_eq!((0 as $T).lcm(&1), 0 as $T);
|
||||
|
@ -655,19 +655,19 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn smoke_lock() {
|
||||
static lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
|
||||
static LK: StaticNativeMutex = NATIVE_MUTEX_INIT;
|
||||
unsafe {
|
||||
let _guard = lock.lock();
|
||||
let _guard = LK.lock();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn smoke_cond() {
|
||||
static lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
|
||||
static LK: StaticNativeMutex = NATIVE_MUTEX_INIT;
|
||||
unsafe {
|
||||
let guard = lock.lock();
|
||||
let guard = LK.lock();
|
||||
let t = Thread::start(proc() {
|
||||
let guard = lock.lock();
|
||||
let guard = LK.lock();
|
||||
guard.signal();
|
||||
});
|
||||
guard.wait();
|
||||
@ -679,25 +679,25 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn smoke_lock_noguard() {
|
||||
static lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
|
||||
static LK: StaticNativeMutex = NATIVE_MUTEX_INIT;
|
||||
unsafe {
|
||||
lock.lock_noguard();
|
||||
lock.unlock_noguard();
|
||||
LK.lock_noguard();
|
||||
LK.unlock_noguard();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn smoke_cond_noguard() {
|
||||
static lock: StaticNativeMutex = NATIVE_MUTEX_INIT;
|
||||
static LK: StaticNativeMutex = NATIVE_MUTEX_INIT;
|
||||
unsafe {
|
||||
lock.lock_noguard();
|
||||
LK.lock_noguard();
|
||||
let t = Thread::start(proc() {
|
||||
lock.lock_noguard();
|
||||
lock.signal_noguard();
|
||||
lock.unlock_noguard();
|
||||
LK.lock_noguard();
|
||||
LK.signal_noguard();
|
||||
LK.unlock_noguard();
|
||||
});
|
||||
lock.wait_noguard();
|
||||
lock.unlock_noguard();
|
||||
LK.wait_noguard();
|
||||
LK.unlock_noguard();
|
||||
|
||||
t.join();
|
||||
}
|
||||
|
@ -2964,8 +2964,8 @@ mod tests {
|
||||
let s = "{\"f\":null,\"a\":[null,123]}";
|
||||
let obj: FloatStruct = super::decode(s).unwrap();
|
||||
assert!(obj.f.is_nan());
|
||||
assert!(obj.a.get(0).is_nan());
|
||||
assert_eq!(obj.a.get(1), &123f64);
|
||||
assert!(obj.a[0].is_nan());
|
||||
assert_eq!(obj.a[1], 123f64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -582,15 +582,15 @@ mod tests {
|
||||
assert_eq!('A'.to_ascii().to_char(), 'A');
|
||||
assert_eq!('A'.to_ascii().to_byte(), 65u8);
|
||||
|
||||
assert_eq!('A'.to_ascii().to_lower().to_char(), 'a');
|
||||
assert_eq!('Z'.to_ascii().to_lower().to_char(), 'z');
|
||||
assert_eq!('a'.to_ascii().to_upper().to_char(), 'A');
|
||||
assert_eq!('z'.to_ascii().to_upper().to_char(), 'Z');
|
||||
assert_eq!('A'.to_ascii().to_lowercase().to_char(), 'a');
|
||||
assert_eq!('Z'.to_ascii().to_lowercase().to_char(), 'z');
|
||||
assert_eq!('a'.to_ascii().to_uppercase().to_char(), 'A');
|
||||
assert_eq!('z'.to_ascii().to_uppercase().to_char(), 'Z');
|
||||
|
||||
assert_eq!('@'.to_ascii().to_lower().to_char(), '@');
|
||||
assert_eq!('['.to_ascii().to_lower().to_char(), '[');
|
||||
assert_eq!('`'.to_ascii().to_upper().to_char(), '`');
|
||||
assert_eq!('{'.to_ascii().to_upper().to_char(), '{');
|
||||
assert_eq!('@'.to_ascii().to_lowercase().to_char(), '@');
|
||||
assert_eq!('['.to_ascii().to_lowercase().to_char(), '[');
|
||||
assert_eq!('`'.to_ascii().to_uppercase().to_char(), '`');
|
||||
assert_eq!('{'.to_ascii().to_uppercase().to_char(), '{');
|
||||
|
||||
assert!('0'.to_ascii().is_digit());
|
||||
assert!('9'.to_ascii().is_digit());
|
||||
|
@ -273,8 +273,8 @@ mod tests {
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
flags AnotherSetOfFlags: uint {
|
||||
const AnotherFlag = 1u,
|
||||
flags AnotherSetOfFlags: i8 {
|
||||
const AnotherFlag = -1_i8,
|
||||
}
|
||||
}
|
||||
|
||||
@ -283,6 +283,9 @@ mod tests {
|
||||
assert_eq!(Flags::empty().bits(), 0x00000000);
|
||||
assert_eq!(FlagA.bits(), 0x00000001);
|
||||
assert_eq!(FlagABC.bits(), 0x00000111);
|
||||
|
||||
assert_eq!(AnotherSetOfFlags::empty().bits(), 0x00);
|
||||
assert_eq!(AnotherFlag.bits(), !0_i8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -292,6 +295,8 @@ mod tests {
|
||||
assert!(Flags::from_bits(0x10) == Some(FlagB));
|
||||
assert!(Flags::from_bits(0x11) == Some(FlagA | FlagB));
|
||||
assert!(Flags::from_bits(0x1000) == None);
|
||||
|
||||
assert!(AnotherSetOfFlags::from_bits(!0_i8) == Some(AnotherFlag));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -302,6 +307,8 @@ mod tests {
|
||||
assert!(Flags::from_bits_truncate(0x11) == (FlagA | FlagB));
|
||||
assert!(Flags::from_bits_truncate(0x1000) == Flags::empty());
|
||||
assert!(Flags::from_bits_truncate(0x1001) == FlagA);
|
||||
|
||||
assert!(AnotherSetOfFlags::from_bits_truncate(0_i8) == AnotherSetOfFlags::empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -309,6 +316,8 @@ mod tests {
|
||||
assert!(Flags::empty().is_empty());
|
||||
assert!(!FlagA.is_empty());
|
||||
assert!(!FlagABC.is_empty());
|
||||
|
||||
assert!(!AnotherFlag.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -316,6 +325,8 @@ mod tests {
|
||||
assert!(Flags::all().is_all());
|
||||
assert!(!FlagA.is_all());
|
||||
assert!(FlagABC.is_all());
|
||||
|
||||
assert!(AnotherFlag.is_all());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -323,6 +334,8 @@ mod tests {
|
||||
let e1 = Flags::empty();
|
||||
let e2 = Flags::empty();
|
||||
assert!(!e1.intersects(e2));
|
||||
|
||||
assert!(AnotherFlag.intersects(AnotherFlag));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -353,6 +366,8 @@ mod tests {
|
||||
assert!(!e1.contains(e2));
|
||||
assert!(e2.contains(e1));
|
||||
assert!(FlagABC.contains(e2));
|
||||
|
||||
assert!(AnotherFlag.contains(AnotherFlag));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -361,6 +376,10 @@ mod tests {
|
||||
let e2 = FlagA | FlagB;
|
||||
e1.insert(e2);
|
||||
assert!(e1 == e2);
|
||||
|
||||
let mut e3 = AnotherSetOfFlags::empty();
|
||||
e3.insert(AnotherFlag);
|
||||
assert!(e3 == AnotherFlag);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -369,6 +388,10 @@ mod tests {
|
||||
let e2 = FlagA | FlagC;
|
||||
e1.remove(e2);
|
||||
assert!(e1 == FlagB);
|
||||
|
||||
let mut e3 = AnotherFlag;
|
||||
e3.remove(AnotherFlag);
|
||||
assert!(e3 == AnotherSetOfFlags::empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -383,6 +406,10 @@ mod tests {
|
||||
let mut e3 = e1;
|
||||
e3.toggle(e2);
|
||||
assert!(e3 == FlagA | FlagB);
|
||||
|
||||
let mut m4 = AnotherSetOfFlags::empty();
|
||||
m4.toggle(AnotherSetOfFlags::empty());
|
||||
assert!(m4 == AnotherSetOfFlags::empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1930,6 +1930,7 @@ mod test_map {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)] // insert_or_update_with
|
||||
fn test_update_with() {
|
||||
let mut m = HashMap::with_capacity(4);
|
||||
assert!(m.insert(1i, 2i));
|
||||
|
@ -400,7 +400,7 @@ mod test {
|
||||
|
||||
impl Reader for ShortReader {
|
||||
fn read(&mut self, _: &mut [u8]) -> io::IoResult<uint> {
|
||||
match self.lengths.shift() {
|
||||
match self.lengths.remove(0) {
|
||||
Some(i) => Ok(i),
|
||||
None => Err(io::standard_error(io::EndOfFile))
|
||||
}
|
||||
@ -551,7 +551,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_read_line() {
|
||||
let in_buf = MemReader::new(Vec::from_slice(b"a\nb\nc"));
|
||||
let in_buf = MemReader::new(b"a\nb\nc".to_vec());
|
||||
let mut reader = BufferedReader::with_capacity(2, in_buf);
|
||||
assert_eq!(reader.read_line(), Ok("a\n".to_string()));
|
||||
assert_eq!(reader.read_line(), Ok("b\n".to_string()));
|
||||
@ -561,7 +561,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_lines() {
|
||||
let in_buf = MemReader::new(Vec::from_slice(b"a\nb\nc"));
|
||||
let in_buf = MemReader::new(b"a\nb\nc".to_vec());
|
||||
let mut reader = BufferedReader::with_capacity(2, in_buf);
|
||||
let mut it = reader.lines();
|
||||
assert_eq!(it.next(), Some(Ok("a\n".to_string())));
|
||||
|
@ -1415,7 +1415,7 @@ mod test {
|
||||
check!(copy(&input, &output));
|
||||
|
||||
assert_eq!(check!(File::open(&output).read_to_end()),
|
||||
(Vec::from_slice(b"foo")));
|
||||
b"foo".to_vec());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1459,7 +1459,7 @@ mod test {
|
||||
}
|
||||
assert_eq!(check!(stat(&out)).size, check!(stat(&input)).size);
|
||||
assert_eq!(check!(File::open(&out).read_to_end()),
|
||||
(Vec::from_slice(b"foobar")));
|
||||
b"foobar".to_vec());
|
||||
}
|
||||
|
||||
#[cfg(not(windows))] // apparently windows doesn't like symlinks
|
||||
@ -1497,7 +1497,7 @@ mod test {
|
||||
assert_eq!(check!(stat(&out)).size, check!(stat(&input)).size);
|
||||
assert_eq!(check!(stat(&out)).size, check!(input.stat()).size);
|
||||
assert_eq!(check!(File::open(&out).read_to_end()),
|
||||
(Vec::from_slice(b"foobar")));
|
||||
b"foobar".to_vec());
|
||||
|
||||
// can't link to yourself
|
||||
match link(&input, &input) {
|
||||
@ -1560,7 +1560,7 @@ mod test {
|
||||
check!(file.fsync());
|
||||
assert_eq!(check!(file.stat()).size, 10);
|
||||
assert_eq!(check!(File::open(&path).read_to_end()),
|
||||
(Vec::from_slice(b"foobar\0\0\0\0")));
|
||||
b"foobar\0\0\0\0".to_vec());
|
||||
|
||||
// Truncate to a smaller length, don't seek, and then write something.
|
||||
// Ensure that the intermediate zeroes are all filled in (we're seeked
|
||||
@ -1571,7 +1571,7 @@ mod test {
|
||||
check!(file.fsync());
|
||||
assert_eq!(check!(file.stat()).size, 9);
|
||||
assert_eq!(check!(File::open(&path).read_to_end()),
|
||||
(Vec::from_slice(b"fo\0\0\0\0wut")));
|
||||
b"fo\0\0\0\0wut".to_vec());
|
||||
drop(file);
|
||||
}
|
||||
|
||||
|
@ -617,7 +617,7 @@ mod test {
|
||||
#[bench]
|
||||
fn bench_mem_reader(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
let buf = Vec::from_slice([5 as u8, ..100]);
|
||||
let buf = [5 as u8, ..100].to_vec();
|
||||
{
|
||||
let mut rdr = MemReader::new(buf);
|
||||
for _i in range(0u, 10) {
|
||||
|
@ -1949,62 +1949,62 @@ mod tests {
|
||||
return Ok(0);
|
||||
}
|
||||
};
|
||||
behavior.shift();
|
||||
behavior.remove(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_read_at_least() {
|
||||
let mut r = BadReader::new(MemReader::new(Vec::from_slice(b"hello, world!")),
|
||||
Vec::from_slice([GoodBehavior(uint::MAX)]));
|
||||
let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()),
|
||||
vec![GoodBehavior(uint::MAX)]);
|
||||
let mut buf = [0u8, ..5];
|
||||
assert!(r.read_at_least(1, buf).unwrap() >= 1);
|
||||
assert!(r.read_exact(5).unwrap().len() == 5); // read_exact uses read_at_least
|
||||
assert!(r.read_at_least(0, buf).is_ok());
|
||||
|
||||
let mut r = BadReader::new(MemReader::new(Vec::from_slice(b"hello, world!")),
|
||||
Vec::from_slice([BadBehavior(50), GoodBehavior(uint::MAX)]));
|
||||
let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()),
|
||||
vec![BadBehavior(50), GoodBehavior(uint::MAX)]);
|
||||
assert!(r.read_at_least(1, buf).unwrap() >= 1);
|
||||
|
||||
let mut r = BadReader::new(MemReader::new(Vec::from_slice(b"hello, world!")),
|
||||
Vec::from_slice([BadBehavior(1), GoodBehavior(1),
|
||||
BadBehavior(50), GoodBehavior(uint::MAX)]));
|
||||
let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()),
|
||||
vec![BadBehavior(1), GoodBehavior(1),
|
||||
BadBehavior(50), GoodBehavior(uint::MAX)]);
|
||||
assert!(r.read_at_least(1, buf).unwrap() >= 1);
|
||||
assert!(r.read_at_least(1, buf).unwrap() >= 1);
|
||||
|
||||
let mut r = BadReader::new(MemReader::new(Vec::from_slice(b"hello, world!")),
|
||||
Vec::from_slice([BadBehavior(uint::MAX)]));
|
||||
let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()),
|
||||
vec![BadBehavior(uint::MAX)]);
|
||||
assert_eq!(r.read_at_least(1, buf).unwrap_err().kind, NoProgress);
|
||||
|
||||
let mut r = MemReader::new(Vec::from_slice(b"hello, world!"));
|
||||
let mut r = MemReader::new(b"hello, world!".to_vec());
|
||||
assert_eq!(r.read_at_least(5, buf).unwrap(), 5);
|
||||
assert_eq!(r.read_at_least(6, buf).unwrap_err().kind, InvalidInput);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_push_at_least() {
|
||||
let mut r = BadReader::new(MemReader::new(Vec::from_slice(b"hello, world!")),
|
||||
Vec::from_slice([GoodBehavior(uint::MAX)]));
|
||||
let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()),
|
||||
vec![GoodBehavior(uint::MAX)]);
|
||||
let mut buf = Vec::new();
|
||||
assert!(r.push_at_least(1, 5, &mut buf).unwrap() >= 1);
|
||||
assert!(r.push_at_least(0, 5, &mut buf).is_ok());
|
||||
|
||||
let mut r = BadReader::new(MemReader::new(Vec::from_slice(b"hello, world!")),
|
||||
Vec::from_slice([BadBehavior(50), GoodBehavior(uint::MAX)]));
|
||||
let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()),
|
||||
vec![BadBehavior(50), GoodBehavior(uint::MAX)]);
|
||||
assert!(r.push_at_least(1, 5, &mut buf).unwrap() >= 1);
|
||||
|
||||
let mut r = BadReader::new(MemReader::new(Vec::from_slice(b"hello, world!")),
|
||||
Vec::from_slice([BadBehavior(1), GoodBehavior(1),
|
||||
BadBehavior(50), GoodBehavior(uint::MAX)]));
|
||||
let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()),
|
||||
vec![BadBehavior(1), GoodBehavior(1),
|
||||
BadBehavior(50), GoodBehavior(uint::MAX)]);
|
||||
assert!(r.push_at_least(1, 5, &mut buf).unwrap() >= 1);
|
||||
assert!(r.push_at_least(1, 5, &mut buf).unwrap() >= 1);
|
||||
|
||||
let mut r = BadReader::new(MemReader::new(Vec::from_slice(b"hello, world!")),
|
||||
Vec::from_slice([BadBehavior(uint::MAX)]));
|
||||
let mut r = BadReader::new(MemReader::new(b"hello, world!".to_vec()),
|
||||
vec![BadBehavior(uint::MAX)]);
|
||||
assert_eq!(r.push_at_least(1, 5, &mut buf).unwrap_err().kind, NoProgress);
|
||||
|
||||
let mut r = MemReader::new(Vec::from_slice(b"hello, world!"));
|
||||
let mut r = MemReader::new(b"hello, world!".to_vec());
|
||||
assert_eq!(r.push_at_least(5, 1, &mut buf).unwrap_err().kind, InvalidInput);
|
||||
}
|
||||
|
||||
|
@ -126,9 +126,7 @@ fn lookup(hostname: Option<&str>, servname: Option<&str>, hint: Option<Hint>)
|
||||
#[cfg(all(test, not(target_os = "android")))]
|
||||
mod test {
|
||||
use super::*;
|
||||
use io::net::tcp::*;
|
||||
use io::net::ip::*;
|
||||
use io::net::udp::*;
|
||||
|
||||
#[test]
|
||||
fn dns_smoke_test() {
|
||||
|
@ -521,10 +521,8 @@ impl Clone for TcpAcceptor {
|
||||
#[cfg(test)]
|
||||
#[allow(experimental)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use io::net::tcp::*;
|
||||
use io::net::ip::*;
|
||||
use io::net::udp::*;
|
||||
use io::*;
|
||||
use io::test::*;
|
||||
use prelude::*;
|
||||
|
@ -118,7 +118,6 @@ impl Writer for PipeStream {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use prelude::*;
|
||||
|
||||
#[test]
|
||||
|
@ -727,7 +727,7 @@ mod tests {
|
||||
assert!(p.is_ok());
|
||||
let mut p = p.unwrap();
|
||||
assert!(p.stdout.is_some());
|
||||
let ret = read_all(p.stdout.get_mut_ref() as &mut Reader);
|
||||
let ret = read_all(p.stdout.as_mut().unwrap() as &mut Reader);
|
||||
assert!(p.wait().unwrap().success());
|
||||
return ret;
|
||||
}
|
||||
@ -758,9 +758,9 @@ mod tests {
|
||||
.stdin(CreatePipe(true, false))
|
||||
.stdout(CreatePipe(false, true))
|
||||
.spawn().unwrap();
|
||||
p.stdin.get_mut_ref().write("foobar".as_bytes()).unwrap();
|
||||
p.stdin.as_mut().unwrap().write("foobar".as_bytes()).unwrap();
|
||||
drop(p.stdin.take());
|
||||
let out = read_all(p.stdout.get_mut_ref() as &mut Reader);
|
||||
let out = read_all(p.stdout.as_mut().unwrap() as &mut Reader);
|
||||
assert!(p.wait().unwrap().success());
|
||||
assert_eq!(out, "foobar\n".to_string());
|
||||
}
|
||||
@ -1019,7 +1019,7 @@ mod tests {
|
||||
fn test_add_to_env() {
|
||||
let prog = env_cmd().env("RUN_TEST_NEW_ENV", "123").spawn().unwrap();
|
||||
let result = prog.wait_with_output().unwrap();
|
||||
let output = str::from_utf8_lossy(result.output.as_slice()).into_string();
|
||||
let output = String::from_utf8_lossy(result.output.as_slice()).into_string();
|
||||
|
||||
assert!(output.as_slice().contains("RUN_TEST_NEW_ENV=123"),
|
||||
"didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output);
|
||||
|
@ -385,6 +385,7 @@ mod tests {
|
||||
use super::*;
|
||||
use prelude::*;
|
||||
|
||||
#[test]
|
||||
fn smoke() {
|
||||
// Just make sure we can acquire handles
|
||||
stdin();
|
||||
@ -392,6 +393,7 @@ mod tests {
|
||||
stderr();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn capture_stdout() {
|
||||
use io::{ChanReader, ChanWriter};
|
||||
|
||||
@ -404,9 +406,10 @@ mod tests {
|
||||
assert_eq!(r.read_to_string().unwrap(), "hello!\n".to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn capture_stderr() {
|
||||
use realstd::comm::channel;
|
||||
use realstd::io::{Writer, ChanReader, ChanWriter, Reader};
|
||||
use realstd::io::{ChanReader, ChanWriter, Reader};
|
||||
|
||||
let (tx, rx) = channel();
|
||||
let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx));
|
||||
|
@ -235,7 +235,6 @@ mod test {
|
||||
use super::*;
|
||||
use time::Duration;
|
||||
use task::spawn;
|
||||
use io::*;
|
||||
use prelude::*;
|
||||
|
||||
#[test]
|
||||
|
@ -819,72 +819,82 @@ mod bench {
|
||||
mod uint {
|
||||
use super::test::Bencher;
|
||||
use rand::{weak_rng, Rng};
|
||||
use num::ToStrRadix;
|
||||
use std::fmt;
|
||||
|
||||
#[inline]
|
||||
fn to_string(x: uint, base: u8) {
|
||||
format!("{}", fmt::radix(x, base));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn to_str_bin(b: &mut Bencher) {
|
||||
let mut rng = weak_rng();
|
||||
b.iter(|| { rng.gen::<uint>().to_str_radix(2); })
|
||||
b.iter(|| { to_string(rng.gen::<uint>(), 2); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn to_str_oct(b: &mut Bencher) {
|
||||
let mut rng = weak_rng();
|
||||
b.iter(|| { rng.gen::<uint>().to_str_radix(8); })
|
||||
b.iter(|| { to_string(rng.gen::<uint>(), 8); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn to_str_dec(b: &mut Bencher) {
|
||||
let mut rng = weak_rng();
|
||||
b.iter(|| { rng.gen::<uint>().to_str_radix(10); })
|
||||
b.iter(|| { to_string(rng.gen::<uint>(), 10); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn to_str_hex(b: &mut Bencher) {
|
||||
let mut rng = weak_rng();
|
||||
b.iter(|| { rng.gen::<uint>().to_str_radix(16); })
|
||||
b.iter(|| { to_string(rng.gen::<uint>(), 16); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn to_str_base_36(b: &mut Bencher) {
|
||||
let mut rng = weak_rng();
|
||||
b.iter(|| { rng.gen::<uint>().to_str_radix(36); })
|
||||
b.iter(|| { to_string(rng.gen::<uint>(), 36); })
|
||||
}
|
||||
}
|
||||
|
||||
mod int {
|
||||
use super::test::Bencher;
|
||||
use rand::{weak_rng, Rng};
|
||||
use num::ToStrRadix;
|
||||
use std::fmt;
|
||||
|
||||
#[inline]
|
||||
fn to_string(x: int, base: u8) {
|
||||
format!("{}", fmt::radix(x, base));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn to_str_bin(b: &mut Bencher) {
|
||||
let mut rng = weak_rng();
|
||||
b.iter(|| { rng.gen::<int>().to_str_radix(2); })
|
||||
b.iter(|| { to_string(rng.gen::<int>(), 2); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn to_str_oct(b: &mut Bencher) {
|
||||
let mut rng = weak_rng();
|
||||
b.iter(|| { rng.gen::<int>().to_str_radix(8); })
|
||||
b.iter(|| { to_string(rng.gen::<int>(), 8); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn to_str_dec(b: &mut Bencher) {
|
||||
let mut rng = weak_rng();
|
||||
b.iter(|| { rng.gen::<int>().to_str_radix(10); })
|
||||
b.iter(|| { to_string(rng.gen::<int>(), 10); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn to_str_hex(b: &mut Bencher) {
|
||||
let mut rng = weak_rng();
|
||||
b.iter(|| { rng.gen::<int>().to_str_radix(16); })
|
||||
b.iter(|| { to_string(rng.gen::<int>(), 16); })
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn to_str_base_36(b: &mut Bencher) {
|
||||
let mut rng = weak_rng();
|
||||
b.iter(|| { rng.gen::<int>().to_str_radix(36); })
|
||||
b.iter(|| { to_string(rng.gen::<int>(), 36); })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -775,7 +775,7 @@ mod tests {
|
||||
t!(s: "a/b/c", ["d".to_string(), "e".to_string()], "a/b/c/d/e");
|
||||
t!(v: b"a/b/c", [b"d", b"e"], b"a/b/c/d/e");
|
||||
t!(v: b"a/b/c", [b"d", b"/e", b"f"], b"/e/f");
|
||||
t!(v: b"a/b/c", [Vec::from_slice(b"d"), Vec::from_slice(b"e")], b"a/b/c/d/e");
|
||||
t!(v: b"a/b/c", [b"d".to_vec(), b"e".to_vec()], b"a/b/c/d/e");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -879,7 +879,7 @@ mod tests {
|
||||
t!(s: "a/b/c", ["d", "/e", "f"], "/e/f");
|
||||
t!(s: "a/b/c", ["d".to_string(), "e".to_string()], "a/b/c/d/e");
|
||||
t!(v: b"a/b/c", [b"d", b"e"], b"a/b/c/d/e");
|
||||
t!(v: b"a/b/c", [Vec::from_slice(b"d"), Vec::from_slice(b"e")], b"a/b/c/d/e");
|
||||
t!(v: b"a/b/c", [b"d".to_vec(), b"e".to_vec()], b"a/b/c/d/e");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -76,7 +76,6 @@ mod test {
|
||||
|
||||
use super::ReaderRng;
|
||||
use io::MemReader;
|
||||
use mem;
|
||||
use rand::Rng;
|
||||
|
||||
#[test]
|
||||
@ -87,25 +86,25 @@ mod test {
|
||||
0, 0, 0, 0, 0, 0, 0, 3];
|
||||
let mut rng = ReaderRng::new(MemReader::new(v));
|
||||
|
||||
assert_eq!(rng.next_u64(), mem::to_be64(1));
|
||||
assert_eq!(rng.next_u64(), mem::to_be64(2));
|
||||
assert_eq!(rng.next_u64(), mem::to_be64(3));
|
||||
assert_eq!(rng.next_u64(), 1_u64.to_be());
|
||||
assert_eq!(rng.next_u64(), 2_u64.to_be());
|
||||
assert_eq!(rng.next_u64(), 3_u64.to_be());
|
||||
}
|
||||
#[test]
|
||||
fn test_reader_rng_u32() {
|
||||
let v = vec![0u8, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3];
|
||||
let mut rng = ReaderRng::new(MemReader::new(v));
|
||||
|
||||
assert_eq!(rng.next_u32(), mem::to_be32(1));
|
||||
assert_eq!(rng.next_u32(), mem::to_be32(2));
|
||||
assert_eq!(rng.next_u32(), mem::to_be32(3));
|
||||
assert_eq!(rng.next_u32(), 1_u32.to_be());
|
||||
assert_eq!(rng.next_u32(), 2_u32.to_be());
|
||||
assert_eq!(rng.next_u32(), 3_u32.to_be());
|
||||
}
|
||||
#[test]
|
||||
fn test_reader_rng_fill_bytes() {
|
||||
let v = [1u8, 2, 3, 4, 5, 6, 7, 8];
|
||||
let mut w = [0u8, .. 8];
|
||||
|
||||
let mut rng = ReaderRng::new(MemReader::new(Vec::from_slice(v)));
|
||||
let mut rng = ReaderRng::new(MemReader::new(v.as_slice().to_vec()));
|
||||
rng.fill_bytes(w);
|
||||
|
||||
assert!(v == w);
|
||||
|
@ -447,6 +447,7 @@ mod test {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn test_with_wrapper() {
|
||||
let (tx, rx) = channel();
|
||||
TaskBuilder::new().with_wrapper(proc(body) {
|
||||
|
@ -59,10 +59,11 @@ impl<S:Send,R:Send> DuplexStream<S, R> {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::prelude::*;
|
||||
use comm::{duplex};
|
||||
use comm::duplex;
|
||||
|
||||
#[test]
|
||||
pub fn duplex_stream_1() {
|
||||
|
@ -553,14 +553,12 @@ mod tests {
|
||||
let threads = range(0, NTHREADS).map(|_| {
|
||||
let s = s.clone();
|
||||
Thread::start(proc() {
|
||||
unsafe {
|
||||
loop {
|
||||
match s.steal() {
|
||||
Data(2) => { HITS.fetch_add(1, SeqCst); }
|
||||
Data(..) => fail!(),
|
||||
_ if DONE.load(SeqCst) => break,
|
||||
_ => {}
|
||||
}
|
||||
loop {
|
||||
match s.steal() {
|
||||
Data(2) => { HITS.fetch_add(1, SeqCst); }
|
||||
Data(..) => fail!(),
|
||||
_ if DONE.load(SeqCst) => break,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -572,7 +570,7 @@ mod tests {
|
||||
if rng.gen_range(0i, 3) == 2 {
|
||||
match w.pop() {
|
||||
None => {}
|
||||
Some(2) => unsafe { HITS.fetch_add(1, SeqCst); },
|
||||
Some(2) => { HITS.fetch_add(1, SeqCst); },
|
||||
Some(_) => fail!(),
|
||||
}
|
||||
} else {
|
||||
@ -581,22 +579,20 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
unsafe {
|
||||
while HITS.load(SeqCst) < AMT as uint {
|
||||
match w.pop() {
|
||||
None => {}
|
||||
Some(2) => { HITS.fetch_add(1, SeqCst); },
|
||||
Some(_) => fail!(),
|
||||
}
|
||||
while HITS.load(SeqCst) < AMT as uint {
|
||||
match w.pop() {
|
||||
None => {}
|
||||
Some(2) => { HITS.fetch_add(1, SeqCst); },
|
||||
Some(_) => fail!(),
|
||||
}
|
||||
DONE.store(true, SeqCst);
|
||||
}
|
||||
DONE.store(true, SeqCst);
|
||||
|
||||
for thread in threads.into_iter() {
|
||||
thread.join();
|
||||
}
|
||||
|
||||
assert_eq!(unsafe { HITS.load(SeqCst) }, expected as uint);
|
||||
assert_eq!(HITS.load(SeqCst), expected as uint);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -655,7 +651,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
unsafe { DONE.store(true, SeqCst); }
|
||||
DONE.store(true, SeqCst);
|
||||
|
||||
for thread in threads.into_iter() {
|
||||
thread.join();
|
||||
|
@ -536,32 +536,32 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn smoke_static() {
|
||||
static m: StaticMutex = MUTEX_INIT;
|
||||
static M: StaticMutex = MUTEX_INIT;
|
||||
unsafe {
|
||||
drop(m.lock());
|
||||
drop(m.lock());
|
||||
m.destroy();
|
||||
drop(M.lock());
|
||||
drop(M.lock());
|
||||
M.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lots_and_lots() {
|
||||
static m: StaticMutex = MUTEX_INIT;
|
||||
static M: StaticMutex = MUTEX_INIT;
|
||||
static mut CNT: uint = 0;
|
||||
static M: uint = 1000;
|
||||
static N: uint = 3;
|
||||
static J: uint = 1000;
|
||||
static K: uint = 3;
|
||||
|
||||
fn inc() {
|
||||
for _ in range(0, M) {
|
||||
for _ in range(0, J) {
|
||||
unsafe {
|
||||
let _g = m.lock();
|
||||
let _g = M.lock();
|
||||
CNT += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let (tx, rx) = channel();
|
||||
for _ in range(0, N) {
|
||||
for _ in range(0, K) {
|
||||
let tx2 = tx.clone();
|
||||
native::task::spawn(proc() { inc(); tx2.send(()); });
|
||||
let tx2 = tx.clone();
|
||||
@ -569,12 +569,12 @@ mod test {
|
||||
}
|
||||
|
||||
drop(tx);
|
||||
for _ in range(0, 2 * N) {
|
||||
for _ in range(0, 2 * K) {
|
||||
rx.recv();
|
||||
}
|
||||
assert_eq!(unsafe {CNT}, M * N * 2);
|
||||
assert_eq!(unsafe {CNT}, J * K * 2);
|
||||
unsafe {
|
||||
m.destroy();
|
||||
M.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,17 +126,17 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn smoke_once() {
|
||||
static o: Once = ONCE_INIT;
|
||||
static O: Once = ONCE_INIT;
|
||||
let mut a = 0i;
|
||||
o.doit(|| a += 1);
|
||||
O.doit(|| a += 1);
|
||||
assert_eq!(a, 1);
|
||||
o.doit(|| a += 1);
|
||||
O.doit(|| a += 1);
|
||||
assert_eq!(a, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stampede_once() {
|
||||
static o: Once = ONCE_INIT;
|
||||
static O: Once = ONCE_INIT;
|
||||
static mut run: bool = false;
|
||||
|
||||
let (tx, rx) = channel();
|
||||
@ -145,7 +145,7 @@ mod test {
|
||||
spawn(proc() {
|
||||
for _ in range(0u, 4) { task::deschedule() }
|
||||
unsafe {
|
||||
o.doit(|| {
|
||||
O.doit(|| {
|
||||
assert!(!run);
|
||||
run = true;
|
||||
});
|
||||
@ -156,7 +156,7 @@ mod test {
|
||||
}
|
||||
|
||||
unsafe {
|
||||
o.doit(|| {
|
||||
O.doit(|| {
|
||||
assert!(!run);
|
||||
run = true;
|
||||
});
|
||||
|
@ -575,7 +575,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<Vec<u8> ,String> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::{expand,Words,Variables,Number};
|
||||
use super::{expand,Param,Words,Variables,Number};
|
||||
use std::result::Ok;
|
||||
|
||||
#[test]
|
||||
@ -605,40 +605,39 @@ mod test {
|
||||
fn test_param_stack_failure_conditions() {
|
||||
let mut varstruct = Variables::new();
|
||||
let vars = &mut varstruct;
|
||||
fn get_res(fmt: &str, cap: &str, params: &[Param], vars: &mut Variables) ->
|
||||
Result<Vec<u8>, String>
|
||||
{
|
||||
let mut u8v: Vec<_> = fmt.bytes().collect();
|
||||
u8v.extend(cap.as_bytes().iter().map(|&b| b));
|
||||
expand(u8v.as_slice(), params, vars)
|
||||
}
|
||||
|
||||
let caps = ["%d", "%c", "%s", "%Pa", "%l", "%!", "%~"];
|
||||
for cap in caps.iter() {
|
||||
let res = expand(cap.as_bytes(), [], vars);
|
||||
for &cap in caps.iter() {
|
||||
let res = get_res("", cap, [], vars);
|
||||
assert!(res.is_err(),
|
||||
"Op {} succeeded incorrectly with 0 stack entries", *cap);
|
||||
let p = if *cap == "%s" || *cap == "%l" {
|
||||
"Op {} succeeded incorrectly with 0 stack entries", cap);
|
||||
let p = if cap == "%s" || cap == "%l" {
|
||||
Words("foo".to_string())
|
||||
} else {
|
||||
Number(97)
|
||||
};
|
||||
let res = expand("%p1".bytes().collect::<Vec<_>>()
|
||||
.append(cap.as_bytes()).as_slice(),
|
||||
[p],
|
||||
vars);
|
||||
let res = get_res("%p1", cap, [p], vars);
|
||||
assert!(res.is_ok(),
|
||||
"Op {} failed with 1 stack entry: {}", *cap, res.unwrap_err());
|
||||
"Op {} failed with 1 stack entry: {}", cap, res.unwrap_err());
|
||||
}
|
||||
let caps = ["%+", "%-", "%*", "%/", "%m", "%&", "%|", "%A", "%O"];
|
||||
for cap in caps.iter() {
|
||||
for &cap in caps.iter() {
|
||||
let res = expand(cap.as_bytes(), [], vars);
|
||||
assert!(res.is_err(),
|
||||
"Binop {} succeeded incorrectly with 0 stack entries", *cap);
|
||||
let res = expand("%{1}".bytes().collect::<Vec<_>>()
|
||||
.append(cap.as_bytes()).as_slice(),
|
||||
[],
|
||||
vars);
|
||||
"Binop {} succeeded incorrectly with 0 stack entries", cap);
|
||||
let res = get_res("%{1}", cap, [], vars);
|
||||
assert!(res.is_err(),
|
||||
"Binop {} succeeded incorrectly with 1 stack entry", *cap);
|
||||
let res = expand("%{1}%{2}".bytes().collect::<Vec<_>>()
|
||||
.append(cap.as_bytes()).as_slice(),
|
||||
[],
|
||||
vars);
|
||||
"Binop {} succeeded incorrectly with 1 stack entry", cap);
|
||||
let res = get_res("%{1}%{2}", cap, [], vars);
|
||||
assert!(res.is_ok(),
|
||||
"Binop {} failed with 2 stack entries: {}", *cap, res.unwrap_err());
|
||||
"Binop {} failed with 2 stack entries: {}", cap, res.unwrap_err());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user