Improve testing with an error method

This commit is contained in:
Jeff 2023-12-16 19:47:23 -05:00
parent 9a4196fb2a
commit ece75d7b9c
3 changed files with 11 additions and 12 deletions

View File

@ -185,6 +185,9 @@ mod tests {
", ",
); );
assert!(result.unwrap_err().is_type_check_error()) assert!(result.unwrap_err().is_type_check_error(&Error::TypeCheck {
expected: Type::String,
actual: Type::Integer
}))
} }
} }

View File

@ -243,13 +243,10 @@ mod tests {
fn simple_type_check() { fn simple_type_check() {
let result = evaluate("x <bool> = 1"); let result = evaluate("x <bool> = 1");
assert_eq!( assert!(result.unwrap_err().is_type_check_error(&Error::TypeCheck {
Err(Error::TypeCheck { expected: Type::Boolean,
expected: Type::Boolean, actual: Type::Integer
actual: Type::Integer }));
}),
result
);
} }
#[test] #[test]

View File

@ -214,11 +214,10 @@ impl Error {
} }
} }
pub fn is_type_check_error(&self) -> bool { pub fn is_type_check_error(&self, other: &Error) -> bool {
match self { match self {
Error::TypeCheck { .. } => true, Error::WithContext { error, .. } => error.as_ref() == other,
Error::WithContext { error, .. } => error.is_type_check_error(), _ => self == other,
_ => false,
} }
} }
} }