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

Function TestSACalledTwice

string_array_test.go:118–154  ·  string_array_test.go::TestSACalledTwice
(t *testing.T)

Source from the content-addressed store, hash-verified

116}
117
118func TestSACalledTwice(t *testing.T) {
119 var sa []string
120 f := setUpSAFlagSet(&sa)
121
122 in := []string{"one", "two"}
123 expected := []string{"one", "two"}
124 argfmt := "--sa=%s"
125 arg1 := fmt.Sprintf(argfmt, in[0])
126 arg2 := fmt.Sprintf(argfmt, in[1])
127 err := f.Parse([]string{arg1, arg2})
128 if err != nil {
129 t.Fatal("expected no error; got", err)
130 }
131
132 if len(expected) != len(sa) {
133 t.Fatalf("expected number of sa to be %d but got: %d", len(expected), len(sa))
134 }
135 for i, v := range sa {
136 if expected[i] != v {
137 t.Fatalf("expected sa[%d] to be %s but got: %s", i, expected[i], v)
138 }
139 }
140
141 values, err := f.GetStringArray("sa")
142 if err != nil {
143 t.Fatal("expected no error; got", err)
144 }
145
146 if len(expected) != len(values) {
147 t.Fatalf("expected number of values to be %d but got: %d", len(expected), len(sa))
148 }
149 for i, v := range values {
150 if expected[i] != v {
151 t.Fatalf("expected got sa[%d] to be %s but got: %s", i, expected[i], v)
152 }
153 }
154}
155
156func TestSAWithSpecialChar(t *testing.T) {
157 var sa []string

Callers

nothing calls this directly

Calls 3

setUpSAFlagSetFunction · 0.85
GetStringArrayMethod · 0.80
ParseMethod · 0.65

Tested by

no test coverage detected