Skip to content

Commit

Permalink
Convert delegate doctest to unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed May 12, 2022
1 parent 9dc52d7 commit 36bd58a
Showing 1 changed file with 48 additions and 9 deletions.
57 changes: 48 additions & 9 deletions src/delegate.rs
Original file line number Diff line number Diff line change
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]);
}

0 comments on commit 36bd58a

Please sign in to comment.