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

Function TestS2IWithDefault

string_to_int_test.go:111–136  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

109}
110
111func TestS2IWithDefault(t *testing.T) {
112 var s2i map[string]int
113 f := setUpS2IFlagSetWithDefault(&s2i)
114
115 vals := map[string]int{"a": 1, "b": 2}
116 arg := fmt.Sprintf("--s2i=%s", createS2IFlag(vals))
117 err := f.Parse([]string{arg})
118 if err != nil {
119 t.Fatal("expected no error; got", err)
120 }
121 for k, v := range s2i {
122 if vals[k] != v {
123 t.Fatalf("expected s2i[%s] to be %d but got: %d", k, vals[k], v)
124 }
125 }
126
127 getS2I, err := f.GetStringToInt("s2i")
128 if err != nil {
129 t.Fatal("got an error from GetStringToInt():", err)
130 }
131 for k, v := range getS2I {
132 if vals[k] != v {
133 t.Fatalf("expected s2i[%s] to be %d from GetStringToInt but got: %d", k, vals[k], v)
134 }
135 }
136}
137
138func TestS2ICalledTwice(t *testing.T) {
139 var s2i map[string]int

Callers

nothing calls this directly

Calls 4

createS2IFlagFunction · 0.85
GetStringToIntMethod · 0.80
ParseMethod · 0.65

Tested by

no test coverage detected