From ed47529604913337f3a5f4f1bcfb23dc04550526 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 3 Mar 2023 08:40:17 +0100 Subject: [PATCH 1/2] Add some tests for GetTextStyle The tests show that setting a hex color doesn't work; we'll fix that in the next commit. --- pkg/theme/style_test.go | 65 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 pkg/theme/style_test.go diff --git a/pkg/theme/style_test.go b/pkg/theme/style_test.go new file mode 100644 index 000000000..99ba16c90 --- /dev/null +++ b/pkg/theme/style_test.go @@ -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) + } + }) + } +} From 63e8b8c01c30df9c810778d6e30b151b8925b397 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 2 Mar 2023 21:01:18 +0100 Subject: [PATCH 2/2] Fix setting gui.selectedRangeBgColor as a hex value --- pkg/theme/style.go | 4 ++-- pkg/theme/style_test.go | 8 -------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/pkg/theme/style.go b/pkg/theme/style.go index 69c404e3b..f090068e0 100644 --- a/pkg/theme/style.go +++ b/pkg/theme/style.go @@ -30,9 +30,9 @@ func GetTextStyle(keys []string, background bool) style.TextStyle { } else if utils.IsValidHexValue(key) { c := style.NewRGBColor(color.HEX(key, background)) if background { - s.SetBg(c) + s = s.SetBg(c) } else { - s.SetFg(c) + s = s.SetFg(c) } } } diff --git a/pkg/theme/style_test.go b/pkg/theme/style_test.go index 99ba16c90..e20191b55 100644 --- a/pkg/theme/style_test.go +++ b/pkg/theme/style_test.go @@ -37,21 +37,13 @@ func TestGetTextStyle(t *testing.T) { 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(), }, }