-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: improves coverage for command line argument parser.
- Loading branch information
1 parent
99985c7
commit c9640f1
Showing
2 changed files
with
58 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package jvm | ||
|
||
import "testing" | ||
|
||
func Test_readArg(t *testing.T) { | ||
type args struct { | ||
cmdline []string | ||
longArg string | ||
shortArg string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
}{ | ||
{ | ||
name: "combined form", | ||
args: args{ | ||
cmdline: []string{"--arg=VAL"}, | ||
longArg: "arg", | ||
shortArg: "a", | ||
}, | ||
want: "VAL", | ||
}, | ||
{ | ||
name: "separate form", | ||
args: args{ | ||
cmdline: []string{"--arg", "VAL"}, | ||
longArg: "arg", | ||
shortArg: "a", | ||
}, | ||
want: "VAL", | ||
}, | ||
{ | ||
name: "separate form with short arg", | ||
args: args{ | ||
cmdline: []string{"-a", "VAL"}, | ||
longArg: "arg", | ||
shortArg: "a", | ||
}, | ||
want: "VAL", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := readArg(tt.args.cmdline, tt.args.longArg, tt.args.shortArg); got != tt.want { | ||
t.Errorf("readArg() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |