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

Function TestCheckErrorData

checker/checker_test.go:2775–2806  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2773}
2774
2775func TestCheckErrorData(t *testing.T) {
2776 p, err := parser.NewParser(
2777 parser.EnableOptionalSyntax(true),
2778 parser.Macros(parser.AllMacros...),
2779 )
2780 if err != nil {
2781 t.Fatalf("parser.NewParser() failed: %v", err)
2782 }
2783 src := common.NewTextSource(`a || true`)
2784 ast, iss := p.Parse(src)
2785 if len(iss.GetErrors()) != 0 {
2786 t.Fatalf("Parse() failed: %v", iss.ToDisplayString())
2787 }
2788
2789 reg := newTestRegistry(t)
2790 env, err := NewEnv(containers.DefaultContainer, reg)
2791 if err != nil {
2792 t.Fatalf("NewEnv(cont, reg) failed: %v", err)
2793 }
2794 env.AddFunctions(stdlib.Functions()...)
2795 _, iss = Check(ast, src, env)
2796 if len(iss.GetErrors()) != 1 {
2797 t.Fatalf("Check() of a bad expression did produce a single error: %v", iss.ToDisplayString())
2798 }
2799 celErr := iss.GetErrors()[0]
2800 if celErr.ExprID != 1 {
2801 t.Errorf("got exprID %v, wanted 1", celErr.ExprID)
2802 }
2803 if !strings.Contains(celErr.Message, "undeclared reference") {
2804 t.Errorf("got message %v, wanted undeclared reference", celErr.Message)
2805 }
2806}
2807
2808func TestCheckInvalidOptSelectMember(t *testing.T) {
2809 fac := ast.NewExprFactory()

Callers

nothing calls this directly

Calls 13

ParseMethod · 0.95
AddFunctionsMethod · 0.95
NewParserFunction · 0.92
EnableOptionalSyntaxFunction · 0.92
MacrosFunction · 0.92
NewTextSourceFunction · 0.92
FunctionsFunction · 0.92
CheckFunction · 0.85
GetErrorsMethod · 0.80
newTestRegistryFunction · 0.70
NewEnvFunction · 0.70
ContainsMethod · 0.65

Tested by

no test coverage detected