@@ -4,23 +4,23 @@ import "testing"
44
55func TestRouterStatic (t * testing.T ) {
66 r := New ().Router
7- r .Add ("GET" , "/users/joe/books " , func (c * Context ) {})
8- h , _ , _ := r .Find ("GET" , "/users/joe/books " )
7+ r .Add ("GET" , "/folders/files/bolt.gif " , func (c * Context ) {})
8+ h , _ , _ := r .Find ("GET" , "/folders/files/bolt.gif " )
99 if h == nil {
1010 t .Fatal ("handle not found" )
1111 }
1212}
1313
1414func TestRouterParam (t * testing.T ) {
1515 r := New ().Router
16- r .Add ("GET" , "/users/:name " , func (c * Context ) {})
17- h , c , _ := r .Find ("GET" , "/users/joe " )
16+ r .Add ("GET" , "/users/:id " , func (c * Context ) {})
17+ h , c , _ := r .Find ("GET" , "/users/1 " )
1818 if h == nil {
1919 t .Fatal ("handle not found" )
2020 }
21- p := c .Param ("name " )
22- if p != "joe " {
23- t .Errorf ("name should be equal to joe , found %s" , p )
21+ p := c .Param ("id " )
22+ if p != "1 " {
23+ t .Errorf ("id should be equal to 1 , found %s" , p )
2424 }
2525}
2626
@@ -53,3 +53,13 @@ func TestRouterMicroParam(t *testing.T) {
5353 t .Errorf ("p3 should be equal to c, found %s" , p3 )
5454 }
5555}
56+
57+ func TestPrintTree (t * testing.T ) {
58+ r := New ().Router
59+ r .Add ("GET" , "/users" , nil )
60+ r .Add ("GET" , "/users/:id" , nil )
61+ r .Add ("GET" , "/users/:id/books" , nil )
62+ r .Add ("GET" , "/users/:id/files" , nil )
63+ r .Add ("POST" , "/files" , nil )
64+ r .printTree ()
65+ }
0 commit comments