Skip to content

Commit

Permalink
color tests
Browse files Browse the repository at this point in the history
  • Loading branch information
david-littlefarmer committed Jan 31, 2024
1 parent 6820774 commit 250ec09
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion color.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var colors = []color{
}

func getColor(c Color) color {
if c >= 0 && int(c) < len(colors) {
if int(c) < len(colors) {
return colors[c]
}

Expand Down
18 changes: 18 additions & 0 deletions color_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,31 @@ import (
)

func Test_Color(t *testing.T) {
test_GetColor(t)

b := []byte("Hello")
test_ColorCs(t, b)
test_ColorCsf(t, b)
test_ColorCsb(t, b)
test_ColorUl(t, b)
}

func test_GetColor(t *testing.T) {
result := getColor(Black)
expected := colors[1].fg

if !bytes.Equal(expected, result.fg) {
t.Errorf("\nExpected: %s\nResult: %s\nExpected: %[1]q\nResult: %[2]q", expected, result)
}

result = getColor(Color(20))
expected = colors[8].fg

if !bytes.Equal(expected, result.fg) {
t.Errorf("\nExpected: %s\nResult: %s\nExpected: %[1]q\nResult: %[2]q", expected, result)
}
}

func test_ColorCs(t *testing.T, b []byte) {
result := cs(b, fgGreen)

Expand Down

0 comments on commit 250ec09

Please sign in to comment.