-
Notifications
You must be signed in to change notification settings - Fork 4
/
sgr_test.go
36 lines (31 loc) · 890 Bytes
/
sgr_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
package crt
import (
"bytes"
"github.com/charmbracelet/lipgloss"
"github.com/muesli/termenv"
"github.com/stretchr/testify/assert"
"testing"
)
func TestSGR(t *testing.T) {
buf := &bytes.Buffer{}
lip := lipgloss.NewRenderer(buf, termenv.WithProfile(termenv.TrueColor))
testString := lip.NewStyle().Bold(true).Foreground(lipgloss.Color("#ff00ff")).Render("Hello World") + "asdasdasdasdasd" + lip.NewStyle().Italic(true).Background(lipgloss.Color("#ff00ff")).Render("Hello World")
var sequences []any
for i := 0; i < len(testString); i++ {
sgr, ok := extractSGR(testString[i:])
if ok {
i += len(sgr) - 1
if res, ok := parseSGR(sgr); ok {
sequences = append(sequences, res...)
}
}
}
assert.Equal(t, []any{
SGRBold{},
SGRFgTrueColor{R: 255, G: 0, B: 255},
SGRReset{},
SGRItalic{},
SGRBgTrueColor{R: 255, G: 0, B: 255},
SGRReset{},
}, sequences)
}