From 3cbd3bbf3c7d63f6a9c4898f2d036bc6f49f2902 Mon Sep 17 00:00:00 2001 From: Jeff Date: Fri, 5 Jan 2024 23:33:51 -0500 Subject: [PATCH] Improve error interface --- src/error.rs | 2 +- tests/interpret.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/error.rs b/src/error.rs index de399b2..7efdcc4 100644 --- a/src/error.rs +++ b/src/error.rs @@ -229,7 +229,7 @@ impl Error { } } - pub fn is_type_check_error(&self, other: &Error) -> bool { + pub fn is_error(&self, other: &Error) -> bool { match self { Error::AtSourcePosition { error, .. } => error.as_ref() == other, _ => self == other, diff --git a/tests/interpret.rs b/tests/interpret.rs index 0784f03..a7db5db 100644 --- a/tests/interpret.rs +++ b/tests/interpret.rs @@ -40,7 +40,7 @@ mod assignment { ", ); - assert!(result.unwrap_err().is_type_check_error(&Error::TypeCheck { + assert!(result.unwrap_err().is_error(&Error::TypeCheck { expected: Type::String, actual: Type::Integer })) @@ -172,7 +172,7 @@ mod value { fn map_type_errors() { assert!(interpret("{ foo = 'bar' }") .unwrap_err() - .is_type_check_error(&Error::TypeCheck { + .is_error(&Error::TypeCheck { expected: Type::Boolean, actual: Type::String })) @@ -435,7 +435,7 @@ mod type_definition { fn simple_type_check() { let result = interpret("x = 1"); - assert!(result.unwrap_err().is_type_check_error(&Error::TypeCheck { + assert!(result.unwrap_err().is_error(&Error::TypeCheck { expected: Type::Boolean, actual: Type::Integer })); @@ -468,7 +468,7 @@ mod type_definition { ", ); - assert!(result.unwrap_err().is_type_check_error(&Error::TypeCheck { + assert!(result.unwrap_err().is_error(&Error::TypeCheck { expected: Type::Function { parameter_types: vec![], return_type: Box::new(Type::Boolean),