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

Function TestRuntimeCost

interpreter/runtimecost_test.go:245–906  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

243}
244
245func TestRuntimeCost(t *testing.T) {
246 allTypes := types.NewObjectType("google.expr.proto3.test.TestAllTypes")
247 allList := types.NewListType(allTypes)
248 intList := types.NewListType(types.IntType)
249 nestedList := types.NewListType(allList)
250
251 allMap := types.NewMapType(types.StringType, allTypes)
252 nestedMap := types.NewMapType(types.StringType, allMap)
253 cases := []struct {
254 name string
255 expr string
256 vars []*decls.VariableDecl
257 want uint64
258 in any
259 testFuncCost bool
260 limit uint64
261 options []CostTrackerOption
262
263 expectExceedsLimit bool
264 }{
265 {
266 name: "const",
267 expr: `"Hello World!"`,
268 want: 0,
269 },
270 {
271 name: "identity",
272 expr: `input`,
273 vars: []*decls.VariableDecl{decls.NewVariable("input", intList)},
274 want: 1,
275 in: map[string]any{"input": []int{1, 2}},
276 },
277 {
278 name: "select: map",
279 expr: `input['key']`,
280 vars: []*decls.VariableDecl{decls.NewVariable("input", types.NewMapType(types.StringType, types.StringType))},
281 want: 2,
282 in: map[string]any{"input": map[string]string{"key": "v"}},
283 },
284 {
285 name: "select: array index",
286 expr: `input[0]`,
287 vars: []*decls.VariableDecl{decls.NewVariable("input", types.NewListType(types.StringType))},
288 want: 2,
289 in: map[string]any{"input": []string{"v"}},
290 },
291 {
292 name: "select: field",
293 expr: `input.single_int32`,
294 vars: []*decls.VariableDecl{decls.NewVariable("input", allTypes)},
295 want: 2,
296 in: map[string]any{
297 "input": &proto3pb.TestAllTypes{
298 RepeatedBool: []bool{false},
299 MapInt64NestedType: map[int64]*proto3pb.NestedTestAllTypes{
300 1: {},
301 },
302 MapStringString: map[string]string{},

Callers

nothing calls this directly

Calls 11

NewObjectTypeFunction · 0.92
NewListTypeFunction · 0.92
NewMapTypeFunction · 0.92
NewVariableFunction · 0.92
randSeqFunction · 0.85
OverloadCostTrackerFunction · 0.85
constructActivationFunction · 0.85
CostTrackerLimitFunction · 0.85
computeCostFunction · 0.85
PresenceTestHasCostFunction · 0.70
actualSizeFunction · 0.70

Tested by

no test coverage detected