diff --git a/wrap.go b/wrap.go index 10c69db..7e9e463 100644 --- a/wrap.go +++ b/wrap.go @@ -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++ { diff --git a/wrap_test.go b/wrap_test.go index 4693ba3..04dbc08 100644 --- a/wrap_test.go +++ b/wrap_test.go @@ -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) +}