1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
package tui
import (
"bytes"
"strings"
"testing"
)
func TestRenderFull_TrimsTrailingEmptyCells(t *testing.T) {
buf := NewBuffer(10, 2)
buf.SetCell(0, 0, NewCell('h', NewStyle()))
buf.SetCell(1, 0, NewCell('i', NewStyle()))
var out bytes.Buffer
term := NewANSITerminalWithCaps(&out, nil, Capabilities{Colors: Color16})
RenderFull(term, buf)
s := out.String()
if !strings.Contains(s, "hi") {
t.Fatalf("content missing from output: %q", s)
}
if strings.Contains(s, "hi ") {
t.Errorf("trailing space written after content: %q", s)
}
if strings.Contains(s, strings.Repeat(" ", 5)) {
t.Errorf("empty cells painted as spaces: %q", s)
}
}
func TestDiff_ShrinkClearsTailWithEraseLine(t *testing.T) {
buf := NewBuffer(20, 1)
for x, r := range "a long line here!!!!" {
buf.SetCell(x, 0, NewCell(r, NewStyle()))
}
var f1 bytes.Buffer
t1 := NewANSITerminalWithCaps(&f1, nil, Capabilities{Colors: Color16})
Render(t1, buf)
buf.Clear()
for x, r := range "short" {
buf.SetCell(x, 0, NewCell(r, NewStyle()))
}
var f2 bytes.Buffer
t2 := NewANSITerminalWithCaps(&f2, nil, Capabilities{Colors: Color16})
Render(t2, buf)
s := f2.String()
if !strings.Contains(s, "short") {
t.Fatalf("new content missing: %q", s)
}
if !strings.Contains(s, "\x1b[K") {
t.Errorf("expected erase-to-end-of-line (ESC[K) to clear the tail: %q", s)
}
if strings.Contains(s, "short ") || strings.Contains(s, strings.Repeat(" ", 3)) {
t.Errorf("tail cleared by writing spaces instead of erase-line: %q", s)
}
}
|