@@ -10,7 +10,98 @@ import (
10
10
"github.com/stretchr/testify/assert"
11
11
)
12
12
13
- func TestArgs (t * testing.T ) {
13
+ func TestArgsV3 (t * testing.T ) {
14
+ tests := []struct {
15
+ Args []string
16
+ ExpectedCalls []taskfile.Call
17
+ ExpectedGlobals * taskfile.Vars
18
+ }{
19
+ {
20
+ Args : []string {"task-a" , "task-b" , "task-c" },
21
+ ExpectedCalls : []taskfile.Call {
22
+ {Task : "task-a" },
23
+ {Task : "task-b" },
24
+ {Task : "task-c" },
25
+ },
26
+ },
27
+ {
28
+ Args : []string {"task-a" , "FOO=bar" , "task-b" , "task-c" , "BAR=baz" , "BAZ=foo" },
29
+ ExpectedCalls : []taskfile.Call {
30
+ {Task : "task-a" },
31
+ {Task : "task-b" },
32
+ {Task : "task-c" },
33
+ },
34
+ ExpectedGlobals : & taskfile.Vars {
35
+ Keys : []string {"FOO" , "BAR" , "BAZ" },
36
+ Mapping : map [string ]taskfile.Var {
37
+ "FOO" : taskfile.Var {Static : "bar" },
38
+ "BAR" : taskfile.Var {Static : "baz" },
39
+ "BAZ" : taskfile.Var {Static : "foo" },
40
+ },
41
+ },
42
+ },
43
+ {
44
+ Args : []string {"task-a" , "CONTENT=with some spaces" },
45
+ ExpectedCalls : []taskfile.Call {
46
+ {Task : "task-a" },
47
+ },
48
+ ExpectedGlobals : & taskfile.Vars {
49
+ Keys : []string {"CONTENT" },
50
+ Mapping : map [string ]taskfile.Var {
51
+ "CONTENT" : taskfile.Var {Static : "with some spaces" },
52
+ },
53
+ },
54
+ },
55
+ {
56
+ Args : []string {"FOO=bar" , "task-a" , "task-b" },
57
+ ExpectedCalls : []taskfile.Call {
58
+ {Task : "task-a" },
59
+ {Task : "task-b" },
60
+ },
61
+ ExpectedGlobals : & taskfile.Vars {
62
+ Keys : []string {"FOO" },
63
+ Mapping : map [string ]taskfile.Var {
64
+ "FOO" : {Static : "bar" },
65
+ },
66
+ },
67
+ },
68
+ {
69
+ Args : nil ,
70
+ ExpectedCalls : []taskfile.Call {
71
+ {Task : "default" },
72
+ },
73
+ },
74
+ {
75
+ Args : []string {},
76
+ ExpectedCalls : []taskfile.Call {
77
+ {Task : "default" },
78
+ },
79
+ },
80
+ {
81
+ Args : []string {"FOO=bar" , "BAR=baz" },
82
+ ExpectedCalls : []taskfile.Call {
83
+ {Task : "default" },
84
+ },
85
+ ExpectedGlobals : & taskfile.Vars {
86
+ Keys : []string {"FOO" , "BAR" },
87
+ Mapping : map [string ]taskfile.Var {
88
+ "FOO" : {Static : "bar" },
89
+ "BAR" : {Static : "baz" },
90
+ },
91
+ },
92
+ },
93
+ }
94
+
95
+ for i , test := range tests {
96
+ t .Run (fmt .Sprintf ("TestArgs%d" , i + 1 ), func (t * testing.T ) {
97
+ calls , globals := args .ParseV3 (test .Args ... )
98
+ assert .Equal (t , test .ExpectedCalls , calls )
99
+ assert .Equal (t , test .ExpectedGlobals , globals )
100
+ })
101
+ }
102
+ }
103
+
104
+ func TestArgsV2 (t * testing.T ) {
14
105
tests := []struct {
15
106
Args []string
16
107
ExpectedCalls []taskfile.Call
@@ -105,7 +196,7 @@ func TestArgs(t *testing.T) {
105
196
106
197
for i , test := range tests {
107
198
t .Run (fmt .Sprintf ("TestArgs%d" , i + 1 ), func (t * testing.T ) {
108
- calls , globals := args .Parse (test .Args ... )
199
+ calls , globals := args .ParseV2 (test .Args ... )
109
200
assert .Equal (t , test .ExpectedCalls , calls )
110
201
assert .Equal (t , test .ExpectedGlobals , globals )
111
202
})
0 commit comments