-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix grammar: allow import between rules and complex expression in els…
…e statement (#80) * fix grammar: allow import between rules and allow "complex" expression in else statement also merge 'else keyword' and 'else keyword 2' tests into 'else keyword' Signed-off-by: Vincent Gramer <[email protected]>
- Loading branch information
Showing
6 changed files
with
66 additions
and
13 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
43 changes: 42 additions & 1 deletion
43
src/test/resources/org/openpolicyagent/ideaplugin/lang/parser/fixtures/else_keyword.rego
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 |
---|---|---|
@@ -1,4 +1,45 @@ | ||
package main | ||
a := [] | ||
|
||
# In order to handle manifest with one or many resources, we turns the input into an array, if it's not an array already. | ||
as_array(x) = [x] {not is_array(x)} else = x {true} | ||
as_array(x) = [x] {not is_array(x)} else = x {true} | ||
|
||
|
||
authorize = "allow" { | ||
input.user == "superuser" # allow 'superuser' to perform any operation. | ||
} else = "deny" { | ||
input.path[0] == "admin" # disallow 'admin' operations... | ||
input.source_network == "external" # from external networks. | ||
} | ||
|
||
|
||
check_function_call_for_else(x) = x { | ||
x % 2 == 0 | ||
}else = abs(x) { | ||
true | ||
} | ||
|
||
check_infix_op_for_else(x) = x { | ||
x % 2 == 0 | ||
} else = x *2 - 1 { | ||
true | ||
} | ||
|
||
|
||
check_array_comprehension_for_else(x) = x { | ||
x % 2 == 0 | ||
} else = [y | some y; a[y] == x] { | ||
true | ||
} | ||
|
||
check_set_comprehension_for_else(x) = x { | ||
x % 2 == 0 | ||
} else = {y | some y; a[y]} { | ||
true | ||
} | ||
|
||
check_object_comprehension_for_else(x) = x { | ||
x % 2 == 0 | ||
} else = {y : "true" | some y; a[y] } { | ||
true | ||
} |
8 changes: 0 additions & 8 deletions
8
src/test/resources/org/openpolicyagent/ideaplugin/lang/parser/fixtures/else_keyword_2.rego
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
src/test/resources/org/openpolicyagent/ideaplugin/lang/parser/fixtures/imports.rego
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package test | ||
|
||
import data.policy | ||
import data.security.policy as p | ||
|
||
default allow = false | ||
allow { | ||
|
18 changes: 18 additions & 0 deletions
18
.../resources/org/openpolicyagent/ideaplugin/lang/parser/fixtures/imports_between_rules.rego
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,18 @@ | ||
package test | ||
|
||
import data.policy | ||
import data.security.policy as p | ||
|
||
default allow = false | ||
allow { | ||
true | ||
} | ||
|
||
import data.domain | ||
import data.otherdomain as od | ||
|
||
rule_1 { | ||
1 == 1 | ||
} | ||
|
||
import data.something |