cargo fmt

This commit is contained in:
Ophir LOJKINE 2022-03-14 15:07:38 +01:00
parent a219f0b66f
commit 9eedc8e93b
2 changed files with 10 additions and 2 deletions

View File

@ -123,7 +123,12 @@ pub fn builtin_function(identifier: &str) -> Option<Function> {
})), })),
"if" => Some(Function::new(|argument| { "if" => Some(Function::new(|argument| {
if let [condition, if_true, if_false] = &argument.as_fixed_len_tuple(3)?[..] { if let [condition, if_true, if_false] = &argument.as_fixed_len_tuple(3)?[..] {
return Ok(if condition.as_boolean()? { if_true } else { if_false }.clone()) return Ok(if condition.as_boolean()? {
if_true
} else {
if_false
}
.clone());
} }
Err(EvalexprError::type_error( Err(EvalexprError::type_error(
argument.clone(), argument.clone(),

View File

@ -410,7 +410,10 @@ fn test_builtin_functions() {
assert_eq!(eval("shr(-6, 5)"), Ok(Value::Int(-1))); assert_eq!(eval("shr(-6, 5)"), Ok(Value::Int(-1)));
assert_eq!(eval("if(true, -6, 5)"), Ok(Value::Int(-6))); assert_eq!(eval("if(true, -6, 5)"), Ok(Value::Int(-6)));
assert_eq!(eval("if(false, -6, 5)"), Ok(Value::Int(5))); assert_eq!(eval("if(false, -6, 5)"), Ok(Value::Int(5)));
assert_eq!(eval("if(2-1==1, \"good\", 0)"), Ok(Value::String(String::from("good")))); assert_eq!(
eval("if(2-1==1, \"good\", 0)"),
Ok(Value::String(String::from("good")))
);
} }
#[test] #[test]