test: Use the new for protocol
This commit is contained in:
@@ -393,6 +393,7 @@ pub impl<T> DList<T> {
|
||||
}
|
||||
|
||||
/// Iterate over nodes.
|
||||
#[cfg(stage0)]
|
||||
fn each_node(@mut self, f: &fn(@mut DListNode<T>) -> bool) {
|
||||
let mut link = self.peek_n();
|
||||
while link.is_some() {
|
||||
@@ -401,6 +402,17 @@ pub impl<T> DList<T> {
|
||||
link = nobe.next_link();
|
||||
}
|
||||
}
|
||||
/// Iterate over nodes.
|
||||
#[cfg(not(stage0))]
|
||||
fn each_node(@mut self, f: &fn(@mut DListNode<T>) -> bool) -> bool {
|
||||
let mut link = self.peek_n();
|
||||
while link.is_some() {
|
||||
let nobe = link.get();
|
||||
if !f(nobe) { return false; }
|
||||
link = nobe.next_link();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Check data structure integrity. O(n).
|
||||
fn assert_consistent(@mut self) {
|
||||
|
||||
@@ -256,10 +256,21 @@ impl FileInput {
|
||||
(line numbers and file names, see documentation for
|
||||
`FileInputState`). Otherwise identical to `lines_each`.
|
||||
*/
|
||||
#[cfg(stage0)]
|
||||
pub fn each_line_state(&self,
|
||||
f: &fn(&str, FileInputState) -> bool) {
|
||||
self.each_line(|line| f(line, copy self.fi.state));
|
||||
}
|
||||
/**
|
||||
Apply `f` to each line successively, along with some state
|
||||
(line numbers and file names, see documentation for
|
||||
`FileInputState`). Otherwise identical to `lines_each`.
|
||||
*/
|
||||
#[cfg(not(stage0))]
|
||||
pub fn each_line_state(&self,
|
||||
f: &fn(&str, FileInputState) -> bool) -> bool {
|
||||
self.each_line(|line| f(line, copy self.fi.state))
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -367,10 +378,22 @@ reading from `stdin`).
|
||||
|
||||
Fails when attempting to read from a file that can't be opened.
|
||||
*/
|
||||
#[cfg(stage0)]
|
||||
pub fn input(f: &fn(&str) -> bool) {
|
||||
let mut i = FileInput::from_args();
|
||||
i.each_line(f);
|
||||
}
|
||||
/**
|
||||
Iterate directly over the command line arguments (no arguments implies
|
||||
reading from `stdin`).
|
||||
|
||||
Fails when attempting to read from a file that can't be opened.
|
||||
*/
|
||||
#[cfg(not(stage0))]
|
||||
pub fn input(f: &fn(&str) -> bool) -> bool {
|
||||
let mut i = FileInput::from_args();
|
||||
i.each_line(f)
|
||||
}
|
||||
|
||||
/**
|
||||
Iterate directly over the command line arguments (no arguments
|
||||
@@ -379,20 +402,44 @@ provided at each call.
|
||||
|
||||
Fails when attempting to read from a file that can't be opened.
|
||||
*/
|
||||
#[cfg(stage0)]
|
||||
pub fn input_state(f: &fn(&str, FileInputState) -> bool) {
|
||||
let mut i = FileInput::from_args();
|
||||
i.each_line_state(f);
|
||||
}
|
||||
/**
|
||||
Iterate directly over the command line arguments (no arguments
|
||||
implies reading from `stdin`) with the current state of the iteration
|
||||
provided at each call.
|
||||
|
||||
Fails when attempting to read from a file that can't be opened.
|
||||
*/
|
||||
#[cfg(not(stage0))]
|
||||
pub fn input_state(f: &fn(&str, FileInputState) -> bool) -> bool {
|
||||
let mut i = FileInput::from_args();
|
||||
i.each_line_state(f)
|
||||
}
|
||||
|
||||
/**
|
||||
Iterate over a vector of files (an empty vector implies just `stdin`).
|
||||
|
||||
Fails when attempting to read from a file that can't be opened.
|
||||
*/
|
||||
#[cfg(stage0)]
|
||||
pub fn input_vec(files: ~[Option<Path>], f: &fn(&str) -> bool) {
|
||||
let mut i = FileInput::from_vec(files);
|
||||
i.each_line(f);
|
||||
}
|
||||
/**
|
||||
Iterate over a vector of files (an empty vector implies just `stdin`).
|
||||
|
||||
Fails when attempting to read from a file that can't be opened.
|
||||
*/
|
||||
#[cfg(not(stage0))]
|
||||
pub fn input_vec(files: ~[Option<Path>], f: &fn(&str) -> bool) -> bool {
|
||||
let mut i = FileInput::from_vec(files);
|
||||
i.each_line(f)
|
||||
}
|
||||
|
||||
/**
|
||||
Iterate over a vector of files (an empty vector implies just `stdin`)
|
||||
@@ -400,11 +447,24 @@ with the current state of the iteration provided at each call.
|
||||
|
||||
Fails when attempting to read from a file that can't be opened.
|
||||
*/
|
||||
#[cfg(stage0)]
|
||||
pub fn input_vec_state(files: ~[Option<Path>],
|
||||
f: &fn(&str, FileInputState) -> bool) {
|
||||
let mut i = FileInput::from_vec(files);
|
||||
i.each_line_state(f);
|
||||
}
|
||||
/**
|
||||
Iterate over a vector of files (an empty vector implies just `stdin`)
|
||||
with the current state of the iteration provided at each call.
|
||||
|
||||
Fails when attempting to read from a file that can't be opened.
|
||||
*/
|
||||
#[cfg(not(stage0))]
|
||||
pub fn input_vec_state(files: ~[Option<Path>],
|
||||
f: &fn(&str, FileInputState) -> bool) -> bool {
|
||||
let mut i = FileInput::from_vec(files);
|
||||
i.each_line_state(f)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
@@ -674,7 +674,7 @@ impl<T: TotalOrd> Set<T> for TreeSet<T> {
|
||||
a = x.next();
|
||||
}
|
||||
}
|
||||
return a.each(|&x| f(x)) && y.advance(f);
|
||||
return b.each(|&x| f(x)) && y.advance(f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1326,7 +1326,7 @@ mod test_set {
|
||||
}
|
||||
|
||||
fn check(a: &[int], b: &[int], expected: &[int],
|
||||
f: &fn(&TreeSet<int>, &TreeSet<int>, f: &fn(&int) -> bool)) {
|
||||
f: &fn(&TreeSet<int>, &TreeSet<int>, f: &fn(&int) -> bool) -> bool) {
|
||||
let mut set_a = TreeSet::new();
|
||||
let mut set_b = TreeSet::new();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user