forked from aws/aws-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_stack_test.go
61 lines (53 loc) · 1.25 KB
/
parse_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
54
55
56
57
58
59
60
61
// +build go1.7
package ini
import (
"reflect"
"testing"
)
func newMockAST(v []rune) AST {
return newASTWithRootToken(ASTKindNone, Token{raw: v})
}
func TestStack(t *testing.T) {
cases := []struct {
asts []AST
expected []AST
}{
{
asts: []AST{
newMockAST([]rune("0")),
newMockAST([]rune("1")),
newMockAST([]rune("2")),
newMockAST([]rune("3")),
newMockAST([]rune("4")),
},
expected: []AST{
newMockAST([]rune("0")),
newMockAST([]rune("1")),
newMockAST([]rune("2")),
newMockAST([]rune("3")),
newMockAST([]rune("4")),
},
},
}
for _, c := range cases {
p := newParseStack(10, 10)
for _, ast := range c.asts {
p.Push(ast)
p.MarkComplete(ast)
}
if e, a := len(c.expected), p.Len(); e != a {
t.Errorf("expected the same legnth with %d, but received %d", e, a)
}
for i := len(c.expected) - 1; i >= 0; i-- {
if e, a := c.expected[i], p.Pop(); !reflect.DeepEqual(e, a) {
t.Errorf("stack element %d invalid: expected %v, but received %v", i, e, a)
}
}
if e, a := len(c.expected), p.index; e != a {
t.Errorf("expected %d, but received %d", e, a)
}
if e, a := c.asts, p.list[:p.index]; !reflect.DeepEqual(e, a) {
t.Errorf("expected %v, but received %v", e, a)
}
}
}