diff --git a/src/utils.rs b/src/utils.rs index 9719f88a..b5aa3c20 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -36,6 +36,7 @@ pub fn write_byte_string(f: &mut Formatter, byte_string: &[u8]) -> fmt::Result { Ok(()) } +/// An iterator that merges two sorted iterators into one sorted iterator pub(crate) struct MergeIter where It1: Iterator, @@ -284,4 +285,30 @@ mod tests { ]); assert_eq!(format!("{:?}", bytes), r##""Class IRI=\"#B\"""##); } + + #[test] + fn merge_empty() { + let iter = MergeIter::new(vec![].into_iter(), vec![].into_iter()); + assert_eq!(iter.collect::>(), vec![]); + } + + #[test] + fn merge_single_empty() { + let iter = MergeIter::new(vec![1].into_iter(), vec![].into_iter()); + assert_eq!(iter.collect::>(), vec![1]); + let iter = MergeIter::new(vec![].into_iter(), vec![1].into_iter()); + assert_eq!(iter.collect::>(), vec![1]); + } + + #[test] + fn merge_whole_side_before() { + let iter = MergeIter::new(vec![1, 2, 3].into_iter(), vec![4, 5, 6].into_iter()); + assert_eq!(iter.collect::>(), vec![1, 2, 3, 4, 5, 6]); + } + + #[test] + fn merge_interleave() { + let iter = MergeIter::new(vec![1, 2, 8, 20].into_iter(), vec![3, 4, 22, 23].into_iter()); + assert_eq!(iter.collect::>(), vec![1, 2, 3, 4, 8, 20, 22, 23]); + } }