(t *testing.T)
| 508 | } |
| 509 | |
| 510 | func 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 |
nothing calls this directly
no test coverage detected