use crate::{
client::result::{ParsedClientResult, ParsedRXingResult, ParsedRXingResultType, ResultParser},
BarcodeFormat, RXingResult,
};
#[test]
fn testEmailAddress() {
do_test_single("srowen@example.org", "srowen@example.org", "", "");
do_test_single("mailto:srowen@example.org", "srowen@example.org", "", "");
}
#[test]
fn testTos() {
do_test(
"mailto:srowen@example.org,bob@example.org",
&["srowen@example.org", "bob@example.org"],
&Vec::new(),
&Vec::new(),
"",
"",
);
do_test(
"mailto:?to=srowen@example.org,bob@example.org",
&["srowen@example.org", "bob@example.org"],
&Vec::new(),
&Vec::new(),
"",
"",
);
}
#[test]
fn testCCs() {
do_test(
"mailto:?cc=srowen@example.org",
&Vec::new(),
&["srowen@example.org"],
&Vec::new(),
"",
"",
);
do_test(
"mailto:?cc=srowen@example.org,bob@example.org",
&Vec::new(),
&["srowen@example.org", "bob@example.org"],
&Vec::new(),
"",
"",
);
}
#[test]
fn testBCCs() {
do_test(
"mailto:?bcc=srowen@example.org",
&Vec::new(),
&Vec::new(),
&["srowen@example.org"],
"",
"",
);
do_test(
"mailto:?bcc=srowen@example.org,bob@example.org",
&Vec::new(),
&Vec::new(),
&["srowen@example.org", "bob@example.org"],
"",
"",
);
}
#[test]
fn testAll() {
do_test(
"mailto:bob@example.org?cc=foo@example.org&bcc=srowen@example.org&subject=baz&body=buzz",
&["bob@example.org"],
&["foo@example.org"],
&["srowen@example.org"],
"baz",
"buzz",
);
}
#[test]
fn testEmailDocomo() {
do_test_single(
"MATMSG:TO:srowen@example.org;;",
"srowen@example.org",
"",
"",
);
do_test_single(
"MATMSG:TO:srowen@example.org;SUB:Stuff;;",
"srowen@example.org",
"Stuff",
"",
);
do_test_single(
"MATMSG:TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;",
"srowen@example.org",
"Stuff",
"This is some text",
);
}
#[test]
fn testSMTP() {
do_test_single("smtp:srowen@example.org", "srowen@example.org", "", "");
do_test_single("SMTP:srowen@example.org", "srowen@example.org", "", "");
do_test_single(
"smtp:srowen@example.org:foo",
"srowen@example.org",
"foo",
"",
);
do_test_single(
"smtp:srowen@example.org:foo:bar",
"srowen@example.org",
"foo",
"bar",
);
}
fn do_test_single(contents: &str, to: &str, subject: &str, body: &str) {
do_test(contents, &[to], &Vec::new(), &Vec::new(), subject, body);
}
fn do_test(contents: &str, tos: &[&str], ccs: &[&str], bccs: &[&str], subject: &str, body: &str) {
let fakeRXingResult =
RXingResult::new(contents, Vec::new(), Vec::new(), BarcodeFormat::QR_CODE);
let result = ResultParser::parseRXingResult(&fakeRXingResult);
assert_eq!(ParsedRXingResultType::EMAIL_ADDRESS, result.getType());
if let ParsedClientResult::EmailResult(emailRXingResult) = result {
assert_eq!(tos, emailRXingResult.getTos());
assert_eq!(ccs, emailRXingResult.getCCs());
assert_eq!(bccs, emailRXingResult.getBCCs());
assert_eq!(subject, emailRXingResult.getSubject());
assert_eq!(body, emailRXingResult.getBody());
} else {
panic!("Expected EmailResult");
}
}