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

Function TestLexerErrorRecovery

parser/lexer_test.go:540–574  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

538}
539
540func TestLexerErrorRecovery(t *testing.T) {
541 buf := runes.NewBuffer("1e, {2 3}")
542 lexer := newLexer(buf)
543
544 tok := lexer.Lex()
545 if tok.kind != tokError {
546 t.Fatalf("tok = %v, want tokError", tok.kind)
547 }
548 if lexer.GetError().message != "floating point literal missing digits after exponent separator" {
549 t.Errorf("got error message %q", lexer.GetError().message)
550 }
551
552 tok = lexer.Lex()
553 if tok.kind != tokComma {
554 t.Errorf("tok = %v, want tokComma", tok.kind)
555 }
556
557 tok = lexer.Lex()
558 if tok.kind != tokWhitespace {
559 t.Errorf("tok = %v, want tokWhitespace", tok.kind)
560 }
561
562 tok = lexer.Lex()
563 if tok.kind != tokLeftBrace {
564 t.Errorf("tok = %v, want tokLeftBrace", tok.kind)
565 }
566
567 tok = lexer.Lex()
568 if tok.kind != tokInt {
569 t.Errorf("tok = %v, want tokInt", tok.kind)
570 }
571 if tok.start != 5 || tok.end != 6 {
572 t.Errorf("tok position = (%d, %d), want (5, 6)", tok.start, tok.end)
573 }
574}
575
576func BenchmarkLexer(b *testing.B) {
577 expr := `a > 5 && b < 10 || c == "xyz" + 42u - 3.14 * (foo.bar(1, 2, [3, ?4]))`

Callers

nothing calls this directly

Calls 4

NewBufferFunction · 0.92
newLexerFunction · 0.85
LexMethod · 0.80
GetErrorMethod · 0.80

Tested by

no test coverage detected