-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree_test.go
More file actions
36 lines (32 loc) · 769 Bytes
/
Copy pathtree_test.go
File metadata and controls
36 lines (32 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package flex
import (
"fmt"
"testing"
)
func log(h HandlerFunc) HandlerFunc {
return func(ctx *Context) error {
fmt.Println("log middleware before...")
err := h(ctx)
fmt.Println("log middleware after...")
return err
}
}
func hello(ctx *Context) error {
fmt.Println("hello handler...")
return nil
}
func TestTreeInsert(t *testing.T) {
tree := newTree()
tree.insert("/post/{id:\\d+}/hello", hello)
t.Log(tree)
}
func TestTreeFind(t *testing.T) {
tree := newTree()
tree.insert("/post/{id:\\w+}/hello", hello)
tree.insert("/post/{id:\\w+}/comment", hello)
tree.insert("/article/{id:\\d+}", hello)
n := tree.find("/post/abc/hello")
t.Log(string(n.params["id"]) == "abc")
n2 := tree.find("/article/123")
t.Log(string(n2.params["id"]) == "123")
}