@@ -812,29 +812,42 @@ func TestRouterStaticDynamicConflict(t *testing.T) {
812
812
assert .Equal (t , 3 , c .Get ("c" ))
813
813
}
814
814
815
- func TestRouterAPI (t * testing.T ) {
815
+ func testRouterAPI (t * testing.T , api [] Route ) {
816
816
e := New ()
817
817
r := e .router
818
818
819
- for _ , route := range gitHubAPI {
819
+ for _ , route := range api {
820
820
r .Add (route .Method , route .Path , func (c Context ) error {
821
821
return nil
822
822
})
823
823
}
824
824
c := e .NewContext (nil , nil ).(* context )
825
- for _ , route := range gitHubAPI {
825
+ for _ , route := range api {
826
826
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 )
832
831
}
833
832
}
834
833
}
835
834
}
836
835
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 ) {
838
851
e := New ()
839
852
r := e .router
840
853
b .ReportAllocs ()
@@ -856,20 +869,20 @@ func benchmarkRoutes(b *testing.B, routes []Route) {
856
869
}
857
870
}
858
871
859
- func BenchmarkStaticRoute (b * testing.B ) {
860
- benchmarkRoutes (b , staticRoutes )
872
+ func BenchmarkRouterStaticRoutes (b * testing.B ) {
873
+ benchmarkRouterRoutes (b , staticRoutes )
861
874
}
862
875
863
- func BenchmarkGitHubAPI (b * testing.B ) {
864
- benchmarkRoutes (b , gitHubAPI )
876
+ func BenchmarkRouterGitHubAPI (b * testing.B ) {
877
+ benchmarkRouterRoutes (b , gitHubAPI )
865
878
}
866
879
867
- func BenchmarkParseAPI (b * testing.B ) {
868
- benchmarkRoutes (b , parseAPI )
880
+ func BenchmarkRouterParseAPI (b * testing.B ) {
881
+ benchmarkRouterRoutes (b , parseAPI )
869
882
}
870
883
871
- func BenchmarkGooglePlusAPI (b * testing.B ) {
872
- benchmarkRoutes (b , googlePlusAPI )
884
+ func BenchmarkRouterGooglePlusAPI (b * testing.B ) {
885
+ benchmarkRouterRoutes (b , googlePlusAPI )
873
886
}
874
887
875
888
func (n * node ) printTree (pfx string , tail bool ) {
0 commit comments