From cb55f19565a32b3276779ad1771b759d4f10e9c3 Mon Sep 17 00:00:00 2001 From: Ivan Marquez Date: Sun, 8 Sep 2019 21:25:24 -0400 Subject: [PATCH] WIP: console package tests (palette) 53% code coverage. --- console/palette_test.go | 75 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 4 deletions(-) diff --git a/console/palette_test.go b/console/palette_test.go index 55a205e..1df5cf5 100644 --- a/console/palette_test.go +++ b/console/palette_test.go @@ -1,6 +1,10 @@ package console -import "testing" +import ( + "testing" + + ui "github.com/gizak/termui/v3" +) func TestGetPalette(t *testing.T) { var ( @@ -17,7 +21,7 @@ func TestGetPalette(t *testing.T) { tests := []struct { name string input Theme - want Palette + Palette }{ {"should return dark theme with base color white", ThemeDark, darkPalette}, {"should return light theme with base color black", ThemeLight, lightPalette}, @@ -25,8 +29,71 @@ func TestGetPalette(t *testing.T) { for _, test := range tests { palette := GetPalette(test.input) - if got := palette.BaseColor; got != test.want.BaseColor { - t.Errorf("GetPalette(%q) = %d, want %d", test.input, got, test.want.BaseColor) + if got := palette.BaseColor; got != test.BaseColor { + t.Errorf("GetPalette(%q) = %d, want %d", test.input, got, test.BaseColor) + } + } +} + +func TestGetPaletteInvalidTheme(t *testing.T) { + const invalid Theme = "invalid" + + defer func() { + if r := recover(); r == nil { + t.Errorf("GetPalette(%q) should have panicked", invalid) + } + }() + + GetPalette(invalid) +} + +func TestGetGradientColor(t *testing.T) { + type args struct { + gradient []ui.Color + cur int + max int + } + + var ( + lightThemeGradientInput = args{ + gradient: []ui.Color{ + 250, 248, 246, 244, 242, 240, 238, 236, 234, 232, 16, + }, + cur: 200, + max: 250, + } + + darkThemeGradientInput = args{ + gradient: []ui.Color{ + 39, 33, 62, 93, 164, 161, + }, + cur: 40, + max: 180, + } + + grey ui.Color = 234 + + blue ui.Color = 33 + ) + + tests := []struct { + name string + args + want ui.Color + }{ + {"should return color grey", lightThemeGradientInput, grey}, + {"should return color blue", darkThemeGradientInput, blue}, + } + + for _, test := range tests { + gradientColor := GetGradientColor( + test.gradient, + test.cur, + test.max, + ) + + if got := gradientColor; got != test.want { + t.Errorf("GetGradientColor(%v) = %d, want %d", test.args, got, test.want) } } }