Return Ok when disabling builtin functions in EmptyContext and enabling builtin functions in EmptyContextWithBuiltinFunctions.

These are noops anyways.
This commit is contained in:
Sebastian Schmidt 2023-05-21 10:22:46 +03:00
parent 5a4dcf9516
commit c01a23bcf8
2 changed files with 15 additions and 5 deletions

View File

@ -94,8 +94,12 @@ impl Context for EmptyContext {
} }
/// Builtin functions can't be enabled for `EmptyContext`. /// Builtin functions can't be enabled for `EmptyContext`.
fn set_builtin_functions_disabled(&mut self, _disabled: bool) -> EvalexprResult<()> { fn set_builtin_functions_disabled(&mut self, disabled: bool) -> EvalexprResult<()> {
Err(EvalexprError::BuiltinFunctionsCannotBeEnabled) if disabled {
Ok(())
} else {
Err(EvalexprError::BuiltinFunctionsCannotBeEnabled)
}
} }
} }
@ -134,8 +138,12 @@ impl Context for EmptyContextWithBuiltinFunctions {
} }
/// Builtin functions can't be disabled for EmptyContextWithBuiltinFunctions. /// Builtin functions can't be disabled for EmptyContextWithBuiltinFunctions.
fn set_builtin_functions_disabled(&mut self, _disabled: bool) -> EvalexprResult<()> { fn set_builtin_functions_disabled(&mut self, disabled: bool) -> EvalexprResult<()> {
Err(EvalexprError::BuiltinFunctionsCannotBeDisabled) if disabled {
Err(EvalexprError::BuiltinFunctionsCannotBeDisabled)
} else {
Ok(())
}
} }
} }

View File

@ -1527,6 +1527,7 @@ fn test_empty_context() {
"max" "max"
))) )))
); );
assert_eq!(context.set_builtin_functions_disabled(true), Ok(()));
assert_eq!( assert_eq!(
context.set_builtin_functions_disabled(false), context.set_builtin_functions_disabled(false),
Err(EvalexprError::BuiltinFunctionsCannotBeEnabled) Err(EvalexprError::BuiltinFunctionsCannotBeEnabled)
@ -1542,9 +1543,10 @@ fn test_empty_context_with_builtin_functions() {
Err(EvalexprError::FunctionIdentifierNotFound("abc".to_owned())) Err(EvalexprError::FunctionIdentifierNotFound("abc".to_owned()))
); );
assert_eq!(eval_with_context("max(1,3)", &context), Ok(Value::Int(3))); assert_eq!(eval_with_context("max(1,3)", &context), Ok(Value::Int(3)));
assert_eq!(context.set_builtin_functions_disabled(false), Ok(()));
assert_eq!( assert_eq!(
context.set_builtin_functions_disabled(true), context.set_builtin_functions_disabled(true),
Err(EvalexprError::BuiltinFunctionsCannotBeEnabled) Err(EvalexprError::BuiltinFunctionsCannotBeDisabled)
); );
} }