summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-02-28 22:25:43 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-06-01 13:58:19 +0200
commitf58ebaca1650dfc6ac8e74eee946825ceff7402d (patch)
treebd5bb06d84f1387f2f7f6d2e658fea96c870d4f2
parent1eee42525000055045845131c7786755b73abcf0 (diff)
Add helper function to fill arena with testing data
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--lib/domain/libimagmail/src/mailtree.rs21
1 files changed, 21 insertions, 0 deletions
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<I>(mut it: I) -> Option<(NodeId, Mailtree)>
+ where I: Iterator<Item = String>
+ {
+ 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<String>, store: &'a MailStoreWithConnection<'a>, root: LoadedMail) -> Result<NodeId> {