Skip to content

Commit

Permalink
Add logical operator short circuiting tests for list and map accesses (
Browse files Browse the repository at this point in the history
…#404)

Signed-off-by: Justin King <[email protected]>
  • Loading branch information
jcking authored Oct 22, 2024
1 parent 9a79788 commit 55cd8c3
Show file tree
Hide file tree
Showing 27 changed files with 312 additions and 1 deletion.
3 changes: 3 additions & 0 deletions tests/simple/testdata/basic.textproto
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# proto-file: ../../../proto/test/v1/simple.proto
# proto-message: google.api.expr.test.v1.SimpleTestFile

name: "basic"
description: "Basic conformance tests that all implementations should pass."
section {
Expand Down
3 changes: 3 additions & 0 deletions tests/simple/testdata/bindings_ext.textproto
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# proto-file: ../../../proto/test/v1/simple.proto
# proto-message: google.api.expr.test.v1.SimpleTestFile

name: "bindings_ext"
description: "Tests for the bindings extension library."
section: {
Expand Down
3 changes: 3 additions & 0 deletions tests/simple/testdata/block_ext.textproto
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# proto-file: ../../../proto/test/v1/simple.proto
# proto-message: google.api.expr.test.v1.SimpleTestFile

# This conformance test relies on the test-only macros cel.block, cel.index,
# cel.iterVar, and cel.accuVar. These test-only macros allow excercising
# cel.block without the optimizers being present.
Expand Down
3 changes: 3 additions & 0 deletions tests/simple/testdata/comparisons.textproto
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# proto-file: ../../../proto/test/v1/simple.proto
# proto-message: google.api.expr.test.v1.SimpleTestFile

name: "comparisons"
description: "Tests for boolean-valued functions and operators."
section {
Expand Down
3 changes: 3 additions & 0 deletions tests/simple/testdata/conversions.textproto
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# proto-file: ../../../proto/test/v1/simple.proto
# proto-message: google.api.expr.test.v1.SimpleTestFile

name: "conversions"
description: "Tests for type conversions."
section {
Expand Down
3 changes: 3 additions & 0 deletions tests/simple/testdata/dynamic.textproto
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# proto-file: ../../../proto/test/v1/simple.proto
# proto-message: google.api.expr.test.v1.SimpleTestFile

name: "dynamic"
description: "Tests for 'dynamic' proto behavior, including JSON, wrapper, and Any messages."
section {
Expand Down
3 changes: 3 additions & 0 deletions tests/simple/testdata/encoders_ext.textproto
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# proto-file: ../../../proto/test/v1/simple.proto
# proto-message: google.api.expr.test.v1.SimpleTestFile

name: "encoders_ext"
description: "Tests for the encoders extension library."
section: {
Expand Down
3 changes: 3 additions & 0 deletions tests/simple/testdata/enums.textproto
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# proto-file: ../../../proto/test/v1/simple.proto
# proto-message: google.api.expr.test.v1.SimpleTestFile

name: "enums"
description: "Tests for enum types."
section {
Expand Down
178 changes: 178 additions & 0 deletions tests/simple/testdata/fields.textproto
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# proto-file: ../../../proto/test/v1/simple.proto
# proto-message: google.api.expr.test.v1.SimpleTestFile

name: "fields"
description: "Tests for field access in maps."
section {
Expand Down Expand Up @@ -86,6 +89,61 @@ section {
errors: { message: "no such key" }
}
}
test {
name: "map_no_such_key_or_false"
expr: "dyn({0:1,2:2,5:3}[1]) || false"
eval_error: {
errors: { message: "no such key" }
}
}
test {
name: "map_no_such_key_or_true"
expr: "dyn({0:1,2:2,5:3}[1]) || true"
value: { bool_value: true }
}
test {
name: "map_no_such_key_and_false"
expr: "dyn({0:1,2:2,5:3}[1]) && false"
value: { bool_value: false }
}
test {
name: "map_no_such_key_and_true"
expr: "dyn({0:1,2:2,5:3}[1]) && true"
eval_error: {
errors: { message: "no such key" }
}
}
test {
name: "map_bad_key_type"
expr: "{0:1,2:2,5:3}[dyn(b'')]"
eval_error: {
errors: { message: "no such key" }
}
}
test {
name: "map_bad_key_type_or_false"
expr: "dyn({0:1,2:2,5:3}[dyn(b'')]) || false"
eval_error: {
errors: { message: "no such key" }
}
}
test {
name: "map_bad_key_type_or_true"
expr: "dyn({0:1,2:2,5:3}[dyn(b'')]) || true"
value: { bool_value: true }
}
test {
name: "map_bad_key_type_and_false"
expr: "dyn({0:1,2:2,5:3}[dyn(b'')]) && false"
value: { bool_value: false }
}
test {
name: "map_bad_key_type_and_true"
expr: "dyn({0:1,2:2,5:3}[dyn(b'')]) && true"
eval_error: {
errors: { message: "no such key" }
}
}
test {
name: "map_field_select_no_such_key"
expr: "x.name"
Expand Down Expand Up @@ -117,6 +175,126 @@ section {
errors: { message:"no such key: 'name'" }
}
}
test {
name: "map_field_select_no_such_key_or_false"
expr: "dyn(x.name) || false"
type_env: {
name: "x",
ident: {
type: {
map_type: {
key_type: {primitive: STRING}
value_type: {primitive: STRING}
}
}
}
}
bindings: {
key: "x",
value: {
value: {
map_value: {
entries {
key: { string_value: "holiday" }
value: { string_value: "field" }
}
}
}
}
}
eval_error: {
errors: { message:"no such key: 'name'" }
}
}
test {
name: "map_field_select_no_such_key_or_true"
expr: "dyn(x.name) || true"
type_env: {
name: "x",
ident: {
type: {
map_type: {
key_type: {primitive: STRING}
value_type: {primitive: STRING}
}
}
}
}
bindings: {
key: "x",
value: {
value: {
map_value: {
entries {
key: { string_value: "holiday" }
value: { string_value: "field" }
}
}
}
}
}
value: { bool_value: true }
}
test {
name: "map_field_select_no_such_key_and_false"
expr: "dyn(x.name) && false"
type_env: {
name: "x",
ident: {
type: {
map_type: {
key_type: {primitive: STRING}
value_type: {primitive: STRING}
}
}
}
}
bindings: {
key: "x",
value: {
value: {
map_value: {
entries {
key: { string_value: "holiday" }
value: { string_value: "field" }
}
}
}
}
}
value: { bool_value: false }
}
test {
name: "map_field_select_no_such_key_and_true"
expr: "dyn(x.name) && true"
type_env: {
name: "x",
ident: {
type: {
map_type: {
key_type: {primitive: STRING}
value_type: {primitive: STRING}
}
}
}
}
bindings: {
key: "x",
value: {
value: {
map_value: {
entries {
key: { string_value: "holiday" }
value: { string_value: "field" }
}
}
}
}
}
eval_error: {
errors: { message:"no such key: 'name'" }
}
}
test {
name: "map_value_null"
expr: '{true:null}[true]'
Expand Down
3 changes: 3 additions & 0 deletions tests/simple/testdata/fp_math.textproto
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# proto-file: ../../../proto/test/v1/simple.proto
# proto-message: google.api.expr.test.v1.SimpleTestFile

name: "fp_math"
description: "Tests for floating-point math."
section {
Expand Down
3 changes: 3 additions & 0 deletions tests/simple/testdata/integer_math.textproto
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# proto-file: ../../../proto/test/v1/simple.proto
# proto-message: google.api.expr.test.v1.SimpleTestFile

name: "integer_math"
description: "Tests for int and uint math."
section {
Expand Down
60 changes: 59 additions & 1 deletion tests/simple/testdata/lists.textproto
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# proto-file: ../../../proto/test/v1/simple.proto
# proto-message: google.api.expr.test.v1.SimpleTestFile

name: "lists"
description: "Tests for list operations."
section {
Expand Down Expand Up @@ -90,12 +93,67 @@ section {
value: { string_value: "Ringo" }
}
test {
name: "range"
name: "index_out_of_bounds"
expr: "[1, 2, 3][3]"
eval_error {
errors { message: "invalid_argument" }
}
}
test {
name: "index_out_of_bounds_or_false"
expr: "dyn([1, 2, 3][3]) || false"
eval_error {
errors { message: "invalid_argument" }
}
}
test {
name: "index_out_of_bounds_or_true"
expr: "dyn([1, 2, 3][3]) || true"
value: { bool_value: true }
}
test {
name: "index_out_of_bounds_and_false"
expr: "dyn([1, 2, 3][3]) && false"
value: { bool_value: false }
}
test {
name: "index_out_of_bounds_and_true"
expr: "dyn([1, 2, 3][3]) && true"
eval_error {
errors { message: "invalid_argument" }
}
}
test {
name: "bad_index_type"
expr: "[1, 2, 3][dyn('')]"
eval_error {
errors { message: "invalid_argument" }
}
}
test {
name: "bad_index_type_or_false"
expr: "dyn([1, 2, 3][dyn('')]) || false"
eval_error {
errors { message: "invalid_argument" }
}
}
test {
name: "bad_index_type_or_true"
expr: "dyn([1, 2, 3][dyn('')]) || true"
value: { bool_value: true }
}
test {
name: "bad_index_type_and_false"
expr: "dyn([1, 2, 3][dyn('')]) && false"
value: { bool_value: false }
}
test {
name: "bad_index_type_and_true"
expr: "dyn([1, 2, 3][dyn('')]) && true"
eval_error {
errors { message: "invalid_argument" }
}
}
}
section {
name: "in"
Expand Down
3 changes: 3 additions & 0 deletions tests/simple/testdata/logic.textproto
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# proto-file: ../../../proto/test/v1/simple.proto
# proto-message: google.api.expr.test.v1.SimpleTestFile

name: "logic"
description: "Tests for logical special operators."
section {
Expand Down
3 changes: 3 additions & 0 deletions tests/simple/testdata/macros.textproto
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# proto-file: ../../../proto/test/v1/simple.proto
# proto-message: google.api.expr.test.v1.SimpleTestFile

name: "macros"
description: "Tests for CEL macros."
section {
Expand Down
3 changes: 3 additions & 0 deletions tests/simple/testdata/math_ext.textproto
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# proto-file: ../../../proto/test/v1/simple.proto
# proto-message: google.api.expr.test.v1.SimpleTestFile

name: "math_ext"
description: "Tests for the math extension library."
section: {
Expand Down
3 changes: 3 additions & 0 deletions tests/simple/testdata/namespace.textproto
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# proto-file: ../../../proto/test/v1/simple.proto
# proto-message: google.api.expr.test.v1.SimpleTestFile

name: "namespace"
description: "Uses of qualified identifiers and namespaces."
section {
Expand Down
3 changes: 3 additions & 0 deletions tests/simple/testdata/optionals.textproto
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# proto-file: ../../../proto/test/v1/simple.proto
# proto-message: google.api.expr.test.v1.SimpleTestFile

name: "optionals"
description: "Tests for optionals."
section: {
Expand Down
3 changes: 3 additions & 0 deletions tests/simple/testdata/parse.textproto
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# proto-file: ../../../proto/test/v1/simple.proto
# proto-message: google.api.expr.test.v1.SimpleTestFile

name: "parse"
description: "End-to-end parsing tests."
section {
Expand Down
3 changes: 3 additions & 0 deletions tests/simple/testdata/plumbing.textproto
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# proto-file: ../../../proto/test/v1/simple.proto
# proto-message: google.api.expr.test.v1.SimpleTestFile

name: "plumbing"
description: "Check that the ConformanceService server can accept all arguments and return all responses."
section {
Expand Down
3 changes: 3 additions & 0 deletions tests/simple/testdata/proto2.textproto
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# proto-file: ../../../proto/test/v1/simple.proto
# proto-message: google.api.expr.test.v1.SimpleTestFile

name: "proto2"
description: "Protocol buffer version 2 tests. See notes for the available set of protos for tests."

Expand Down
Loading

0 comments on commit 55cd8c3

Please sign in to comment.