add back mime::version tests

This commit is contained in:
Quentin 2023-07-22 10:10:26 +02:00
parent 75780c232b
commit 8fff581fb4
Signed by: quentin
GPG key ID: E9602264D639FF68
2 changed files with 39 additions and 4 deletions

View file

@ -91,8 +91,8 @@ pub enum MultipartSubtype {
Report,
Unknown,
}
impl<'a> MultipartSubtype<'a> {
pub fn from_naive_type(nt: &NaiveType<'a>) -> Self {
impl<'a> From<&NaiveType<'a>> for MultipartSubtype<'a> {
pub fn from(nt: &NaiveType<'a>) -> Self {
match nt.sub.as_ascii_lowercase().as_slice() {
b"alternative" => Self::Alternative,
b"mixed" => Self::Mixed,
@ -105,11 +105,21 @@ impl<'a> MultipartSubtype<'a> {
}
#[derive(Debug, PartialEq)]
pub enum MessageSubtype<'a> {
pub enum MessageSubtype {
RFC822,
Partial,
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)]

View file

@ -34,3 +34,28 @@ fn is_digit(c: &[u8]) -> bool {
fn ascii_to_u8(c: &[u8]) -> u8 {
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 })),
);
}
}