Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ impl StdError for Error {
fn description(&self) -> &str {
match *self {
Method => "Invalid Method specified",
Uri(_) => "Invalid Request URI specified",
Version => "Invalid HTTP version specified",
Header => "Invalid Header provided",
TooLarge => "Message head is too large",
Status => "Invalid Status provided",
Uri(ref e) => e.description(),
Io(ref e) => e.description(),
Ssl(ref e) => e.description(),
}
Expand Down Expand Up @@ -107,3 +107,51 @@ impl From<httparse::Error> for Error {
}
}
}

#[cfg(test)]
mod tests {
use std::error::Error as StdError;
use std::io;
use httparse;
use openssl::ssl::error::SslError;
use url;
use super::Error;
use super::Error::*;

#[test]
fn test_cause() {
let orig = io::Error::new(io::ErrorKind::Other, "other");
let desc = orig.description().to_owned();
let e = Io(orig);
assert_eq!(e.cause().unwrap().description(), desc);
}

macro_rules! from {
($from:expr => $error:pat) => {
match Error::from($from) {
$error => (),
_ => panic!("{:?}", $from)
}
}
}

#[test]
fn test_from() {

from!(io::Error::new(io::ErrorKind::Other, "other") => Io(..));
from!(url::ParseError::EmptyHost => Uri(..));

from!(SslError::StreamError(io::Error::new(io::ErrorKind::Other, "ssl")) => Io(..));
from!(SslError::SslSessionClosed => Ssl(..));


from!(httparse::Error::HeaderName => Header);
from!(httparse::Error::HeaderName => Header);
from!(httparse::Error::HeaderValue => Header);
from!(httparse::Error::NewLine => Header);
from!(httparse::Error::Status => Status);
from!(httparse::Error::Token => Header);
from!(httparse::Error::TooManyHeaders => TooLarge);
from!(httparse::Error::Version => Version);
}
}