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

Function TestSimpleVariables

policy/parser_test.go:332–371  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

330}
331
332func TestSimpleVariables(t *testing.T) {
333 tst := `name: "test"
334rule:
335 variables:
336 - first: "1.5"
337 - second: "2.5"
338 match:
339 - output: >
340 variables.first + variables.second
341
342`
343
344 parser, err := NewParser(SimpleVariables())
345 if err != nil {
346 t.Fatalf("NewParser() failed: %v", err)
347 }
348 policy, iss := parser.Parse(StringSource(tst, "<input>"))
349 if iss != nil {
350 t.Fatalf("Parse() failed: %v", iss.Err())
351 }
352 env, err := cel.NewEnv(ext.Bindings())
353 if err != nil {
354 t.Fatalf("NewEnv() failed: %v", err)
355 }
356 ast, iss := Compile(env, policy)
357 if iss != nil {
358 t.Fatalf("Compile() failed: %v", iss.Err())
359 }
360 prg, err := env.Program(ast)
361 if err != nil {
362 t.Fatalf("Program() failed: %v", err)
363 }
364 out, _, err := prg.Eval(cel.NoVars())
365 if err != nil {
366 t.Fatalf("prg.Eval() failed: %v", err)
367 }
368 if out != types.Double(4.0) {
369 t.Errorf("got %v, wanted 4.0", out)
370 }
371}
372
373type testTagHandler struct {
374 defaultTagVisitor

Callers

nothing calls this directly

Calls 12

ParseMethod · 0.95
ProgramMethod · 0.95
NewEnvFunction · 0.92
BindingsFunction · 0.92
NoVarsFunction · 0.92
DoubleTypeAlias · 0.92
SimpleVariablesFunction · 0.85
StringSourceFunction · 0.85
CompileFunction · 0.85
ErrMethod · 0.80
NewParserFunction · 0.70
EvalMethod · 0.65

Tested by

no test coverage detected