From 250ec09bbab0b74d7462250ab8a6f2e207235043 Mon Sep 17 00:00:00 2001 From: david-littlefarmer Date: Wed, 31 Jan 2024 14:46:17 +0100 Subject: [PATCH] color tests --- color.go | 2 +- color_test.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/color.go b/color.go index 40ed085..b6d57ed 100644 --- a/color.go +++ b/color.go @@ -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] } diff --git a/color_test.go b/color_test.go index 158ddb8..366b88b 100644 --- a/color_test.go +++ b/color_test.go @@ -6,6 +6,8 @@ import ( ) func Test_Color(t *testing.T) { + test_GetColor(t) + b := []byte("Hello") test_ColorCs(t, b) test_ColorCsf(t, b) @@ -13,6 +15,22 @@ func Test_Color(t *testing.T) { 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)