Test for the new regexp library, still not available in stable Go.
(t *testing.T)
| 652 | |
| 653 | // Test for the new regexp library, still not available in stable Go. |
| 654 | func TestNewRegexp(t *testing.T) { |
| 655 | var p *routeRegexp |
| 656 | var matches []string |
| 657 | |
| 658 | tests := map[string]map[string][]string{ |
| 659 | "/{foo:a{2}}": { |
| 660 | "/a": nil, |
| 661 | "/aa": {"aa"}, |
| 662 | "/aaa": nil, |
| 663 | "/aaaa": nil, |
| 664 | }, |
| 665 | "/{foo:a{2,}}": { |
| 666 | "/a": nil, |
| 667 | "/aa": {"aa"}, |
| 668 | "/aaa": {"aaa"}, |
| 669 | "/aaaa": {"aaaa"}, |
| 670 | }, |
| 671 | "/{foo:a{2,3}}": { |
| 672 | "/a": nil, |
| 673 | "/aa": {"aa"}, |
| 674 | "/aaa": {"aaa"}, |
| 675 | "/aaaa": nil, |
| 676 | }, |
| 677 | "/{foo:[a-z]{3}}/{bar:[a-z]{2}}": { |
| 678 | "/a": nil, |
| 679 | "/ab": nil, |
| 680 | "/abc": nil, |
| 681 | "/abcd": nil, |
| 682 | "/abc/ab": {"abc", "ab"}, |
| 683 | "/abc/abc": nil, |
| 684 | "/abcd/ab": nil, |
| 685 | }, |
| 686 | `/{foo:\w{3,}}/{bar:\d{2,}}`: { |
| 687 | "/a": nil, |
| 688 | "/ab": nil, |
| 689 | "/abc": nil, |
| 690 | "/abc/1": nil, |
| 691 | "/abc/12": {"abc", "12"}, |
| 692 | "/abcd/12": {"abcd", "12"}, |
| 693 | "/abcd/123": {"abcd", "123"}, |
| 694 | }, |
| 695 | } |
| 696 | |
| 697 | for pattern, paths := range tests { |
| 698 | p, _ = newRouteRegexp(pattern, regexpTypePath, routeRegexpOptions{}) |
| 699 | for path, result := range paths { |
| 700 | matches = p.regexp.FindStringSubmatch(path) |
| 701 | if result == nil { |
| 702 | if matches != nil { |
| 703 | t.Errorf("%v should not match %v.", pattern, path) |
| 704 | } |
| 705 | } else { |
| 706 | if len(matches) != len(result)+1 { |
| 707 | t.Errorf("Expected %v matches, got %v.", len(result)+1, len(matches)) |
| 708 | } else { |
| 709 | for k, v := range result { |
| 710 | if matches[k+1] != v { |
| 711 | t.Errorf("Expected %v, got %v.", v, matches[k+1]) |
nothing calls this directly
no test coverage detected