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

Function TestSourceInfoToProto

common/ast/conversion_test.go:510–674  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

508}
509
510func TestSourceInfoToProto(t *testing.T) {
511 expr := `[{}, {'field': true}].exists(i, has(i.field))`
512 p, err := parser.NewParser(
513 parser.Macros(parser.AllMacros...),
514 parser.EnableOptionalSyntax(true),
515 parser.PopulateMacroCalls(true))
516 if err != nil {
517 t.Fatalf("parser.NewParser() failed: %v", err)
518 }
519 parsed, errs := p.Parse(common.NewTextSource(expr))
520 if len(errs.GetErrors()) != 0 {
521 t.Fatalf("Parse() failed: %s", errs.ToDisplayString())
522 }
523 pbInfo, err := ast.SourceInfoToProto(parsed.SourceInfo())
524 if err != nil {
525 t.Fatalf("SourceInfoToProto() failed: %v", err)
526 }
527 wantInfo := `
528 location: "<input>"
529 line_offsets: 46
530 positions: {
531 key: 1
532 value: 0
533 }
534 positions: {
535 key: 2
536 value: 1
537 }
538 positions: {
539 key: 3
540 value: 5
541 }
542 positions: {
543 key: 4
544 value: 13
545 }
546 positions: {
547 key: 5
548 value: 6
549 }
550 positions: {
551 key: 6
552 value: 15
553 }
554 positions: {
555 key: 8
556 value: 29
557 }
558 positions: {
559 key: 10
560 value: 36
561 }
562 positions: {
563 key: 11
564 value: 37
565 }
566 positions: {
567 key: 12

Callers

nothing calls this directly

Calls 11

ParseMethod · 0.95
NewParserFunction · 0.92
MacrosFunction · 0.92
EnableOptionalSyntaxFunction · 0.92
PopulateMacroCallsFunction · 0.92
NewTextSourceFunction · 0.92
SourceInfoToProtoFunction · 0.92
GetErrorsMethod · 0.80
EqualMethod · 0.65
ToDisplayStringMethod · 0.45
SourceInfoMethod · 0.45

Tested by

no test coverage detected