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

Function TestSSWithComma

string_slice_test.go:178–215  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

176}
177
178func TestSSWithComma(t *testing.T) {
179 var ss []string
180 f := setUpSSFlagSet(&ss)
181
182 in := []string{`"one,two"`, `"three"`, `"four,five",six`}
183 expected := []string{"one,two", "three", "four,five", "six"}
184 argfmt := "--ss=%s"
185 arg1 := fmt.Sprintf(argfmt, in[0])
186 arg2 := fmt.Sprintf(argfmt, in[1])
187 arg3 := fmt.Sprintf(argfmt, in[2])
188 err := f.Parse([]string{arg1, arg2, arg3})
189 if err != nil {
190 t.Fatal("expected no error; got", err)
191 }
192
193 if len(expected) != len(ss) {
194 t.Fatalf("expected number of ss to be %d but got: %d", len(expected), len(ss))
195 }
196 for i, v := range ss {
197 if expected[i] != v {
198 t.Fatalf("expected ss[%d] to be %s but got: %s", i, expected[i], v)
199 }
200 }
201
202 values, err := f.GetStringSlice("ss")
203 if err != nil {
204 t.Fatal("expected no error; got", err)
205 }
206
207 if len(expected) != len(values) {
208 t.Fatalf("expected number of values to be %d but got: %d", len(expected), len(values))
209 }
210 for i, v := range values {
211 if expected[i] != v {
212 t.Fatalf("expected got ss[%d] to be %s but got: %s", i, expected[i], v)
213 }
214 }
215}
216
217func TestSSWithSquareBrackets(t *testing.T) {
218 var ss []string

Callers

nothing calls this directly

Calls 3

setUpSSFlagSetFunction · 0.85
GetStringSliceMethod · 0.80
ParseMethod · 0.65

Tested by

no test coverage detected