mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 00:03:43 +00:00
dlist: handle iter early break properly
This commit is contained in:
parent
1ffc0720bb
commit
e993b838ca
@ -441,6 +441,16 @@ mod tests {
|
||||
assert iter::foldl(l, 0, |accum,elem| accum+elem) == 5050;
|
||||
}
|
||||
#[test]
|
||||
fn test_dlist_break_early() {
|
||||
let l = from_vec(~[1,2,3,4,5]);
|
||||
let mut x = 0;
|
||||
for l.each |i| {
|
||||
x += 1;
|
||||
if (i == 3) { break; }
|
||||
}
|
||||
assert x == 3;
|
||||
}
|
||||
#[test]
|
||||
fn test_dlist_remove_head() {
|
||||
let l = create::<int>();
|
||||
l.assert_consistent(); let one = l.push_n(1);
|
||||
|
@ -18,7 +18,7 @@ fn EACH<A>(self: IMPL_T<A>, f: fn(A) -> bool) {
|
||||
!box::ptr_eq(*option::get(nobe.root), *self) {
|
||||
fail "Iteration encountered a dlist node not on this dlist."
|
||||
}
|
||||
f(nobe.data);
|
||||
if !f(nobe.data) { break; }
|
||||
// Check that the user didn't do a remove.
|
||||
// Note that this makes it ok for the user to remove the node and then
|
||||
// immediately put it back in a different position. I allow this.
|
||||
|
Loading…
Reference in New Issue
Block a user