# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto # proto-message: cel.expr.conformance.test.SimpleTestFile # This conformance test relies on the test-only macros cel.block, cel.index, # cel.iterVar, and cel.accuVar. These test-only macros allow exercising # cel.block without the optimizers being present. # `cel.block(l, e)` must rewrite itself to be `cel.block(l, e)` # `cel.index(N)` must rewrite itself to `@indexN` # `cel.iterVar(N, M)` must rewrite itself to `@it:N:M` # `cel.accuVar(N, M)` must rewrite itself to `@ac:N:M` name: "block_ext" description: "Tests for cel.block." section: { name: "basic" test: { name: "int_add" expr: "cel.block([1, cel.index(0) + 1, cel.index(1) + 1, cel.index(2) + 1], cel.index(3))" value: { int64_value: 4 } } test: { name: "size_1" expr: "cel.block([[1, 2], size(cel.index(0)), cel.index(1) + cel.index(1), cel.index(2) + 1], cel.index(3))" value: { int64_value: 5 } } test: { name: "size_2" expr: "cel.block([[1, 2], size(cel.index(0)), 2 + cel.index(1), cel.index(2) + cel.index(1), cel.index(3) + 1], cel.index(4))" value: { int64_value: 7 } } test: { name: "size_3" expr: "cel.block([[0], size(cel.index(0)), [1, 2], size(cel.index(2)), cel.index(1) + cel.index(1), cel.index(4) + cel.index(3), cel.index(5) + cel.index(3)], cel.index(6))" value: { int64_value: 6 } } test: { name: "size_4" expr: "cel.block([[0], size(cel.index(0)), [1, 2], size(cel.index(2)), [1, 2, 3], size(cel.index(4)), 5 + cel.index(1), cel.index(6) + cel.index(1), cel.index(7) + cel.index(3), cel.index(8) + cel.index(3), cel.index(9) + cel.index(5), cel.index(10) + cel.index(5)], cel.index(11))" value: { int64_value: 17 } } test: { name: "timestamp" expr: "cel.block([timestamp(1000000000), int(cel.index(0)), timestamp(cel.index(1)), cel.index(2).getFullYear(), timestamp(50), int(cel.index(4)), timestamp(cel.index(5)), timestamp(200), int(cel.index(7)), timestamp(cel.index(8)), cel.index(9).getFullYear(), timestamp(75), int(cel.index(11)), timestamp(cel.index(12)), cel.index(13).getFullYear(), cel.index(3) + cel.index(14), cel.index(6).getFullYear(), cel.index(15) + cel.index(16), cel.index(17) + cel.index(3), cel.index(6).getSeconds(), cel.index(18) + cel.index(19), cel.index(20) + cel.index(10), cel.index(21) + cel.index(10), cel.index(13).getMinutes(), cel.index(22) + cel.index(23), cel.index(24) + cel.index(3)], cel.index(25))" value: { int64_value: 13934 } } test: { name: "map_index" expr: "cel.block([{\"a\": 2}, cel.index(0)[\"a\"], cel.index(1) * cel.index(1), cel.index(1) + cel.index(2)], cel.index(3))" value: { int64_value: 6 } } test: { name: "nested_map_construction" expr: "cel.block([{\"b\": 1}, {\"e\": cel.index(0)}], {\"a\": cel.index(0), \"c\": cel.index(0), \"d\": cel.index(1), \"e\": cel.index(1)})" value: { map_value: { entries { key: { string_value: 'a' } value: { map_value: { entries { key: { string_value: 'b' } value: { int64_value: 1 } } } } } entries { key: { string_value: 'c' } value: { map_value: { entries { key: { string_value: 'b' } value: { int64_value: 1 } } } } } entries { key: { string_value: 'd' } value: { map_value: { entries { key: { string_value: 'e' } value: { map_value: { entries { key: { string_value: 'b' } value: { int64_value: 1 } } } } } } } } entries { key: { string_value: 'e' } value: { map_value: { entries { key: { string_value: 'e' } value: { map_value: { entries { key: { string_value: 'b' } value: { int64_value: 1 } } } } } } } } } } } test: { name: "nested_list_construction" expr: "cel.block([[1, 2, 3, 4], [1, 2], [cel.index(1), cel.index(0)]], [1, cel.index(0), 2, cel.index(0), 5, cel.index(0), 7, cel.index(2), cel.index(1)])" value: { list_value: { values { int64_value: 1 } values { list_value: { values { int64_value: 1 } values { int64_value: 2 } values { int64_value: 3 } values { int64_value: 4 } } } values { int64_value: 2 } values { list_value: { values { int64_value: 1 } values { int64_value: 2 } values { int64_value: 3 } values { int64_value: 4 } } } values { int64_value: 5 } values { list_value: { values { int64_value: 1 } values { int64_value: 2 } values { int64_value: 3 } values { int64_value: 4 } } } values { int64_value: 7 } values { list_value: { values { list_value: { values { int64_value: 1 } values { int64_value: 2 } } } values { list_value: { values { int64_value: 1 } values { int64_value: 2 } values { int64_value: 3 } values { int64_value: 4 } } } } } values { list_value: { values { int64_value: 1 } values { int64_value: 2 } } } } } } test: { name: "select" expr: "cel.block([msg.single_int64, cel.index(0) + cel.index(0)], cel.index(1))" value: { int64_value: 6 } type_env: { name: "msg" ident: { type: { message_type: "cel.expr.conformance.proto3.TestAllTypes" }} } bindings: { key: "msg" value: { value: { object_value: { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_int64: 3 single_int32: 5 oneof_type: { payload: { single_int32: 8 single_int64: 10 map_int32_int64 { key: 0 value: 1 } map_int32_int64 { key: 1 value: 5 } map_int32_int64 { key: 2 value: 2 } map_string_string { key: "key" value: "A" } } } } } } } } } test: { name: "select_nested_1" expr: "cel.block([msg.oneof_type, cel.index(0).payload, cel.index(1).single_int64, cel.index(1).single_int32, cel.index(2) + cel.index(3), cel.index(4) + cel.index(2), msg.single_int64, cel.index(5) + cel.index(6), cel.index(1).oneof_type, cel.index(8).payload, cel.index(9).single_int64, cel.index(7) + cel.index(10)], cel.index(11))" value: { int64_value: 31 } type_env: { name: "msg" ident: { type: { message_type: "cel.expr.conformance.proto3.TestAllTypes" }} } bindings: { key: "msg" value: { value: { object_value: { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_int64: 3 single_int32: 5 oneof_type: { payload: { single_int32: 8 single_int64: 10 map_int32_int64 { key: 0 value: 1 } map_int32_int64 { key: 1 value: 5 } map_int32_int64 { key: 2 value: 2 } map_string_string { key: "key" value: "A" } } } } } } } } } test: { name: "select_nested_2" expr: "cel.block([msg.oneof_type, cel.index(0).payload, cel.index(1).oneof_type, cel.index(2).payload, cel.index(3).oneof_type, cel.index(4).payload, cel.index(5).oneof_type, cel.index(6).payload, cel.index(7).single_bool, true || cel.index(8), cel.index(4).child, cel.index(10).child, cel.index(11).payload, cel.index(12).single_bool], cel.index(9) || cel.index(13))" value: { bool_value: true } type_env: { name: "msg" ident: { type: { message_type: "cel.expr.conformance.proto3.TestAllTypes" }} } bindings: { key: "msg" value: { value: { object_value: { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_int64: 3 single_int32: 5 oneof_type: { payload: { single_int32: 8 single_int64: 10 map_int32_int64 { key: 0 value: 1 } map_int32_int64 { key: 1 value: 5 } map_int32_int64 { key: 2 value: 2 } map_string_string { key: "key" value: "A" } } } } } } } } } test: { name: "select_nested_message_map_index_1" expr: "cel.block([msg.oneof_type, cel.index(0).payload, cel.index(1).map_int32_int64, cel.index(2)[1], cel.index(3) + cel.index(3), cel.index(4) + cel.index(3)], cel.index(5))" value: { int64_value: 15 } type_env: { name: "msg" ident: { type: { message_type: "cel.expr.conformance.proto3.TestAllTypes" }} } bindings: { key: "msg" value: { value: { object_value: { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_int64: 3 single_int32: 5 oneof_type: { payload: { single_int32: 8 single_int64: 10 map_int32_int64 { key: 0 value: 1 } map_int32_int64 { key: 1 value: 5 } map_int32_int64 { key: 2 value: 2 } map_string_string { key: "key" value: "A" } } } } } } } } } test: { name: "select_nested_message_map_index_2" expr: "cel.block([msg.oneof_type, cel.index(0).payload, cel.index(1).map_int32_int64, cel.index(2)[0], cel.index(2)[1], cel.index(3) + cel.index(4), cel.index(2)[2], cel.index(5) + cel.index(6)], cel.index(7))" value: { int64_value: 8 } type_env: { name: "msg" ident: { type: { message_type: "cel.expr.conformance.proto3.TestAllTypes" }} } bindings: { key: "msg" value: { value: { object_value: { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_int64: 3 single_int32: 5 oneof_type: { payload: { single_int32: 8 single_int64: 10 map_int32_int64 { key: 0 value: 1 } map_int32_int64 { key: 1 value: 5 } map_int32_int64 { key: 2 value: 2 } map_string_string { key: "key" value: "A" } } } } } } } } } test: { name: "ternary" expr: "cel.block([msg.single_int64, cel.index(0) > 0, cel.index(1) ? cel.index(0) : 0], cel.index(2))" value: { int64_value: 3 } type_env: { name: "msg" ident: { type: { message_type: "cel.expr.conformance.proto3.TestAllTypes" }} } bindings: { key: "msg" value: { value: { object_value: { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_int64: 3 single_int32: 5 oneof_type: { payload: { single_int32: 8 single_int64: 10 map_int32_int64 { key: 0 value: 1 } map_int32_int64 { key: 1 value: 5 } map_int32_int64 { key: 2 value: 2 } map_string_string { key: "key" value: "A" } } } } } } } } } test: { name: "nested_ternary" expr: "cel.block([msg.single_int64, msg.single_int32, cel.index(0) > 0, cel.index(1) > 0, cel.index(0) + cel.index(1), cel.index(3) ? cel.index(4) : 0, cel.index(2) ? cel.index(5) : 0], cel.index(6))" value: { int64_value: 8 } type_env: { name: "msg" ident: { type: { message_type: "cel.expr.conformance.proto3.TestAllTypes" }} } bindings: { key: "msg" value: { value: { object_value: { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_int64: 3 single_int32: 5 oneof_type: { payload: { single_int32: 8 single_int64: 10 map_int32_int64 { key: 0 value: 1 } map_int32_int64 { key: 1 value: 5 } map_int32_int64 { key: 2 value: 2 } map_string_string { key: "key" value: "A" } } } } } } } } } test: { name: "multiple_macros_1" expr: "cel.block([[1].exists(cel.iterVar(0, 0), cel.iterVar(0, 0) > 0), size([cel.index(0)]), [2].exists(cel.iterVar(0, 0), cel.iterVar(0, 0) > 1), size([cel.index(2)])], cel.index(1) + cel.index(1) + cel.index(3) + cel.index(3))" value: { int64_value: 4 } } test: { name: "multiple_macros_2" expr: "cel.block([[1].exists(cel.iterVar(0, 0), cel.iterVar(0, 0) > 0), [cel.index(0)], ['a'].exists(cel.iterVar(0, 1), cel.iterVar(0, 1) == 'a'), [cel.index(2)]], cel.index(1) + cel.index(1) + cel.index(3) + cel.index(3))" value: { list_value: { values { bool_value: true } values { bool_value: true } values { bool_value: true } values { bool_value: true } } } } test: { name: "multiple_macros_3" expr: "cel.block([[1].exists(cel.iterVar(0, 0), cel.iterVar(0, 0) > 0)], cel.index(0) && cel.index(0) && [1].exists(cel.iterVar(0, 0), cel.iterVar(0, 0) > 1) && [2].exists(cel.iterVar(0, 0), cel.iterVar(0, 0) > 1))" value: { bool_value: false } } test: { name: "nested_macros_1" expr: "cel.block([[1, 2, 3]], cel.index(0).map(cel.iterVar(0, 0), cel.index(0).map(cel.iterVar(1, 0), cel.iterVar(1, 0) + 1)))" value: { list_value: { values { list_value: { values { int64_value: 2 } values { int64_value: 3 } values { int64_value: 4 } } } values { list_value: { values { int64_value: 2 } values { int64_value: 3 } values { int64_value: 4 } } } values { list_value: { values { int64_value: 2 } values { int64_value: 3 } values { int64_value: 4 } } } } } } test: { name: "nested_macros_2" expr: "[1, 2].map(cel.iterVar(0, 0), [1, 2, 3].filter(cel.iterVar(1, 0), cel.iterVar(1, 0) == cel.iterVar(0, 0)))" value: { list_value: { values { list_value: { values { int64_value: 1 } } } values { list_value: { values { int64_value: 2 } } } } } } test: { name: "adjacent_macros" expr: "cel.block([[1, 2, 3], cel.index(0).map(cel.iterVar(0, 0), cel.index(0).map(cel.iterVar(1, 0), cel.iterVar(1, 0) + 1))], cel.index(1) == cel.index(1))" value: { bool_value: true } } test: { name: "macro_shadowed_variable_1" expr: "cel.block([x - 1, cel.index(0) > 3], [cel.index(1) ? cel.index(0) : 5].exists(cel.iterVar(0, 0), cel.iterVar(0, 0) - 1 > 3) || cel.index(1))" value: { bool_value: true } type_env: { name: "x" ident: { type: { primitive: INT64 }} } bindings: { key: "x" value: { value: { int64_value: 5 } } } } test: { name: "macro_shadowed_variable_2" expr: "['foo', 'bar'].map(cel.iterVar(1, 0), [cel.iterVar(1, 0) + cel.iterVar(1, 0), cel.iterVar(1, 0) + cel.iterVar(1, 0)]).map(cel.iterVar(0, 0), [cel.iterVar(0, 0) + cel.iterVar(0, 0), cel.iterVar(0, 0) + cel.iterVar(0, 0)])" value: { list_value: { values { list_value: { values { list_value: { values { string_value: "foofoo" } values { string_value: "foofoo" } values { string_value: "foofoo" } values { string_value: "foofoo" } } } values { list_value: { values { string_value: "foofoo" } values { string_value: "foofoo" } values { string_value: "foofoo" } values { string_value: "foofoo" } } } } } values { list_value: { values { list_value: { values { string_value: "barbar" } values { string_value: "barbar" } values { string_value: "barbar" } values { string_value: "barbar" } } } values { list_value: { values { string_value: "barbar" } values { string_value: "barbar" } values { string_value: "barbar" } values { string_value: "barbar" } } } } } } } type_env: { name: "x" ident: { type: { primitive: INT64 }} } bindings: { key: "x" value: { value: { int64_value: 5 } } } } test: { name: "inclusion_list" expr: "cel.block([[1, 2, 3], 1 in cel.index(0), 2 in cel.index(0), cel.index(1) && cel.index(2), [3, cel.index(0)], 3 in cel.index(4), cel.index(5) && cel.index(1)], cel.index(3) && cel.index(6))" value: { bool_value: true } } test: { name: "inclusion_map" expr: "cel.block([{true: false}, {\"a\": 1, 2: cel.index(0), 3: cel.index(0)}], 2 in cel.index(1))" value: { bool_value: true } } test: { name: "presence_test" expr: "cel.block([{\"a\": true}, has(cel.index(0).a), cel.index(0)[\"a\"]], cel.index(1) && cel.index(2))" value: { bool_value: true } } test: { name: "presence_test_2" expr: "cel.block([{\"a\": true}, has(cel.index(0).a)], cel.index(1) && cel.index(1))" value: { bool_value: true } } test: { name: "presence_test_with_ternary" expr: "cel.block([msg.oneof_type, has(cel.index(0).payload), cel.index(0).payload, cel.index(2).single_int64, cel.index(1) ? cel.index(3) : 0], cel.index(4))" value: { int64_value: 10 } type_env: { name: "msg" ident: { type: { message_type: "cel.expr.conformance.proto3.TestAllTypes" }} } bindings: { key: "msg" value: { value: { object_value: { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_int64: 3 single_int32: 5 oneof_type: { payload: { single_int32: 8 single_int64: 10 map_int32_int64 { key: 0 value: 1 } map_int32_int64 { key: 1 value: 5 } map_int32_int64 { key: 2 value: 2 } map_string_string { key: "key" value: "A" } } } } } } } } } test: { name: "presence_test_with_ternary_2" expr: "cel.block([msg.oneof_type, cel.index(0).payload, cel.index(1).single_int64, has(cel.index(0).payload), cel.index(2) * 0, cel.index(3) ? cel.index(2) : cel.index(4)], cel.index(5))" value: { int64_value: 10 } type_env: { name: "msg" ident: { type: { message_type: "cel.expr.conformance.proto3.TestAllTypes" }} } bindings: { key: "msg" value: { value: { object_value: { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_int64: 3 single_int32: 5 oneof_type: { payload: { single_int32: 8 single_int64: 10 map_int32_int64 { key: 0 value: 1 } map_int32_int64 { key: 1 value: 5 } map_int32_int64 { key: 2 value: 2 } map_string_string { key: "key" value: "A" } } } } } } } } } test: { name: "presence_test_with_ternary_3" expr: "cel.block([msg.oneof_type, cel.index(0).payload, cel.index(1).single_int64, has(cel.index(1).single_int64), cel.index(2) * 0, cel.index(3) ? cel.index(2) : cel.index(4)], cel.index(5))" value: { int64_value: 10 } type_env: { name: "msg" ident: { type: { message_type: "cel.expr.conformance.proto3.TestAllTypes" }} } bindings: { key: "msg" value: { value: { object_value: { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_int64: 3 single_int32: 5 oneof_type: { payload: { single_int32: 8 single_int64: 10 map_int32_int64 { key: 0 value: 1 } map_int32_int64 { key: 1 value: 5 } map_int32_int64 { key: 2 value: 2 } map_string_string { key: "key" value: "A" } } } } } } } } } test: { name: "presence_test_with_ternary_nested" expr: "cel.block([msg.oneof_type, cel.index(0).payload, cel.index(1).map_string_string, has(msg.oneof_type), has(cel.index(0).payload), cel.index(3) && cel.index(4), has(cel.index(1).single_int64), cel.index(5) && cel.index(6), has(cel.index(1).map_string_string), has(cel.index(2).key), cel.index(8) && cel.index(9), cel.index(2).key, cel.index(11) == \"A\", cel.index(10) ? cel.index(12) : false], cel.index(7) ? cel.index(13) : false)" value: { bool_value: true } type_env: { name: "msg" ident: { type: { message_type: "cel.expr.conformance.proto3.TestAllTypes" }} } bindings: { key: "msg" value: { value: { object_value: { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { single_int64: 3 single_int32: 5 oneof_type: { payload: { single_int32: 8 single_int64: 10 map_int32_int64 { key: 0 value: 1 } map_int32_int64 { key: 1 value: 5 } map_int32_int64 { key: 2 value: 2 } map_string_string { key: "key" value: "A" } } } } } } } } } test: { name: "optional_list" expr: "cel.block([optional.none(), [?cel.index(0), ?optional.of(opt_x)], [5], [10, ?cel.index(0), cel.index(1), cel.index(1)], [10, cel.index(2), cel.index(2)]], cel.index(3) == cel.index(4))" value: { bool_value: true } type_env: { name: "opt_x" ident: { type: { primitive: INT64 }} } bindings: { key: "opt_x", value: { value: { int64_value: 5 } } } } test: { name: "optional_map" expr: "cel.block([optional.of(\"hello\"), {?\"hello\": cel.index(0)}, cel.index(1)[\"hello\"], cel.index(2) + cel.index(2)], cel.index(3) == \"hellohello\")" value: { bool_value: true } } test: { name: "optional_map_chained" expr: "cel.block([{\"key\": \"test\"}, optional.of(\"test\"), {?\"key\": cel.index(1)}, cel.index(2)[?\"bogus\"], cel.index(0)[?\"bogus\"], cel.index(3).or(cel.index(4)), cel.index(0)[\"key\"], cel.index(5).orValue(cel.index(6))], cel.index(7))" value: { string_value: 'test' } } test: { name: "optional_message" container: "cel.expr.conformance.proto3" expr: "cel.block([optional.ofNonZeroValue(1), optional.of(4), TestAllTypes{?single_int64: cel.index(0), ?single_int32: cel.index(1)}, cel.index(2).single_int32, cel.index(2).single_int64, cel.index(3) + cel.index(4)], cel.index(5))" value: { int64_value: 5 } } test: { name: "call" expr: "cel.block([\"h\" + \"e\", cel.index(0) + \"l\", cel.index(1) + \"l\", cel.index(2) + \"o\", cel.index(3) + \" world\"], cel.index(4).matches(cel.index(3)))" value: { bool_value: true } } }