File: parse_stack_test.go

package info (click to toggle)
golang-github-aws-aws-sdk-go 1.16.18%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, buster-backports, experimental
  • size: 93,084 kB
  • sloc: ruby: 193; makefile: 174; xml: 11
file content (61 lines) | stat: -rw-r--r-- 1,278 bytes parent folder | download | duplicates (2)
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)
		}
	}
}