-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_test.go
54 lines (51 loc) 路 1.45 KB
/
parse_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
package clo
import (
"github.com/boggydigital/testo"
"strconv"
"testing"
)
func TestDefinitionsParse(t *testing.T) {
tests := []struct {
args []string
expCmd string
expLastArg string
expLenArgs int
expErr bool
}{
{[]string{"", "command1", "--argument1"}, "command1", "argument1", 1, false},
{[]string{"--argument1"}, "command1", "argument1", 1, false},
{[]string{"unknown-token"}, "command1", "argument1", 1, false},
}
for ii, tt := range tests {
t.Run(strconv.Itoa(ii), func(t *testing.T) {
defs := mockDefinitions()
req, err := defs.parseRequest(tt.args)
testo.Error(t, err, tt.expErr)
testo.EqualValues(t, req.Command, tt.expCmd)
testo.EqualValues(t, req.lastArgument, tt.expLastArg)
testo.EqualValues(t, len(req.Arguments), tt.expLenArgs)
})
}
}
func TestDefinitionsNoDefaultsParse(t *testing.T) {
tests := []struct {
args []string
expCmd string
expLastArg string
expLenArgs int
expErr bool
}{
{[]string{"command2"}, "", "", 0, true},
{[]string{"command1", "argument1", "value-that-doesnt-exist"}, "command1", "", 0, true},
}
for ii, tt := range tests {
t.Run(strconv.Itoa(ii), func(t *testing.T) {
defs := mockDefinitionsNoDefaults()
req, err := defs.parseRequest(tt.args)
testo.Error(t, err, tt.expErr)
testo.EqualValues(t, req.Command, tt.expCmd)
testo.EqualValues(t, req.lastArgument, tt.expLastArg)
testo.EqualValues(t, len(req.Arguments), tt.expLenArgs)
})
}
}