-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselect_test.go
More file actions
56 lines (46 loc) · 1.37 KB
/
Copy pathselect_test.go
File metadata and controls
56 lines (46 loc) · 1.37 KB
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
package termview
import (
"fmt"
"strings"
"testing"
tea "charm.land/bubbletea/v2"
)
func TestSelectedTextIncludesOffscreenLines(t *testing.T) {
m := newTestModel(20, 5)
for i := 1; i <= 12; i++ {
fmt.Fprintf(m.emu, "line%d\r\n", i)
}
sbLen := m.emu.ScrollbackLen()
m.isSelecting = true
m.startX, m.startY = 0, 0
m.endX, m.endY = 19, sbLen+m.height-1
got := m.selectedText()
if !strings.Contains(got, "line1") {
t.Errorf("copy missing oldest scrollback line:\n%s", got)
}
if !strings.Contains(got, "line12") {
t.Errorf("copy missing live-screen line:\n%s", got)
}
}
func TestBufferCellRejectsRowsPastScreen(t *testing.T) {
m := newTestModel(20, 5)
fmt.Fprint(m.emu, "hello\r\n")
sbLen := m.emu.ScrollbackLen()
if cell := m.bufferCell(0, sbLen+m.height); cell != nil {
t.Errorf("bufferCell past the live screen = %#v, want nil", cell)
}
}
func TestWheelWithoutCoordsKeepsPointer(t *testing.T) {
m := newTestModel(20, 5)
for i := 1; i <= 12; i++ {
fmt.Fprintf(m.emu, "line%d\r\n", i)
}
m = m.Focus()
m, _ = m.Update(tea.MouseClickMsg{Button: tea.MouseLeft, X: 4, Y: 3})
m, _ = m.Update(tea.MouseMotionMsg{Button: tea.MouseLeft, X: 4, Y: 3})
m, _ = m.Update(tea.MouseWheelMsg{Button: tea.MouseWheelUp})
wantY := m.bufferY(3)
if m.endX != 4 || m.endY != wantY {
t.Errorf("end = (%d,%d), want (4,%d) from last pointer after scroll", m.endX, m.endY, wantY)
}
}