cargo fmt
This commit is contained in:
parent
a219f0b66f
commit
9eedc8e93b
@ -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(),
|
||||||
|
@ -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]
|
||||||
|
Loading…
Reference in New Issue
Block a user