From 79cb25bc9dcb70fbb1e339c8d58bee7fef4018cf Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Thu, 13 Jan 2022 15:18:06 +0200 Subject: [PATCH] Increase test coverage. --- src/error/mod.rs | 33 +++++++++++++++++++++++++++++++++ tests/integration.rs | 2 ++ 2 files changed, 35 insertions(+) diff --git a/src/error/mod.rs b/src/error/mod.rs index 46cd116..a4b2d44 100644 --- a/src/error/mod.rs +++ b/src/error/mod.rs @@ -366,3 +366,36 @@ impl std::error::Error for EvalexprError {} /// Standard result type used by this crate. pub type EvalexprResult = Result; + +#[cfg(test)] +mod tests { + use crate::{EvalexprError, Value, ValueType}; + + /// Tests whose only use is to bring test coverage of trivial lines up, like trivial constructors. + #[test] + fn trivial_coverage_tests() { + assert_eq!( + EvalexprError::type_error(Value::Int(3), vec![ValueType::String]), + EvalexprError::TypeError { + actual: Value::Int(3), + expected: vec![ValueType::String] + } + ); + assert_eq!( + EvalexprError::expected_type(&Value::String("abc".to_string()), Value::Empty), + EvalexprError::expected_string(Value::Empty) + ); + assert_eq!( + EvalexprError::expected_type(&Value::Boolean(false), Value::Empty), + EvalexprError::expected_boolean(Value::Empty) + ); + assert_eq!( + EvalexprError::expected_type(&Value::Tuple(vec![]), Value::Empty), + EvalexprError::expected_tuple(Value::Empty) + ); + assert_eq!( + EvalexprError::expected_type(&Value::Empty, Value::String("abc".to_string())), + EvalexprError::expected_empty(Value::String("abc".to_string())) + ); + } +} diff --git a/tests/integration.rs b/tests/integration.rs index 5bf6c24..a6f244c 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -582,6 +582,7 @@ fn test_shortcut_functions() { eval_number("abc"), Err(EvalexprError::VariableIdentifierNotFound("abc".to_owned())) ); + assert_eq!(eval_number_with_context("3.5", &context), Ok(3.5)); assert_eq!(eval_number_with_context("3", &context), Ok(3.0)); assert_eq!( eval_number_with_context("true", &context), @@ -593,6 +594,7 @@ fn test_shortcut_functions() { eval_number_with_context("abc", &context), Err(EvalexprError::VariableIdentifierNotFound("abc".to_owned())) ); + assert_eq!(eval_number_with_context_mut("3.5", &mut context), Ok(3.5)); assert_eq!(eval_number_with_context_mut("3", &mut context), Ok(3.0)); assert_eq!( eval_number_with_context_mut("true", &mut context),