Tests for types functions

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
Anand Krishnamoorthi
2023-02-21 20:46:11 -08:00
committed by Anand Krishnamoorthi
parent ae3866b1ab
commit c4ae2d4cc2
5 changed files with 62 additions and 32 deletions
+11
View File
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
use regorus::builtins;
use regorus::Value;
// Lockdown calls that cannot happen via rego.
#[test]
fn type_name_undefined() {
assert_eq!(builtins::types::get_type(&Value::Undefined), "undefined");
}
@@ -0,0 +1,48 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
cases:
- note: all
data: {}
modules:
- |
package test
items = [
[],
true,
null,
0,
{},
set(),
"abc",
]
results = {
"is_array" : [x | x = items[_]; is_array(x)],
"is_boolean" : [x | x = items[_]; is_boolean(x)],
"is_null" : [x | x = items[_]; is_null(x)],
"is_number" : [x | x = items[_]; is_number(x)],
"is_object" : [x | x = items[_]; is_object(x)],
"is_set" : [x | x = items[_]; is_set(x)],
"is_string" : [x | x = items[_]; is_string(x)],
"type_names": [n | n = type_name(items[_])],
}
query: data.test.results
want_result:
is_array: [[]]
is_boolean: [true]
is_null: [null]
is_number: [0]
is_object: [{}]
is_set:
- set!: []
is_string: ["abc"]
type_names:
- "array"
- "boolean"
- "null"
- "number"
- "object"
- "set"
- "string"
+1
View File
@@ -2,6 +2,7 @@
// Licensed under the MIT License.
mod arithmetic;
mod builtins;
mod compr;
mod r#in;
mod variables;