Skip to content

Commit

Permalink
Revert some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dearchap committed Jun 26, 2023
1 parent 26f3cb3 commit 2bf504c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 73 deletions.
79 changes: 11 additions & 68 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1253,41 +1253,11 @@ func TestCommand_ParseSliceFlags(t *testing.T) {
},
}

_ = cmd.Run(buildTestContext(t), []string{"", "cmd", "-p", "22", "-p", "80", "-ip", "8.8.8.8", "-ip", "8.8.4.4"})

IntsEquals := func(a, b []int64) bool {
if len(a) != len(b) {
return false
}
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}

StrsEquals := func(a, b []string) bool {
if len(a) != len(b) {
return false
}
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}
expectedIntSlice := []int64{22, 80}
expectedStringSlice := []string{"8.8.8.8", "8.8.4.4"}

if !IntsEquals(parsedIntSlice, expectedIntSlice) {
t.Errorf("%v does not match %v", parsedIntSlice, expectedIntSlice)
}
r := require.New(t)

if !StrsEquals(parsedStringSlice, expectedStringSlice) {
t.Errorf("%v does not match %v", parsedStringSlice, expectedStringSlice)
}
r.NoError(cmd.Run(buildTestContext(t), []string{"", "cmd", "-p", "22", "-p", "80", "-ip", "8.8.8.8", "-ip", "8.8.4.4"}))
r.Equal([]int64{22, 80}, parsedIntSlice)
r.Equal([]string{"8.8.8.8", "8.8.4.4"}, parsedStringSlice)
}

func TestCommand_ParseSliceFlagsWithMissingValue(t *testing.T) {
Expand All @@ -1311,18 +1281,11 @@ func TestCommand_ParseSliceFlagsWithMissingValue(t *testing.T) {
},
}

_ = cmd.Run(buildTestContext(t), []string{"", "cmd", "-a", "2", "-str", "A"})

expectedIntSlice := []int64{2}
expectedStringSlice := []string{"A"}

if parsedIntSlice[0] != expectedIntSlice[0] {
t.Errorf("%v does not match %v", parsedIntSlice[0], expectedIntSlice[0])
}
r := require.New(t)

if parsedStringSlice[0] != expectedStringSlice[0] {
t.Errorf("%v does not match %v", parsedIntSlice[0], expectedIntSlice[0])
}
r.NoError(cmd.Run(buildTestContext(t), []string{"", "cmd", "-a", "2", "-str", "A"}))
r.Equal([]int64{2}, parsedIntSlice)
r.Equal([]string{"A"}, parsedStringSlice)
}

func TestCommand_DefaultStdin(t *testing.T) {
Expand Down Expand Up @@ -2776,16 +2739,6 @@ func TestFlagAction(t *testing.T) {
{
name: "flag_uint_error",
args: []string{"app", "--f_uint=0"},
err: "zero uint",
},
{
name: "flag_uint64",
args: []string{"app", "--f_uint64=1"},
exp: "1 ",
},
{
name: "flag_uint64_error",
args: []string{"app", "--f_uint64=0"},
err: "zero uint64",
},
{
Expand Down Expand Up @@ -2940,18 +2893,8 @@ func TestFlagAction(t *testing.T) {
return err
},
},
&UintFlag{
Name: "f_uint",
Action: func(cCtx *Context, v uint) error {
if v == 0 {
return fmt.Errorf("zero uint")
}
_, err := cCtx.Command.Root().Writer.Write([]byte(fmt.Sprintf("%v ", v)))
return err
},
},
&Uint64Flag{
Name: "f_uint64",
Name: "f_uint",
Action: func(cCtx *Context, v uint64) error {
if v == 0 {
return fmt.Errorf("zero uint64")
Expand Down Expand Up @@ -3156,10 +3099,10 @@ func TestFlagDuplicates(t *testing.T) {
name: "all args present once",
args: []string{"foo", "--sflag", "hello", "--isflag", "1", "--isflag", "2", "--fsflag", "2.0", "--iflag", "10"},
},
/*{
{
name: "duplicate non slice flag(duplicatable)",
args: []string{"foo", "--sflag", "hello", "--isflag", "1", "--isflag", "2", "--fsflag", "2.0", "--iflag", "10", "--iflag", "20"},
},*/
},
{
name: "duplicate non slice flag(non duplicatable)",
args: []string{"foo", "--sflag", "hello", "--isflag", "1", "--isflag", "2", "--fsflag", "2.0", "--iflag", "10", "--sflag", "trip"},
Expand Down
5 changes: 2 additions & 3 deletions flag_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ func (f fnValue) Serialize() string {
return f.v.String()
}

func (f fnValue) IsBoolFlag() bool { return f.isBool }
func (f fnValue) GetFlagValue() Value { return f.v }
func (f fnValue) Count() int { return *f.count }
func (f fnValue) IsBoolFlag() bool { return f.isBool }
func (f fnValue) Count() int { return *f.count }

// ValueCreator is responsible for creating a flag.Value emulation
// as well as custom formatting
Expand Down
4 changes: 2 additions & 2 deletions flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ func TestIntSliceFlagApply_UsesEnvValues_noDefault(t *testing.T) {
r := require.New(t)
r.NoError(fl.Apply(set))
r.NoError(set.Parse(nil))
//r.Equal([]int64{1, 2}, fl.value.(flag.Getter).Get())
r.Equal([]int64{1, 2}, fl.value.(flag.Getter).Get())
}

func TestIntSliceFlagApply_UsesEnvValues_withDefault(t *testing.T) {
Expand All @@ -1164,7 +1164,7 @@ func TestIntSliceFlagApply_UsesEnvValues_withDefault(t *testing.T) {
r.NoError(fl.Apply(set))
r.NoError(set.Parse(nil))
r.Equal([]int64{3, 4}, val)
//r.Equal([]int64{1, 2}, fl.value.(flag.Getter).Get())
r.Equal([]int64{1, 2}, fl.value.(flag.Getter).Get())
}

func TestIntSliceFlagApply_DefaultValueWithDestination(t *testing.T) {
Expand Down

0 comments on commit 2bf504c

Please sign in to comment.