forked from charmbracelet/bubbletea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
screen_test.go
65 lines (54 loc) · 1.32 KB
/
screen_test.go
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
package tea
import (
"bytes"
"io"
"testing"
)
func TestScreen(t *testing.T) {
exercise := func(t *testing.T, fn func(io.Writer), expect []byte) {
var w bytes.Buffer
fn(&w)
if !bytes.Equal(w.Bytes(), expect) {
t.Errorf("expected %q, got %q", expect, w.Bytes())
}
}
t.Run("change scrolling region", func(t *testing.T) {
exercise(t, func(w io.Writer) {
changeScrollingRegion(w, 16, 22)
}, []byte("\x1b[16;22r"))
})
t.Run("line", func(t *testing.T) {
t.Run("clear", func(t *testing.T) {
exercise(t, clearLine, []byte("\x1b[2K"))
})
t.Run("insert", func(t *testing.T) {
exercise(t, func(w io.Writer) {
insertLine(w, 12)
}, []byte("\x1b[12L"))
})
})
t.Run("cursor", func(t *testing.T) {
t.Run("hide", func(t *testing.T) {
exercise(t, hideCursor, []byte("\x1b[?25l"))
})
t.Run("show", func(t *testing.T) {
exercise(t, showCursor, []byte("\x1b[?25h"))
})
t.Run("up", func(t *testing.T) {
exercise(t, cursorUp, []byte("\x1b[1A"))
})
t.Run("down", func(t *testing.T) {
exercise(t, cursorDown, []byte("\x1b[1B"))
})
t.Run("move", func(t *testing.T) {
exercise(t, func(w io.Writer) {
moveCursor(w, 10, 20)
}, []byte("\x1b[10;20H"))
})
t.Run("back", func(t *testing.T) {
exercise(t, func(w io.Writer) {
cursorBack(w, 15)
}, []byte("\x1b[15D"))
})
})
}