@@ -812,29 +812,42 @@ func TestRouterStaticDynamicConflict(t *testing.T) {
812812 assert .Equal (t , 3 , c .Get ("c" ))
813813}
814814
815- func TestRouterAPI (t * testing.T ) {
815+ func testRouterAPI (t * testing.T , api [] Route ) {
816816 e := New ()
817817 r := e .router
818818
819- for _ , route := range gitHubAPI {
819+ for _ , route := range api {
820820 r .Add (route .Method , route .Path , func (c Context ) error {
821821 return nil
822822 })
823823 }
824824 c := e .NewContext (nil , nil ).(* context )
825- for _ , route := range gitHubAPI {
825+ for _ , route := range api {
826826 r .Find (route .Method , route .Path , c )
827- for _ , n := range c .pnames {
828- for _ , p := range strings .Split (n , "," ) {
829- if assert .NotEmpty (t , p ) {
830- assert .Equal (t , c .Param (p ), ":" + p )
831- }
827+ tokens := strings .Split (route .Path [1 :], "/" )
828+ for _ , token := range tokens {
829+ if token [0 ] == ':' {
830+ assert .Equal (t , c .Param (token [1 :]), token )
832831 }
833832 }
834833 }
835834}
836835
837- func benchmarkRoutes (b * testing.B , routes []Route ) {
836+ func TestRouterGitHubAPI (t * testing.T ) {
837+ testRouterAPI (t , gitHubAPI )
838+ }
839+
840+ // Issue #729
841+ func TestRouterParamAlias (t * testing.T ) {
842+ api := []Route {
843+ {GET , "/users/:userID/following" , "" },
844+ {GET , "/users/:userID/followedBy" , "" },
845+ {GET , "/users/:userID/follow" , "" },
846+ }
847+ testRouterAPI (t , api )
848+ }
849+
850+ func benchmarkRouterRoutes (b * testing.B , routes []Route ) {
838851 e := New ()
839852 r := e .router
840853 b .ReportAllocs ()
@@ -856,20 +869,20 @@ func benchmarkRoutes(b *testing.B, routes []Route) {
856869 }
857870}
858871
859- func BenchmarkStaticRoute (b * testing.B ) {
860- benchmarkRoutes (b , staticRoutes )
872+ func BenchmarkRouterStaticRoutes (b * testing.B ) {
873+ benchmarkRouterRoutes (b , staticRoutes )
861874}
862875
863- func BenchmarkGitHubAPI (b * testing.B ) {
864- benchmarkRoutes (b , gitHubAPI )
876+ func BenchmarkRouterGitHubAPI (b * testing.B ) {
877+ benchmarkRouterRoutes (b , gitHubAPI )
865878}
866879
867- func BenchmarkParseAPI (b * testing.B ) {
868- benchmarkRoutes (b , parseAPI )
880+ func BenchmarkRouterParseAPI (b * testing.B ) {
881+ benchmarkRouterRoutes (b , parseAPI )
869882}
870883
871- func BenchmarkGooglePlusAPI (b * testing.B ) {
872- benchmarkRoutes (b , googlePlusAPI )
884+ func BenchmarkRouterGooglePlusAPI (b * testing.B ) {
885+ benchmarkRouterRoutes (b , googlePlusAPI )
873886}
874887
875888func (n * node ) printTree (pfx string , tail bool ) {
0 commit comments