-
Notifications
You must be signed in to change notification settings - Fork 0
/
fmt_test.go
59 lines (48 loc) · 903 Bytes
/
fmt_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
package terminfo
import (
"bytes"
"fmt"
"testing"
)
func TestFmt(t *testing.T) {
b, err := Fmt([]byte("0x1b[%i%p1%d;%p2%dH"), 10, 20)
if err != nil {
t.Error(err)
}
if !bytes.Equal(b, []byte("0x1b[11;21H")) {
t.Fail()
}
}
func TestFmtColor(t *testing.T) {
eseq := []byte("\\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m")
for i := 0; i < 8; i++ {
b, err := Fmt(eseq, i)
if err != nil {
t.Error(err)
}
r := fmt.Sprintf("\\E[3%dm", i)
if !bytes.Equal(b, []byte(r)) {
t.Fail()
}
}
for i := 8; i < 16; i++ {
b, err := Fmt(eseq, i)
if err != nil {
t.Error(err)
}
r := fmt.Sprintf("\\E[9%dm", i-8)
if !bytes.Equal(b, []byte(r)) {
t.Fail()
}
}
for i := 16; i < 256; i++ {
b, err := Fmt(eseq, i)
if err != nil {
t.Error(err)
}
r := fmt.Sprintf("\\E[38;5;%dm", i)
if !bytes.Equal(b, []byte(r)) {
t.Fail()
}
}
}