@@ -226,24 +226,43 @@ func TestGetEnv(t *testing.T) {
226
226
func TestProcessWithMatches (t * testing.T ) {
227
227
shlex := NewLex ('\\' )
228
228
229
- w , matches , err := shlex .ProcessWordWithMatches ("foo ${BAR} ${UNUSED}" , map [string ]string {
230
- "ANOTHER" : "bar" ,
231
- "BAR" : "baz" ,
232
- })
233
- require .NoError (t , err )
234
- require .Equal (t , "foo baz " , w )
235
-
236
- require .Equal (t , 1 , len (matches ))
237
- _ , ok := matches ["BAR" ]
238
- require .True (t , ok )
229
+ tc := []struct {
230
+ input string
231
+ envs map [string ]string
232
+ expected string
233
+ expectedErr bool
234
+ matches map [string ]struct {}
235
+ }{
236
+ {
237
+ input : "foo ${BAR} ${UNUSED}" ,
238
+ envs : map [string ]string {"ANOTHER" : "bar" , "BAR" : "baz" },
239
+ expected : "foo baz " ,
240
+ matches : map [string ]struct {}{"BAR" : {}},
241
+ },
242
+ {
243
+ input : "foo ${BAR:-abc} ${UNUSED}" ,
244
+ envs : map [string ]string {"ANOTHER" : "bar" },
245
+ expected : "foo abc " ,
246
+ matches : map [string ]struct {}{},
247
+ },
248
+ }
239
249
240
- w , matches , err = shlex .ProcessWordWithMatches ("foo ${BAR:-abc} ${UNUSED}" , map [string ]string {
241
- "ANOTHER" : "bar" ,
242
- })
243
- require .NoError (t , err )
244
- require .Equal (t , "foo abc " , w )
250
+ for _ , c := range tc {
251
+ c := c
252
+ t .Run (c .input , func (t * testing.T ) {
253
+ w , matches , err := shlex .ProcessWordWithMatches (c .input , c .envs )
254
+ if c .expectedErr {
255
+ require .Error (t , err )
256
+ return
257
+ }
258
+ require .NoError (t , err )
259
+ require .Equal (t , c .expected , w )
245
260
246
- require .Equal (t , 0 , len (matches ))
261
+ require .Equal (t , len (c .matches ), len (matches ))
262
+ for k := range c .matches {
263
+ require .Contains (t , matches , k )
264
+ }
265
+ }
247
266
}
248
267
249
268
func TestProcessWithMatchesPlatform (t * testing.T ) {
0 commit comments