-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflags_test.go
More file actions
44 lines (41 loc) · 785 Bytes
/
flags_test.go
File metadata and controls
44 lines (41 loc) · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package cli
import (
"github.com/stretchr/testify/require"
"reflect"
"testing"
)
func Test_ParseFlagValue(t *testing.T) {
cases := []struct {
Flag Flag
SetTo string
Expected any
}{
{
Flag: BoolFlag{},
SetTo: "false",
Expected: false,
},
{
Flag: StringFlag{Default: "default"},
SetTo: "new",
Expected: "new",
},
{
Flag: IntFlag{Default: 10},
SetTo: "22",
Expected: 22,
},
{
Flag: Float32Flag{Default: 1.0},
SetTo: "1.35",
Expected: float32(1.35),
},
}
for _, c := range cases {
f := c.Flag
require.Equal(t, reflect.ValueOf(f).FieldByName("Default").Interface(), f.Value())
f, err := f.WithValue(c.SetTo)
require.NoError(t, err)
require.Equal(t, c.Expected, f.Value())
}
}