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

Function TestStringFormatHeterogeneousLiteralsV2

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

Source from the content-addressed store, hash-verified

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

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