-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic_test.go
executable file
·97 lines (79 loc) · 1.47 KB
/
basic_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
package termios
// basic_test.go contains a test function that can be used to debug key sequences.
import (
"fmt"
"testing"
"time"
)
func TestRawCooked(t *testing.T) {
term, err := Open()
if err != nil {
t.Fatal(err)
}
defer term.Close()
for i := 0; i < 3; i++ {
err := term.SetRaw(false)
if err != nil {
t.Fatal(err)
}
_, err = term.WriteString("Now it should be cooked")
if err != nil {
t.Fatal(err)
}
_, err = term.Read()
if err != nil {
t.Fatal(err)
}
err = term.SetRaw(true)
if err != nil {
t.Fatal(err)
}
_, err = term.WriteString("Now it should be raw")
if err != nil {
t.Fatal(err)
}
_, err = term.Read()
if err != nil {
t.Fatal(err)
}
}
}
func TestBasicOpen(t *testing.T) {
term, err := Open()
if err != nil {
t.Error(err)
}
var buf []Key
term.SetRaw(true)
for i := 0; i < 100; i++ {
buf, err = term.Read()
if err != nil {
t.Error(err)
}
for _, k := range buf {
_, err = term.WriteString(k.String() + "\r\n")
if err != nil {
t.Error(err)
}
if k.Type == KeyLetter && k.Mod == 0 && k.Value == 'q' {
term.Close()
t.SkipNow()
}
}
}
term.Close()
}
func TestSizeReading(t *testing.T) {
term, err := Open()
if err != nil {
t.Error(err)
}
for i := 0; i < 20; i++ {
_, err = term.WriteString(fmt.Sprintf("Current size: width %d, height %d\r\n",
term.GetSize().Width, term.GetSize().Height))
if err != nil {
t.Fatal(err)
}
time.Sleep(1 * time.Second)
}
}