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

Function TestSimpleVariables

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

Source from the content-addressed store, hash-verified

367}
368
369func TestSimpleVariables(t *testing.T) {
370 tst := `name: "test"
371rule:
372 variables:
373 - first: "1.5"
374 - second: "2.5"
375 match:
376 - output: >
377 variables.first + variables.second
378
379`
380
381 parser, err := NewParser(SimpleVariables())
382 if err != nil {
383 t.Fatalf("NewParser() failed: %v", err)
384 }
385 policy, iss := parser.Parse(StringSource(tst, "<input>"))
386 if iss != nil {
387 t.Fatalf("Parse() failed: %v", iss.Err())
388 }
389 env, err := cel.NewEnv(ext.Bindings())
390 if err != nil {
391 t.Fatalf("NewEnv() failed: %v", err)
392 }
393 ast, iss := Compile(env, policy)
394 if iss != nil {
395 t.Fatalf("Compile() failed: %v", iss.Err())
396 }
397 prg, err := env.Program(ast)
398 if err != nil {
399 t.Fatalf("Program() failed: %v", err)
400 }
401 out, _, err := prg.Eval(cel.NoVars())
402 if err != nil {
403 t.Fatalf("prg.Eval() failed: %v", err)
404 }
405 if out != types.Double(4.0) {
406 t.Errorf("got %v, wanted 4.0", out)
407 }
408}
409
410type testTagHandler struct {
411 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
ErrMethod · 0.80
NewParserFunction · 0.70
CompileFunction · 0.70
EvalMethod · 0.65

Tested by

no test coverage detected