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

Function TestS2I64WithDefault

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

Source from the content-addressed store, hash-verified

109}
110
111func TestS2I64WithDefault(t *testing.T) {
112 var s2i map[string]int64
113 f := setUpS2I64FlagSetWithDefault(&s2i)
114
115 vals := map[string]int64{"a": 1, "b": 2}
116 arg := fmt.Sprintf("--s2i=%s", createS2I64Flag(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.GetStringToInt64("s2i")
128 if err != nil {
129 t.Fatal("got an error from GetStringToInt64():", err)
130 }
131 for k, v := range getS2I {
132 if vals[k] != v {
133 t.Fatalf("expected s2i[%s] to be %d from GetStringToInt64 but got: %d", k, vals[k], v)
134 }
135 }
136}
137
138func TestS2I64CalledTwice(t *testing.T) {
139 var s2i map[string]int64

Callers

nothing calls this directly

Calls 4

createS2I64FlagFunction · 0.85
GetStringToInt64Method · 0.80
ParseMethod · 0.65

Tested by

no test coverage detected