cargo fmt
This commit is contained in:
parent
8eedf720e7
commit
9d5ef651ae
@ -24,9 +24,9 @@ macro_rules! simple_math {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn float_is(func: fn(f64) -> bool) -> Option<Function> {
|
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())
|
Ok(func(argument.as_number()?).into())
|
||||||
))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! int_function {
|
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_infinite" => float_is(f64::is_infinite),
|
||||||
"math::is_normal" => float_is(f64::is_normal),
|
"math::is_normal" => float_is(f64::is_normal),
|
||||||
// Other
|
// Other
|
||||||
"typeof" => Some(Function::new(move |argument|
|
"typeof" => Some(Function::new(move |argument| {
|
||||||
Ok(match argument {
|
Ok(match argument {
|
||||||
Value::String(_) => "string",
|
Value::String(_) => "string",
|
||||||
Value::Float(_) => "float",
|
Value::Float(_) => "float",
|
||||||
@ -95,8 +95,9 @@ pub fn builtin_function(identifier: &str) -> Option<Function> {
|
|||||||
Value::Boolean(_) => "boolean",
|
Value::Boolean(_) => "boolean",
|
||||||
Value::Tuple(_) => "tuple",
|
Value::Tuple(_) => "tuple",
|
||||||
Value::Empty => "empty",
|
Value::Empty => "empty",
|
||||||
}.into())
|
}
|
||||||
)),
|
.into())
|
||||||
|
})),
|
||||||
"min" => Some(Function::new(|argument| {
|
"min" => Some(Function::new(|argument| {
|
||||||
let arguments = argument.as_tuple()?;
|
let arguments = argument.as_tuple()?;
|
||||||
let mut min_int = IntType::max_value();
|
let mut min_int = IntType::max_value();
|
||||||
|
@ -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(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/0.0)"), Ok(Value::Boolean(false)));
|
||||||
assert_eq!(eval("math::is_finite(0.0)"), Ok(Value::Boolean(true)));
|
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_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(1.0/0.0)"), Ok(Value::Boolean(false)));
|
||||||
assert_eq!(eval("math::is_normal(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("!(()true)"), Err(EvalexprError::AppendedToLeafNode));
|
||||||
assert_eq!(eval("math::is_nan(\"xxx\")"), Err(EvalexprError::ExpectedNumber {
|
assert_eq!(
|
||||||
actual: Value::String("xxx".to_string())
|
eval("math::is_nan(\"xxx\")"),
|
||||||
}));
|
Err(EvalexprError::ExpectedNumber {
|
||||||
|
actual: Value::String("xxx".to_string())
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user