fixed tests
This commit is contained in:
parent
50b837438e
commit
f98b43aaba
6 changed files with 44 additions and 40 deletions
|
@ -26,6 +26,7 @@ impl<'a> Text<'a> {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::text::ascii;
|
||||
|
||||
#[test]
|
||||
fn test_text() {
|
||||
|
|
|
@ -166,20 +166,20 @@ mod tests {
|
|||
#[test]
|
||||
fn test_ptext() {
|
||||
assert_eq!(
|
||||
ptext("Accus=E9_de_r=E9ception_(affich=E9)"),
|
||||
Ok(("", vec![
|
||||
QuotedChunk::Safe("Accus"),
|
||||
ptext(b"Accus=E9_de_r=E9ception_(affich=E9)"),
|
||||
Ok((&b""[..], vec![
|
||||
QuotedChunk::Safe(&b"Accus"[..]),
|
||||
QuotedChunk::Encoded(0xe9),
|
||||
QuotedChunk::Space,
|
||||
QuotedChunk::Safe("de"),
|
||||
QuotedChunk::Safe(&b"de"[..]),
|
||||
QuotedChunk::Space,
|
||||
QuotedChunk::Safe("r"),
|
||||
QuotedChunk::Safe(&b"r"[..]),
|
||||
QuotedChunk::Encoded(0xe9),
|
||||
QuotedChunk::Safe("ception"),
|
||||
QuotedChunk::Safe(&b"ception"[..]),
|
||||
QuotedChunk::Space,
|
||||
QuotedChunk::Safe("(affich"),
|
||||
QuotedChunk::Safe(&b"(affich"[..]),
|
||||
QuotedChunk::Encoded(0xe9),
|
||||
QuotedChunk::Safe(")"),
|
||||
QuotedChunk::Safe(&b")"[..]),
|
||||
]))
|
||||
);
|
||||
}
|
||||
|
@ -188,8 +188,8 @@ mod tests {
|
|||
#[test]
|
||||
fn test_decode_word() {
|
||||
assert_eq!(
|
||||
encoded_word("=?iso8859-1?Q?Accus=E9_de_r=E9ception_(affich=E9)?="),
|
||||
Ok(("", "Accusé de réception (affiché)".into())),
|
||||
encoded_word(b"=?iso8859-1?Q?Accus=E9_de_r=E9ception_(affich=E9)?=").unwrap().1.to_string(),
|
||||
"Accusé de réception (affiché)".to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -197,8 +197,8 @@ mod tests {
|
|||
#[test]
|
||||
fn test_decode_word_b64() {
|
||||
assert_eq!(
|
||||
encoded_word("=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?="),
|
||||
Ok(("", "If you can read this yo".into()))
|
||||
encoded_word(b"=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=").unwrap().1.to_string(),
|
||||
"If you can read this yo".to_string(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -152,14 +152,17 @@ mod tests {
|
|||
use super::*;
|
||||
#[test]
|
||||
fn test_phrase() {
|
||||
assert_eq!(phrase("hello world"), Ok(("", "hello world".into())));
|
||||
assert_eq!(
|
||||
phrase("salut \"le\" monde"),
|
||||
Ok(("", "salut le monde".into()))
|
||||
phrase(b"hello world").unwrap().1.to_string(),
|
||||
"hello world".to_string(),
|
||||
);
|
||||
assert_eq!(
|
||||
phrase("fin\r\n du\r\nmonde"),
|
||||
Ok(("\r\nmonde", "fin du".into()))
|
||||
phrase(b"salut \"le\" monde").unwrap().1.to_string(),
|
||||
"salut le monde".to_string(),
|
||||
);
|
||||
|
||||
let (rest, parsed) = phrase(b"fin\r\n du\r\nmonde").unwrap();
|
||||
assert_eq!(rest, &b"\r\nmonde"[..]);
|
||||
assert_eq!(parsed.to_string(), "fin du".to_string());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ use crate::text::buffer;
|
|||
/// obs-qp = "\" (%d0 / obs-NO-WS-CTL / LF / CR)
|
||||
/// ```
|
||||
pub fn quoted_pair(input: &[u8]) -> IResult<&[u8], &[u8]> {
|
||||
preceded(tag(&[ascii::SLASH]), take(1usize))(input)
|
||||
preceded(tag(&[ascii::BACKSLASH]), take(1usize))(input)
|
||||
}
|
||||
|
||||
|
||||
|
@ -93,7 +93,7 @@ mod tests {
|
|||
text.push(b"world");
|
||||
assert_eq!(
|
||||
quoted_string(b" \"hello\\\"world\" "),
|
||||
Ok(("", text))
|
||||
Ok((&b""[..], text))
|
||||
);
|
||||
|
||||
let mut text = buffer::Text::default();
|
||||
|
@ -102,7 +102,7 @@ mod tests {
|
|||
text.push(b"world");
|
||||
assert_eq!(
|
||||
quoted_string(b"\"hello\r\n world\""),
|
||||
Ok(("", text))
|
||||
Ok((&b""[..], text))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,43 +149,43 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_obs_crlf() {
|
||||
assert_eq!(obs_crlf("\rworld"), Ok(("world", "\r")));
|
||||
assert_eq!(obs_crlf("\r\nworld"), Ok(("world", "\r\n")));
|
||||
assert_eq!(obs_crlf("\nworld"), Ok(("world", "\n")));
|
||||
assert_eq!(obs_crlf(b"\rworld"), Ok((&b"world"[..], &b"\r"[..])));
|
||||
assert_eq!(obs_crlf(b"\r\nworld"), Ok((&b"world"[..], &b"\r\n"[..])));
|
||||
assert_eq!(obs_crlf(b"\nworld"), Ok((&b"world"[..], &b"\n"[..])));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fws() {
|
||||
assert_eq!(fws("\r\n world"), Ok(("world", ' ')));
|
||||
assert_eq!(fws(" \r\n \r\n world"), Ok(("world", ' ')));
|
||||
assert_eq!(fws(" world"), Ok(("world", ' ')));
|
||||
assert!(fws("\r\nFrom: test").is_err());
|
||||
assert_eq!(fws(b"\r\n world"), Ok((&b"world"[..], ascii::SP)));
|
||||
assert_eq!(fws(b" \r\n \r\n world"), Ok((&b"world"[..], ascii::SP)));
|
||||
assert_eq!(fws(b" world"), Ok((&b"world"[..], ascii::SP)));
|
||||
assert!(fws(b"\r\nFrom: test").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cfws() {
|
||||
assert_eq!(
|
||||
cfws("(A nice \\) chap) <pete(his account)@silly.test(his host)>"),
|
||||
cfws(b"(A nice \\) chap) <pete(his account)@silly.test(his host)>"),
|
||||
Ok((
|
||||
"<pete(his account)@silly.test(his host)>",
|
||||
"(A nice \\) chap) "
|
||||
&b"<pete(his account)@silly.test(his host)>"[..],
|
||||
&b"(A nice \\) chap) "[..]
|
||||
))
|
||||
);
|
||||
assert_eq!(
|
||||
cfws("(Chris's host.)public.example>,"),
|
||||
Ok(("public.example>,", "(Chris's host.)"))
|
||||
cfws(b"(Chris's host.)public.example>,"),
|
||||
Ok((&b"public.example>,"[..], &b"(Chris's host.)"[..]))
|
||||
);
|
||||
assert_eq!(
|
||||
cfws("(double (comment) is fun) wouch"),
|
||||
Ok(("wouch", "(double (comment) is fun) "))
|
||||
cfws(b"(double (comment) is fun) wouch"),
|
||||
Ok((&b"wouch"[..], &b"(double (comment) is fun) "[..]))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cfws_encoded_word() {
|
||||
assert_eq!(
|
||||
cfws("(=?US-ASCII?Q?Keith_Moore?=)"),
|
||||
Ok(("", "(=?US-ASCII?Q?Keith_Moore?=)")),
|
||||
cfws(b"(=?US-ASCII?Q?Keith_Moore?=)"),
|
||||
Ok((&b""[..], &b"(=?US-ASCII?Q?Keith_Moore?=)"[..])),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,16 +118,16 @@ mod tests {
|
|||
#[test]
|
||||
fn test_dot_atom_text() {
|
||||
assert_eq!(
|
||||
dot_atom_text("quentin.dufour.io abcdef"),
|
||||
Ok((" abcdef", "quentin.dufour.io"))
|
||||
dot_atom_text(b"quentin.dufour.io abcdef"),
|
||||
Ok((&b" abcdef"[..], &b"quentin.dufour.io"[..]))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dot_atom() {
|
||||
assert_eq!(
|
||||
dot_atom(" (skip) quentin.dufour.io abcdef"),
|
||||
Ok(("abcdef", "quentin.dufour.io"))
|
||||
dot_atom(b" (skip) quentin.dufour.io abcdef"),
|
||||
Ok((&b"abcdef"[..], &b"quentin.dufour.io"[..]))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue