Improve testing with an error method
This commit is contained in:
parent
9a4196fb2a
commit
ece75d7b9c
@ -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
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
@ -243,13 +243,10 @@ mod tests {
|
||||
fn simple_type_check() {
|
||||
let result = evaluate("x <bool> = 1");
|
||||
|
||||
assert_eq!(
|
||||
Err(Error::TypeCheck {
|
||||
assert!(result.unwrap_err().is_type_check_error(&Error::TypeCheck {
|
||||
expected: Type::Boolean,
|
||||
actual: Type::Integer
|
||||
}),
|
||||
result
|
||||
);
|
||||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -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 {
|
||||
Error::TypeCheck { .. } => true,
|
||||
Error::WithContext { error, .. } => error.is_type_check_error(),
|
||||
_ => false,
|
||||
Error::WithContext { error, .. } => error.as_ref() == other,
|
||||
_ => self == other,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user