File: helpwrap1.18_test.go

package info (click to toggle)
golang-github-alecthomas-kong 0.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 832 kB
  • sloc: sh: 32; makefile: 2
file content (47 lines) | stat: -rw-r--r-- 989 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//go:build !go1.19
// +build !go1.19

package kong_test

import (
	"bytes"
	"testing"

	"github.com/alecthomas/assert/v2"
	"github.com/alecthomas/kong"
)

func TestCustomWrap(t *testing.T) {
	var cli struct {
		Flag string `help:"A string flag with very long help that wraps a lot and is verbose and is really verbose."`
	}

	w := bytes.NewBuffer(nil)
	app := mustNew(t, &cli,
		kong.Name("test-app"),
		kong.Description("A test app."),
		kong.HelpOptions{
			WrapUpperBound: 50,
		},
		kong.Writers(w, w),
		kong.Exit(func(int) {}),
	)

	_, err := app.Parse([]string{"--help"})
	assert.NoError(t, err)
	expected := `Usage: test-app

A test app.

Flags:
  -h, --help           Show context-sensitive
                       help.
      --flag=STRING    A string flag with very
                       long help that wraps a lot
                       and is verbose and is
                       really verbose.
`
	t.Log(w.String())
	t.Log(expected)
	assert.Equal(t, expected, w.String())
}