Skip to content

Commit 57bfb7b

Browse files
authored
Add tests for repeated enum field accesses (#464)
* Add tests for repeated enum field accesses * Additional tests for repeated enum assingability
1 parent 252372e commit 57bfb7b

File tree

4 files changed

+140
-0
lines changed

4 files changed

+140
-0
lines changed

tests/simple/testdata/enums.textproto

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,49 @@ section {
104104
}
105105
}
106106
}
107+
test {
108+
name: "access_repeated_enum"
109+
container: "cel.expr.conformance.proto2"
110+
expr: "TestAllTypes{}.repeated_nested_enum"
111+
value {
112+
list_value {}
113+
}
114+
}
115+
test {
116+
name: "assign_repeated_enum"
117+
container: "cel.expr.conformance.proto2"
118+
expr:
119+
"TestAllTypes{"
120+
" repeated_nested_enum: ["
121+
" TestAllTypes.NestedEnum.FOO,"
122+
" TestAllTypes.NestedEnum.BAR]}"
123+
value {
124+
object_value {
125+
[type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] {
126+
repeated_nested_enum: FOO
127+
repeated_nested_enum: BAR
128+
}
129+
}
130+
}
131+
}
132+
test {
133+
name: "list_enum_as_list_int"
134+
container: "cel.expr.conformance.proto2"
135+
expr:
136+
"0 in "
137+
"TestAllTypes{"
138+
" repeated_nested_enum: ["
139+
" TestAllTypes.NestedEnum.FOO,"
140+
" TestAllTypes.NestedEnum.BAR]}"
141+
".repeated_nested_enum"
142+
value: { bool_value: true }
143+
}
144+
test {
145+
name: "enum_as_int"
146+
container: "cel.expr.conformance.proto2"
147+
expr: "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.FOO}.standalone_enum in [0]"
148+
value: { bool_value: true }
149+
}
107150
}
108151
section {
109152
name: "legacy_proto3"
@@ -302,6 +345,49 @@ section {
302345
}
303346
}
304347
}
348+
test {
349+
name: "access_repeated_enum"
350+
container: "cel.expr.conformance.proto2"
351+
expr: "TestAllTypes{}.repeated_nested_enum"
352+
value {
353+
list_value {}
354+
}
355+
}
356+
test {
357+
name: "assign_repeated_enum"
358+
container: "cel.expr.conformance.proto2"
359+
expr:
360+
"TestAllTypes{"
361+
" repeated_nested_enum: ["
362+
" TestAllTypes.NestedEnum.FOO,"
363+
" TestAllTypes.NestedEnum.BAR]}"
364+
value {
365+
object_value {
366+
[type.googleapis.com/cel.expr.conformance.proto2.TestAllTypes] {
367+
repeated_nested_enum: FOO
368+
repeated_nested_enum: BAR
369+
}
370+
}
371+
}
372+
}
373+
test {
374+
name: "list_enum_as_list_int"
375+
container: "cel.expr.conformance.proto2"
376+
expr:
377+
"0 in "
378+
"TestAllTypes{"
379+
" repeated_nested_enum: ["
380+
" TestAllTypes.NestedEnum.FOO,"
381+
" TestAllTypes.NestedEnum.BAR]}"
382+
".repeated_nested_enum"
383+
value: { bool_value: true }
384+
}
385+
test {
386+
name: "enum_as_int"
387+
container: "cel.expr.conformance.proto2"
388+
expr: "TestAllTypes{standalone_enum: TestAllTypes.NestedEnum.FOO}.standalone_enum in [0]"
389+
value: { bool_value: true }
390+
}
305391
}
306392
section {
307393
name: "strong_proto2"

tests/simple/testdata/proto2.textproto

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,13 @@ section {
588588
value: { list_value: {} }
589589
}
590590
591+
test {
592+
name: "repeated_enum"
593+
container: "cel.expr.conformance.proto3"
594+
expr: "TestAllTypes{}.repeated_nested_enum"
595+
value: { list_value: {} }
596+
}
597+
591598
test {
592599
name: "repeated_nested"
593600
container: "cel.expr.conformance.proto2"

tests/simple/testdata/proto3.textproto

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,13 @@ section {
497497
value: { list_value: {} }
498498
}
499499
500+
test {
501+
name: "repeated_enum"
502+
container: "cel.expr.conformance.proto3"
503+
expr: "TestAllTypes{}.repeated_nested_enum"
504+
value: { list_value: {} }
505+
}
506+
500507
test {
501508
name: "repeated_nested"
502509
container: "cel.expr.conformance.proto3"

tests/simple/testdata/type_deduction.textproto

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,46 @@ section {
193193
}
194194
}
195195
}
196+
test {
197+
name: "enum_field"
198+
container: "cel.expr.conformance.proto3"
199+
expr: "TestAllTypes{}.standalone_enum"
200+
typed_result {
201+
result {
202+
int64_value: 0
203+
}
204+
deduced_type { primitive: INT64 }
205+
}
206+
}
207+
test {
208+
name: "repeated_enum_field"
209+
container: "cel.expr.conformance.proto3"
210+
expr: "TestAllTypes{}.repeated_nested_enum"
211+
typed_result {
212+
result {
213+
list_value {}
214+
}
215+
deduced_type {
216+
list_type { elem_type { primitive: INT64 } }
217+
}
218+
}
219+
}
220+
test {
221+
name: "enum_map_field"
222+
container: "cel.expr.conformance.proto3"
223+
expr: "TestAllTypes{}.map_int32_enum"
224+
typed_result {
225+
result {
226+
map_value {}
227+
}
228+
deduced_type {
229+
map_type {
230+
key_type { primitive: INT64 }
231+
value_type { primitive: INT64 }
232+
}
233+
}
234+
}
235+
}
196236
}
197237
198238
section {

0 commit comments

Comments
 (0)