Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func WordWrap(txt string, lineLength int) string {

final = append(final, line[startIndex:startIndex+newIndex])
startIndex += newIndex
endIndex = startIndex

// clear any extra space
for ; startIndex < len(line) && line[startIndex] == ' '; startIndex++ {
Expand Down
7 changes: 7 additions & 0 deletions wrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ func TestWrappingTrailingWhitespace(t *testing.T) {
wrapped = textplain.WordWrap("1234567890"+strings.Repeat(" ", 20), 10)
assert.Equal(t, "1234567890\n", wrapped)
}

func TestWrappingShorterThanLimit(t *testing.T) {
body := "1 12 12 1"

wrapped := textplain.WordWrap(body, 3)
assert.Equal(t, "1\n12\n12\n1", wrapped)
}