forked from alecthomas/kingpin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer_test.go
39 lines (36 loc) · 1.05 KB
/
lexer_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
package kingpin
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestLexer(t *testing.T) {
tokens := Tokenize([]string{"-abc", "foo", "--foo=bar", "--bar", "foo", "--", "-123"}).Tokens
assert.Equal(t, 9, len(tokens))
tok := tokens.Peek()
assert.Equal(t, &Token{TokenShort, "a"}, tok)
tokens = tokens.Next()
tok = tokens.Peek()
assert.Equal(t, &Token{TokenShort, "b"}, tok)
tokens = tokens.Next()
tok = tokens.Peek()
assert.Equal(t, &Token{TokenShort, "c"}, tok)
tokens = tokens.Next()
tok = tokens.Peek()
assert.Equal(t, &Token{TokenArg, "foo"}, tok)
tokens = tokens.Next()
tok = tokens.Peek()
assert.Equal(t, &Token{TokenLong, "foo"}, tok)
tokens = tokens.Next()
tok = tokens.Peek()
assert.Equal(t, &Token{TokenArg, "bar"}, tok)
tokens = tokens.Next()
tok = tokens.Peek()
assert.Equal(t, &Token{TokenLong, "bar"}, tok)
tokens = tokens.Next()
tok = tokens.Peek()
assert.Equal(t, &Token{TokenArg, "foo"}, tok)
tokens = tokens.Next()
tok = tokens.Peek()
assert.Equal(t, &Token{TokenArg, "-123"}, tok)
tokens = tokens.Next()
}