generated from atomicgo/template
-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
cursor_test.go
101 lines (88 loc) · 1.71 KB
/
cursor_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
89
90
91
92
93
94
95
96
97
98
99
100
101
package cursor
import (
"bytes"
"fmt"
"runtime"
"testing"
)
func TestHeightChanges(t *testing.T) {
for i := 0; i < 4; i++ {
fmt.Println()
}
Up(3)
if height != 3 {
t.Errorf("height should be 3 but is %d", height)
}
Down(3)
if height != 0 {
t.Errorf("height should be 0 but is %d", height)
}
}
func TestHeightCannotBeNegative(t *testing.T) {
Down(10)
if height < 0 {
t.Errorf("height is negative: %d", height)
}
}
func TestCustomIOWriter(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skipping these tests on windows")
}
var w bytes.Buffer
SetTarget(&w)
Up(2)
expected := "\x1b[2A"
actual := w.String()
if expected != actual {
t.Errorf("wanted: %v, got %v", expected, actual)
}
w.Reset()
Down(2)
expected = "\x1b[2B"
actual = w.String()
if expected != actual {
t.Errorf("wanted: %v, got %v", expected, actual)
}
w.Reset()
Right(2)
expected = "\x1b[2C"
actual = w.String()
if expected != actual {
t.Errorf("wanted: %v, got %v", expected, actual)
}
w.Reset()
Left(2)
expected = "\x1b[2D"
actual = w.String()
if expected != actual {
t.Errorf("wanted: %v, got %v", expected, actual)
}
w.Reset()
Hide()
expected = "\x1b[?25l"
actual = w.String()
if expected != actual {
t.Errorf("wanted: %v, got %v", expected, actual)
}
w.Reset()
Show()
expected = "\x1b[?25h"
actual = w.String()
if expected != actual {
t.Errorf("wanted: %v, got %v", expected, actual)
}
w.Reset()
ClearLine()
expected = "\x1b[2K"
actual = w.String()
if expected != actual {
t.Errorf("wanted: %v, got %v", expected, actual)
}
w.Reset()
HorizontalAbsolute(3)
expected = "\x1b[4G"
actual = w.String()
if expected != actual {
t.Errorf("wanted: %v, got %v", expected, actual)
}
}