# proto-file: ../../../proto/cel/expr/conformance/test/simple.proto # proto-message: cel.expr.conformance.test.SimpleTestFile name: "enums" description: "Tests for enum types." section { name: "legacy_proto2" description: "Legacy semantics where all enums are ints, proto2." test { name: "literal_global" container: "cel.expr.conformance.proto2" expr: "GlobalEnum.GAZ" value { int64_value: 2 } } test { name: "literal_nested" container: "cel.expr.conformance.proto2" expr: "TestAllTypes.NestedEnum.BAR" value { int64_value: 1 } } test { name: "literal_zero" container: "cel.expr.conformance.proto2" expr: "GlobalEnum.GOO" value { int64_value: 0 } } test { name: "comparison" container: "cel.expr.conformance.proto2" expr: "GlobalEnum.GAR == 1" value { bool_value: true } } test { name: "arithmetic" container: "cel.expr.conformance.proto2" expr: "TestAllTypes.NestedEnum.BAR + 3" value { int64_value: 4 } } test { name: "type_global" container: "cel.expr.conformance.proto2" expr: "type(GlobalEnum.GOO)" value { type_value: "int" } } test { name: "type_nested" container: "cel.expr.conformance.proto2" expr: "type(TestAllTypes.NestedEnum.BAZ)" value { type_value: "int" } } test { name: "select_default" container: "cel.expr.conformance.proto2" expr: "TestAllTypes{}.standalone_enum" value { int64_value: 0 } } test { name: "field_type" container: "cel.expr.conformance.proto2" expr: "type(TestAllTypes{}.standalone_enum)" value { type_value: "int" } } test { name: "assign_standalone_name" container: "cel.expr.conformance.proto2" expr: "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.BAZ}" value { object_value { [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { standalone_enum: BAZ } } } } test { name: "assign_standalone_int" container: "cel.expr.conformance.proto2" expr: "TestAllTypes{standalone_enum: 1}" value { object_value { [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { standalone_enum: BAR } } } } test { name: "assign_standalone_int_too_big" container: "cel.expr.conformance.proto2" expr: "TestAllTypes{standalone_enum: 5000000000}" eval_error { errors { message: "range" } } } test { name: "assign_standalone_int_too_neg" container: "cel.expr.conformance.proto2" expr: "TestAllTypes{standalone_enum: -7000000000}" eval_error { errors { message: "range" } } } test { name: "access_repeated_enum" container: "cel.expr.conformance.proto2" expr: "TestAllTypes{}.repeated_nested_enum" value { list_value {} } } test { name: "assign_repeated_enum" container: "cel.expr.conformance.proto2" expr: "TestAllTypes{" " repeated_nested_enum: [" " TestAllTypes.NestedEnum.FOO," " TestAllTypes.NestedEnum.BAR]}" value { object_value { [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { repeated_nested_enum: FOO repeated_nested_enum: BAR } } } } test { name: "list_enum_as_list_int" container: "cel.expr.conformance.proto2" expr: "0 in " "TestAllTypes{" " repeated_nested_enum: [" " TestAllTypes.NestedEnum.FOO," " TestAllTypes.NestedEnum.BAR]}" ".repeated_nested_enum" value: { bool_value: true } } test { name: "enum_as_int" container: "cel.expr.conformance.proto2" expr: "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.FOO}.standalone_enum in [0]" value: { bool_value: true } } } section { name: "legacy_proto3" description: "Legacy semantics where all enums are ints, proto3" test { name: "literal_global" container: "cel.expr.conformance.proto3" expr: "GlobalEnum.GAZ" value { int64_value: 2 } } test { name: "literal_nested" container: "cel.expr.conformance.proto3" expr: "TestAllTypes.NestedEnum.BAR" value { int64_value: 1 } } test { name: "literal_zero" container: "cel.expr.conformance.proto3" expr: "GlobalEnum.GOO" value { int64_value: 0 } } test { name: "comparison" container: "cel.expr.conformance.proto3" expr: "GlobalEnum.GAR == 1" value { bool_value: true } } test { name: "arithmetic" container: "cel.expr.conformance.proto3" expr: "TestAllTypes.NestedEnum.BAR + 3" value { int64_value: 4 } } test { name: "type_global" container: "cel.expr.conformance.proto3" expr: "type(GlobalEnum.GOO)" value { type_value: "int" } } test { name: "type_nested" container: "cel.expr.conformance.proto3" expr: "type(TestAllTypes.NestedEnum.BAZ)" value { type_value: "int" } } test { name: "select_default" container: "cel.expr.conformance.proto3" expr: "TestAllTypes{}.standalone_enum" value { int64_value: 0 } } test { name: "select" container: "cel.expr.conformance.proto3" expr: "x.standalone_enum" type_env { name: "x" ident { type { message_type: "cel.expr.conformance.proto3.TestAllTypes" } } } bindings { key: "x" value { value { object_value { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { standalone_enum: 2 } } } } } value { int64_value: 2 } } test { name: "select_big" container: "cel.expr.conformance.proto3" expr: "x.standalone_enum" type_env { name: "x" ident { type { message_type: "cel.expr.conformance.proto3.TestAllTypes" } } } bindings { key: "x" value { value { object_value { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { standalone_enum: 108 } } } } } value { int64_value: 108 } } test { name: "select_neg" container: "cel.expr.conformance.proto3" expr: "x.standalone_enum" type_env { name: "x" ident { type { message_type: "cel.expr.conformance.proto3.TestAllTypes" } } } bindings { key: "x" value { value { object_value { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { standalone_enum: -3 } } } } } value { int64_value: -3 } } test { name: "field_type" container: "cel.expr.conformance.proto3" expr: "type(TestAllTypes{}.standalone_enum)" value { type_value: "int" } } test { name: "assign_standalone_name" container: "cel.expr.conformance.proto3" expr: "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.BAZ}" value { object_value { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { standalone_enum: BAZ } } } } test { name: "assign_standalone_int" container: "cel.expr.conformance.proto3" expr: "TestAllTypes{standalone_enum: 1}" value { object_value { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { standalone_enum: BAR } } } } test { name: "assign_standalone_int_big" container: "cel.expr.conformance.proto3" expr: "TestAllTypes{standalone_enum: 99}" value { object_value { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { standalone_enum: 99 } } } } test { name: "assign_standalone_int_neg" container: "cel.expr.conformance.proto3" expr: "TestAllTypes{standalone_enum: -1}" value { object_value { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { standalone_enum: -1 } } } } test { name: "assign_standalone_int_too_big" container: "cel.expr.conformance.proto3" expr: "TestAllTypes{standalone_enum: 5000000000}" eval_error { errors { message: "range" } } } test { name: "assign_standalone_int_too_neg" container: "cel.expr.conformance.proto3" expr: "TestAllTypes{standalone_enum: -7000000000}" eval_error { errors { message: "range" } } } test { name: "access_repeated_enum" container: "cel.expr.conformance.proto2" expr: "TestAllTypes{}.repeated_nested_enum" value { list_value {} } } test { name: "assign_repeated_enum" container: "cel.expr.conformance.proto2" expr: "TestAllTypes{" " repeated_nested_enum: [" " TestAllTypes.NestedEnum.FOO," " TestAllTypes.NestedEnum.BAR]}" value { object_value { [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { repeated_nested_enum: FOO repeated_nested_enum: BAR } } } } test { name: "list_enum_as_list_int" container: "cel.expr.conformance.proto2" expr: "0 in " "TestAllTypes{" " repeated_nested_enum: [" " TestAllTypes.NestedEnum.FOO," " TestAllTypes.NestedEnum.BAR]}" ".repeated_nested_enum" value: { bool_value: true } } test { name: "enum_as_int" container: "cel.expr.conformance.proto2" expr: "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.FOO}.standalone_enum in [0]" value: { bool_value: true } } } section { name: "strong_proto2" description: "String semantics where enums are distinct types, proto2." test { name: "literal_global" container: "cel.expr.conformance.proto2" expr: "GlobalEnum.GAZ" value { enum_value { type: "cel.expr.conformance.proto2.GlobalEnum" value: 2 } } } test { name: "literal_nested" container: "cel.expr.conformance.proto2" expr: "TestAllTypes.NestedEnum.BAR" value { enum_value { type: "cel.expr.conformance.proto2.TestAllTypes.NestedEnum" value: 1 } } } test { name: "literal_zero" container: "cel.expr.conformance.proto2" expr: "GlobalEnum.GOO" value { enum_value { type: "cel.expr.conformance.proto2.GlobalEnum" value: 0 } } } test { name: "comparison_true" container: "cel.expr.conformance.proto2" expr: "GlobalEnum.GAR == GlobalEnum.GAR" value { bool_value: true } } test { name: "comparison_false" container: "cel.expr.conformance.proto2" expr: "GlobalEnum.GAR == GlobalEnum.GAZ" value { bool_value: false } } test { name: "type_global" container: "cel.expr.conformance.proto2" expr: "type(GlobalEnum.GOO)" value { type_value: "cel.expr.conformance.proto2.GlobalEnum" } } test { name: "type_nested" container: "cel.expr.conformance.proto2" expr: "type(TestAllTypes.NestedEnum.BAZ)" value { type_value: "cel.expr.conformance.proto2.TestAllTypes.NestedEnum" } } test { name: "select_default" container: "cel.expr.conformance.proto2" expr: "TestAllTypes{}.standalone_enum" value { enum_value { type: "cel.expr.conformance.proto2.TestAllTypes.NestedEnum" value: 0 } } } test { name: "field_type" container: "cel.expr.conformance.proto2" expr: "type(TestAllTypes{}.standalone_enum)" value { type_value: "cel.expr.conformance.proto2.TestAllTypes.NestedEnum" } } test { name: "assign_standalone_name" container: "cel.expr.conformance.proto2" expr: "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.BAZ}" value { object_value { [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { standalone_enum: BAZ } } } } test { name: "assign_standalone_int" container: "cel.expr.conformance.proto2" expr: "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum(1)}" value { object_value { [type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] { standalone_enum: BAR } } } } test { name: "convert_symbol_to_int" container: "cel.expr.conformance.proto2" expr: "int(GlobalEnum.GAZ)" value { int64_value: 2 } } test { name: "convert_unnamed_to_int" description: "Disable check - missing way to declare enums." expr: "int(x)" disable_check: true bindings { key: "x" value { value { enum_value { type: "cel.expr.conformance.proto2.GlobalEnum" value: 444 } } } } value { int64_value: 444 } } test { name: "convert_int_inrange" container: "cel.expr.conformance.proto2" expr: "TestAllTypes.NestedEnum(2)" value { enum_value { type: "cel.expr.conformance.proto2.TestAllTypes.NestedEnum" value: 2 } } } test { name: "convert_int_big" container: "cel.expr.conformance.proto2" expr: "TestAllTypes.NestedEnum(20000)" value { enum_value { type: "cel.expr.conformance.proto2.TestAllTypes.NestedEnum" value: 20000 } } } test { name: "convert_int_neg" container: "cel.expr.conformance.proto2" expr: "GlobalEnum(-33)" value { enum_value { type: "cel.expr.conformance.proto2.GlobalEnum" value: -33 } } } test { name: "convert_int_too_big" container: "cel.expr.conformance.proto2" expr: "TestAllTypes.NestedEnum(5000000000)" eval_error { errors { message: "range" } } } test { name: "convert_int_too_neg" container: "cel.expr.conformance.proto2" expr: "TestAllTypes.NestedEnum(-7000000000)" eval_error { errors { message: "range" } } } test { name: "convert_string" container: "cel.expr.conformance.proto2" expr: "TestAllTypes.NestedEnum('BAZ')" value { enum_value { type: "cel.expr.conformance.proto2.TestAllTypes.NestedEnum" value: 2 } } } test { name: "convert_string_bad" container: "cel.expr.conformance.proto2" expr: "TestAllTypes.NestedEnum('BLETCH')" eval_error { errors { message: "invalid" } } } } section { name: "strong_proto3" description: "String semantics where enums are distinct types, proto3." test { name: "literal_global" container: "cel.expr.conformance.proto3" expr: "GlobalEnum.GAZ" value { enum_value { type: "cel.expr.conformance.proto3.GlobalEnum" value: 2 } } } test { name: "literal_nested" container: "cel.expr.conformance.proto3" expr: "TestAllTypes.NestedEnum.BAR" value { enum_value { type: "cel.expr.conformance.proto3.TestAllTypes.NestedEnum" value: 1 } } } test { name: "literal_zero" container: "cel.expr.conformance.proto3" expr: "GlobalEnum.GOO" value { enum_value { type: "cel.expr.conformance.proto3.GlobalEnum" value: 0 } } } test { name: "comparison_true" container: "cel.expr.conformance.proto3" expr: "GlobalEnum.GAR == GlobalEnum.GAR" value { bool_value: true } } test { name: "comparison_false" container: "cel.expr.conformance.proto3" expr: "GlobalEnum.GAR == GlobalEnum.GAZ" value { bool_value: false } } test { name: "type_global" container: "cel.expr.conformance.proto3" expr: "type(GlobalEnum.GOO)" value { type_value: "cel.expr.conformance.proto3.GlobalEnum" } } test { name: "type_nested" container: "cel.expr.conformance.proto3" expr: "type(TestAllTypes.NestedEnum.BAZ)" value { type_value: "cel.expr.conformance.proto3.TestAllTypes.NestedEnum" } } test { name: "select_default" container: "cel.expr.conformance.proto3" expr: "TestAllTypes{}.standalone_enum" value { enum_value { type: "cel.expr.conformance.proto3.TestAllTypes.NestedEnum" value: 0 } } } test { name: "select" container: "cel.expr.conformance.proto3" expr: "x.standalone_enum" type_env { name: "x" ident { type { message_type: "cel.expr.conformance.proto3.TestAllTypes" } } } bindings { key: "x" value { value { object_value { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { standalone_enum: 2 } } } } } value { enum_value { type: "cel.expr.conformance.proto3.TestAllTypes.NestedEnum" value: 2 } } } test { name: "select_big" container: "cel.expr.conformance.proto3" expr: "x.standalone_enum" type_env { name: "x" ident { type { message_type: "cel.expr.conformance.proto3.TestAllTypes" } } } bindings { key: "x" value { value { object_value { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { standalone_enum: 108 } } } } } value { enum_value { type: "cel.expr.conformance.proto3.TestAllTypes.NestedEnum" value: 108 } } } test { name: "select_neg" container: "cel.expr.conformance.proto3" expr: "x.standalone_enum" type_env { name: "x" ident { type { message_type: "cel.expr.conformance.proto3.TestAllTypes" } } } bindings { key: "x" value { value { object_value { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { standalone_enum: -3 } } } } } value { enum_value { type: "cel.expr.conformance.proto3.TestAllTypes.NestedEnum" value: -3 } } } test { name: "field_type" container: "cel.expr.conformance.proto3" expr: "type(TestAllTypes{}.standalone_enum)" value { type_value: "cel.expr.conformance.proto3.TestAllTypes.NestedEnum" } } test { name: "assign_standalone_name" container: "cel.expr.conformance.proto3" expr: "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.BAZ}" value { object_value { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { standalone_enum: BAZ } } } } test { name: "assign_standalone_int" container: "cel.expr.conformance.proto3" expr: "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum(1)}" value { object_value { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { standalone_enum: BAR } } } } test { name: "assign_standalone_int_big" container: "cel.expr.conformance.proto3" expr: "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum(99)}" value { object_value { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { standalone_enum: 99 } } } } test { name: "assign_standalone_int_neg" container: "cel.expr.conformance.proto3" expr: "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum(-1)}" value { object_value { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { standalone_enum: -1 } } } } test { name: "convert_symbol_to_int" container: "cel.expr.conformance.proto3" expr: "int(GlobalEnum.GAZ)" value { int64_value: 2 } } test { name: "convert_unnamed_to_int" description: "Disable check - missing way to declare enums." expr: "int(x)" disable_check: true bindings { key: "x" value { value { enum_value { type: "cel.expr.conformance.proto3.GlobalEnum" value: 444 } } } } value { int64_value: 444 } } test { name: "convert_unnamed_to_int_select" expr: "int(x.standalone_enum)" type_env { name: "x" ident { type { message_type: "cel.expr.conformance.proto3.TestAllTypes" } } } bindings { key: "x" value { value { object_value { [type.googleapis.com/cel.expr.conformance.proto3.TestAllTypes] { standalone_enum: -987 } } } } } value { int64_value: -987 } } test { name: "convert_int_inrange" container: "cel.expr.conformance.proto3" expr: "TestAllTypes.NestedEnum(2)" value { enum_value { type: "cel.expr.conformance.proto3.TestAllTypes.NestedEnum" value: 2 } } } test { name: "convert_int_big" container: "cel.expr.conformance.proto3" expr: "TestAllTypes.NestedEnum(20000)" value { enum_value { type: "cel.expr.conformance.proto3.TestAllTypes.NestedEnum" value: 20000 } } } test { name: "convert_int_neg" container: "cel.expr.conformance.proto3" expr: "GlobalEnum(-33)" value { enum_value { type: "cel.expr.conformance.proto3.GlobalEnum" value: -33 } } } test { name: "convert_int_too_big" container: "cel.expr.conformance.proto3" expr: "TestAllTypes.NestedEnum(5000000000)" eval_error { errors { message: "range" } } } test { name: "convert_int_too_neg" container: "cel.expr.conformance.proto3" expr: "TestAllTypes.NestedEnum(-7000000000)" eval_error { errors { message: "range" } } } test { name: "convert_string" container: "cel.expr.conformance.proto3" expr: "TestAllTypes.NestedEnum('BAZ')" value { enum_value { type: "cel.expr.conformance.proto3.TestAllTypes.NestedEnum" value: 2 } } } test { name: "convert_string_bad" container: "cel.expr.conformance.proto3" expr: "TestAllTypes.NestedEnum('BLETCH')" eval_error { errors { message: "invalid" } } } }