From ece75d7b9c9082171f6908d38e6a6999a52e615d Mon Sep 17 00:00:00 2001 From: Jeff Date: Sat, 16 Dec 2023 19:47:23 -0500 Subject: [PATCH] Improve testing with an error method --- src/abstract_tree/assignment.rs | 5 ++++- src/abstract_tree/type_definition.rs | 11 ++++------- src/error.rs | 7 +++---- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/abstract_tree/assignment.rs b/src/abstract_tree/assignment.rs index 15003bc..7fd9696 100644 --- a/src/abstract_tree/assignment.rs +++ b/src/abstract_tree/assignment.rs @@ -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 + })) } } diff --git a/src/abstract_tree/type_definition.rs b/src/abstract_tree/type_definition.rs index 9d729e3..5bbfbd5 100644 --- a/src/abstract_tree/type_definition.rs +++ b/src/abstract_tree/type_definition.rs @@ -243,13 +243,10 @@ mod tests { fn simple_type_check() { let result = evaluate("x = 1"); - assert_eq!( - Err(Error::TypeCheck { - expected: Type::Boolean, - actual: Type::Integer - }), - result - ); + assert!(result.unwrap_err().is_type_check_error(&Error::TypeCheck { + expected: Type::Boolean, + actual: Type::Integer + })); } #[test] diff --git a/src/error.rs b/src/error.rs index 7341506..740b4a9 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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, } } }