diff --git a/v2/tools/generator/internal/astbuilder/comments.go b/v2/tools/generator/internal/astbuilder/comments.go index 1a3acc8d4af..214de988cf0 100644 --- a/v2/tools/generator/internal/astbuilder/comments.go +++ b/v2/tools/generator/internal/astbuilder/comments.go @@ -87,6 +87,9 @@ func AddComment(commentList *dst.Decorations, comment string) { // formatComment splits the supplied comment string up ready for use as a documentation comment func formatComment(comment string, width int) []string { + if comment == "" { + return []string{} + } // Remove markdown bolding text := strings.ReplaceAll(comment, "**", "") @@ -122,6 +125,10 @@ func docCommentWrap(lines []string, width int) []string { func WordWrap(text string, width int) []string { var result []string + if width == 0 && text == "" { + return []string{} + } + start := 0 for start < len(text) { finish := findBreakPoint(text, start, width) diff --git a/v2/tools/generator/internal/astbuilder/comments_test.go b/v2/tools/generator/internal/astbuilder/comments_test.go index 84e961c4766..f120e3b4fb7 100644 --- a/v2/tools/generator/internal/astbuilder/comments_test.go +++ b/v2/tools/generator/internal/astbuilder/comments_test.go @@ -38,6 +38,7 @@ func TestDocumentationCommentFormatting(t *testing.T) { {"**foo**\nbar", []string{"foo", "bar"}}, {"foo\n**bar**", []string{"foo", "bar"}}, {"foo\n**bar**\nbaz", []string{"foo", "bar", "baz"}}, + {"", []string{}}, // Expect long lines to be wrapped { "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", @@ -70,6 +71,8 @@ func TestWordWrap(t *testing.T) { {"this is a simple line of text", 16, []string{"this is a simple ", "line of text"}}, {"this is a simple line of text", 20, []string{"this is a simple ", "line of text"}}, {"this is a simple line of text", 21, []string{"this is a simple line ", "of text"}}, + {"", 0, []string{}}, + {"this is a sample text", 0, []string{"this ", "is ", "a ", "sample ", "text"}}, } for _, c := range cases {