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

Function TestSSWithSquareBrackets

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

Source from the content-addressed store, hash-verified

215}
216
217func TestSSWithSquareBrackets(t *testing.T) {
218 var ss []string
219 f := setUpSSFlagSet(&ss)
220
221 in := []string{`"[a-z]"`, `"[a-z]+"`}
222 expected := []string{"[a-z]", "[a-z]+"}
223 argfmt := "--ss=%s"
224 arg1 := fmt.Sprintf(argfmt, in[0])
225 arg2 := fmt.Sprintf(argfmt, in[1])
226 err := f.Parse([]string{arg1, arg2})
227 if err != nil {
228 t.Fatal("expected no error; got", err)
229 }
230
231 if len(expected) != len(ss) {
232 t.Fatalf("expected number of ss to be %d but got: %d", len(expected), len(ss))
233 }
234 for i, v := range ss {
235 if expected[i] != v {
236 t.Fatalf("expected ss[%d] to be %s but got: %s", i, expected[i], v)
237 }
238 }
239
240 values, err := f.GetStringSlice("ss")
241 if err != nil {
242 t.Fatal("expected no error; got", err)
243 }
244
245 if len(expected) != len(values) {
246 t.Fatalf("expected number of values to be %d but got: %d", len(expected), len(values))
247 }
248 for i, v := range values {
249 if expected[i] != v {
250 t.Fatalf("expected got ss[%d] to be %s but got: %s", i, expected[i], v)
251 }
252 }
253}
254
255func TestSSAsSliceValue(t *testing.T) {
256 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