-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstack_test.go
53 lines (43 loc) · 1 KB
/
stack_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
package layer
import (
"github.com/nbio/st"
"testing"
)
func TestStack(t *testing.T) {
s := &Stack{}
first := MiddlewareFunc(nil)
head := MiddlewareFunc(nil)
tail := MiddlewareFunc(nil)
s.Push(Normal, first)
st.Expect(t, s.Len(), 1)
s.Push(Head, head)
st.Expect(t, s.Len(), 2)
s.Push(Tail, tail)
st.Expect(t, s.Len(), 3)
st.Expect(t, s.Join()[0], head)
st.Expect(t, s.Join()[1], first)
st.Expect(t, s.Join()[2], tail)
}
func TestStackMemoization(t *testing.T) {
s := &Stack{}
first := MiddlewareFunc(nil)
head := MiddlewareFunc(nil)
tail := MiddlewareFunc(nil)
s.Push(Normal, first)
st.Expect(t, s.Len(), 1)
s.Push(Head, head)
st.Expect(t, s.Len(), 2)
s.Push(Tail, tail)
st.Expect(t, s.Len(), 3)
memo := s.Join()
st.Expect(t, memo[0], head)
st.Expect(t, memo[1], first)
st.Expect(t, memo[2], tail)
st.Expect(t, s.memo, memo)
s.Push(Tail, tail)
st.Expect(t, s.Len(), 4)
st.Expect(t, len(s.memo), 0)
newMemo := s.Join()
st.Expect(t, s.memo, newMemo)
st.Expect(t, s.memo, s.Join())
}