MCPcopy
hub / github.com/urfave/cli / TestFlagValue

Function TestFlagValue

flag_test.go:3040–3098  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3038}
3039
3040func TestFlagValue(t *testing.T) {
3041 t.SkipNow()
3042 cases := []*flagValueTestCase{
3043 {
3044 name: "stringSlice",
3045 flag: &StringSliceFlag{Name: "flag", Value: []string{"default1", "default2"}},
3046 toParse: []string{"--flag", "parsed,parsed2", "--flag", "parsed3,parsed4"},
3047 expect: `[parsed parsed2 parsed3 parsed4]`,
3048 },
3049 {
3050 name: "float64Slice",
3051 flag: &FloatSliceFlag{Name: "flag", Value: []float64{1.1, 2.2}},
3052 toParse: []string{"--flag", "13.3,14.4", "--flag", "15.5,16.6"},
3053 expect: `[]float64{13.3, 14.4, 15.5, 16.6}`,
3054 },
3055 {
3056 name: "intSlice",
3057 flag: &Int64SliceFlag{Name: "flag", Value: []int64{1, 2}},
3058 toParse: []string{"--flag", "13,14", "--flag", "15,16"},
3059 expect: `[]int64{13, 14, 15, 16}`,
3060 },
3061 {
3062 name: "uintSlice",
3063 flag: &Uint64SliceFlag{Name: "flag", Value: []uint64{1, 2}},
3064 toParse: []string{"--flag", "13,14", "--flag", "15,16"},
3065 expect: `[]uint64{13, 14, 15, 16}`,
3066 },
3067 {
3068 name: "stringMap",
3069 flag: &StringMapFlag{Name: "flag", Value: map[string]string{"default1": "default2"}},
3070 toParse: []string{"--flag", "parsed=parsed2", "--flag", "parsed3=parsed4"},
3071 expect: `map[parsed:parsed2 parsed3:parsed4]`,
3072 },
3073 {
3074 name: "int",
3075 flag: &IntFlag{Name: "flag", Value: 1},
3076 toParse: []string{"--flag", "42"},
3077 expect: `int(42)`,
3078 },
3079 {
3080 name: "uint",
3081 flag: &UintFlag{Name: "flag", Value: 1},
3082 toParse: []string{"--flag", "42"},
3083 expect: `uint(42)`,
3084 },
3085 }
3086 for _, v := range cases {
3087 t.Run(v.name, func(t *testing.T) {
3088 cmd := &Command{
3089 Flags: []Flag{
3090 v.flag,
3091 },
3092 }
3093 assert.NoError(t, cmd.Run(buildTestContext(t), append([]string{""}, v.toParse...)))
3094 f := cmd.lookupFlag("flag")
3095 require.Equal(t, v.expect, f.String())
3096 })
3097 }

Callers

nothing calls this directly

Calls 4

RunMethod · 0.95
lookupFlagMethod · 0.95
buildTestContextFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected