TestStringMatch tests the stringMatch function with various conditions.
(t *testing.T)
| 562 | |
| 563 | // TestStringMatch tests the stringMatch function with various conditions. |
| 564 | func TestStringMatch(t *testing.T) { |
| 565 | tests := []struct { |
| 566 | name string |
| 567 | searchFor string |
| 568 | searchIn string |
| 569 | allowContains bool |
| 570 | wantPartial bool |
| 571 | wantFull bool |
| 572 | }{ |
| 573 | {"exact", "sword", "sword", false, true, true}, |
| 574 | {"partial prefix", "sw", "sword", false, true, false}, |
| 575 | {"no match prefix", "abc", "sword", false, false, false}, |
| 576 | {"contains partial", "wor", "sword", true, false, false}, |
| 577 | {"contains full", "sword", "MYswordX", true, false, false}, // "sword" is not a prefix of the single word "myswordx" |
| 578 | {"case mismatch", "SWORD", "sword", false, true, true}, |
| 579 | } |
| 580 | for _, tt := range tests { |
| 581 | partial, full := stringMatch(tt.searchFor, tt.searchIn, tt.allowContains) |
| 582 | if partial != tt.wantPartial || full != tt.wantFull { |
| 583 | t.Errorf("stringMatch(%q, %q, %t) got (%v, %v), want (%v, %v)", |
| 584 | tt.searchFor, tt.searchIn, tt.allowContains, |
| 585 | partial, full, tt.wantPartial, tt.wantFull) |
| 586 | } |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | // TestHash checks Hash outputs a known format. |
| 591 | func TestHash(t *testing.T) { |
nothing calls this directly
no test coverage detected