Browse Source

Add tests/ dir and a test

Add a test for generating mail with melib's Draft struct.
tags/pre-alpha-0.4.0
Manos Pitsidianakis 3 weeks ago
parent
commit
a5e272c36e
No known key found for this signature in database
4 changed files with 90 additions and 1 deletions
  1. 40
    0
      tests/generated.mail
  2. 49
    0
      tests/generating_email.rs
  3. BIN
      tests/test_image.gif
  4. 1
    1
      ui/src/lib.rs

+ 40
- 0
tests/generated.mail View File

@@ -0,0 +1,40 @@
From:
To:
Cc:
Bcc:
Subject:
MIME-Version: 1.0
Content-Type: multipart/mixed; charset="utf-8"; boundary="bzz_bzz__bzz__"

This is a MIME formatted message with attachments. Use a MIME-compliant client to view it properly.
--bzz_bzz__bzz__

hello world.
--bzz_bzz__bzz__
Content-Type: image/gif; name="test_image.gif"; charset="utf-8"
Content-Transfer-Encoding: base64

R0lGODdhKAAXAOfZAAABzAADzQAEzgQFtBEAxAAGxBcAxwALvRcFwAAPwBcLugATuQEUuxoNuxYQ
sxwOvAYVvBsStSAVtx8YsRUcuhwhth4iuCQsyDAwuDc1vTc3uDg4uT85rkc9ukJBvENCvURGukdF
wUVKt0hLuUxPvVZSvFlYu1hbt2BZuFxdul5joGhqlnNuf3FvlnBvwXJyt3Jxw3N0oXx1gH12gV99
z317f3N7spFxwHp5wH99gYB+goF/g25+26tziIOBhWqD3oiBjICAuudkjIN+zHeC2n6Bzc1vh4eF
iYaBw8F0kImHi4KFxYyHmIWIvI2Lj4uIvYaJyY+IuJGMi5iJl4qKxZSMmIuLxpONnpGPk42NvI2M
1LKGl46OvZePm5ORlZiQnJqSnpaUmLyJnJuTn5iVmZyUoJGVyZ2VoZSVw5iXoZmWrO18rJiUyp6W
opuYnKaVnZ+Xo5yZncaMoaCYpJiaqo+Z2Z2annuf5qGZpa2WoJybpZmayZ2Z0KCZypydrZ6dp6Cd
oZ6a0aGay5ucy5+eqKGeouWMgp+b0qKbzKCfqdqPnp2ezaGgqqOgpKafqrScpp+gz6ajqKujr62j
qayksKmmq62lsaiosqqorOyWnaqqtKeqzLGptaurta2rr7Kqtq+ssLOrt6+uuLGusuqhfbWtubCv
ubKvs7GwurOwtPSazbevu+ali7SxtbiwvOykjLOyvLWytuCmqOankrSzvbazuLmyvrW0vre0uba1
wLi1ury0wLm2u721wbe3wbq3vMC2vLi4wr+3w7m5w8C4xLi6yry6vsG5xbu7xcC6zMK6xry8xry+
u8O7x729x8C9wb++yMG+wsO+vMK/w8a+y8e/zMnBzcXH18nL2///////////////////////////
////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////ywAAAAAKAAXAAAI/gBP4Cjh
IYMLEh0w4EgBgsMLEyFGFBEB5cOFABgzatS4AVssZAOsLOHCxooVMzCyoNmzaBOkJlS0VEDyZMjG
mxk3XOMF60CDBgsoPABK9KcDCRImPCiQYAECAgQCRMU4VSrGCjFarBgUSJCgQ10FBTrkNRCfPnz4
dA3UNa1btnDZqgU7Ntqzu3ej2X2mFy9eaHuhNRtMGJrhwYYN930G2K7eaNIY34U2mfJkwpgzI9Yr
GBqwR2KSvAlMOXHnw5pTNzPdLNoWIWtU9XjGjDEYS8LAlFm1SrVvzIKj5TH0KpORSZOryPgCZgqL
Ob+jG0YVRBErUrOiiGJ8KxgtYsh27xWL/tswnTtEbsiRVYdJNMHk4yOGhswGjR88UKjQ9Ey+/8TL
XKKGGn7Akph/8XX2WDTTcAYfguVt9hhrEPqmzIOJ3VUheb48WJiHG6amC4i+WVJKKCimqGIoYxyj
WWK8kKjaJ9bA18sxvXjYhourmbbMMrjI+OIn1QymDCVXANGFK4S1gQw0PxozzC+33FLLKUJq9gk1
gyWDhyNwrMLkYGUEM4wvuLRiCiieXIJJJVlmJskcZ9TZRht1lnFGGmTMkMoonVQSSSOFAGJHHI0w
ouiijDaaCCGQRgrpH3q4QYYXWDihxBE+7KCDDjnUIEVAADs=
--bzz_bzz__bzz__--

+ 49
- 0
tests/generating_email.rs View File

@@ -0,0 +1,49 @@
use melib;
use ui::mime_apps;

use melib::email::Draft;
use mime_apps::query_mime_info;

#[test]
fn build_draft() {
let mut new_draft = Draft::default();
let mut attachment = melib::email::attachment_from_file(&"./tests/test_image.gif")
.expect("Could not open test_image.gif.");
if let Ok(mime_type) = query_mime_info("./tests/test_image.gif") {
match attachment.content_type {
melib::email::ContentType::Other { ref mut tag, .. } => {
*tag = mime_type;
}
_ => {}
}
}
if new_draft.headers().contains_key("User-Agent") {
new_draft.headers_mut().remove("User-Agent");
let pos = new_draft
.header_order
.iter()
.position(|k| k == "User-Agent")
.unwrap();
new_draft.header_order.remove(pos);
}
{
new_draft.headers_mut().remove("Date");
let pos = new_draft
.header_order
.iter()
.position(|k| k == "Date")
.unwrap();
new_draft.header_order.remove(pos);
}

new_draft.attachments_mut().push(attachment);
new_draft.set_body("hello world.".to_string());
let raw = new_draft.finalise().expect("could not finalise draft");
let boundary_def = raw.find("bzz_bzz__bzz__").unwrap();
let boundary_end = boundary_def + raw[boundary_def..].find("\"").unwrap();
let boundary = raw[boundary_def..boundary_end].to_string();
let boundary_str = &boundary["bzz_bzz__bzz__".len()..];

let raw = raw.replace(boundary_str, "");
assert_eq!(include_str!("generated.mail"), &raw);
}

BIN
tests/test_image.gif View File


+ 1
- 1
ui/src/lib.rs View File

@@ -25,7 +25,7 @@

#[macro_use]
extern crate melib;
extern crate mime_apps;
pub extern crate mime_apps;
extern crate notify_rust;
extern crate text_processing;
#[macro_use]

Loading…
Cancel
Save