-
Notifications
You must be signed in to change notification settings - Fork 0
/
router_test.go
75 lines (62 loc) · 1.37 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package giorouter
import "testing"
const (
initialRoute = "home"
gotoRoute = "test"
dummyRoute = "dummy"
)
func newRouter() *Router {
r := NewRouter(nil)
r.SetRoutes(Routes{
gotoRoute: nil,
initialRoute: nil,
}, initialRoute)
go func() {
for range r.C {
}
}()
return r
}
func TestInitialRoute(t *testing.T) {
r := newRouter()
if r.Top() != initialRoute {
t.Errorf("Invalid current route, expected %s got %s", initialRoute, r.Top())
}
}
func TestPushRoute(t *testing.T) {
r := newRouter()
r.Push(gotoRoute)
top := r.Top()
if top != gotoRoute {
t.Errorf("Invalid top route, expected %s got %s", gotoRoute, top)
}
}
func TestPopRoute(t *testing.T) {
r := newRouter()
if len(r.Stack) != 1 {
t.Errorf("Invalid stack's length, expected %d got %d", 1, len(r.Stack))
}
pop := r.Pop()
if pop != "" {
t.Errorf("Invalid pop, expected %s got %s", "''", pop)
}
if len(r.Stack) != 1 {
t.Errorf("Invalid stack's length, expected %d got %d", 1, len(r.Stack))
}
r.Push(gotoRoute)
if len(r.Stack) != 2 {
t.Errorf("Invalid stack's length, expected %d got %d", 2, len(r.Stack))
}
pop = r.Pop()
if pop == "" {
t.Errorf("Invalid pop, expected %s got %s", "'something'", pop)
}
}
func TestStackEmpty(t *testing.T) {
r := newRouter()
r.Stack = r.Stack[:0]
top := r.Top()
if top != "" {
t.Errorf("Invalid top, expected %s got %s", "''", top)
}
}