Add tests for error types with custom functions and types

This commit is contained in:
Matthias Beyer 2016-05-17 00:14:10 +02:00
parent 603b4de593
commit b117d7fb9f

View file

@ -115,7 +115,11 @@ macro_rules! generate_error_types {
$kindname: ident,
$($kind:ident => $string:expr),*
) => {
generate_custom_error_types!($name, $kindname, members = {}, functions = {}, $($kind),*);
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Copy)]
pub struct SomeNotExistingTypeWithATypeNameNoOneWillEverChoose {}
generate_custom_error_types!($name, $kindname,
SomeNotExistingTypeWithATypeNameNoOneWillEverChoose,
$($kind => $string),*);
}
}
@ -129,6 +133,36 @@ mod test {
TestErrorKindB => "testerrorkind B");
);
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Copy)]
pub struct CustomData {
pub test: i32,
pub othr: i64,
}
generate_error_imports!();
generate_custom_error_types!(CustomTestError, CustomTestErrorKind,
CustomData,
CustomErrorKindA => "customerrorkind a",
CustomErrorKindB => "customerrorkind B");
impl CustomTestError {
pub fn test(&self) -> i32 {
match self.custom_data {
Some(t) => t.test,
None => 0,
}
}
pub fn bar(&self) -> i64 {
match self.custom_data {
Some(t) => t.othr,
None => 0,
}
}
}
#[test]
fn test_a() {
use self::error::{TestError, TestErrorKind};