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

Function TestListsRuntimeErrors

ext/lists_test.go:119–162  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

117}
118
119func TestListsRuntimeErrors(t *testing.T) {
120 env, err := cel.NewEnv(Lists(ListsVersion(1)))
121 if err != nil {
122 t.Fatalf("cel.NewEnv() failed: %v", err)
123 }
124 listsTests := []struct {
125 expr string
126 err string
127 }{
128 {
129 expr: "dyn({}).flatten()",
130 err: "no such overload",
131 },
132 {
133 expr: "dyn({}).flatten(0)",
134 err: "no such overload",
135 },
136 {
137 expr: "[].flatten(-1)",
138 err: "level must be non-negative",
139 },
140 {
141 expr: "[].flatten(dyn('1'))",
142 err: "no such overload",
143 },
144 }
145 for i, tst := range listsTests {
146 tc := tst
147 t.Run(fmt.Sprintf("[%d]", i), func(t *testing.T) {
148 ast, iss := env.Compile(tc.expr)
149 if iss.Err() != nil {
150 t.Fatalf("env.Compile(%q) failed: %v", tc.expr, iss.Err())
151 }
152 prg, err := env.Program(ast)
153 if err != nil {
154 t.Fatalf("env.Program() failed: %v", err)
155 }
156 _, _, err = prg.Eval(cel.NoVars())
157 if err == nil || !strings.Contains(err.Error(), tc.err) {
158 t.Errorf("prg.Eval() got %v, wanted %v", err, tc.err)
159 }
160 })
161 }
162}
163
164func TestListsVersion(t *testing.T) {
165 versionCases := []struct {

Callers

nothing calls this directly

Calls 10

CompileMethod · 0.95
ProgramMethod · 0.95
NewEnvFunction · 0.92
NoVarsFunction · 0.92
ListsFunction · 0.85
ListsVersionFunction · 0.85
ErrMethod · 0.80
EvalMethod · 0.65
ContainsMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected