(t *testing.T)
| 533 | } |
| 534 | |
| 535 | func TestSearchService_CodeTextMatch(t *testing.T) { |
| 536 | t.Parallel() |
| 537 | client, mux, _ := setup(t) |
| 538 | |
| 539 | mux.HandleFunc("/search/code", func(w http.ResponseWriter, r *http.Request) { |
| 540 | testMethod(t, r, "GET") |
| 541 | |
| 542 | textMatchResponse := ` |
| 543 | { |
| 544 | "total_count": 1, |
| 545 | "incomplete_results": false, |
| 546 | "items": [ |
| 547 | { |
| 548 | "name":"gopher1", |
| 549 | "text_matches": [ |
| 550 | { |
| 551 | "fragment": "I'm afraid my friend what you have found\nIs a gopher who lives to feed", |
| 552 | "matches": [ |
| 553 | { |
| 554 | "text": "gopher", |
| 555 | "indices": [ |
| 556 | 14, |
| 557 | 21 |
| 558 | ] |
| 559 | } |
| 560 | ] |
| 561 | } |
| 562 | ] |
| 563 | } |
| 564 | ] |
| 565 | } |
| 566 | ` |
| 567 | |
| 568 | fmt.Fprint(w, textMatchResponse) |
| 569 | }) |
| 570 | |
| 571 | opts := &SearchOptions{Sort: "forks", Order: "desc", ListOptions: ListOptions{Page: 2, PerPage: 2}, TextMatch: true} |
| 572 | ctx := t.Context() |
| 573 | result, _, err := client.Search.Code(ctx, "blah", opts) |
| 574 | if err != nil { |
| 575 | t.Errorf("Search.Code returned error: %v", err) |
| 576 | } |
| 577 | |
| 578 | wantedCodeResult := &CodeResult{ |
| 579 | Name: Ptr("gopher1"), |
| 580 | TextMatches: []*TextMatch{ |
| 581 | { |
| 582 | Fragment: Ptr("I'm afraid my friend what you have found\nIs a gopher who lives to feed"), |
| 583 | Matches: []*Match{{Text: Ptr("gopher"), Indices: []int{14, 21}}}, |
| 584 | }, |
| 585 | }, |
| 586 | } |
| 587 | |
| 588 | want := &CodeSearchResult{ |
| 589 | Total: Ptr(1), |
| 590 | IncompleteResults: Ptr(false), |
| 591 | CodeResults: []*CodeResult{wantedCodeResult}, |
| 592 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…