Add a bunch of files to the test/mailstore directory for runnings tests
against; Partially write tests for Gemtext parser
This commit is contained in:
parent
22972ed43d
commit
608d63def9
23 changed files with 199 additions and 26 deletions
|
@ -80,7 +80,7 @@ impl<'a> GemtextNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_senders(text: &'a str) -> Self {
|
fn parse_senders(text: &'a str) -> Self {
|
||||||
let Some(line) = text.strip_prefix('<') else {
|
let Some(line) = text.strip_prefix('<').map(|x| x.trim()) else {
|
||||||
return Self::Text(text.to_string());
|
return Self::Text(text.to_string());
|
||||||
};
|
};
|
||||||
if let Ok(user) = line.parse() {
|
if let Ok(user) = line.parse() {
|
||||||
|
@ -107,7 +107,10 @@ impl<'a> GemtextNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_timestamp(text: &'a str) -> Self {
|
fn parse_timestamp(text: &'a str) -> Self {
|
||||||
todo!()
|
let Some(line) = text.strip_prefix('@').map(|x| x.trim()) else {
|
||||||
|
return Self::Text(text.to_string());
|
||||||
|
};
|
||||||
|
Self::Timestamp(line.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,6 +209,10 @@ impl<'a> Parser<'a> {
|
||||||
self.lines.push(GemtextNode::parse_recipients(line));
|
self.lines.push(GemtextNode::parse_recipients(line));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn timestamp(&mut self, line: &'a str) {
|
||||||
|
self.lines.push(GemtextNode::parse_timestamp(line));
|
||||||
|
}
|
||||||
|
|
||||||
fn parse_normal(&mut self, line: &'a str) {
|
fn parse_normal(&mut self, line: &'a str) {
|
||||||
match line {
|
match line {
|
||||||
s if s.starts_with("=>") => self.link(s),
|
s if s.starts_with("=>") => self.link(s),
|
||||||
|
@ -215,7 +222,7 @@ impl<'a> Parser<'a> {
|
||||||
s if s.starts_with("```") => self.enter_preformatted(s),
|
s if s.starts_with("```") => self.enter_preformatted(s),
|
||||||
s if s.starts_with('<') => self.senders(s),
|
s if s.starts_with('<') => self.senders(s),
|
||||||
s if s.starts_with(':') => self.recipients(s),
|
s if s.starts_with(':') => self.recipients(s),
|
||||||
s if s.starts_with('@') => {}
|
s if s.starts_with('@') => self.timestamp(s),
|
||||||
s => self.lines.push(GemtextNode::Text(s.to_string())),
|
s => self.lines.push(GemtextNode::Text(s.to_string())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,3 +249,76 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::prelude::Host;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
static RAW: &'static str =
|
||||||
|
include_str!("../../test/mailstore/misfin.example.org/jane/Lists/700070.gmi");
|
||||||
|
|
||||||
|
fn parse_raw() -> Vec<GemtextNode> {
|
||||||
|
Parser::new().parse(RAW)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn nodes() {
|
||||||
|
let nodes = parse_raw();
|
||||||
|
let mut nodes = nodes.iter();
|
||||||
|
assert_eq!(
|
||||||
|
nodes.next().cloned().unwrap(),
|
||||||
|
GemtextNode::Sender(Mailbox {
|
||||||
|
username: "ed".to_string(),
|
||||||
|
host: Host {
|
||||||
|
subdomain: None,
|
||||||
|
domain: "iron".to_string(),
|
||||||
|
tld: "maiden".to_string()
|
||||||
|
},
|
||||||
|
blurb: Some("Eddy the Head".to_string())
|
||||||
|
})
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
nodes.next().cloned().unwrap(),
|
||||||
|
GemtextNode::Sender(Mailbox {
|
||||||
|
username: "bruce".to_string(),
|
||||||
|
host: Host {
|
||||||
|
subdomain: None,
|
||||||
|
domain: "dickinson".to_string(),
|
||||||
|
tld: "jam".to_string(),
|
||||||
|
},
|
||||||
|
blurb: Some("Bruce Dickinson".to_string()),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
nodes.next().cloned().unwrap(),
|
||||||
|
GemtextNode::Recipients(Recipients {
|
||||||
|
boxes: vec![
|
||||||
|
Mailbox {
|
||||||
|
username: "nicko".to_string(),
|
||||||
|
host: Host {
|
||||||
|
subdomain: None,
|
||||||
|
domain: "iron".to_string(),
|
||||||
|
tld: "maiden".to_string(),
|
||||||
|
},
|
||||||
|
blurb: None,
|
||||||
|
},
|
||||||
|
Mailbox {
|
||||||
|
username: "steve".to_string(),
|
||||||
|
host: Host {
|
||||||
|
subdomain: None,
|
||||||
|
domain: "iron".to_string(),
|
||||||
|
tld: "maiden".to_string()
|
||||||
|
},
|
||||||
|
blurb: None,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
nodes.next().cloned().unwrap(),
|
||||||
|
GemtextNode::Timestamp("2023-06-07T21:27:15Z".to_string()),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -96,18 +96,22 @@ impl Parser {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
const RAW: &'static str = include_str!("../../test/ox42sc69.gmi");
|
const RAW: &'static str =
|
||||||
|
include_str!("../../test/mailstore/misfin.example.org/dick/Inbox/619310.gmi");
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_message() {
|
fn parse_message() {
|
||||||
let msg: Message = Parser::new("ox42sc69").parse(RAW).unwrap();
|
let msg: Message = Parser::new("619310").parse(RAW).unwrap();
|
||||||
assert_eq!(msg.id, "ox42sc69");
|
assert_eq!(msg.id, "619310");
|
||||||
assert_eq!(msg.from.to_string(), "joe@gemini.example.org");
|
assert_eq!(msg.from.to_string(), "joe@gemini.example.org");
|
||||||
assert_eq!(msg.timestamp.unwrap(), "2023-06-07T16:09:42Z");
|
assert_eq!(msg.timestamp.unwrap(), "2023-06-07T16:09:42Z");
|
||||||
assert!(msg.senders.is_empty());
|
assert!(msg.senders.is_empty());
|
||||||
assert!(msg.recipients.is_empty());
|
assert!(msg.recipients.is_empty());
|
||||||
assert_eq!(msg.title.unwrap(), "How 'bout dose Bears?");
|
assert_eq!(msg.title.unwrap(), "How 'bout dose Bears?");
|
||||||
assert_eq!(msg.body, "# How 'bout dose Bears?\nWhen are they coming for dinner anyway?\n");
|
assert_eq!(
|
||||||
|
msg.body,
|
||||||
|
"# How 'bout dose Bears?\nWhen are they coming for dinner anyway?\n"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -216,33 +216,106 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_number_temporary() {
|
fn to_number_temporary() {
|
||||||
assert_eq!(u8::from(Status::TemporaryFailure(TemporaryFailure::TemporaryError)), 40);
|
assert_eq!(
|
||||||
assert_eq!(u8::from(Status::TemporaryFailure(TemporaryFailure::ServerUnavailable)), 41);
|
u8::from(Status::TemporaryFailure(TemporaryFailure::TemporaryError)),
|
||||||
assert_eq!(u8::from(Status::TemporaryFailure(TemporaryFailure::CgiError)), 42);
|
40
|
||||||
assert_eq!(u8::from(Status::TemporaryFailure(TemporaryFailure::ProxyError)), 43);
|
);
|
||||||
assert_eq!(u8::from(Status::TemporaryFailure(TemporaryFailure::RateLimit)), 44);
|
assert_eq!(
|
||||||
assert_eq!(u8::from(Status::TemporaryFailure(TemporaryFailure::MailboxFull)), 45);
|
u8::from(Status::TemporaryFailure(
|
||||||
assert_eq!(u8::from(Status::TemporaryFailure(TemporaryFailure::Other)), 46);
|
TemporaryFailure::ServerUnavailable
|
||||||
|
)),
|
||||||
|
41
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
u8::from(Status::TemporaryFailure(TemporaryFailure::CgiError)),
|
||||||
|
42
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
u8::from(Status::TemporaryFailure(TemporaryFailure::ProxyError)),
|
||||||
|
43
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
u8::from(Status::TemporaryFailure(TemporaryFailure::RateLimit)),
|
||||||
|
44
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
u8::from(Status::TemporaryFailure(TemporaryFailure::MailboxFull)),
|
||||||
|
45
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
u8::from(Status::TemporaryFailure(TemporaryFailure::Other)),
|
||||||
|
46
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_number_permanent() {
|
fn to_number_permanent() {
|
||||||
assert_eq!(u8::from(Status::PermanentFailure(PermanentFailure::PermanentError)), 50);
|
assert_eq!(
|
||||||
assert_eq!(u8::from(Status::PermanentFailure(PermanentFailure::MailboxNonexistent)), 51);
|
u8::from(Status::PermanentFailure(PermanentFailure::PermanentError)),
|
||||||
assert_eq!(u8::from(Status::PermanentFailure(PermanentFailure::MailboxGone)), 52);
|
50
|
||||||
assert_eq!(u8::from(Status::PermanentFailure(PermanentFailure::DomainNotServiced)), 53);
|
);
|
||||||
assert_eq!(u8::from(Status::PermanentFailure(PermanentFailure::BadRequest)), 59);
|
assert_eq!(
|
||||||
assert_eq!(u8::from(Status::PermanentFailure(PermanentFailure::Other)), 54);
|
u8::from(Status::PermanentFailure(
|
||||||
|
PermanentFailure::MailboxNonexistent
|
||||||
|
)),
|
||||||
|
51
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
u8::from(Status::PermanentFailure(PermanentFailure::MailboxGone)),
|
||||||
|
52
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
u8::from(Status::PermanentFailure(
|
||||||
|
PermanentFailure::DomainNotServiced
|
||||||
|
)),
|
||||||
|
53
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
u8::from(Status::PermanentFailure(PermanentFailure::BadRequest)),
|
||||||
|
59
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
u8::from(Status::PermanentFailure(PermanentFailure::Other)),
|
||||||
|
54
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn to_number_auth() {
|
fn to_number_auth() {
|
||||||
assert_eq!(u8::from(Status::AuthenticationFailure(AuthenticationFailure::CertificateRequired)), 60);
|
assert_eq!(
|
||||||
assert_eq!(u8::from(Status::AuthenticationFailure(AuthenticationFailure::UnauthorizedSender)), 61);
|
u8::from(Status::AuthenticationFailure(
|
||||||
assert_eq!(u8::from(Status::AuthenticationFailure(AuthenticationFailure::CertificateInvalid)), 62);
|
AuthenticationFailure::CertificateRequired
|
||||||
assert_eq!(u8::from(Status::AuthenticationFailure(AuthenticationFailure::IdentityMismatch)), 63);
|
)),
|
||||||
assert_eq!(u8::from(Status::AuthenticationFailure(AuthenticationFailure::ProofRequired)), 64);
|
60
|
||||||
assert_eq!(u8::from(Status::AuthenticationFailure(AuthenticationFailure::Other)), 65);
|
);
|
||||||
|
assert_eq!(
|
||||||
|
u8::from(Status::AuthenticationFailure(
|
||||||
|
AuthenticationFailure::UnauthorizedSender
|
||||||
|
)),
|
||||||
|
61
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
u8::from(Status::AuthenticationFailure(
|
||||||
|
AuthenticationFailure::CertificateInvalid
|
||||||
|
)),
|
||||||
|
62
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
u8::from(Status::AuthenticationFailure(
|
||||||
|
AuthenticationFailure::IdentityMismatch
|
||||||
|
)),
|
||||||
|
63
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
u8::from(Status::AuthenticationFailure(
|
||||||
|
AuthenticationFailure::ProofRequired
|
||||||
|
)),
|
||||||
|
64
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
u8::from(Status::AuthenticationFailure(AuthenticationFailure::Other)),
|
||||||
|
65
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
0
test/mailstore/mail.gmi.org/dick/Inbox/623273.gmi
Normal file
0
test/mailstore/mail.gmi.org/dick/Inbox/623273.gmi
Normal file
0
test/mailstore/mail.gmi.org/dick/Inbox/738127.gmi
Normal file
0
test/mailstore/mail.gmi.org/dick/Inbox/738127.gmi
Normal file
0
test/mailstore/mail.gmi.org/dick/Lists/158468.gmi
Normal file
0
test/mailstore/mail.gmi.org/dick/Lists/158468.gmi
Normal file
0
test/mailstore/mail.gmi.org/dick/Lists/431652.gmi
Normal file
0
test/mailstore/mail.gmi.org/dick/Lists/431652.gmi
Normal file
1
test/mailstore/mail.gmi.org/dick/blurb
Normal file
1
test/mailstore/mail.gmi.org/dick/blurb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Richard Stallman
|
0
test/mailstore/mail.gmi.org/jane/Inbox/488571.gmi
Normal file
0
test/mailstore/mail.gmi.org/jane/Inbox/488571.gmi
Normal file
0
test/mailstore/mail.gmi.org/jane/Inbox/867017.gmi
Normal file
0
test/mailstore/mail.gmi.org/jane/Inbox/867017.gmi
Normal file
0
test/mailstore/mail.gmi.org/jane/Lists/476324.gmi
Normal file
0
test/mailstore/mail.gmi.org/jane/Lists/476324.gmi
Normal file
0
test/mailstore/mail.gmi.org/jane/Lists/891249.gmi
Normal file
0
test/mailstore/mail.gmi.org/jane/Lists/891249.gmi
Normal file
1
test/mailstore/mail.gmi.org/jane/blurb
Normal file
1
test/mailstore/mail.gmi.org/jane/blurb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Janet Weiss
|
0
test/mailstore/misfin.example.org/dick/Inbox/868379.gmi
Normal file
0
test/mailstore/misfin.example.org/dick/Inbox/868379.gmi
Normal file
0
test/mailstore/misfin.example.org/dick/Lists/448785.gmi
Normal file
0
test/mailstore/misfin.example.org/dick/Lists/448785.gmi
Normal file
0
test/mailstore/misfin.example.org/dick/Lists/645815.gmi
Normal file
0
test/mailstore/misfin.example.org/dick/Lists/645815.gmi
Normal file
1
test/mailstore/misfin.example.org/dick/blurb
Normal file
1
test/mailstore/misfin.example.org/dick/blurb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Rick Baker
|
0
test/mailstore/misfin.example.org/jane/Inbox/252366.gmi
Normal file
0
test/mailstore/misfin.example.org/jane/Inbox/252366.gmi
Normal file
0
test/mailstore/misfin.example.org/jane/Inbox/654064.gmi
Normal file
0
test/mailstore/misfin.example.org/jane/Inbox/654064.gmi
Normal file
0
test/mailstore/misfin.example.org/jane/Lists/620426.gmi
Normal file
0
test/mailstore/misfin.example.org/jane/Lists/620426.gmi
Normal file
12
test/mailstore/misfin.example.org/jane/Lists/700070.gmi
Normal file
12
test/mailstore/misfin.example.org/jane/Lists/700070.gmi
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
< ed@iron.maiden Eddy the Head
|
||||||
|
< bruce@dickinson.jam Bruce Dickinson
|
||||||
|
: nicko@iron.maiden steve@iron.maiden
|
||||||
|
@ 2023-06-07T21:27:15Z
|
||||||
|
|
||||||
|
# Checking in
|
||||||
|
The new album's in the can. A few things:
|
||||||
|
* Needs more cowbell
|
||||||
|
* Adrian's guitar is too loud, drowning out the cowbell
|
||||||
|
* Steve has a fever
|
||||||
|
|
||||||
|
> You're gonna want that cowbell!
|
1
test/mailstore/misfin.example.org/jane/blurb
Normal file
1
test/mailstore/misfin.example.org/jane/blurb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Jane Doh
|
Loading…
Add table
Reference in a new issue