forked from mirror/gin
Updates tree_test.go
This commit is contained in:
parent
20825e7694
commit
b4963aa7de
51
tree_test.go
51
tree_test.go
|
@ -88,7 +88,7 @@ func checkMaxParams(t *testing.T, n *node) uint8 {
|
||||||
maxParams = params
|
maxParams = params
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if n.nType != static && !n.wildChild {
|
if n.nType > root && !n.wildChild {
|
||||||
maxParams++
|
maxParams++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,14 +364,13 @@ func TestTreeDoubleWildcard(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*func TestTreeDuplicateWildcard(t *testing.T) {
|
/*func TestTreeDuplicateWildcard(t *testing.T) {
|
||||||
tree := &node{}
|
tree := &node{}
|
||||||
|
routes := [...]string{
|
||||||
routes := [...]string{
|
"/:id/:name/:id",
|
||||||
"/:id/:name/:id",
|
}
|
||||||
}
|
for _, route := range routes {
|
||||||
for _, route := range routes {
|
...
|
||||||
...
|
}
|
||||||
}
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
func TestTreeTrailingSlashRedirect(t *testing.T) {
|
func TestTreeTrailingSlashRedirect(t *testing.T) {
|
||||||
|
@ -393,6 +392,9 @@ func TestTreeTrailingSlashRedirect(t *testing.T) {
|
||||||
"/1/:id/2",
|
"/1/:id/2",
|
||||||
"/aa",
|
"/aa",
|
||||||
"/a/",
|
"/a/",
|
||||||
|
"/admin",
|
||||||
|
"/admin/:category",
|
||||||
|
"/admin/:category/:page",
|
||||||
"/doc",
|
"/doc",
|
||||||
"/doc/go_faq.html",
|
"/doc/go_faq.html",
|
||||||
"/doc/go1.html",
|
"/doc/go1.html",
|
||||||
|
@ -422,6 +424,9 @@ func TestTreeTrailingSlashRedirect(t *testing.T) {
|
||||||
"/0/go/",
|
"/0/go/",
|
||||||
"/1/go",
|
"/1/go",
|
||||||
"/a",
|
"/a",
|
||||||
|
"/admin/",
|
||||||
|
"/admin/config/",
|
||||||
|
"/admin/config/permissions/",
|
||||||
"/doc/",
|
"/doc/",
|
||||||
}
|
}
|
||||||
for _, route := range tsrRoutes {
|
for _, route := range tsrRoutes {
|
||||||
|
@ -451,6 +456,24 @@ func TestTreeTrailingSlashRedirect(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTreeRootTrailingSlashRedirect(t *testing.T) {
|
||||||
|
tree := &node{}
|
||||||
|
|
||||||
|
recv := catchPanic(func() {
|
||||||
|
tree.addRoute("/:test", fakeHandler("/:test"))
|
||||||
|
})
|
||||||
|
if recv != nil {
|
||||||
|
t.Fatalf("panic inserting test route: %v", recv)
|
||||||
|
}
|
||||||
|
|
||||||
|
handler, _, tsr := tree.getValue("/")
|
||||||
|
if handler != nil {
|
||||||
|
t.Fatalf("non-nil handler")
|
||||||
|
} else if tsr {
|
||||||
|
t.Errorf("expected no TSR recommendation")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestTreeFindCaseInsensitivePath(t *testing.T) {
|
func TestTreeFindCaseInsensitivePath(t *testing.T) {
|
||||||
tree := &node{}
|
tree := &node{}
|
||||||
|
|
||||||
|
@ -583,6 +606,8 @@ func TestTreeFindCaseInsensitivePath(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTreeInvalidNodeType(t *testing.T) {
|
func TestTreeInvalidNodeType(t *testing.T) {
|
||||||
|
const panicMsg = "invalid node type"
|
||||||
|
|
||||||
tree := &node{}
|
tree := &node{}
|
||||||
tree.addRoute("/", fakeHandler("/"))
|
tree.addRoute("/", fakeHandler("/"))
|
||||||
tree.addRoute("/:page", fakeHandler("/:page"))
|
tree.addRoute("/:page", fakeHandler("/:page"))
|
||||||
|
@ -594,15 +619,15 @@ func TestTreeInvalidNodeType(t *testing.T) {
|
||||||
recv := catchPanic(func() {
|
recv := catchPanic(func() {
|
||||||
tree.getValue("/test", nil)
|
tree.getValue("/test", nil)
|
||||||
})
|
})
|
||||||
if rs, ok := recv.(string); !ok || rs != "invalid node type" {
|
if rs, ok := recv.(string); !ok || rs != panicMsg {
|
||||||
t.Fatalf(`Expected panic "invalid node type", got "%v"`, recv)
|
t.Fatalf("Expected panic '"+panicMsg+"', got '%v'", recv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// case-insensitive lookup
|
// case-insensitive lookup
|
||||||
recv = catchPanic(func() {
|
recv = catchPanic(func() {
|
||||||
tree.findCaseInsensitivePath("/test", true)
|
tree.findCaseInsensitivePath("/test", true)
|
||||||
})
|
})
|
||||||
if rs, ok := recv.(string); !ok || rs != "invalid node type" {
|
if rs, ok := recv.(string); !ok || rs != panicMsg {
|
||||||
t.Fatalf(`Expected panic "invalid node type", got "%v"`, recv)
|
t.Fatalf("Expected panic '"+panicMsg+"', got '%v'", recv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue