MCPcopy
hub / github.com/urfave/cli / TestInt8Flag

Function TestInt8Flag

flag_int_test.go:65–116  ·  flag_int_test.go::TestInt8Flag
(t *testing.T)

Source from the content-addressed store, hash-verified

63}
64
65func TestInt8Flag(t *testing.T) {
66 tests := []struct {
67 name string
68 flag Flag
69 arguments []string
70 expectedValue int8
71 expectErr bool
72 }{
73 {
74 name: "valid",
75 flag: &Int8Flag{
76 Name: "number",
77 Aliases: []string{"n"},
78 },
79 arguments: []string{"--number", "127"},
80 expectedValue: 127,
81 },
82 {
83 name: "invalid",
84 flag: &Int8Flag{
85 Name: "number",
86 },
87 arguments: []string{"--number", "gopher"},
88 expectErr: true,
89 },
90 }
91
92 for _, tt := range tests {
93 t.Run(tt.name, func(t *testing.T) {
94 cmd := &Command{
95 Name: "mock",
96 Flags: []Flag{tt.flag},
97 Writer: io.Discard,
98 ErrWriter: io.Discard,
99 }
100
101 err := cmd.Run(buildTestContext(t), append([]string{"mock"}, tt.arguments...))
102
103 if tt.expectErr {
104 require.Error(t, err)
105
106 return
107 }
108
109 require.NoError(t, err)
110
111 for _, name := range tt.flag.Names() {
112 assert.Equal(t, tt.expectedValue, cmd.Int8(name))
113 }
114 })
115 }
116}
117
118func TestInt16Flag(t *testing.T) {
119 tests := []struct {

Callers

nothing calls this directly

Calls 5

RunMethod · 0.95
Int8Method · 0.95
buildTestContextFunction · 0.85
NamesMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected