1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-03 13:21:56 +02:00

Add some tests for GetTextStyle

The tests show that setting a hex color doesn't work; we'll fix that in the next
commit.
This commit is contained in:
Stefan Haller 2023-03-03 08:40:17 +01:00
parent ff5d0155db
commit ed47529604

65
pkg/theme/style_test.go Normal file
View File

@ -0,0 +1,65 @@
package theme
import (
"reflect"
"testing"
"github.com/gookit/color"
"github.com/jesseduffield/lazygit/pkg/gui/style"
)
func TestGetTextStyle(t *testing.T) {
scenarios := []struct {
name string
keys []string
background bool
expected style.TextStyle
}{
{
name: "empty",
keys: []string{""},
background: true,
expected: style.New(),
},
{
name: "named color, fg",
keys: []string{"blue"},
background: false,
expected: style.New().SetFg(style.NewBasicColor(color.FgBlue)),
},
{
name: "named color, bg",
keys: []string{"blue"},
background: true,
expected: style.New().SetBg(style.NewBasicColor(color.BgBlue)),
},
{
name: "hex color, fg",
keys: []string{"#123456"},
background: false,
/* EXPECTED:
expected: style.New().SetFg(style.NewRGBColor(color.RGBColor{0x12, 0x34, 0x56, 0})),
ACTUAL:
*/
expected: style.New(),
},
{
name: "hex color, bg",
keys: []string{"#abcdef"},
background: true,
/* EXPECTED:
expected: style.New().SetBg(style.NewRGBColor(color.RGBColor{0xab, 0xcd, 0xef, 1})),
ACTUAL:
*/
expected: style.New(),
},
}
for _, scenario := range scenarios {
t.Run(scenario.name, func(t *testing.T) {
if actual := GetTextStyle(scenario.keys, scenario.background); !reflect.DeepEqual(actual, scenario.expected) {
t.Errorf("GetTextStyle() = %v, expected %v", actual, scenario.expected)
}
})
}
}