From fe6bd78f3c6af912160074318cb0c8c0f375617b Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Tue, 13 Jun 2023 13:21:00 +0200 Subject: [PATCH] testing address --- src/address.rs | 31 +++++++++++++++++++++++++++++++ src/model.rs | 4 ++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/address.rs b/src/address.rs index 92352fd..cbec0d5 100644 --- a/src/address.rs +++ b/src/address.rs @@ -72,6 +72,7 @@ pub fn address_list(input: &str) -> IResult<&str, Vec> { #[cfg(test)] mod tests { use super::*; + use crate::model::AddrSpec; #[test] fn test_mailbox_list() { @@ -85,4 +86,34 @@ mod tests { _ => panic!(), }; } + + #[test] + fn test_address_list() { + assert_eq!( + address_list(r#"A Group:Ed Jones ,joe@where.test,John ;, Mary Smith "#), + Ok(("", vec![ + AddressRef::Many(GroupRef { + name: "A Group".to_string(), + participants: vec![ + MailboxRef { + name: Some("Ed Jones".into()), + addrspec: AddrSpec { local_part: "c".into(), domain: "a.test".into() }, + }, + MailboxRef { + name: None, + addrspec: AddrSpec { local_part: "joe".into(), domain: "where.test".into() }, + }, + MailboxRef { + name: Some("John".into()), + addrspec: AddrSpec { local_part: "jdoe".into(), domain: "one.test".into() }, + }, + ], + }), + AddressRef::Single(MailboxRef { + name: Some("Mary Smith".into()), + addrspec: AddrSpec { local_part: "mary".into(), domain: "x.test".into() }, + }), + ])) + ); + } } diff --git a/src/model.rs b/src/model.rs index 08cce62..e2abbbf 100644 --- a/src/model.rs +++ b/src/model.rs @@ -35,13 +35,13 @@ impl From for MailboxRef { } } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct GroupRef { pub name: String, pub participants: Vec, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub enum AddressRef { Single(MailboxRef), Many(GroupRef),