Skip to content

Commit

Permalink
chore(tests): add more style tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Feb 6, 2023
1 parent c073b37 commit 2aa5b78
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion style_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

func TestStyleRender(t *testing.T) {
renderer.SetColorProfile(termenv.TrueColor)
renderer.SetHasDarkBackground(true)
t.Parallel()

tt := []struct {
Expand All @@ -19,6 +20,10 @@ func TestStyleRender(t *testing.T) {
NewStyle().Foreground(Color("#5A56E0")),
"\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),
"\x1b[1mhello\x1b[0m",
Expand Down Expand Up @@ -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) {
t.Parallel()

Expand Down Expand Up @@ -271,7 +325,7 @@ func TestStyleValue(t *testing.T) {
},
{
name: "new style with string",
style: NewStyle("bar", "foobar"),
style: NewStyle(WithString("bar", "foobar")),
expected: "bar foobar foo",
},
}
Expand Down

0 comments on commit 2aa5b78

Please sign in to comment.