MCPcopy
hub / github.com/spf13/pflag / TestDSAsSliceValue

Function TestDSAsSliceValue

duration_slice_test.go:147–168  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

145}
146
147func TestDSAsSliceValue(t *testing.T) {
148 var ds []time.Duration
149 f := setUpDSFlagSet(&ds)
150
151 in := []string{"1ns", "2ns"}
152 argfmt := "--ds=%s"
153 arg1 := fmt.Sprintf(argfmt, in[0])
154 arg2 := fmt.Sprintf(argfmt, in[1])
155 err := f.Parse([]string{arg1, arg2})
156 if err != nil {
157 t.Fatal("expected no error; got", err)
158 }
159
160 f.VisitAll(func(f *Flag) {
161 if val, ok := f.Value.(SliceValue); ok {
162 _ = val.Replace([]string{"3ns"})
163 }
164 })
165 if len(ds) != 1 || ds[0] != time.Duration(3) {
166 t.Fatalf("Expected ss to be overwritten with '3ns', but got: %v", ds)
167 }
168}
169
170func TestDSCalledTwice(t *testing.T) {
171 var ds []time.Duration

Callers

nothing calls this directly

Calls 5

setUpDSFlagSetFunction · 0.85
VisitAllMethod · 0.80
DurationMethod · 0.80
ParseMethod · 0.65
ReplaceMethod · 0.65

Tested by

no test coverage detected