From 661a11fecd5d8e7cc560f0ab5154fafe95e2f4d6 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Sat, 16 May 2020 08:54:45 +0200 Subject: [PATCH] Added tests for HexColor. --- colors.go => color.go | 0 color_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) rename colors.go => color.go (100%) create mode 100644 color_test.go diff --git a/colors.go b/color.go similarity index 100% rename from colors.go rename to color.go diff --git a/color_test.go b/color_test.go new file mode 100644 index 0000000..05cd5e9 --- /dev/null +++ b/color_test.go @@ -0,0 +1,33 @@ +package zntg + +import ( + "image/color" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestHexColor(t *testing.T) { + type test struct { + Hex string + Success bool + Expected color.RGBA + } + tests := []test{ + test{Hex: "#AA3939", Success: true, Expected: color.RGBA{R: 170, G: 57, B: 57, A: 255}}, + test{Hex: "AA3939", Success: true, Expected: color.RGBA{R: 170, G: 57, B: 57, A: 255}}, + test{Hex: "#AA3939BB", Success: true, Expected: color.RGBA{R: 170, G: 57, B: 57, A: 187}}, + test{Hex: "AG3939", Success: false, Expected: color.RGBA{}}, + test{Hex: "AA3939A", Success: false, Expected: color.RGBA{}}, + test{Hex: "AA39A", Success: false, Expected: color.RGBA{}}, + } + for _, test := range tests { + color, err := HexColor(test.Hex) + if test.Success { + assert.Nil(t, err) + assert.Equal(t, color, test.Expected) + } else { + assert.NotNil(t, err) + } + } +}