forked from open-policy-agent/opa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
topdown: add yaml.is_valid and json.is_valid
Signed-off-by: Jasper Van der Jeugt <jasper@fugue.co>
- Loading branch information
1 parent
99a8143
commit d8947db
Showing
5 changed files
with
143 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
cases: | ||
- note: jsonbuiltins/json is_valid | ||
query: data.generated.p = x | ||
modules: | ||
- | | ||
package generated | ||
documents = [ | ||
`plainstring`, | ||
`{`, | ||
`{"json": "ok"}`, | ||
] | ||
p = [x | doc = documents[_]; json.is_valid(doc, x)] | ||
want_result: | ||
- x: | ||
- false | ||
- false | ||
- true | ||
|
||
- note: jsonbuiltins/json is_valid not string | ||
modules: | ||
- | | ||
package generated | ||
p = x { | ||
json.is_valid(input.foo, x) | ||
} | ||
query: data.generated.p = x | ||
input: {"foo": 1} | ||
want_error: operand 1 must be string but got number | ||
want_error_code: eval_type_error | ||
|
||
- note: jsonbuiltins/yaml is_valid | ||
query: data.generated.p = x | ||
modules: | ||
- | | ||
package generated | ||
documents = [ | ||
`foo: | ||
- qux: bar | ||
- baz: 2`, | ||
`foo: | ||
- qux: bar | ||
- baz: {`, | ||
`{"json": "ok"}`, | ||
] | ||
p = [x | doc = documents[_]; yaml.is_valid(doc, x)] | ||
want_result: | ||
- x: | ||
- true | ||
- false | ||
- true | ||
|
||
- note: jsonbuiltins/yaml is_valid not string | ||
modules: | ||
- | | ||
package generated | ||
p = x { | ||
yaml.is_valid(input.foo, x) | ||
} | ||
query: data.generated.p = x | ||
input: {"foo": 1} | ||
want_error: operand 1 must be string but got number | ||
want_error_code: eval_type_error |
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