add back mime::version tests
This commit is contained in:
parent
75780c232b
commit
8fff581fb4
2 changed files with 39 additions and 4 deletions
|
@ -91,8 +91,8 @@ pub enum MultipartSubtype {
|
||||||
Report,
|
Report,
|
||||||
Unknown,
|
Unknown,
|
||||||
}
|
}
|
||||||
impl<'a> MultipartSubtype<'a> {
|
impl<'a> From<&NaiveType<'a>> for MultipartSubtype<'a> {
|
||||||
pub fn from_naive_type(nt: &NaiveType<'a>) -> Self {
|
pub fn from(nt: &NaiveType<'a>) -> Self {
|
||||||
match nt.sub.as_ascii_lowercase().as_slice() {
|
match nt.sub.as_ascii_lowercase().as_slice() {
|
||||||
b"alternative" => Self::Alternative,
|
b"alternative" => Self::Alternative,
|
||||||
b"mixed" => Self::Mixed,
|
b"mixed" => Self::Mixed,
|
||||||
|
@ -105,11 +105,21 @@ impl<'a> MultipartSubtype<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum MessageSubtype<'a> {
|
pub enum MessageSubtype {
|
||||||
RFC822,
|
RFC822,
|
||||||
Partial,
|
Partial,
|
||||||
External,
|
External,
|
||||||
Other(&'a str),
|
Unknown,
|
||||||
|
}
|
||||||
|
impl<'a> From<&NaiveType<'a>> for MessageSubtype {
|
||||||
|
fn from(nt: &NaiveType<'a>) -> Self {
|
||||||
|
match csub.to_lowercase().as_ref() {
|
||||||
|
"rfc822" => MessageSubtype::RFC822,
|
||||||
|
"partial" => MessageSubtype::Partial,
|
||||||
|
"external" => MessageSubtype::External,
|
||||||
|
_ => Self::Unknown,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Default)]
|
#[derive(Debug, PartialEq, Default)]
|
|
@ -34,3 +34,28 @@ fn is_digit(c: &[u8]) -> bool {
|
||||||
fn ascii_to_u8(c: &[u8]) -> u8 {
|
fn ascii_to_u8(c: &[u8]) -> u8 {
|
||||||
c[0] - ascii::N0
|
c[0] - ascii::N0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_version() {
|
||||||
|
assert_eq!(version(b"1.0"), Ok((&b""[..], Version { major: 1, minor: 0 })),);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
version(b" 1.0 (produced by MetaSend Vx.x)"),
|
||||||
|
Ok((&b""[..], Version { major: 1, minor: 0 })),
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
version(b"(produced by MetaSend Vx.x) 1.0"),
|
||||||
|
Ok((&b""[..], Version { major: 1, minor: 0 })),
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
version(b"1.(produced by MetaSend Vx.x)0"),
|
||||||
|
Ok((&b""[..], Version { major: 1, minor: 0 })),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue