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