Skip to content

Commit

Permalink
Merge pull request #16 from chelnak/color_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chelnak committed Jul 18, 2022
2 parents 5175349 + 5f7a7a7 commit b35c316
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/colors/colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@ func GetColor(c Color) *color.Color {
return nil
}

return color.New(lookup[c])
if val, ok := lookup[c]; ok {
return color.New(val)
}

return nil
}
15 changes: 15 additions & 0 deletions pkg/colors/colors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ func TestGetColor(t *testing.T) {
c: colors.FgHiRed,
want: color.New(color.FgHiRed),
},
{
name: "GetColor returns the correct mapping for FgHiWhite",
c: colors.FgHiWhite,
want: color.New(color.FgHiWhite),
},
{
name: "GetColor returns the correct mapping for NoColor",
c: colors.NoColor,
want: nil,
},
{
name: "GetColor returns nil for an unknown color",
c: colors.Color(100),
want: nil,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit b35c316

Please sign in to comment.