(t *testing.T)
| 521 | } |
| 522 | |
| 523 | func TestString_Match(t *testing.T) { |
| 524 | t.Run("named", func(t *testing.T) { |
| 525 | reporter := newMockReporter(t) |
| 526 | |
| 527 | value := NewString(reporter, "http://example.com/users/john") |
| 528 | |
| 529 | m := value.Match(`http://(?P<host>.+)/users/(?P<user>.+)`) |
| 530 | m.chain.assert(t, success) |
| 531 | |
| 532 | assert.Equal(t, |
| 533 | []string{"http://example.com/users/john", "example.com", "john"}, |
| 534 | m.submatchValues) |
| 535 | }) |
| 536 | |
| 537 | t.Run("unnamed", func(t *testing.T) { |
| 538 | reporter := newMockReporter(t) |
| 539 | |
| 540 | value := NewString(reporter, "http://example.com/users/john") |
| 541 | |
| 542 | m := value.Match(`http://(.+)/users/(.+)`) |
| 543 | m.chain.assert(t, success) |
| 544 | |
| 545 | assert.Equal(t, |
| 546 | []string{"http://example.com/users/john", "example.com", "john"}, |
| 547 | m.submatchValues) |
| 548 | }) |
| 549 | |
| 550 | t.Run("all", func(t *testing.T) { |
| 551 | reporter := newMockReporter(t) |
| 552 | |
| 553 | value := NewString(reporter, |
| 554 | "http://example.com/users/john http://example.com/users/bob") |
| 555 | |
| 556 | m := value.MatchAll(`http://(\S+)/users/(\S+)`) |
| 557 | |
| 558 | assert.Equal(t, 2, len(m)) |
| 559 | |
| 560 | m[0].chain.assert(t, success) |
| 561 | m[1].chain.assert(t, success) |
| 562 | |
| 563 | assert.Equal(t, |
| 564 | []string{"http://example.com/users/john", "example.com", "john"}, |
| 565 | m[0].submatchValues) |
| 566 | |
| 567 | assert.Equal(t, |
| 568 | []string{"http://example.com/users/bob", "example.com", "bob"}, |
| 569 | m[1].submatchValues) |
| 570 | }) |
| 571 | |
| 572 | t.Run("status", func(t *testing.T) { |
| 573 | cases := []struct { |
| 574 | str string |
| 575 | re string |
| 576 | wantMatch chainResult |
| 577 | wantNotMatch chainResult |
| 578 | }{ |
| 579 | { |
| 580 | str: `a`, |
nothing calls this directly
no test coverage detected
searching dependent graphs…