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

Convert delegate doctest to unit tests #935

Merged
merged 1 commit into from May 12, 2022
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
57 changes: 48 additions & 9 deletions src/delegate.rs
Expand Up @@ -8,15 +8,6 @@
/// declared with an `inner` field.
///
/// The implementation of `IntoParallelIterator` should be added separately.
///
/// # Example
///
/// ```
/// delegate_iterator!{
/// MyIntoIter<T, U> => (T, U),
/// impl<T: Ord + Send, U: Send>
/// }
/// ```
macro_rules! delegate_iterator {
($iter:ty => $item:ty ,
impl $( $args:tt )*
Expand Down Expand Up @@ -68,3 +59,51 @@ macro_rules! delegate_indexed_iterator {
}
}
}

#[test]
fn unindexed_example() {
use crate::collections::btree_map::IntoIter;
use crate::iter::plumbing::*;
use crate::prelude::*;

use std::collections::BTreeMap;

struct MyIntoIter<T: Ord + Send, U: Send> {
inner: IntoIter<T, U>,
}

delegate_iterator! {
MyIntoIter<T, U> => (T, U),
impl<T: Ord + Send, U: Send>
}

let map = BTreeMap::from([(1, 'a'), (2, 'b'), (3, 'c')]);
let iter = MyIntoIter {
inner: map.into_par_iter(),
};
let vec: Vec<_> = iter.map(|(k, _)| k).collect();
assert_eq!(vec, &[1, 2, 3]);
}

#[test]
fn indexed_example() {
use crate::iter::plumbing::*;
use crate::prelude::*;
use crate::vec::IntoIter;

struct MyIntoIter<T: Send> {
inner: IntoIter<T>,
}

delegate_indexed_iterator! {
MyIntoIter<T> => T,
impl<T: Send>
}

let iter = MyIntoIter {
inner: vec![1, 2, 3].into_par_iter(),
};
let mut vec = vec![];
iter.collect_into_vec(&mut vec);
assert_eq!(vec, &[1, 2, 3]);
}