mirror of
https://github.com/charmbracelet/lipgloss.git
synced 2024-09-17 17:27:18 +03:00
chore(tests): add more style tests
This commit is contained in:
parent
60d090659b
commit
cb0f2fd931
@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
func TestStyleRender(t *testing.T) {
|
func TestStyleRender(t *testing.T) {
|
||||||
renderer.SetColorProfile(termenv.TrueColor)
|
renderer.SetColorProfile(termenv.TrueColor)
|
||||||
|
renderer.SetHasDarkBackground(true)
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
tt := []struct {
|
tt := []struct {
|
||||||
@ -19,6 +20,10 @@ func TestStyleRender(t *testing.T) {
|
|||||||
NewStyle().Foreground(Color("#5A56E0")),
|
NewStyle().Foreground(Color("#5A56E0")),
|
||||||
"\x1b[38;2;89;86;224mhello\x1b[0m",
|
"\x1b[38;2;89;86;224mhello\x1b[0m",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
NewStyle().Foreground(AdaptiveColor{Light: "#fffe12", Dark: "#5A56E0"}),
|
||||||
|
"\x1b[38;2;89;86;224mhello\x1b[0m",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
NewStyle().Bold(true),
|
NewStyle().Bold(true),
|
||||||
"\x1b[1mhello\x1b[0m",
|
"\x1b[1mhello\x1b[0m",
|
||||||
@ -52,6 +57,55 @@ func TestStyleRender(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStyleCustomRender(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
r := NewRenderer(WithColorProfile(termenv.TrueColor), WithDarkBackground(false))
|
||||||
|
tt := []struct {
|
||||||
|
style Style
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
r.NewStyle().Foreground(Color("#5A56E0")),
|
||||||
|
"\x1b[38;2;89;86;224mhello\x1b[0m",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
r.NewStyle().Foreground(AdaptiveColor{Light: "#fffe12", Dark: "#5A56E0"}),
|
||||||
|
"\x1b[38;2;255;254;18mhello\x1b[0m",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
r.NewStyle().Bold(true),
|
||||||
|
"\x1b[1mhello\x1b[0m",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
r.NewStyle().Italic(true),
|
||||||
|
"\x1b[3mhello\x1b[0m",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
r.NewStyle().Underline(true),
|
||||||
|
"\x1b[4;4mh\x1b[0m\x1b[4;4me\x1b[0m\x1b[4;4ml\x1b[0m\x1b[4;4ml\x1b[0m\x1b[4;4mo\x1b[0m",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
r.NewStyle().Blink(true),
|
||||||
|
"\x1b[5mhello\x1b[0m",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
r.NewStyle().Faint(true),
|
||||||
|
"\x1b[2mhello\x1b[0m",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, tc := range tt {
|
||||||
|
s := tc.style.Copy().SetString("hello")
|
||||||
|
res := s.Render()
|
||||||
|
if res != tc.expected {
|
||||||
|
t.Errorf("Test %d, expected:\n\n`%s`\n`%s`\n\nActual output:\n\n`%s`\n`%s`\n\n",
|
||||||
|
i, tc.expected, formatEscapes(tc.expected),
|
||||||
|
res, formatEscapes(res))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestValueCopy(t *testing.T) {
|
func TestValueCopy(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
@ -271,7 +325,7 @@ func TestStyleValue(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "new style with string",
|
name: "new style with string",
|
||||||
style: NewStyle("bar", "foobar"),
|
style: NewStyle(WithString("bar", "foobar")),
|
||||||
expected: "bar foobar foo",
|
expected: "bar foobar foo",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user