-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcsi_test.go
42 lines (36 loc) · 1.05 KB
/
csi_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
package crt
import (
"fmt"
"github.com/muesli/termenv"
"github.com/stretchr/testify/assert"
"testing"
)
func TestCSI(t *testing.T) {
var testString string
testString += fmt.Sprintf(termenv.CSI+termenv.EraseDisplaySeq, 20)
testString += "HELLO WORLD"
testString += fmt.Sprintf(termenv.CSI+termenv.CursorPositionSeq, 1, 2)
testString += fmt.Sprintf(termenv.CSI+termenv.CursorPositionSeq, 1, 2)
testString += "HELLO WORLD"
testString += termenv.CSI + termenv.ShowCursorSeq
testString += fmt.Sprintf(termenv.CSI+termenv.CursorPositionSeq, 1, 2)
testString += fmt.Sprintf(termenv.CSI+termenv.CursorBackSeq, 5)
var sequences []any
for i := 0; i < len(testString); i++ {
csi, ok := extractCSI(testString[i:])
if ok {
i += len(csi) - 1
if res, ok := parseCSI(csi); ok {
sequences = append(sequences, res)
}
}
}
assert.Equal(t, []any{
EraseDisplaySeq{Type: 20},
CursorPositionSeq{Row: 1, Col: 2},
CursorPositionSeq{Row: 1, Col: 2},
CursorShowSeq{},
CursorPositionSeq{Row: 1, Col: 2},
CursorBackSeq{Count: 5},
}, sequences)
}