diff --git a/lib/Fregot/Eval/Builtins.hs b/lib/Fregot/Eval/Builtins.hs index e2af45fe..60ecd46b 100644 --- a/lib/Fregot/Eval/Builtins.hs +++ b/lib/Fregot/Eval/Builtins.hs @@ -220,6 +220,7 @@ defaultBuiltins = HMS.fromList , (NamedFunction (BuiltinName "indexof"), builtin_indexof) , (NamedFunction (BuiltinName "intersection"), builtin_intersection) , (NamedFunction (BuiltinName "is_array"), builtin_is_array) + , (NamedFunction (BuiltinName "is_boolean"), builtin_is_boolean) , (NamedFunction (BuiltinName "is_object"), builtin_is_object) , (NamedFunction (BuiltinName "is_string"), builtin_is_string) , (NamedFunction (QualifiedName "json" "unmarshal"), builtin_json_unmarshal) @@ -320,6 +321,12 @@ builtin_is_array = Builtin (In Out) $ pure $ ArrayV _ -> return True _ -> return False +builtin_is_boolean :: Monad m => Builtin m +builtin_is_boolean = Builtin (In Out) $ pure $ + \(Cons val Nil) -> case val of + BoolV _ -> return True + _ -> return False + builtin_is_object :: Monad m => Builtin m builtin_is_object = Builtin (In Out) $ pure $ \(Cons val Nil) -> case val of diff --git a/tests/rego/builtins-06.rego b/tests/rego/builtins-06.rego new file mode 100644 index 00000000..ebf0c549 --- /dev/null +++ b/tests/rego/builtins-06.rego @@ -0,0 +1,9 @@ +# 'is_' functions +package fregot.tests.builtins_06 + +test_is_boolean { + is_boolean(true) + is_boolean(false) + not is_boolean(1) + not is_boolean([true]) +}