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

Function Test_FloatFlag

flag_float_test.go:11–62  ·  flag_float_test.go::Test_FloatFlag
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func Test_FloatFlag(t *testing.T) {
12 tests := []struct {
13 name string
14 flag Flag
15 arguments []string
16 expectedValue float64
17 expectErr bool
18 }{
19 {
20 name: "valid",
21 flag: &FloatFlag{
22 Name: "number",
23 Aliases: []string{"n"},
24 },
25 arguments: []string{"--number", "-234567"},
26 expectedValue: -234567,
27 },
28 {
29 name: "invalid",
30 flag: &FloatFlag{
31 Name: "number",
32 },
33 arguments: []string{"--number", "gopher"},
34 expectErr: true,
35 },
36 }
37
38 for _, tt := range tests {
39 t.Run(tt.name, func(t *testing.T) {
40 cmd := &Command{
41 Name: "mock",
42 Flags: []Flag{tt.flag},
43 Writer: io.Discard,
44 ErrWriter: io.Discard,
45 }
46
47 err := cmd.Run(buildTestContext(t), append([]string{"mock"}, tt.arguments...))
48
49 if tt.expectErr {
50 require.Error(t, err)
51
52 return
53 }
54
55 require.NoError(t, err)
56
57 for _, name := range tt.flag.Names() {
58 assert.Equal(t, tt.expectedValue, cmd.Float(name))
59 }
60 })
61 }
62}
63
64func Test_Float32Flag(t *testing.T) {
65 tests := []struct {

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected