From 36bd58aa3d6aeae1be648dd3fe7904aa3ebd7d74 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 12 May 2022 16:34:55 -0700 Subject: [PATCH] Convert delegate doctest to unit tests --- src/delegate.rs | 57 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/src/delegate.rs b/src/delegate.rs index a537489cb..2a6e33193 100644 --- a/src/delegate.rs +++ b/src/delegate.rs @@ -8,15 +8,6 @@ /// declared with an `inner` field. /// /// The implementation of `IntoParallelIterator` should be added separately. -/// -/// # Example -/// -/// ``` -/// delegate_iterator!{ -/// MyIntoIter => (T, U), -/// impl -/// } -/// ``` macro_rules! delegate_iterator { ($iter:ty => $item:ty , impl $( $args:tt )* @@ -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 { + inner: IntoIter, + } + + delegate_iterator! { + MyIntoIter => (T, U), + impl + } + + 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 { + inner: IntoIter, + } + + delegate_indexed_iterator! { + MyIntoIter => T, + impl + } + + 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]); +}