2323import com .google .testing .junit .testparameterinjector .TestParameterInjector ;
2424import dev .cel .common .ast .CelExpr .ExprKind .Kind ;
2525import dev .cel .common .ast .CelMutableExpr .CelMutableCall ;
26+ import dev .cel .common .ast .CelMutableExpr .CelMutableCreateList ;
2627import dev .cel .common .ast .CelMutableExpr .CelMutableIdent ;
2728import dev .cel .common .ast .CelMutableExpr .CelMutableSelect ;
2829import java .util .ArrayList ;
@@ -250,6 +251,55 @@ public void mutableCall_setFunction() {
250251 assertThat (call .function ()).isEqualTo ("function2" );
251252 }
252253
254+ @ Test
255+ public void ofCreateList () {
256+ CelMutableExpr mutableExpr =
257+ CelMutableExpr .ofCreateList (
258+ CelMutableCreateList .create (
259+ CelMutableExpr .ofConstant (CelConstant .ofValue ("element1" )),
260+ CelMutableExpr .ofConstant (CelConstant .ofValue ("element2" ))));
261+
262+ assertThat (mutableExpr .id ()).isEqualTo (0L );
263+ assertThat (mutableExpr .createList ().elements ())
264+ .containsExactly (
265+ CelMutableExpr .ofConstant (CelConstant .ofValue ("element1" )),
266+ CelMutableExpr .ofConstant (CelConstant .ofValue ("element2" )))
267+ .inOrder ();
268+ assertThat (mutableExpr .createList ().optionalIndices ()).isEmpty ();
269+ }
270+
271+ @ Test
272+ public void ofCreateList_withId () {
273+ CelMutableExpr mutableExpr =
274+ CelMutableExpr .ofCreateList (
275+ 1L ,
276+ CelMutableCreateList .create (
277+ ImmutableList .of (
278+ CelMutableExpr .ofConstant (CelConstant .ofValue ("element1" )),
279+ CelMutableExpr .ofConstant (CelConstant .ofValue ("element2" ))),
280+ ImmutableList .of (0 , 1 )));
281+
282+ assertThat (mutableExpr .id ()).isEqualTo (1L );
283+ assertThat (mutableExpr .createList ().elements ())
284+ .containsExactly (
285+ CelMutableExpr .ofConstant (CelConstant .ofValue ("element1" )),
286+ CelMutableExpr .ofConstant (CelConstant .ofValue ("element2" )))
287+ .inOrder ();
288+ assertThat (mutableExpr .createList ().optionalIndices ()).containsExactly (0 , 1 ).inOrder ();
289+ }
290+
291+ @ Test
292+ public void mutableCreateList_setElementAtIndex () {
293+ CelMutableCreateList createList =
294+ CelMutableCreateList .create (CelMutableExpr .ofConstant (CelConstant .ofValue ("element1" )));
295+
296+ createList .setElement (0 , CelMutableExpr .ofConstant (CelConstant .ofValue ("hello" )));
297+
298+ assertThat (createList .elements ())
299+ .containsExactly (CelMutableExpr .ofConstant (CelConstant .ofValue ("hello" )));
300+ assertThat (createList .elements ()).isInstanceOf (ArrayList .class );
301+ }
302+
253303 @ Test
254304 public void equalityTest () {
255305 new EqualsTester ()
@@ -282,6 +332,18 @@ public void equalityTest() {
282332 CelMutableExpr .ofConstant (CelConstant .ofValue ("target" )),
283333 "function" ,
284334 CelMutableExpr .ofConstant (CelConstant .ofValue ("arg" )))))
335+ .addEqualityGroup (CelMutableExpr .ofCreateList (CelMutableCreateList .create ()))
336+ .addEqualityGroup (
337+ CelMutableExpr .ofCreateList (
338+ 6L ,
339+ CelMutableCreateList .create (
340+ CelMutableExpr .ofConstant (CelConstant .ofValue ("element1" )),
341+ CelMutableExpr .ofConstant (CelConstant .ofValue ("element2" )))),
342+ CelMutableExpr .ofCreateList (
343+ 6L ,
344+ CelMutableCreateList .create (
345+ CelMutableExpr .ofConstant (CelConstant .ofValue ("element1" )),
346+ CelMutableExpr .ofConstant (CelConstant .ofValue ("element2" )))))
285347 .testEquals ();
286348 }
287349
@@ -292,7 +354,7 @@ private enum MutableExprKindTestCase {
292354 IDENT (CelMutableExpr .ofIdent ("test" )),
293355 SELECT (CelMutableExpr .ofSelect (CelMutableSelect .create (CelMutableExpr .ofNotSet (), "field" ))),
294356 CALL (CelMutableExpr .ofCall (CelMutableCall .create ("call" ))),
295- ;
357+ CREATE_LIST ( CelMutableExpr . ofCreateList ( CelMutableCreateList . create ())) ;
296358
297359 private final CelMutableExpr mutableExpr ;
298360
@@ -319,6 +381,9 @@ public void getExprValue_invalidKind_throws(@TestParameter MutableExprKindTestCa
319381 if (!testCaseKind .equals (Kind .CALL )) {
320382 assertThrows (IllegalArgumentException .class , testCase .mutableExpr ::call );
321383 }
384+ if (!testCaseKind .equals (Kind .CREATE_LIST )) {
385+ assertThrows (IllegalArgumentException .class , testCase .mutableExpr ::createList );
386+ }
322387 }
323388
324389 @ SuppressWarnings ("Immutable" ) // Mutable by design
@@ -339,6 +404,13 @@ private enum HashCodeTestCase {
339404 "function" ,
340405 CelMutableExpr .ofConstant (CelConstant .ofValue ("arg" )))),
341406 -1735261193 ),
407+ CREATE_LIST (
408+ CelMutableExpr .ofCreateList (
409+ 6L ,
410+ CelMutableCreateList .create (
411+ CelMutableExpr .ofConstant (CelConstant .ofValue ("element1" )),
412+ CelMutableExpr .ofConstant (CelConstant .ofValue ("element2" )))),
413+ 165341403 ),
342414 ;
343415
344416 private final CelMutableExpr mutableExpr ;
0 commit comments