Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BNF tests along with few BNF fixes #39

Merged
merged 8 commits into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/grammar/Rego.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ package ::= "package" ref
import ::= "import" ref ( "as" var )?
policy ::= rule*
rule ::= "default"? rule-head rule-body*
rule-head ::= var ( "(" rule-args ")" )? ("[" term "]" )? ( ( ":=" | "=" ) term )?
rule-head ::= var ( "(" rule-args? ")" )? ("[" term "]" )? ( ( ":=" | "=" ) term )?
rule-args ::= term ( "," term )*
rule-body ::= ( else ( "=" term )? )? "{" query "}"
query ::=( literal |';' )+
Expand All @@ -86,7 +86,7 @@ set-compr ::= "{" term "|" query "}"
object-compr ::= "{" object-item "|" query "}"
infix-operator ::= bool-operator | arith-operator | bin-operator
bool-operator ::= "==" | "!=" | "<" | ">" | ">=" | "<="
arith-operator ::= "+" | "-" | "*" | "/"
arith-operator ::= "+" | "-" | "*" | "/" | "%"
bin-operator ::= "&" | "|"
ref ::= ( expr-call | array | object | set | array-compr | object-compr | set-compr |var ) ref-arg*
ref-arg ::= ref-arg-dot | ref-arg-brack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class RegoParsingTestCase: RegoParsingTestCaseBase() {

fun `test array comprehension`() = doTestNoError()
fun `test set comprehension`() = doTestNoError()
fun `test set comprehensions 2`() = doTestNoError()
fun `test set comprehensions 3`() = doTestNoError()
fun `test object comprehension`() = doTestNoError()

fun `test implicit or`() = doTestNoError()
Expand All @@ -25,4 +27,26 @@ class RegoParsingTestCase: RegoParsingTestCaseBase() {
fun `test complex rule 2`() = doTestNoError()
fun `test complex rule 3`() = doTestNoError()

}

fun `test array comprehensions 2`() = doTestNoError()
fun `test built in functions`() = doTestNoError()
fun `test functions`() = doTestNoError()
fun `test multiple expressions`() = doTestNoError()
fun `test rules`() = doTestNoError()
fun `test self joins`() = doTestNoError()
fun `test with keyword 2`() = doTestNoError()


fun `test composite keys`() = doTestNoError()
fun `test composite values`() = doTestNoError()
fun `test else keyword 2`() = doTestNoError()
fun `test imports`() = doTestNoError()
fun `test negations`() = doTestNoError()
fun `test package with simple rule`() = doTestNoError()
fun `test references`() = doTestNoError()
fun `test rules with single predicates`() = doTestNoError()
fun `test scalars assignment`() = doTestNoError()
fun `test sets`() = doTestNoError()
fun `test strings`() = doTestNoError()
fun `test variables`() = doTestNoError()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package test

apps:={}
sites:={}

app_to_hostnames[app_name] = hostnames {
app := apps[_]
app_name := app.name
hostnames := [hostname | name := app.servers[_]
s := sites[_].servers[_]
s.name == name
hostname := s.hostname]
}

aRule {
app_to_hostnames[app]
}
Loading