// `is` tests applied via the `is` operator, e.g. `{% if x is odd %}`.
//
// Parameterless tests. Tests with arguments (starting_with, containing,
// divisible_by) arrive in a later step.
///|
/// Apply a named `is` test to a value. Unknown tests return false.
pub fn apply_test(name : String, v : Value) -> Bool {
match name {
"odd" =>
match v {
Int(i) => i % 2 != 0
_ => false
}
"even" =>
match v {
Int(i) => i % 2 == 0
_ => false
}
"defined" =>
match v {
Null => false
_ => true
}
"undefined" =>
match v {
Null => true
_ => false
}
"string" =>
match v {
Str(_) => true
_ => false
}
"number" =>
match v {
Int(_) => true
Float(_) => true
_ => false
}
"integer" =>
match v {
Int(_) => true
_ => false
}
"float" =>
match v {
Float(_) => true
_ => false
}
"bool" =>
match v {
Bool(_) => true
_ => false
}
"array" =>
match v {
Array(_) => true
_ => false
}
"object" =>
match v {
Object(_) => true
_ => false
}
"empty" => !v.is_truthy()
"iterable" =>
match v {
Array(_) => true
Object(_) => true
_ => false
}
_ => false
}
}