forked from extrame/goblet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router_test.go
56 lines (51 loc) · 1.88 KB
/
router_test.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package goblet
import (
"fmt"
"testing"
)
func TestAnchor(t *testing.T) {
anchor := &anchor{0, "/", "", []*anchor{}, &HtmlBlockOption{}}
anchor.add("/", &groupBlockOption{})
anchor.add("/stat/days", &groupBlockOption{})
anchor.add("/sc", &HtmlBlockOption{})
anchor.add("/sec", &HtmlBlockOption{BasicBlockOption{name: "right"}})
a, _ := anchor.match("/stat/days/2018-04-19.json", 3)
fmt.Printf("%T,%v\n", a.opt, a.opt)
b, _ := anchor.match("/sec", 4)
fmt.Printf("%T,%v\n", b.opt, b.opt)
}
func TestAnchorShort(t *testing.T) {
anchor := &anchor{0, "/", "", []*anchor{}, &HtmlBlockOption{}}
anchor.add("/", &_staticBlockOption{})
fmt.Println(anchor)
anchor.add("/seeed", &groupBlockOption{})
fmt.Println(anchor)
anchor.add("/sec", &HtmlBlockOption{BasicBlockOption{name: "right"}})
fmt.Println(anchor)
a, _ := anchor.match("/sec", 4)
fmt.Printf("%T,%v\n", a.opt, a.opt)
}
func TestAnchorShortAndSame(t *testing.T) {
anchor := &anchor{0, "/", "", []*anchor{}, &HtmlBlockOption{}}
anchor.add("/", &_staticBlockOption{})
fmt.Println(anchor)
anchor.add("/see", &HtmlBlockOption{BasicBlockOption{name: "right"}})
fmt.Println(anchor)
anchor.add("/seeed", &groupBlockOption{})
fmt.Println(anchor)
a, _ := anchor.match("/see", 4)
fmt.Printf("%T,%v\n", a.opt, a.opt)
}
func TestAnchorOfTwoRest(t *testing.T) {
anchor := &anchor{0, "/", "", []*anchor{}, &HtmlBlockOption{}}
anchor.add("/", &_staticBlockOption{})
anchor.add("/first", &RestBlockOption{BasicBlockOption{name: "first"}})
anchor.add("/first/second", &groupBlockOption{BasicBlockOption{name: "second"}, true})
anchor.add("/first/three", &RestBlockOption{BasicBlockOption{name: "three"}})
a, _ := anchor.match("/first/2/tag", 11)
fmt.Printf("%T,%v\n", a.opt, a.opt)
b, _ := anchor.match("/first/second/222", 17)
fmt.Printf("%T,%v\n", b.opt, b.opt)
c, _ := anchor.match("/first/three", 12)
fmt.Printf("%T,%v\n", c.opt, c.opt)
}