forked from open-policy-agent/opa
-
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.
wasm: Add support for comprehensions
This commit adds suppor for set/array/object comprehensions. No changes are required in the wasm backend because we already have the built-ins for constructing collections dynamically. Fixes open-policy-agent#1120 Signed-off-by: Torin Sandall <torinsandall@gmail.com>
- Loading branch information
Showing
3 changed files
with
146 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
cases: | ||
- note: set comprehension | ||
query: | | ||
{x | input[_] = x} == {1,2,3} | ||
input: [1,2,3] | ||
return_code: 1 | ||
- note: set comprehension (negative) | ||
query: | | ||
{x | input[_] = x; x > 1} == {1,2,3} | ||
input: [1,2,3] | ||
return_code: 0 | ||
- note: array comprehension | ||
query: | | ||
[x | input[_] = x] == [1,2,3] | ||
input: [1,2,3] | ||
return_code: 1 | ||
- note: array comprehension (negative) | ||
query: | | ||
[x | input[_] = x; x > 1] == [1,2,3] | ||
input: [1,2,3] | ||
return_code: 0 | ||
- note: array comprehension unify | ||
query: | | ||
[x | input[_] = x] = [1,y,3] | ||
input: [1,2,3] | ||
return_code: 1 | ||
- note: object comprehension | ||
query: | | ||
{k: v | input[k] = v} == {"a": 1, "b": 2} | ||
input: {"a": 1, "b": 2} | ||
return_code: 1 | ||
- note: object comprehension (negative) | ||
query: | | ||
{k: v | input[k] = v; v > 1} == {"a": 1, "b": 2} | ||
input: {"a": 1, "b": 2} | ||
return_code: 0 | ||
- note: object comprehension unify | ||
query: | | ||
{k: v | input[k] = v} = {"a": y, "b": z} | ||
input: {"a": 1, "b": 2} | ||
return_code: 1 | ||
- note: closure | ||
query: | | ||
a = [1,2,3]; b = 1; {x | a[_] = x; x > b} == {2,3} | ||
return_code: 1 |