From fd5b6786d29d056ff0721a59435b50005f13f05c Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 9 Oct 2022 20:41:09 +0200 Subject: test: add more unit tests --- macros/src/util/iterator_ext.rs | 57 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) (limited to 'macros/src/util/iterator_ext.rs') diff --git a/macros/src/util/iterator_ext.rs b/macros/src/util/iterator_ext.rs index 86db6cb..5001068 100644 --- a/macros/src/util/iterator_ext.rs +++ b/macros/src/util/iterator_ext.rs @@ -9,7 +9,7 @@ pub trait IteratorExt impl IteratorExt for Iter where Iter: Iterator, - Iter::Item: Eq + Hash + Copy, + Iter::Item: Eq + Hash + Clone, { fn find_duplicate(&mut self) -> Option { @@ -26,3 +26,58 @@ where None } } + +#[cfg(test)] +mod tests +{ + use super::*; + + #[test] + fn can_find_duplicate() + { + #[derive(Debug, PartialEq, Eq, Clone, Hash)] + struct Fruit + { + name: String, + } + + assert_eq!( + vec![ + Fruit { + name: "Apple".to_string(), + }, + Fruit { + name: "Banana".to_string(), + }, + Fruit { + name: "Apple".to_string(), + }, + Fruit { + name: "Orange".to_string(), + }, + ] + .iter() + .find_duplicate(), + Some(&Fruit { + name: "Apple".to_string() + }) + ); + + assert_eq!( + vec![ + Fruit { + name: "Banana".to_string(), + }, + Fruit { + name: "Apple".to_string(), + }, + Fruit { + name: "Orange".to_string(), + }, + ] + .iter() + .find_duplicate(), + None + ); + } +} -- cgit v1.2.3-18-g5258