File: parser_test.go

package info (click to toggle)
golang-gopkg-alecthomas-kingpin.v3 3.0~git20180227.b8d601d-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 420 kB
  • sloc: makefile: 6
file content (47 lines) | stat: -rw-r--r-- 904 bytes parent folder | download
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
package kingpin

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func cmdElem() *ParseElement {
	return &ParseElement{
		OneOf: OneOfClause{
			Cmd: &CmdClause{},
		},
	}
}

func TestParseContextPush(t *testing.T) {
	c := tokenize([]string{"foo", "bar"}, false, nil)
	a := c.Next()
	assert.Equal(t, TokenArg, a.Type)
	b := c.Next()
	assert.Equal(t, TokenArg, b.Type)
	c.Push(b)
	c.Push(a)
	a = c.Next()
	assert.Equal(t, "foo", a.Value)
	b = c.Next()
	assert.Equal(t, "bar", b.Value)
}

func TestLastCmd(t *testing.T) {
	e := cmdElem()
	pc := &ParseContext{
		Elements: []*ParseElement{e, cmdElem(), cmdElem()},
	}
	assert.Equal(t, false, pc.LastCmd(e))

	pc = &ParseContext{
		Elements: []*ParseElement{cmdElem(), e, cmdElem()},
	}
	assert.Equal(t, false, pc.LastCmd(e))

	pc = &ParseContext{
		Elements: []*ParseElement{cmdElem(), cmdElem(), e},
	}
	assert.Equal(t, true, pc.LastCmd(e))
}