@@ -1318,6 +1318,50 @@ func TestStringFormat(t *testing.T) {
13181318 }
13191319}
13201320
1321+ func TestStringFormatHeterogeneousLiterals (t * testing.T ) {
1322+ tests := []struct {
1323+ expr string
1324+ out string
1325+ }{
1326+ {
1327+ expr : `"list: %s".format([[[1, 2, [3.0, 4]]]])` ,
1328+ out : `list: [[1, 2, [3.000000, 4]]]` ,
1329+ },
1330+ {
1331+ expr : `"list size: %d".format([[[1, 2, [3.0, 4]]].size()])` ,
1332+ out : `list size: 1` ,
1333+ },
1334+ {
1335+ expr : `"list element: %s".format([[[1, 2, [3.0, 4]]][0]])` ,
1336+ out : `list element: [1, 2, [3.000000, 4]]` ,
1337+ },
1338+ }
1339+ env , err := cel .NewEnv (Strings (), cel .ASTValidators (cel .ValidateHomogeneousAggregateLiterals ()))
1340+ if err != nil {
1341+ t .Fatalf ("cel.NewEnv() failed: %v" , err )
1342+ }
1343+ for _ , tst := range tests {
1344+ tc := tst
1345+ t .Run (tc .expr , func (t * testing.T ) {
1346+ ast , iss := env .Compile (tc .expr )
1347+ if iss .Err () != nil {
1348+ t .Fatalf ("env.Compile(%q) failed: %v" , tc .expr , iss .Err ())
1349+ }
1350+ prg , err := env .Program (ast )
1351+ if err != nil {
1352+ t .Fatalf ("env.Program() failed: %v" , err )
1353+ }
1354+ out , _ , err := prg .Eval (cel .NoVars ())
1355+ if err != nil {
1356+ t .Fatalf ("Eval() failed: %v" , err )
1357+ }
1358+ if out .Value () != tc .out {
1359+ t .Errorf ("Eval() got %v, wanted %v" , out , tc .out )
1360+ }
1361+ })
1362+ }
1363+ }
1364+
13211365func TestBadLocale (t * testing.T ) {
13221366 _ , err := cel .NewEnv (Strings (StringsLocale ("bad-locale" )))
13231367 if err != nil {
0 commit comments