Skip to content

Commit

Permalink
Add tests for double line break
Browse files Browse the repository at this point in the history
  • Loading branch information
dramich committed May 18, 2024
1 parent 50ba2ca commit 83d142c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions doc/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,10 @@ func checkStringOmits(t *testing.T, got, expected string) {
t.Errorf("Expected to not contain: \n %v\nGot: %v", expected, got)
}
}

func checkStringOmitsSuffix(t *testing.T, got, expected string) {
if strings.HasSuffix(got, expected) {
// Note this uses %q so things like line breaks can be seen in the printed output
t.Errorf("Expected to not have suffix: \n %q\nGot: %q", expected, got)
}
}
6 changes: 6 additions & 0 deletions doc/md_docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/spf13/cobra"
)

const doubleLineBreak = "\n\n"

func TestGenMdDoc(t *testing.T) {
// We generate on subcommand so we have both subcommands and parents.
buf := new(bytes.Buffer)
Expand All @@ -40,6 +42,7 @@ func TestGenMdDoc(t *testing.T) {
checkStringContains(t, output, echoSubCmd.Short)
checkStringOmits(t, output, deprecatedCmd.Short)
checkStringContains(t, output, "Options inherited from parent commands")
checkStringOmitsSuffix(t, output, doubleLineBreak)
}

func TestGenMdDocWithNoLongOrSynopsis(t *testing.T) {
Expand All @@ -54,6 +57,7 @@ func TestGenMdDocWithNoLongOrSynopsis(t *testing.T) {
checkStringContains(t, output, dummyCmd.Short)
checkStringContains(t, output, "Options inherited from parent commands")
checkStringOmits(t, output, "### Synopsis")
checkStringOmitsSuffix(t, output, doubleLineBreak)
}

func TestGenMdNoHiddenParents(t *testing.T) {
Expand All @@ -77,6 +81,7 @@ func TestGenMdNoHiddenParents(t *testing.T) {
checkStringContains(t, output, echoSubCmd.Short)
checkStringOmits(t, output, deprecatedCmd.Short)
checkStringOmits(t, output, "Options inherited from parent commands")
checkStringOmitsSuffix(t, output, doubleLineBreak)
}

func TestGenMdNoTag(t *testing.T) {
Expand All @@ -90,6 +95,7 @@ func TestGenMdNoTag(t *testing.T) {
output := buf.String()

checkStringOmits(t, output, "Auto generated")
checkStringOmitsSuffix(t, output, doubleLineBreak)
}

func TestGenMdTree(t *testing.T) {
Expand Down

0 comments on commit 83d142c

Please sign in to comment.