forked from fyne-io/terminal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
escape_test.go
88 lines (70 loc) · 1.97 KB
/
escape_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package terminal
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestClearScreen(t *testing.T) {
term := New()
term.config.Columns = 5
term.config.Rows = 2
term.handleOutput([]byte("Hello"))
assert.Equal(t, "Hello", term.content.Text())
term.handleEscape("2J")
assert.Equal(t, "", term.content.Text())
}
func TestEraseLine(t *testing.T) {
term := New()
term.config.Columns = 5
term.config.Rows = 2
term.handleOutput([]byte("Hello"))
assert.Equal(t, "Hello", term.content.Text())
term.moveCursor(0, 2)
term.handleEscape("K")
assert.Equal(t, "He", term.content.Text())
}
func TestCursorMove(t *testing.T) {
term := New()
term.config.Columns = 5
term.config.Rows = 2
term.handleOutput([]byte("Hello"))
assert.Equal(t, 0, term.cursorRow)
assert.Equal(t, 5, term.cursorCol)
term.handleEscape("1;4H")
assert.Equal(t, 0, term.cursorRow)
assert.Equal(t, 3, term.cursorCol)
term.handleEscape("2D")
assert.Equal(t, 0, term.cursorRow)
assert.Equal(t, 1, term.cursorCol)
term.handleEscape("2C")
assert.Equal(t, 0, term.cursorRow)
assert.Equal(t, 3, term.cursorCol)
term.handleEscape("1B")
assert.Equal(t, 1, term.cursorRow)
assert.Equal(t, 3, term.cursorCol)
term.handleEscape("1A")
assert.Equal(t, 0, term.cursorRow)
assert.Equal(t, 3, term.cursorCol)
}
func TestCursorMove_Overflow(t *testing.T) {
term := New()
term.config.Columns = 2
term.config.Rows = 2
term.handleEscape("2;2H")
assert.Equal(t, 1, term.cursorRow)
assert.Equal(t, 1, term.cursorCol)
term.handleEscape("2D")
assert.Equal(t, 1, term.cursorRow)
assert.Equal(t, 0, term.cursorCol)
term.handleEscape("5C")
assert.Equal(t, 1, term.cursorRow)
assert.Equal(t, 1, term.cursorCol)
term.handleEscape("5A")
assert.Equal(t, 0, term.cursorRow)
assert.Equal(t, 1, term.cursorCol)
term.handleEscape("4B")
assert.Equal(t, 1, term.cursorRow)
assert.Equal(t, 1, term.cursorCol)
}
func TestTrimLeftZeros(t *testing.T) {
assert.Equal(t, "1", trimLeftZeros(string([]byte{0, 0, '1'})))
}