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

Function TestSAWithSquareBrackets

string_array_test.go:219–256  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

setUpSAFlagSetFunction · 0.85
GetStringArrayMethod · 0.80
ParseMethod · 0.65

Tested by

no test coverage detected