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

Function TestBlockEval

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

Source from the content-addressed store, hash-verified

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

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