cargo fmt

This commit is contained in:
Ophir LOJKINE 2022-03-23 18:09:23 +01:00
parent 8eedf720e7
commit 9d5ef651ae
2 changed files with 16 additions and 9 deletions

View File

@ -24,9 +24,9 @@ macro_rules! simple_math {
}
fn float_is(func: fn(f64) -> bool) -> Option<Function> {
Some(Function::new(move |argument|
Some(Function::new(move |argument| {
Ok(func(argument.as_number()?).into())
))
}))
}
macro_rules! int_function {
@ -87,7 +87,7 @@ pub fn builtin_function(identifier: &str) -> Option<Function> {
"math::is_infinite" => float_is(f64::is_infinite),
"math::is_normal" => float_is(f64::is_normal),
// Other
"typeof" => Some(Function::new(move |argument|
"typeof" => Some(Function::new(move |argument| {
Ok(match argument {
Value::String(_) => "string",
Value::Float(_) => "float",
@ -95,8 +95,9 @@ pub fn builtin_function(identifier: &str) -> Option<Function> {
Value::Boolean(_) => "boolean",
Value::Tuple(_) => "tuple",
Value::Empty => "empty",
}.into())
)),
}
.into())
})),
"min" => Some(Function::new(|argument| {
let arguments = argument.as_tuple()?;
let mut min_int = IntType::max_value();

View File

@ -367,7 +367,10 @@ fn test_builtin_functions() {
assert_eq!(eval("math::is_finite(1.0/0.0)"), Ok(Value::Boolean(false)));
assert_eq!(eval("math::is_finite(0.0/0.0)"), Ok(Value::Boolean(false)));
assert_eq!(eval("math::is_finite(0.0)"), Ok(Value::Boolean(true)));
assert_eq!(eval("math::is_infinite(0.0/0.0)"), Ok(Value::Boolean(false)));
assert_eq!(
eval("math::is_infinite(0.0/0.0)"),
Ok(Value::Boolean(false))
);
assert_eq!(eval("math::is_infinite(1.0/0.0)"), Ok(Value::Boolean(true)));
assert_eq!(eval("math::is_normal(1.0/0.0)"), Ok(Value::Boolean(false)));
assert_eq!(eval("math::is_normal(0)"), Ok(Value::Boolean(false)));
@ -449,9 +452,12 @@ fn test_errors() {
})
);
assert_eq!(eval("!(()true)"), Err(EvalexprError::AppendedToLeafNode));
assert_eq!(eval("math::is_nan(\"xxx\")"), Err(EvalexprError::ExpectedNumber {
actual: Value::String("xxx".to_string())
}));
assert_eq!(
eval("math::is_nan(\"xxx\")"),
Err(EvalexprError::ExpectedNumber {
actual: Value::String("xxx".to_string())
})
);
}
#[test]