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

Function TestI32S

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

Source from the content-addressed store, hash-verified

41}
42
43func TestI32S(t *testing.T) {
44 var is []int32
45 f := setUpI32SFlagSet(&is)
46
47 vals := []string{"1", "2", "4", "3"}
48 arg := fmt.Sprintf("--is=%s", strings.Join(vals, ","))
49 err := f.Parse([]string{arg})
50 if err != nil {
51 t.Fatal("expected no error; got", err)
52 }
53 for i, v := range is {
54 d64, err := strconv.ParseInt(vals[i], 0, 32)
55 if err != nil {
56 t.Fatalf("got error: %v", err)
57 }
58 d := int32(d64)
59 if d != v {
60 t.Fatalf("expected is[%d] to be %s but got: %d", i, vals[i], v)
61 }
62 }
63 getI32S, err := f.GetInt32Slice("is")
64 if err != nil {
65 t.Fatalf("got error: %v", err)
66 }
67 for i, v := range getI32S {
68 d64, err := strconv.ParseInt(vals[i], 0, 32)
69 if err != nil {
70 t.Fatalf("got error: %v", err)
71 }
72 d := int32(d64)
73 if d != v {
74 t.Fatalf("expected is[%d] to be %s but got: %d from GetInt32Slice", i, vals[i], v)
75 }
76 }
77}
78
79func TestI32SDefault(t *testing.T) {
80 var is []int32

Callers

nothing calls this directly

Calls 3

setUpI32SFlagSetFunction · 0.85
GetInt32SliceMethod · 0.80
ParseMethod · 0.65

Tested by

no test coverage detected