Skip to content

Commit

Permalink
Adding ref-head tests
Browse files Browse the repository at this point in the history
Fixes: open-policy-agent#6247
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
  • Loading branch information
johanfylling authored and ashutosh-narkar committed Oct 17, 2023
1 parent addf635 commit 0842a65
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions ast/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,12 @@ p := "foo" if {
module: `package test
import future.strict
p contains "q"`,
},
{
note: "`contains` keyword used on partial set rule (ref-head, const key)",
module: `package test
import future.strict
p.q contains "r"`,
},
{
note: "`contains` keyword not used on partial set rule (const key)",
Expand Down Expand Up @@ -1453,6 +1459,12 @@ import future.strict
p[input.x]`,
expectedErrors: []string{"rego_parse_error: `contains` keyword is required for partial set rules"},
},
{
note: "`if` keyword not used on partial object rule (ref-head, var key, implicit `true` value, no body)",
module: `package test
import future.strict
p.q[input.x]`,
},
{
note: "`contains` keyword used on partial set rule (var key)",
module: `package test
Expand All @@ -1476,13 +1488,21 @@ p[x] { x = input.x}`,
"rego_parse_error: `if` keyword is required before rule body",
},
},
{
note: "`contains` and `if` keyword not used on partial object rule (ref-head)",
module: `package test
import future.strict
p.q[x] { x = input.x}`,
expectedErrors: []string{
"rego_parse_error: `if` keyword is required before rule body",
},
},
}

for _, tc := range tests {
t.Run(tc.note, func(t *testing.T) {
_, errs := ParseModuleWithOpts("", tc.module, ParserOptions{})
//parser := NewParser().WithFilename("").WithReader(bytes.NewBufferString(tc.module))
//_, _, errs := parser.Parse()

if len(tc.expectedErrors) == 0 && errs != nil {
t.Fatalf("expected no errors, got:\n\n%v", errs)
}
Expand Down

0 comments on commit 0842a65

Please sign in to comment.