|
8 | 8 | "net/mail" |
9 | 9 | "os" |
10 | 10 | "testing" |
| 11 | + "time" |
11 | 12 |
|
12 | 13 | "github.com/stretchr/testify/require" |
13 | 14 | "github.com/urfave/cli/v3" |
@@ -37,6 +38,32 @@ func normalizeNewlines(d []byte) []byte { |
37 | 38 | ) |
38 | 39 | } |
39 | 40 |
|
| 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 | + |
40 | 67 | func buildExtendedTestCommand(t *testing.T) *cli.Command { |
41 | 68 | return &cli.Command{ |
42 | 69 | Writer: io.Discard, |
@@ -342,6 +369,15 @@ func TestToMarkdown(t *testing.T) { |
342 | 369 | require.NoError(t, err) |
343 | 370 | expectFileContent(t, "testdata/expected-doc-no-usagetext.md", res) |
344 | 371 | }) |
| 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 | + }) |
345 | 381 | } |
346 | 382 |
|
347 | 383 | func TestToMan(t *testing.T) { |
|
0 commit comments