Increase test coverage.

This commit is contained in:
Sebastian Schmidt 2022-01-13 15:18:06 +02:00
parent fcbf284d18
commit 79cb25bc9d
2 changed files with 35 additions and 0 deletions

View File

@ -366,3 +366,36 @@ impl std::error::Error for EvalexprError {}
/// Standard result type used by this crate. /// Standard result type used by this crate.
pub type EvalexprResult<T> = Result<T, EvalexprError>; pub type EvalexprResult<T> = Result<T, EvalexprError>;
#[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()))
);
}
}

View File

@ -582,6 +582,7 @@ fn test_shortcut_functions() {
eval_number("abc"), eval_number("abc"),
Err(EvalexprError::VariableIdentifierNotFound("abc".to_owned())) 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("3", &context), Ok(3.0));
assert_eq!( assert_eq!(
eval_number_with_context("true", &context), eval_number_with_context("true", &context),
@ -593,6 +594,7 @@ fn test_shortcut_functions() {
eval_number_with_context("abc", &context), eval_number_with_context("abc", &context),
Err(EvalexprError::VariableIdentifierNotFound("abc".to_owned())) 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("3", &mut context), Ok(3.0));
assert_eq!( assert_eq!(
eval_number_with_context_mut("true", &mut context), eval_number_with_context_mut("true", &mut context),