@@ -1018,6 +1018,8 @@ func TestSubRouter(t *testing.T) {
1018
1018
subrouter1 := new (Route ).Host ("{v1:[a-z]+}.google.com" ).Subrouter ()
1019
1019
subrouter2 := new (Route ).PathPrefix ("/foo/{v1}" ).Subrouter ()
1020
1020
subrouter3 := new (Route ).PathPrefix ("/foo" ).Subrouter ()
1021
+ subrouter4 := new (Route ).PathPrefix ("/foo/bar" ).Subrouter ()
1022
+ subrouter5 := new (Route ).PathPrefix ("/{category}" ).Subrouter ()
1021
1023
1022
1024
tests := []routeTest {
1023
1025
{
@@ -1049,6 +1051,15 @@ func TestSubRouter(t *testing.T) {
1049
1051
pathTemplate : `/foo/{v1}/baz/{v2}` ,
1050
1052
shouldMatch : true ,
1051
1053
},
1054
+ {
1055
+ route : subrouter2 .Path ("/baz/{v2}" ),
1056
+ request : newRequest ("GET" , "http://localhost/foo/bar" ),
1057
+ vars : map [string ]string {"v1" : "bar" , "v2" : "ding" },
1058
+ host : "" ,
1059
+ path : "/foo/bar/baz/ding" ,
1060
+ pathTemplate : `/foo/{v1}/baz/{v2}` ,
1061
+ shouldMatch : false ,
1062
+ },
1052
1063
{
1053
1064
route : subrouter3 .Path ("/" ),
1054
1065
request : newRequest ("GET" , "http://localhost/foo/" ),
@@ -1059,13 +1070,50 @@ func TestSubRouter(t *testing.T) {
1059
1070
shouldMatch : true ,
1060
1071
},
1061
1072
{
1062
- route : subrouter2 .Path ("/baz/{v2}" ),
1073
+ route : subrouter3 .Path ("" ),
1074
+ request : newRequest ("GET" , "http://localhost/foo" ),
1075
+ vars : map [string ]string {},
1076
+ host : "" ,
1077
+ path : "/foo" ,
1078
+ pathTemplate : `/foo` ,
1079
+ shouldMatch : true ,
1080
+ },
1081
+
1082
+ {
1083
+ route : subrouter4 .Path ("/" ),
1084
+ request : newRequest ("GET" , "http://localhost/foo/bar/" ),
1085
+ vars : map [string ]string {},
1086
+ host : "" ,
1087
+ path : "/foo/bar/" ,
1088
+ pathTemplate : `/foo/bar/` ,
1089
+ shouldMatch : true ,
1090
+ },
1091
+ {
1092
+ route : subrouter4 .Path ("" ),
1063
1093
request : newRequest ("GET" , "http://localhost/foo/bar" ),
1064
- vars : map [string ]string {"v1" : "bar" , "v2" : "ding" },
1094
+ vars : map [string ]string {},
1065
1095
host : "" ,
1066
- path : "/foo/bar/baz/ding" ,
1067
- pathTemplate : `/foo/{v1}/baz/{v2}` ,
1068
- shouldMatch : false ,
1096
+ path : "/foo/bar" ,
1097
+ pathTemplate : `/foo/bar` ,
1098
+ shouldMatch : true ,
1099
+ },
1100
+ {
1101
+ route : subrouter5 .Path ("/" ),
1102
+ request : newRequest ("GET" , "http://localhost/baz/" ),
1103
+ vars : map [string ]string {"category" : "baz" },
1104
+ host : "" ,
1105
+ path : "/baz/" ,
1106
+ pathTemplate : `/{category}/` ,
1107
+ shouldMatch : true ,
1108
+ },
1109
+ {
1110
+ route : subrouter5 .Path ("" ),
1111
+ request : newRequest ("GET" , "http://localhost/baz" ),
1112
+ vars : map [string ]string {"category" : "baz" },
1113
+ host : "" ,
1114
+ path : "/baz" ,
1115
+ pathTemplate : `/{category}` ,
1116
+ shouldMatch : true ,
1069
1117
},
1070
1118
}
1071
1119
0 commit comments