Skip to content

Commit

Permalink
Make specializations tests actually test specialized methods
Browse files Browse the repository at this point in the history
  • Loading branch information
SkiFire13 committed Aug 20, 2021
1 parent 949610d commit bf4ca16
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions tests/specializations.rs
Expand Up @@ -15,16 +15,16 @@ where
}
}

fn check_specialized<'a, V, IterItem, Iter, F>(iterator: &Iter, mapper: F)
where
V: Eq + Debug,
Iter: Iterator<Item = IterItem> + Clone + 'a,
F: Fn(Box<dyn Iterator<Item = IterItem> + 'a>) -> V,
{
assert_eq!(
mapper(Box::new(Unspecialized(iterator.clone()))),
mapper(Box::new(iterator.clone()))
)
macro_rules! check_specialized {
($src:expr, |$it:pat| $closure:expr) => {
let $it = $src.clone();
let v1 = $closure;

let $it = Unspecialized($src.clone());
let v2 = $closure;

assert_eq!(v1, v2);
}
}

fn test_specializations<IterItem, Iter>(
Expand All @@ -33,10 +33,10 @@ fn test_specializations<IterItem, Iter>(
IterItem: Eq + Debug + Clone,
Iter: Iterator<Item = IterItem> + Clone,
{
check_specialized(it, |i| i.count());
check_specialized(it, |i| i.last());
check_specialized(it, |i| i.collect::<Vec<_>>());
check_specialized(it, |i| {
check_specialized!(it, |i| i.count());
check_specialized!(it, |i| i.last());
check_specialized!(it, |i| i.collect::<Vec<_>>());
check_specialized!(it, |i| {
let mut parameters_from_fold = vec![];
let fold_result = i.fold(vec![], |mut acc, v: IterItem| {
parameters_from_fold.push((acc.clone(), v.clone()));
Expand All @@ -45,7 +45,7 @@ fn test_specializations<IterItem, Iter>(
});
(parameters_from_fold, fold_result)
});
check_specialized(it, |mut i| {
check_specialized!(it, |mut i| {
let mut parameters_from_all = vec![];
let first = i.next();
let all_result = i.all(|x| {
Expand All @@ -56,7 +56,7 @@ fn test_specializations<IterItem, Iter>(
});
let size = it.clone().count();
for n in 0..size + 2 {
check_specialized(it, |mut i| i.nth(n));
check_specialized!(it, |mut i| i.nth(n));
}
// size_hint is a bit harder to check
let mut it_sh = it.clone();
Expand Down

0 comments on commit bf4ca16

Please sign in to comment.