Make specializations tests actually test specialized methods
@@ -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>(
@@ -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()));
@@ -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| {
@@ -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();
