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

Function TestBlockEval

ext/bindings_test.go:252–379  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

250}
251
252func TestBlockEval(t *testing.T) {
253 fac := ast.NewExprFactory()
254 tests := []struct {
255 name string
256 expr ast.Expr
257 opts []cel.EnvOption
258 in map[string]any
259 out ref.Val
260 }{
261 {
262 name: "chained block",
263 expr: fac.NewCall(
264 1, "cel.@block",
265 fac.NewList(2, []ast.Expr{
266 fac.NewIdent(3, "x"),
267 fac.NewIdent(4, "@index0"),
268 fac.NewIdent(5, "@index1"),
269 }, []int32{}),
270 fac.NewCall(9, operators.Add,
271 fac.NewCall(6, operators.Add,
272 fac.NewIdent(7, "@index2"),
273 fac.NewIdent(8, "@index1")),
274 fac.NewIdent(10, "@index0"),
275 ),
276 ),
277 opts: []cel.EnvOption{
278 cel.Variable("x", cel.StringType),
279 },
280 in: map[string]any{"x": "hello"},
281 out: types.String("hellohellohello"),
282 },
283 {
284 name: "empty block",
285 expr: fac.NewCall(
286 1, "cel.@block",
287 fac.NewList(2, []ast.Expr{}, []int32{}),
288 fac.NewCall(3, operators.LogicalNot, fac.NewLiteral(4, types.False)),
289 ),
290 in: map[string]any{},
291 out: types.True,
292 },
293 {
294 name: "mixed block constant values",
295 expr: fac.NewCall(
296 1, "cel.@block",
297 fac.NewList(2, []ast.Expr{
298 fac.NewLiteral(3, types.String("hello")),
299 fac.NewLiteral(4, types.Int(5)),
300 }, []int32{}),
301 fac.NewCall(5, operators.Equals,
302 fac.NewCall(6, "size",
303 fac.NewIdent(7, "@index0")),
304 fac.NewIdent(8, "@index1"),
305 ),
306 ),
307 opts: []cel.EnvOption{
308 cel.ExtendedValidations(),
309 },

Callers

nothing calls this directly

Calls 15

NewCallMethod · 0.95
NewListMethod · 0.95
NewIdentMethod · 0.95
NewLiteralMethod · 0.95
PlanProgramMethod · 0.95
NewExprFactoryFunction · 0.92
VariableFunction · 0.92
StringTypeAlias · 0.92
IntTypeAlias · 0.92
ExtendedValidationsFunction · 0.92
NewASTFunction · 0.92
NewEnvFunction · 0.92

Tested by

no test coverage detected