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

Function TestS2I

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

Source from the content-addressed store, hash-verified

56}
57
58func TestS2I(t *testing.T) {
59 var s2i map[string]int
60 f := setUpS2IFlagSet(&s2i)
61
62 vals := map[string]int{"a": 1, "b": 2, "d": 4, "c": 3}
63 arg := fmt.Sprintf("--s2i=%s", createS2IFlag(vals))
64 err := f.Parse([]string{arg})
65 if err != nil {
66 t.Fatal("expected no error; got", err)
67 }
68 for k, v := range s2i {
69 if vals[k] != v {
70 t.Fatalf("expected s2i[%s] to be %d but got: %d", k, vals[k], v)
71 }
72 }
73 getS2I, err := f.GetStringToInt("s2i")
74 if err != nil {
75 t.Fatalf("got error: %v", err)
76 }
77 for k, v := range getS2I {
78 if vals[k] != v {
79 t.Fatalf("expected s2i[%s] to be %d but got: %d from GetStringToInt", k, vals[k], v)
80 }
81 }
82}
83
84func TestS2IDefault(t *testing.T) {
85 var s2i map[string]int

Callers

nothing calls this directly

Calls 4

setUpS2IFlagSetFunction · 0.85
createS2IFlagFunction · 0.85
GetStringToIntMethod · 0.80
ParseMethod · 0.65

Tested by

no test coverage detected