#[cfg(test)]
mod tests {
use crate::http::headers::HttpHeader;
use std::str::FromStr;
use strum::ParseError;
#[test]
fn test_str_to_http_header() {
assert_eq!(Ok(HttpHeader::Accept), HttpHeader::from_str("Accept"));
assert_eq!(
Ok(HttpHeader::Authorization),
HttpHeader::from_str("Authorization")
);
assert_eq!(
Ok(HttpHeader::ContentType),
HttpHeader::from_str("Content-Type")
);
assert_eq!(
Ok(HttpHeader::UserAgent),
HttpHeader::from_str("User-Agent")
);
assert_eq!(Ok(HttpHeader::Host), HttpHeader::from_str("Host"));
assert_eq!(
Ok(HttpHeader::Connection),
HttpHeader::from_str("Connection")
);
assert_eq!(
Ok(HttpHeader::ContentLength),
HttpHeader::from_str("Content-Length")
);
assert_eq!(
Ok(HttpHeader::SetCookie),
HttpHeader::from_str("Set-Cookie")
);
assert_eq!(
Ok(HttpHeader::TransferEncoding),
HttpHeader::from_str("Transfer-Encoding")
);
}
#[test]
fn test_str_to_http_header_lowercase() {
assert_eq!(Ok(HttpHeader::Accept), HttpHeader::from_str("accept"));
assert_eq!(
Ok(HttpHeader::Authorization),
HttpHeader::from_str("authorization")
);
assert_eq!(
Ok(HttpHeader::ContentType),
HttpHeader::from_str("content-type")
);
assert_eq!(
Ok(HttpHeader::UserAgent),
HttpHeader::from_str("user-agent")
);
assert_eq!(Ok(HttpHeader::Host), HttpHeader::from_str("host"));
assert_eq!(
Ok(HttpHeader::Connection),
HttpHeader::from_str("connection")
);
assert_eq!(
Ok(HttpHeader::ContentLength),
HttpHeader::from_str("content-length")
);
assert_eq!(
Ok(HttpHeader::SetCookie),
HttpHeader::from_str("set-cookie")
);
assert_eq!(
Ok(HttpHeader::TransferEncoding),
HttpHeader::from_str("transfer-encoding")
);
}
#[test]
fn test_str_to_http_header_when_unknown_header() {
assert_eq!(
Err(ParseError::VariantNotFound),
HttpHeader::from_str("unknown-header")
);
assert_eq!(
Err(ParseError::VariantNotFound),
HttpHeader::from_str("Unknown-Header")
);
}
}