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

Function TestS2IDefault

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

Source from the content-addressed store, hash-verified

82}
83
84func TestS2IDefault(t *testing.T) {
85 var s2i map[string]int
86 f := setUpS2IFlagSetWithDefault(&s2i)
87
88 vals := map[string]int{"a": 1, "b": 2}
89
90 err := f.Parse([]string{})
91 if err != nil {
92 t.Fatal("expected no error; got", err)
93 }
94 for k, v := range s2i {
95 if vals[k] != v {
96 t.Fatalf("expected s2i[%s] to be %d but got: %d", k, vals[k], v)
97 }
98 }
99
100 getS2I, err := f.GetStringToInt("s2i")
101 if err != nil {
102 t.Fatal("got an error from GetStringToInt():", err)
103 }
104 for k, v := range getS2I {
105 if vals[k] != v {
106 t.Fatalf("expected s2i[%s] to be %d from GetStringToInt but got: %d", k, vals[k], v)
107 }
108 }
109}
110
111func TestS2IWithDefault(t *testing.T) {
112 var s2i map[string]int

Callers

nothing calls this directly

Calls 3

GetStringToIntMethod · 0.80
ParseMethod · 0.65

Tested by

no test coverage detected