Skip to content

Commit fc152cd

Browse files
committed
move 'test zip ...' tests
1 parent af44a2a commit fc152cd

File tree

2 files changed

+95
-103
lines changed

2 files changed

+95
-103
lines changed

Diff for: library/core/tests/iter.rs

+95
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,101 @@ fn test_zip_next_back_side_effects_exhausted() {
376376
assert_eq!(b, vec![200, 300, 400]);
377377
}
378378

379+
#[derive(Debug)]
380+
struct CountClone(Cell<i32>);
381+
382+
fn count_clone() -> CountClone { CountClone(Cell::new(0)) }
383+
384+
impl PartialEq<i32> for CountClone {
385+
fn eq(&self, rhs: &i32) -> bool {
386+
self.0.get() == *rhs
387+
}
388+
}
389+
390+
impl Clone for CountClone {
391+
fn clone(&self) -> Self {
392+
let ret = CountClone(self.0.clone());
393+
let n = self.0.get();
394+
self.0.set(n + 1);
395+
ret
396+
}
397+
}
398+
399+
#[test]
400+
fn test_zip_cloned_sideffectful() {
401+
let xs = [count_clone(), count_clone(), count_clone(), count_clone()];
402+
let ys = [count_clone(), count_clone()];
403+
404+
for _ in xs.iter().cloned().zip(ys.iter().cloned()) { }
405+
406+
assert_eq!(&xs, &[1, 1, 1, 0][..]);
407+
assert_eq!(&ys, &[1, 1][..]);
408+
409+
let xs = [count_clone(), count_clone()];
410+
let ys = [count_clone(), count_clone(), count_clone(), count_clone()];
411+
412+
for _ in xs.iter().cloned().zip(ys.iter().cloned()) { }
413+
414+
assert_eq!(&xs, &[1, 1][..]);
415+
assert_eq!(&ys, &[1, 1, 0, 0][..]);
416+
}
417+
418+
#[test]
419+
fn test_zip_map_sideffectful() {
420+
let mut xs = [0; 6];
421+
let mut ys = [0; 4];
422+
423+
for _ in xs.iter_mut().map(|x| *x += 1).zip(ys.iter_mut().map(|y| *y += 1)) { }
424+
425+
assert_eq!(&xs, &[1, 1, 1, 1, 1, 0]);
426+
assert_eq!(&ys, &[1, 1, 1, 1]);
427+
428+
let mut xs = [0; 4];
429+
let mut ys = [0; 6];
430+
431+
for _ in xs.iter_mut().map(|x| *x += 1).zip(ys.iter_mut().map(|y| *y += 1)) { }
432+
433+
assert_eq!(&xs, &[1, 1, 1, 1]);
434+
assert_eq!(&ys, &[1, 1, 1, 1, 0, 0]);
435+
}
436+
437+
#[test]
438+
fn test_zip_map_rev_sideffectful() {
439+
let mut xs = [0; 6];
440+
let mut ys = [0; 4];
441+
442+
{
443+
let mut it = xs.iter_mut().map(|x| *x += 1).zip(ys.iter_mut().map(|y| *y += 1));
444+
it.next_back();
445+
}
446+
assert_eq!(&xs, &[0, 0, 0, 1, 1, 1]);
447+
assert_eq!(&ys, &[0, 0, 0, 1]);
448+
449+
let mut xs = [0; 6];
450+
let mut ys = [0; 4];
451+
452+
{
453+
let mut it = xs.iter_mut().map(|x| *x += 1).zip(ys.iter_mut().map(|y| *y += 1));
454+
(&mut it).take(5).count();
455+
it.next_back();
456+
}
457+
assert_eq!(&xs, &[1, 1, 1, 1, 1, 1]);
458+
assert_eq!(&ys, &[1, 1, 1, 1]);
459+
}
460+
461+
#[test]
462+
fn test_zip_nested_sideffectful() {
463+
let mut xs = [0; 6];
464+
let ys = [0; 4];
465+
466+
{
467+
// test that it has the side effect nested inside enumerate
468+
let it = xs.iter_mut().map(|x| *x = 1).enumerate().zip(&ys);
469+
it.count();
470+
}
471+
assert_eq!(&xs, &[1, 1, 1, 1, 1, 0]);
472+
}
473+
379474
#[test]
380475
fn test_zip_nth_back_side_effects_exhausted() {
381476
let mut a = Vec::new();

Diff for: src/test/ui/iterators/iter-zip.rs

-103
This file was deleted.

0 commit comments

Comments
 (0)