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() {
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]

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 {
Error::TypeCheck { .. } => true,
Error::WithContext { error, .. } => error.is_type_check_error(),
_ => false,
Error::WithContext { error, .. } => error.as_ref() == other,
_ => self == other,
}
}
}