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

Function TestI32SDefault

int32_slice_test.go:79–114  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

77}
78
79func TestI32SDefault(t *testing.T) {
80 var is []int32
81 f := setUpI32SFlagSetWithDefault(&is)
82
83 vals := []string{"0", "1"}
84
85 err := f.Parse([]string{})
86 if err != nil {
87 t.Fatal("expected no error; got", err)
88 }
89 for i, v := range is {
90 d64, err := strconv.ParseInt(vals[i], 0, 32)
91 if err != nil {
92 t.Fatalf("got error: %v", err)
93 }
94 d := int32(d64)
95 if d != v {
96 t.Fatalf("expected is[%d] to be %d but got: %d", i, d, v)
97 }
98 }
99
100 getI32S, err := f.GetInt32Slice("is")
101 if err != nil {
102 t.Fatal("got an error from GetInt32Slice():", err)
103 }
104 for i, v := range getI32S {
105 d64, err := strconv.ParseInt(vals[i], 0, 32)
106 if err != nil {
107 t.Fatal("got an error from GetInt32Slice():", err)
108 }
109 d := int32(d64)
110 if d != v {
111 t.Fatalf("expected is[%d] to be %d from GetInt32Slice but got: %d", i, d, v)
112 }
113 }
114}
115
116func TestI32SWithDefault(t *testing.T) {
117 var is []int32

Callers

nothing calls this directly

Calls 3

GetInt32SliceMethod · 0.80
ParseMethod · 0.65

Tested by

no test coverage detected