Files
regorus/tests/parser/cases/rules/else.yaml
Anand Krishnamoorthi b11007a1be fix: Disallow else blocks for set rules (#403)
else blocks following contains and old-style sets will raise
a parse error. Consistent with OPA.

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2025-04-29 11:14:37 -05:00

273 lines
5.3 KiB
YAML

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
cases:
- note: no-query
rego: |
package test
x = 10 else {
true
}
error: unexpected keyword `else`
- note: no-query
rego: |
package test
x = 10 {
false
} {
true
}
policy:
- spec:
head:
compr:
refr:
var: x
assign:
op: "="
value:
number: 10
bodies:
- query:
stmts:
- literal:
expr:
false
- query:
stmts:
- literal:
expr:
true
- note: no-else
rego: |
package test
x = 10 {
false
} {
true
}
policy:
- spec:
head:
compr:
refr:
var: x
assign:
op: "="
value:
number: 10
bodies:
- query:
stmts:
- literal:
expr:
false
- query:
stmts:
- literal:
expr:
true
- note: if-no-else
rego: |
package test
import future.keywords.if
x = 10 if {
false
} {
true
}
policy:
- spec:
head:
compr:
refr:
var: x
assign:
op: "="
value:
number: 10
bodies:
- query:
stmts:
- literal:
expr:
false
- query:
stmts:
- literal:
expr:
true
- note: rule-named-if
rego: |
package test
x = 10 if {
false
} {
true
}
policy:
- spec:
head:
compr:
refr:
var: x
assign:
op: "="
value:
number: 10
bodies: []
- spec:
head:
compr:
refr:
var: if
bodies:
- query:
stmts:
- literal:
expr:
false
- query:
stmts:
- literal:
expr:
true
- note: query-else
rego: |
package test
x = 10 {
false
} else {
true
}
policy:
- spec:
head:
compr:
refr:
var: x
assign:
op: "="
value:
number: 10
bodies:
- query:
stmts:
- literal:
expr:
false
- query:
stmts:
- literal:
expr:
true
- note: if-literal-else
rego: |
package test
import future.keywords.if
x = 10 if 1 < 0 else {
true
}
policy:
- spec:
head:
compr:
refr:
var: x
assign:
op: "="
value:
number: 10
bodies:
- query:
stmts:
- literal:
expr:
boolexpr:
op: "<"
lhs:
number: 1
rhs:
number: 0
- query:
stmts:
- literal:
expr:
true
- note: if-literal-else-assign
rego: |
package test
import future.keywords.if
# This will evaluate to 10
x = 10 if 1 < 0 else := 20 {
true
}
policy:
- spec:
head:
compr:
refr:
var: x
assign:
op: "="
value:
number: 10
bodies:
- query:
stmts:
- literal:
expr:
boolexpr:
op: "<"
lhs:
number: 1
rhs:
number: 0
- assign:
op: ":="
value:
number: 20
query:
stmts:
- literal:
expr:
true
- note: contains-else-error
rego: |
package test
import rego.v1
a contains "b" if {
false
} else if {
true
}
error: else cannot be used with set rules
- note: old-style-set-else-error
rego: |
package test
a["b"] {
false
} else {
true
}
error: else cannot be used with set rules