mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
* specific functions added to eval different rego components Signed-off-by: eric-therond <eric.therond.fr@gmail.com> * allow multiple inputs and results Signed-off-by: eric-therond <eric.therond.fr@gmail.com> * prepare_for_eval is necessary to be called Signed-off-by: eric-therond <eric.therond.fr@gmail.com> * test with the suggested code examples and clean scopes Signed-off-by: eric-therond <eric.therond.fr@gmail.com> * try to refactor first steps of evaluations Signed-off-by: eric-therond <eric.therond.fr@gmail.com> * improve coverage and fix clean state internal evaluation Signed-off-by: eric-therond <eric.therond.fr@gmail.com> * add getters and setters and fix clean function Signed-off-by: eric-therond <eric.therond.fr@gmail.com> * Tests are single input by default. Multi input specified via "many!" marker. Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com> --------- Signed-off-by: eric-therond <eric.therond.fr@gmail.com> Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com> Co-authored-by: eric-therond <eric.therond.fr@gmail.com>
47 lines
659 B
Rust
47 lines
659 B
Rust
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT License.
|
|
|
|
#![cfg(test)]
|
|
|
|
use crate::interpreter::*;
|
|
use anyhow::Result;
|
|
|
|
#[test]
|
|
fn basic() -> Result<()> {
|
|
let rego = r#"
|
|
package test
|
|
|
|
add {
|
|
1 + 2 == 3
|
|
}
|
|
|
|
sub {
|
|
5 - 1 == 4
|
|
}
|
|
|
|
mul {
|
|
3 * 4 == 12
|
|
}
|
|
|
|
# Lock down float operation.
|
|
div {
|
|
21 / 5 == 4.2
|
|
}
|
|
"#;
|
|
|
|
let expected = vec![Value::from_json_str(
|
|
r#" {
|
|
"add" : true,
|
|
"sub" : true,
|
|
"mul" : true,
|
|
"div" : true
|
|
}"#,
|
|
)?];
|
|
|
|
assert_eq!(
|
|
eval_file(&[rego.to_owned()], None, None, "data.test", false)?,
|
|
expected
|
|
);
|
|
Ok(())
|
|
}
|