Skip to content

Commit 9c1a23c

Browse files
authored
Merge pull request #19 from 6543-forks/add-string-slice-flag-2-tests
Add test that covers all flag types
2 parents 0333461 + 5bbc1d6 commit 9c1a23c

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

docs_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/mail"
99
"os"
1010
"testing"
11+
"time"
1112

1213
"github.com/stretchr/testify/require"
1314
"github.com/urfave/cli/v3"
@@ -37,6 +38,32 @@ func normalizeNewlines(d []byte) []byte {
3738
)
3839
}
3940

41+
func buildFlagTest(t *testing.T) *cli.Command {
42+
return &cli.Command{
43+
Writer: io.Discard,
44+
Name: "main",
45+
Flags: []cli.Flag{
46+
&cli.BoolFlag{Name: "bool-false"},
47+
&cli.BoolFlag{Name: "bool-true", Value: true},
48+
&cli.StringFlag{Name: "string-empty"},
49+
&cli.StringFlag{Name: "string-set", Value: "a string"},
50+
&cli.StringMapFlag{Name: "string-map-empty"},
51+
&cli.StringMapFlag{Name: "string-map-set", Value: map[string]string{"a": "b"}},
52+
&cli.StringSliceFlag{Name: "string-slice-empty"},
53+
&cli.StringSliceFlag{Name: "string-slice-set", Value: []string{"a", "b"}},
54+
&cli.IntFlag{Name: "string-empty"},
55+
&cli.IntFlag{Name: "string-set", Value: 42},
56+
&cli.UintFlag{Name: "string-empty"},
57+
&cli.UintFlag{Name: "string-set", Value: 21},
58+
&cli.FloatFlag{Name: "string-empty"},
59+
&cli.FloatFlag{Name: "string-set", Value: 88.32},
60+
&cli.DurationFlag{Name: "string-empty"},
61+
&cli.DurationFlag{Name: "string-set", Value: 12 * time.Minute},
62+
&cli.TimestampFlag{Name: "string-empty"},
63+
&cli.TimestampFlag{Name: "string-set", Value: time.Unix(1729456800, 0).UTC()},
64+
}}
65+
}
66+
4067
func buildExtendedTestCommand(t *testing.T) *cli.Command {
4168
return &cli.Command{
4269
Writer: io.Discard,
@@ -342,6 +369,15 @@ func TestToMarkdown(t *testing.T) {
342369
require.NoError(t, err)
343370
expectFileContent(t, "testdata/expected-doc-no-usagetext.md", res)
344371
})
372+
373+
t.Run("test all flag types", func(t *testing.T) {
374+
app := buildFlagTest(t)
375+
376+
res, err := ToMarkdown(app)
377+
378+
require.NoError(t, err)
379+
expectFileContent(t, "testdata/expected-doc-all-flag-types.md", res)
380+
})
345381
}
346382

347383
func TestToMan(t *testing.T) {
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# NAME
2+
3+
main
4+
5+
# SYNOPSIS
6+
7+
main
8+
9+
```
10+
[--bool-false]
11+
[--bool-true]
12+
[--string-empty]=[value]
13+
[--string-empty]=[value]
14+
[--string-empty]=[value]
15+
[--string-empty]=[value]
16+
[--string-empty]=[value]
17+
[--string-empty]=[value]
18+
[--string-map-empty]=[value]
19+
[--string-map-set]=[value]
20+
[--string-set]=[value]
21+
[--string-set]=[value]
22+
[--string-set]=[value]
23+
[--string-set]=[value]
24+
[--string-set]=[value]
25+
[--string-set]=[value]
26+
[--string-slice-empty]=[value]
27+
[--string-slice-set]=[value]
28+
```
29+
30+
**Usage**:
31+
32+
```
33+
main [GLOBAL OPTIONS] [command [COMMAND OPTIONS]] [ARGUMENTS...]
34+
```
35+
36+
# GLOBAL OPTIONS
37+
38+
**--bool-false**: (default: false)
39+
40+
**--bool-true**: (default: true)
41+
42+
**--string-empty**="":
43+
44+
**--string-empty**="": (default: 0)
45+
46+
**--string-empty**="": (default: 0)
47+
48+
**--string-empty**="": (default: 0)
49+
50+
**--string-empty**="": (default: 0001-01-01 00:00:00 +0000 UTC)
51+
52+
**--string-empty**="": (default: 0s)
53+
54+
**--string-map-empty**="": (default: map[])
55+
56+
**--string-map-set**="": (default: map[a:b])
57+
58+
**--string-set**="": (default: 12m0s)
59+
60+
**--string-set**="": (default: 2024-10-20 20:40:00 +0000 UTC)
61+
62+
**--string-set**="": (default: 21)
63+
64+
**--string-set**="": (default: 42)
65+
66+
**--string-set**="": (default: 88.32)
67+
68+
**--string-set**="": (default: a string)
69+
70+
**--string-slice-empty**="": (default: [])
71+
72+
**--string-slice-set**="": (default: [a b])
73+

0 commit comments

Comments
 (0)