From f58ebaca1650dfc6ac8e74eee946825ceff7402d Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 28 Feb 2020 22:25:43 +0100 Subject: Add helper function to fill arena with testing data Signed-off-by: Matthias Beyer --- lib/domain/libimagmail/src/mailtree.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/domain/libimagmail/src/mailtree.rs b/lib/domain/libimagmail/src/mailtree.rs index 3b7ca745..944a0c4b 100644 --- a/lib/domain/libimagmail/src/mailtree.rs +++ b/lib/domain/libimagmail/src/mailtree.rs @@ -52,6 +52,27 @@ impl Mailtree { pub fn traverse(&self) -> Traverse { Traverse::with(self) } + + #[cfg(test)] + fn fill_from_iter(mut it: I) -> Option<(NodeId, Mailtree)> + where I: Iterator + { + let mut arena = Arena::new(); + if let Some(rootdata) = it.next() { + let root = arena.new_node(rootdata); + let mut old_id = root.clone(); + + while let Some(next_data) = it.next() { + let next_id = arena.new_node(next_data); + old_id.append(next_id.clone(), &mut arena); + + old_id = next_id; + } + Some((root, Mailtree { arena, root: root })) + } else { + None + } + } } fn fill_arena_with<'a>(arena: &mut Arena, store: &'a MailStoreWithConnection<'a>, root: LoadedMail) -> Result { -- cgit v1.2.3