mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
Tests for types functions
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
committed by
Anand Krishnamoorthi
parent
ae3866b1ab
commit
c4ae2d4cc2
@@ -27,7 +27,8 @@ lazy_static! {
|
||||
|
||||
numbers::register(&mut m);
|
||||
aggregates::register(&mut m);
|
||||
arrays::register(&mut m);
|
||||
arrays::register(&mut m);
|
||||
types::register(&mut m);
|
||||
|
||||
m
|
||||
};
|
||||
|
||||
11
tests/interpreter/cases/builtins/mod.rs
Normal file
11
tests/interpreter/cases/builtins/mod.rs
Normal 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");
|
||||
}
|
||||
48
tests/interpreter/cases/builtins/types.yaml
Normal file
48
tests/interpreter/cases/builtins/types.yaml
Normal file
@@ -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"
|
||||
@@ -2,6 +2,7 @@
|
||||
// Licensed under the MIT License.
|
||||
|
||||
mod arithmetic;
|
||||
mod builtins;
|
||||
mod compr;
|
||||
mod r#in;
|
||||
mod variables;
|
||||
|
||||
@@ -350,37 +350,6 @@ fn one_yaml() -> Result<()> {
|
||||
yaml_test(file.as_str())
|
||||
}
|
||||
|
||||
/*
|
||||
fn run_yaml_tests_in(folder: &str) -> Result<()> {
|
||||
let mut total = 0;
|
||||
|
||||
for entry in WalkDir::new(folder)
|
||||
.follow_links(true)
|
||||
.into_iter()
|
||||
.filter_map(|e| e.ok())
|
||||
{
|
||||
let path = entry
|
||||
.path()
|
||||
.to_str()
|
||||
.ok_or_else(|| anyhow!("failed to convert path to utf8 {:?}", entry.path()))?;
|
||||
if !path.ends_with(".yaml") {
|
||||
continue;
|
||||
}
|
||||
|
||||
total += 1;
|
||||
yaml_test(path)?;
|
||||
}
|
||||
|
||||
println!("{} yaml tests passed.", total);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_yaml_tests() -> Result<()> {
|
||||
run_yaml_tests_in("tests/interpreter")
|
||||
}
|
||||
*/
|
||||
|
||||
#[test_resources("tests/interpreter/**/*.yaml")]
|
||||
fn run(path: &str) {
|
||||
yaml_test(path).unwrap()
|
||||
|
||||
Reference in New Issue
Block a user