Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test specializations #782

Merged
merged 3 commits into from
Oct 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 15 additions & 12 deletions tests/specializations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,25 @@ where
}
}

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>(it: &Iter)
where
IterItem: Eq + Debug + Clone,
Iter: Iterator<Item = IterItem> + Clone,
{
macro_rules! check_specialized {
($src:expr, |$it:pat| $closure:expr) => {
// Many iterators special-case the first elements, so we test specializations for iterators that have already been advanced.
let mut src = $src.clone();
for _ in 0..5 {
let $it = src.clone();
let v1 = $closure;
let $it = Unspecialized(src.clone());
let v2 = $closure;
assert_eq!(v1, v2);
src.next();
}
}
}
check_specialized!(it, |i| i.count());
check_specialized!(it, |i| i.last());
check_specialized!(it, |i| i.collect::<Vec<_>>());
Expand Down Expand Up @@ -127,6 +129,7 @@ quickcheck! {
}

quickcheck! {
// TODO Replace this function by a normal call to test_specializations
fn process_results(v: Vec<Result<u8, u8>>) -> () {
helper(v.iter().copied());
helper(v.iter().copied().filter(Result::is_ok));
Expand Down