Do not add a trailing newline when wrapping

This commit is contained in:
Kovid Goyal
2023-03-20 21:18:53 +05:30
parent e42b4fd9a6
commit 924cd4cadd
4 changed files with 8 additions and 7 deletions

View File

@@ -481,7 +481,9 @@ func (self *wrapper) wrap_text(text string) []string {
if last_line == self.current_line.reset() {
last_line = ""
}
self.append_line(last_line)
if last_line != "" {
self.append_line(last_line)
}
return self.lines
}

View File

@@ -12,7 +12,7 @@ func TestFormatWithIndent(t *testing.T) {
screen_width := 11
tx := func(text string, expected ...string) {
q := indent + strings.Join(expected, "") + "\n"
q := indent + strings.Join(expected, "")
actual := WrapText(text, indent, screen_width)
if actual != q {
t.Fatalf("%#v\nexpected: %#v\nactual: %#v", text, q, actual)
@@ -35,4 +35,6 @@ func TestFormatWithIndent(t *testing.T) {
screen_width = 3
tx("one", "one")
tx("four", "fou\nr")
tx("nl\n\n", "nl\n\n")
tx("four\n\n", "fou\nr\n\n")
}