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

Function TestParseErrorData

parser/parser_test.go:3905–3923  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3903}
3904
3905func TestParseErrorData(t *testing.T) {
3906 for _, pratt := range []bool{false, true} {
3907 t.Run(fmt.Sprintf("enablePrattParser=%t", pratt), func(t *testing.T) {
3908 p := newTestParser(t, EnablePrattParser(pratt))
3909 src := common.NewTextSource(`a.?b`)
3910 _, iss := p.Parse(src)
3911 if len(iss.GetErrors()) != 1 {
3912 t.Fatalf("Check() of a bad expression did produce a single error: %v", iss.ToDisplayString())
3913 }
3914 celErr := iss.GetErrors()[0]
3915 if celErr.ExprID != 2 {
3916 t.Errorf("got exprID %v, wanted 2", celErr.ExprID)
3917 }
3918 if !strings.Contains(celErr.Message, "unsupported syntax") {
3919 t.Errorf("got message %v, wanted unsupported syntax", celErr.Message)
3920 }
3921 })
3922 }
3923}
3924
3925func newTestParser(t *testing.T, options ...Option) *Parser {
3926 t.Helper()

Callers

nothing calls this directly

Calls 7

NewTextSourceFunction · 0.92
newTestParserFunction · 0.85
EnablePrattParserFunction · 0.85
GetErrorsMethod · 0.80
ParseMethod · 0.65
ContainsMethod · 0.65
ToDisplayStringMethod · 0.45

Tested by

no test coverage detected