MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestStringFormatHeterogeneousLiteralsV2

Function TestStringFormatHeterogeneousLiteralsV2

ext/formatting_v2_test.go:1030–1072  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1028}
1029
1030func TestStringFormatHeterogeneousLiteralsV2(t *testing.T) {
1031 tests := []struct {
1032 expr string
1033 out string
1034 }{
1035 {
1036 expr: `"list: %s".format([[[1, 2, [3.0, 4]]]])`,
1037 out: `list: [[1, 2, [3, 4]]]`,
1038 },
1039 {
1040 expr: `"list size: %d".format([[[1, 2, [3.0, 4]]].size()])`,
1041 out: `list size: 1`,
1042 },
1043 {
1044 expr: `"list element: %s".format([[[1, 2, [3.0, 4]]][0]])`,
1045 out: `list element: [1, 2, [3, 4]]`,
1046 },
1047 }
1048 env, err := cel.NewEnv(Strings(), cel.ASTValidators(cel.ValidateHomogeneousAggregateLiterals()))
1049 if err != nil {
1050 t.Fatalf("cel.NewEnv() failed: %v", err)
1051 }
1052 for _, tst := range tests {
1053 tc := tst
1054 t.Run(tc.expr, func(t *testing.T) {
1055 ast, iss := env.Compile(tc.expr)
1056 if iss.Err() != nil {
1057 t.Fatalf("env.Compile(%q) failed: %v", tc.expr, iss.Err())
1058 }
1059 prg, err := env.Program(ast)
1060 if err != nil {
1061 t.Fatalf("env.Program() failed: %v", err)
1062 }
1063 out, _, err := prg.Eval(cel.NoVars())
1064 if err != nil {
1065 t.Fatalf("Eval() failed: %v", err)
1066 }
1067 if out.Value() != tc.out {
1068 t.Errorf("Eval() got %v, wanted %v", out, tc.out)
1069 }
1070 })
1071 }
1072}

Callers

nothing calls this directly

Calls 10

CompileMethod · 0.95
ProgramMethod · 0.95
NewEnvFunction · 0.92
ASTValidatorsFunction · 0.92
NoVarsFunction · 0.92
StringsFunction · 0.85
ErrMethod · 0.80
EvalMethod · 0.65
ValueMethod · 0.65

Tested by

no test coverage detected