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

Function TestCheckErrorData

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

Source from the content-addressed store, hash-verified

2815}
2816
2817func TestCheckErrorData(t *testing.T) {
2818 p, err := parser.NewParser(
2819 parser.EnableOptionalSyntax(true),
2820 parser.Macros(parser.AllMacros...),
2821 )
2822 if err != nil {
2823 t.Fatalf("parser.NewParser() failed: %v", err)
2824 }
2825 src := common.NewTextSource(`a || true`)
2826 ast, iss := p.Parse(src)
2827 if len(iss.GetErrors()) != 0 {
2828 t.Fatalf("Parse() failed: %v", iss.ToDisplayString())
2829 }
2830
2831 reg := newTestRegistry(t)
2832 env, err := NewEnv(containers.DefaultContainer, reg)
2833 if err != nil {
2834 t.Fatalf("NewEnv(cont, reg) failed: %v", err)
2835 }
2836 env.AddFunctions(stdlib.Functions()...)
2837 _, iss = Check(ast, src, env)
2838 if len(iss.GetErrors()) != 1 {
2839 t.Fatalf("Check() of a bad expression did produce a single error: %v", iss.ToDisplayString())
2840 }
2841 celErr := iss.GetErrors()[0]
2842 if celErr.ExprID != 1 {
2843 t.Errorf("got exprID %v, wanted 1", celErr.ExprID)
2844 }
2845 if !strings.Contains(celErr.Message, "undeclared reference") {
2846 t.Errorf("got message %v, wanted undeclared reference", celErr.Message)
2847 }
2848}
2849
2850func TestCheckInvalidOptSelectMember(t *testing.T) {
2851 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