@@ -4,23 +4,23 @@ import "testing"
4
4
5
5
func TestRouterStatic (t * testing.T ) {
6
6
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 " )
9
9
if h == nil {
10
10
t .Fatal ("handle not found" )
11
11
}
12
12
}
13
13
14
14
func TestRouterParam (t * testing.T ) {
15
15
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 " )
18
18
if h == nil {
19
19
t .Fatal ("handle not found" )
20
20
}
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 )
24
24
}
25
25
}
26
26
@@ -53,3 +53,13 @@ func TestRouterMicroParam(t *testing.T) {
53
53
t .Errorf ("p3 should be equal to c, found %s" , p3 )
54
54
}
55
55
}
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