fix: Standardize and wrap example descriptions at 80 chars (#2894)

This commit is contained in:
Mathias Fredriksson
2022-07-11 19:08:09 +03:00
committed by GitHub
parent 50e8a27d04
commit 749694b7de
12 changed files with 223 additions and 103 deletions

66
cli/root_internal_test.go Normal file
View File

@ -0,0 +1,66 @@
package cli
import (
"testing"
"github.com/stretchr/testify/require"
)
func Test_formatExamples(t *testing.T) {
t.Parallel()
tests := []struct {
name string
examples []example
wantMatches []string
}{
{
name: "No examples",
examples: nil,
wantMatches: nil,
},
{
name: "Output examples",
examples: []example{
{
Description: "Hello world",
Command: "echo hello",
},
{
Description: "Bye bye",
Command: "echo bye",
},
},
wantMatches: []string{
"Hello world", "echo hello",
"Bye bye", "echo bye",
},
},
{
name: "No description outputs commands",
examples: []example{
{
Command: "echo hello",
},
},
wantMatches: []string{
"echo hello",
},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got := formatExamples(tt.examples...)
if len(tt.wantMatches) == 0 {
require.Empty(t, got)
} else {
for _, want := range tt.wantMatches {
require.Contains(t, got, want)
}
}
})
}
}