File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -795,6 +795,8 @@ mod test {
795
795
use std:: string:: FromUtf8Error ;
796
796
use std:: error:: Error ;
797
797
798
+ use super :: ResultExt ;
799
+
798
800
quick_error ! {
799
801
#[ derive( Debug ) ]
800
802
pub enum Bare {
@@ -962,4 +964,23 @@ mod test {
962
964
assert_eq ! ( err. description( ) , descr) ;
963
965
assert ! ( err. cause( ) . is_none( ) ) ;
964
966
}
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
+ }
965
986
}
You can’t perform that action at this time.
0 commit comments