Skip to content

Commit 0193fac

Browse files
committed
Add tests for context implementation
1 parent 72c2f18 commit 0193fac

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,8 @@ mod test {
795795
use std::string::FromUtf8Error;
796796
use std::error::Error;
797797

798+
use super::ResultExt;
799+
798800
quick_error! {
799801
#[derive(Debug)]
800802
pub enum Bare {
@@ -962,4 +964,23 @@ mod test {
962964
assert_eq!(err.description(), descr);
963965
assert!(err.cause().is_none());
964966
}
967+
968+
quick_error! {
969+
#[derive(Debug)]
970+
pub enum ContextErr {
971+
Parse(src: String, err: ParseFloatError) {
972+
context(s: &'a str, e: ParseFloatError) -> (s.to_string(), e)
973+
display("Error parsing {:?}: {}", src, err)
974+
}
975+
}
976+
}
977+
978+
#[test]
979+
fn parse_float_error() {
980+
fn parse_float(s: &str) -> Result<f32, ContextErr> {
981+
Ok(try!(s.parse().context(s)))
982+
}
983+
assert_eq!(format!("{}", parse_float("12ab").unwrap_err()),
984+
r#"Error parsing "12ab": invalid float literal"#);
985+
}
965986
}

0 commit comments

Comments
 (0)