vec: remove BaseIter implementation

I removed the `static-method-test.rs` test because it was heavily based
on `BaseIter` and there are plenty of other more complex uses of static
methods anyway.
This commit is contained in:
Daniel Micay 2013-06-21 08:29:53 -04:00
parent c9342663df
commit d2e9912aea
181 changed files with 796 additions and 876 deletions

View file

@ -517,6 +517,7 @@ mod tests {
use arc::*;
use core::vec;
use core::cell::Cell;
use core::comm;
use core::task;
@ -725,7 +726,7 @@ mod tests {
}
// Wait for children to pass their asserts
for children.each |r| {
for children.iter().advance |r| {
r.recv();
}
@ -790,7 +791,7 @@ mod tests {
assert_eq!(*state, 42);
*state = 31337;
// send to other readers
for reader_convos.each |x| {
for vec::each(reader_convos) |x| {
match *x {
(ref rc, _) => rc.send(()),
}
@ -799,7 +800,7 @@ mod tests {
let read_mode = arc.downgrade(write_mode);
do (&read_mode).read |state| {
// complete handshake with other readers
for reader_convos.each |x| {
for vec::each(reader_convos) |x| {
match *x {
(_, ref rp) => rp.recv(),
}

View file

@ -421,7 +421,7 @@ mod test {
fn make_file(path : &Path, contents: &[~str]) {
let file = io::file_writer(path, [io::Create, io::Truncate]).get();
for contents.each |&str| {
for contents.iter().advance |&str| {
file.write_str(str);
file.write_char('\n');
}

View file

@ -295,7 +295,7 @@ pub fn getopts(args: &[~str], opts: &[Opt]) -> Result {
}
}
let mut name_pos = 0;
for names.each() |nm| {
for names.iter().advance() |nm| {
name_pos += 1;
let optid = match find_opt(opts, copy *nm) {
Some(id) => id,
@ -373,7 +373,7 @@ pub fn opt_count(mm: &Matches, nm: &str) -> uint {
/// Returns true if any of several options were matched
pub fn opts_present(mm: &Matches, names: &[~str]) -> bool {
for names.each |nm| {
for names.iter().advance |nm| {
match find_opt(mm.opts, mkname(*nm)) {
Some(id) if !mm.vals[id].is_empty() => return true,
_ => (),
@ -400,7 +400,7 @@ pub fn opt_str(mm: &Matches, nm: &str) -> ~str {
* option took an argument
*/
pub fn opts_str(mm: &Matches, names: &[~str]) -> ~str {
for names.each |nm| {
for names.iter().advance |nm| {
match opt_val(mm, *nm) {
Val(ref s) => return copy *s,
_ => ()

View file

@ -1385,7 +1385,7 @@ mod tests {
fn mk_object(items: &[(~str, Json)]) -> Json {
let mut d = ~HashMap::new();
for items.each |item| {
for items.iter().advance |item| {
match *item {
(ref key, ref value) => { d.insert(copy *key, copy *value); },
}

View file

@ -426,7 +426,7 @@ mod test {
let results = result::unwrap(ga_result);
debug!("test_get_addr: Number of results for %s: %?",
localhost_name, results.len());
for results.each |r| {
for results.iter().advance |r| {
let ipv_prefix = match *r {
Ipv4(_) => ~"IPv4",
Ipv6(_) => ~"IPv6"

View file

@ -210,7 +210,7 @@ pub fn encode_form_urlencoded(m: &HashMap<~str, ~[~str]>) -> ~str {
for m.each |key, values| {
let key = encode_plus(*key);
for values.each |value| {
for values.iter().advance |value| {
if first {
first = false;
} else {
@ -342,7 +342,7 @@ fn query_from_str(rawquery: &str) -> Query {
pub fn query_to_str(query: &Query) -> ~str {
let mut strvec = ~[];
for query.each |kv| {
for query.iter().advance |kv| {
match kv {
&(ref k, ref v) => {
strvec.push(fmt!("%s=%s",

View file

@ -1349,7 +1349,7 @@ mod biguint_tests {
#[test]
fn test_add() {
for sum_triples.each |elm| {
for sum_triples.iter().advance |elm| {
let (aVec, bVec, cVec) = *elm;
let a = BigUint::from_slice(aVec);
let b = BigUint::from_slice(bVec);
@ -1362,7 +1362,7 @@ mod biguint_tests {
#[test]
fn test_sub() {
for sum_triples.each |elm| {
for sum_triples.iter().advance |elm| {
let (aVec, bVec, cVec) = *elm;
let a = BigUint::from_slice(aVec);
let b = BigUint::from_slice(bVec);
@ -1413,7 +1413,7 @@ mod biguint_tests {
#[test]
fn test_mul() {
for mul_triples.each |elm| {
for mul_triples.iter().advance |elm| {
let (aVec, bVec, cVec) = *elm;
let a = BigUint::from_slice(aVec);
let b = BigUint::from_slice(bVec);
@ -1423,7 +1423,7 @@ mod biguint_tests {
assert!(b * a == c);
}
for div_rem_quadruples.each |elm| {
for div_rem_quadruples.iter().advance |elm| {
let (aVec, bVec, cVec, dVec) = *elm;
let a = BigUint::from_slice(aVec);
let b = BigUint::from_slice(bVec);
@ -1437,7 +1437,7 @@ mod biguint_tests {
#[test]
fn test_div_rem() {
for mul_triples.each |elm| {
for mul_triples.iter().advance |elm| {
let (aVec, bVec, cVec) = *elm;
let a = BigUint::from_slice(aVec);
let b = BigUint::from_slice(bVec);
@ -1451,7 +1451,7 @@ mod biguint_tests {
}
}
for div_rem_quadruples.each |elm| {
for div_rem_quadruples.iter().advance |elm| {
let (aVec, bVec, cVec, dVec) = *elm;
let a = BigUint::from_slice(aVec);
let b = BigUint::from_slice(bVec);
@ -1567,9 +1567,10 @@ mod biguint_tests {
#[test]
fn test_to_str_radix() {
for to_str_pairs().each |num_pair| {
let r = to_str_pairs();
for r.iter().advance |num_pair| {
let &(n, rs) = num_pair;
for rs.each |str_pair| {
for rs.iter().advance |str_pair| {
let &(radix, str) = str_pair;
assert_eq!(n.to_str_radix(radix), str);
}
@ -1578,9 +1579,10 @@ mod biguint_tests {
#[test]
fn test_from_str_radix() {
for to_str_pairs().each |num_pair| {
let r = to_str_pairs();
for r.iter().advance |num_pair| {
let &(n, rs) = num_pair;
for rs.each |str_pair| {
for rs.iter().advance |str_pair| {
let &(radix, str) = str_pair;
assert_eq!(&n, &FromStrRadix::from_str_radix(str, radix).get());
}
@ -1756,7 +1758,7 @@ mod bigint_tests {
#[test]
fn test_add() {
for sum_triples.each |elm| {
for sum_triples.iter().advance |elm| {
let (aVec, bVec, cVec) = *elm;
let a = BigInt::from_slice(Plus, aVec);
let b = BigInt::from_slice(Plus, bVec);
@ -1775,7 +1777,7 @@ mod bigint_tests {
#[test]
fn test_sub() {
for sum_triples.each |elm| {
for sum_triples.iter().advance |elm| {
let (aVec, bVec, cVec) = *elm;
let a = BigInt::from_slice(Plus, aVec);
let b = BigInt::from_slice(Plus, bVec);
@ -1832,7 +1834,7 @@ mod bigint_tests {
#[test]
fn test_mul() {
for mul_triples.each |elm| {
for mul_triples.iter().advance |elm| {
let (aVec, bVec, cVec) = *elm;
let a = BigInt::from_slice(Plus, aVec);
let b = BigInt::from_slice(Plus, bVec);
@ -1845,7 +1847,7 @@ mod bigint_tests {
assert!((-b) * a == -c);
}
for div_rem_quadruples.each |elm| {
for div_rem_quadruples.iter().advance |elm| {
let (aVec, bVec, cVec, dVec) = *elm;
let a = BigInt::from_slice(Plus, aVec);
let b = BigInt::from_slice(Plus, bVec);
@ -1884,7 +1886,7 @@ mod bigint_tests {
}
}
for mul_triples.each |elm| {
for mul_triples.iter().advance |elm| {
let (aVec, bVec, cVec) = *elm;
let a = BigInt::from_slice(Plus, aVec);
let b = BigInt::from_slice(Plus, bVec);
@ -1894,7 +1896,7 @@ mod bigint_tests {
if !b.is_zero() { check(&c, &b, &a, &Zero::zero()); }
}
for div_rem_quadruples.each |elm| {
for div_rem_quadruples.iter().advance |elm| {
let (aVec, bVec, cVec, dVec) = *elm;
let a = BigInt::from_slice(Plus, aVec);
let b = BigInt::from_slice(Plus, bVec);
@ -1927,7 +1929,7 @@ mod bigint_tests {
check_sub(&a.neg(), b, &q.neg(), &r.neg());
check_sub(&a.neg(), &b.neg(), q, &r.neg());
}
for mul_triples.each |elm| {
for mul_triples.iter().advance |elm| {
let (aVec, bVec, cVec) = *elm;
let a = BigInt::from_slice(Plus, aVec);
let b = BigInt::from_slice(Plus, bVec);
@ -1937,7 +1939,7 @@ mod bigint_tests {
if !b.is_zero() { check(&c, &b, &a, &Zero::zero()); }
}
for div_rem_quadruples.each |elm| {
for div_rem_quadruples.iter().advance |elm| {
let (aVec, bVec, cVec, dVec) = *elm;
let a = BigInt::from_slice(Plus, aVec);
let b = BigInt::from_slice(Plus, bVec);

View file

@ -238,14 +238,14 @@ mod test {
fn test_scale_unscale() {
assert_eq!(_05_05i.scale(2f), _1_1i);
assert_eq!(_1_1i.unscale(2f), _05_05i);
for all_consts.each |&c| {
for all_consts.iter().advance |&c| {
assert_eq!(c.scale(2f).unscale(2f), c);
}
}
#[test]
fn test_conj() {
for all_consts.each |&c| {
for all_consts.iter().advance |&c| {
assert_eq!(c.conj(), Cmplx::new(c.re, -c.im));
assert_eq!(c.conj().conj(), c);
}
@ -282,7 +282,7 @@ mod test {
let (r, theta) = c.to_polar();
assert!((c - Cmplx::from_polar(&r, &theta)).norm() < 1e-6);
}
for all_consts.each |&c| { test(c); }
for all_consts.iter().advance |&c| { test(c); }
}
mod arith {
@ -295,7 +295,7 @@ mod test {
assert_eq!(_0_1i + _1_0i, _1_1i);
assert_eq!(_1_0i + _neg1_1i, _0_1i);
for all_consts.each |&c| {
for all_consts.iter().advance |&c| {
assert_eq!(_0_0i + c, c);
assert_eq!(c + _0_0i, c);
}
@ -307,7 +307,7 @@ mod test {
assert_eq!(_0_1i - _1_0i, _neg1_1i);
assert_eq!(_0_1i - _neg1_1i, _1_0i);
for all_consts.each |&c| {
for all_consts.iter().advance |&c| {
assert_eq!(c - _0_0i, c);
assert_eq!(c - c, _0_0i);
}
@ -322,7 +322,7 @@ mod test {
assert_eq!(_0_1i * _0_1i, -_1_0i);
assert_eq!(_0_1i * _0_1i * _0_1i * _0_1i, _1_0i);
for all_consts.each |&c| {
for all_consts.iter().advance |&c| {
assert_eq!(c * _1_0i, c);
assert_eq!(_1_0i * c, c);
}
@ -330,7 +330,7 @@ mod test {
#[test]
fn test_div() {
assert_eq!(_neg1_1i / _0_1i, _1_1i);
for all_consts.each |&c| {
for all_consts.iter().advance |&c| {
if c != Zero::zero() {
assert_eq!(c / c, _1_0i);
}
@ -340,7 +340,7 @@ mod test {
fn test_neg() {
assert_eq!(-_1_0i + _0_1i, _neg1_1i);
assert_eq!((-_0_1i) * _0_1i, _1_0i);
for all_consts.each |&c| {
for all_consts.iter().advance |&c| {
assert_eq!(-(-c), c);
}
}

View file

@ -482,7 +482,8 @@ mod test {
assert_eq!(FromStr::from_str::<Rational>(s), None);
}
for ["0 /1", "abc", "", "1/", "--1/2","3/2/1"].each |&s| {
let xs = ["0 /1", "abc", "", "1/", "--1/2","3/2/1"];
for xs.iter().advance |&s| {
test(s);
}
}
@ -521,7 +522,8 @@ mod test {
assert_eq!(FromStrRadix::from_str_radix::<Rational>(s, 3), None);
}
for ["0 /1", "abc", "", "1/", "--1/2","3/2/1", "3/2"].each |&s| {
let xs = ["0 /1", "abc", "", "1/", "--1/2","3/2/1", "3/2"];
for xs.iter().advance |&s| {
test(s);
}
}

View file

@ -28,9 +28,9 @@ impl<T:Ord> BaseIter<T> for PriorityQueue<T> {
/// Visit all values in the underlying vector.
///
/// The values are **not** visited in order.
fn each(&self, f: &fn(&T) -> bool) -> bool { self.data.each(f) }
fn each(&self, f: &fn(&T) -> bool) -> bool { self.data.iter().advance(f) }
fn size_hint(&self) -> Option<uint> { self.data.size_hint() }
fn size_hint(&self) -> Option<uint> { Some(self.data.len()) }
}
impl<T:Ord> Container for PriorityQueue<T> {

View file

@ -250,7 +250,7 @@ pub fn sha1() -> @Sha1 {
fn result_str(&mut self) -> ~str {
let rr = mk_result(self);
let mut s = ~"";
for rr.each |b| {
for rr.iter().advance |b| {
let hex = uint::to_str_radix(*b as uint, 16u);
if hex.len() == 1 {
s += "0";
@ -375,7 +375,7 @@ mod tests {
// Test that it works when accepting the message all at once
let mut sh = sha1::sha1();
for tests.each |t| {
for tests.iter().advance |t| {
sh.input_str(t.input);
let out = sh.result();
check_vec_eq(copy t.output, out);
@ -389,7 +389,7 @@ mod tests {
// Test that it works when accepting the message in pieces
for tests.each |t| {
for tests.iter().advance |t| {
let len = t.input.len();
let mut left = len;
while left > 0u {

View file

@ -846,7 +846,7 @@ mod test_qsort {
let immut_names = names;
let pairs = vec::zip_slice(expected, immut_names);
for pairs.each |p| {
for pairs.iter().advance |p| {
let (a, b) = *p;
debug!("%d %d", a, b);
assert_eq!(a, b);

View file

@ -72,7 +72,7 @@ impl<'self> Stats for &'self [f64] {
} else {
let mean = self.mean();
let mut v = 0.0;
for self.each |s| {
for self.iter().advance |s| {
let x = *s - mean;
v += x*x;
}

View file

@ -994,13 +994,13 @@ mod tests {
}
// wait until all children get in the mutex
for ports.each |port| { let _ = port.recv(); }
for ports.iter().advance |port| { let _ = port.recv(); }
do m.lock_cond |cond| {
let num_woken = cond.broadcast();
assert_eq!(num_woken, num_waiters);
}
// wait until all children wake up
for ports.each |port| { let _ = port.recv(); }
for ports.iter().advance |port| { let _ = port.recv(); }
}
#[test]
fn test_mutex_cond_broadcast() {
@ -1085,7 +1085,7 @@ mod tests {
}
}
}
for sibling_convos.each |p| {
for sibling_convos.iter().advance |p| {
let _ = p.recv(); // wait for sibling to get in the mutex
}
do m2.lock { }
@ -1361,13 +1361,13 @@ mod tests {
}
// wait until all children get in the mutex
for ports.each |port| { let _ = port.recv(); }
for ports.iter().advance |port| { let _ = port.recv(); }
do lock_cond(x, dg2) |cond| {
let num_woken = cond.broadcast();
assert_eq!(num_woken, num_waiters);
}
// wait until all children wake up
for ports.each |port| { let _ = port.recv(); }
for ports.iter().advance |port| { let _ = port.recv(); }
}
#[test]
fn test_rwlock_cond_broadcast() {

View file

@ -36,7 +36,7 @@ pub struct TaskPool<T> {
#[unsafe_destructor]
impl<T> Drop for TaskPool<T> {
fn finalize(&self) {
for self.channels.each |channel| {
for self.channels.iter().advance |channel| {
channel.send(Quit);
}
}

View file

@ -55,7 +55,7 @@ pub fn get_dbpath_for_term(term: &str) -> Option<~path> {
};
// Look for the terminal in all of the search directories
for dirs_to_search.each |p| {
for dirs_to_search.iter().advance |p| {
let newp = ~p.push_many(&[str::from_char(first_char), term.to_owned()]);
if os::path_exists(p) && os::path_exists(newp) {
return Some(newp);

View file

@ -369,7 +369,7 @@ fn print_failures(st: &ConsoleTestState) {
failures.push(name.to_str());
}
sort::tim_sort(failures);
for failures.each |name| {
for failures.iter().advance |name| {
st.out.write_line(fmt!(" %s", name.to_str()));
}
}
@ -947,7 +947,7 @@ mod tests {
{
fn testfn() { }
let mut tests = ~[];
for names.each |name| {
for names.iter().advance |name| {
let test = TestDescAndFn {
desc: TestDesc {
name: DynTestName(copy *name),
@ -973,7 +973,7 @@ mod tests {
let pairs = vec::zip(expected, filtered);
for pairs.each |p| {
for pairs.iter().advance |p| {
match *p {
(ref a, ref b) => {
assert!(*a == b.desc.name.to_str());

View file

@ -1033,7 +1033,7 @@ mod tests {
}
}
for [
let days = [
~"Sunday",
~"Monday",
~"Tuesday",
@ -1041,11 +1041,12 @@ mod tests {
~"Thursday",
~"Friday",
~"Saturday"
].each |day| {
];
for days.iter().advance |day| {
assert!(test(*day, "%A"));
}
for [
let days = [
~"Sun",
~"Mon",
~"Tue",
@ -1053,11 +1054,12 @@ mod tests {
~"Thu",
~"Fri",
~"Sat"
].each |day| {
];
for days.iter().advance |day| {
assert!(test(*day, "%a"));
}
for [
let months = [
~"January",
~"February",
~"March",
@ -1070,11 +1072,12 @@ mod tests {
~"October",
~"November",
~"December"
].each |day| {
];
for months.iter().advance |day| {
assert!(test(*day, "%B"));
}
for [
let months = [
~"Jan",
~"Feb",
~"Mar",
@ -1087,7 +1090,8 @@ mod tests {
~"Oct",
~"Nov",
~"Dec"
].each |day| {
];
for months.iter().advance |day| {
assert!(test(*day, "%b"));
}

View file

@ -217,7 +217,7 @@ mod test {
for repeat.times {
let ch = ch.clone();
for spec.each |spec| {
for spec.iter().advance |spec| {
let (times, maxms) = *spec;
let ch = ch.clone();
let hl_loop_clone = hl_loop.clone();

View file

@ -781,13 +781,13 @@ mod test_treemap {
fn check_equal<K: Eq + TotalOrd, V: Eq>(ctrl: &[(K, V)],
map: &TreeMap<K, V>) {
assert_eq!(ctrl.is_empty(), map.is_empty());
for ctrl.each |x| {
for ctrl.iter().advance |x| {
let &(k, v) = x;
assert!(map.find(&k).unwrap() == &v)
}
for map.each |map_k, map_v| {
let mut found = false;
for ctrl.each |x| {
for ctrl.iter().advance |x| {
let &(ctrl_k, ctrl_v) = x;
if *map_k == ctrl_k {
assert!(*map_v == ctrl_v);
@ -1135,8 +1135,8 @@ mod test_set {
let mut set_a = TreeSet::new();
let mut set_b = TreeSet::new();
for a.each |x| { assert!(set_a.insert(*x)) }
for b.each |y| { assert!(set_b.insert(*y)) }
for a.iter().advance |x| { assert!(set_a.insert(*x)) }
for b.iter().advance |y| { assert!(set_b.insert(*y)) }
let mut i = 0;
for f(&set_a, &set_b) |x| {

View file

@ -157,7 +157,7 @@ impl<D:Decoder> Decodable<D> for WorkMap {
fn decode(d: &mut D) -> WorkMap {
let v : ~[(WorkKey,~str)] = Decodable::decode(d);
let mut w = WorkMap::new();
for v.each |&(k, v)| {
for v.iter().advance |&(k, v)| {
w.insert(copy k, copy v);
}
w