forked from microsoft/regorus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* specific functions added to eval different rego components Signed-off-by: eric-therond <[email protected]> * allow multiple inputs and results Signed-off-by: eric-therond <[email protected]> * prepare_for_eval is necessary to be called Signed-off-by: eric-therond <[email protected]> * test with the suggested code examples and clean scopes Signed-off-by: eric-therond <[email protected]> * try to refactor first steps of evaluations Signed-off-by: eric-therond <[email protected]> * improve coverage and fix clean state internal evaluation Signed-off-by: eric-therond <[email protected]> * add getters and setters and fix clean function Signed-off-by: eric-therond <[email protected]> * Tests are single input by default. Multi input specified via "many!" marker. Signed-off-by: Anand Krishnamoorthi <[email protected]> --------- Signed-off-by: eric-therond <[email protected]> Signed-off-by: Anand Krishnamoorthi <[email protected]> Co-authored-by: eric-therond <[email protected]>
- Loading branch information
1 parent
2ba718b
commit 2436467
Showing
11 changed files
with
430 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// 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 | ||
x[a] { | ||
a = y | ||
} | ||
y[a] { | ||
a = input.x + 5 | ||
} | ||
"#; | ||
|
||
let input = ValueOrVec::Many(vec![ | ||
Value::from_json_str(r#"{"x": 1}"#)?, | ||
Value::from_json_str(r#"{"x": 6}"#)?, | ||
]); | ||
|
||
let expected = vec![ | ||
Value::from_json_str( | ||
r#" { | ||
"y": {"set!": [6]}, | ||
"x": {"set!": [{"set!":[6]}]} | ||
}"#, | ||
)?, | ||
Value::from_json_str( | ||
r#" { | ||
"y": {"set!": [11]}, | ||
"x": {"set!": [{"set!":[11]}]} | ||
}"#, | ||
)?, | ||
]; | ||
|
||
assert_match( | ||
eval_file_first_rule(&[rego.to_owned()], None, Some(input), "data.test", false)?, | ||
expected, | ||
); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
cases: | ||
- note: input-multiple-1 | ||
data: {} | ||
input: | ||
many!: | ||
- { x: 1 } | ||
- { x: 5 } | ||
modules: | ||
- | | ||
package test | ||
x[a] { | ||
a = y | ||
} | ||
y[a] { | ||
a = input.x + 5 | ||
} | ||
query: data.test | ||
want_result: | ||
many!: | ||
- y: | ||
set!: [6] | ||
x: | ||
set!: [ set!: [6] ] | ||
- y: | ||
set!: [10] | ||
x: | ||
set!: [ set!: [10] ] |
Oops, something went wrong.