Skip to content

Commit

Permalink
feat: update unit tets
Browse files Browse the repository at this point in the history
  • Loading branch information
FGYFFFF committed Oct 27, 2022
1 parent c5da5f6 commit ad7dfde
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3387,27 +3387,18 @@ func TestSliceShortOptionHandle(t *testing.T) {

// Test issue #1541
func TestCustomizedSliceFlagSeparator(t *testing.T) {
defaultSliceFlagSeparator = ";"
defer func() {
defaultSliceFlagSeparator = ","
}()
opts := []string{"opt1", "opt2", "opt3,op", "opt4"}
// set args for examples sake
os.Args = []string{"multi_values",
"--stringSlice=" + strings.Join(opts, ";"),
}
app := NewApp()
app.Name = "multi_values"
app.Flags = []Flag{
&StringSliceFlag{Name: "stringSlice"},
}
app.SliceFlagSeparator = ";"
app.Action = func(ctx *Context) error {
ret := ctx.StringSlice("stringSlice")
for idx, r := range ret {
if r != opts[idx] {
t.Fatalf("get %dth failed, wanted: %s, but get: %s", idx, opts[idx], r)
}
ret := flagSplitMultiValues(strings.Join(opts, ";"))
if len(ret) != 4 {
t.Fatalf("split slice flag failed, want: 4, but get: %d", len(ret))
}
for idx, r := range ret {
if r != opts[idx] {
t.Fatalf("get %dth failed, wanted: %s, but get: %s", idx, opts[idx], r)
}
return nil
}

_ = app.Run(os.Args)
defaultSliceFlagSeparator = ","
}
}

0 comments on commit ad7dfde

Please sign in to comment.