Loading extract/colors.go +3 −3 Original line number Diff line number Diff line Loading @@ -97,10 +97,10 @@ func ExtraColors(req *http.Request) (color.RGBA, color.RGBA) { var err error var bg, fg color.RGBA if bg, err = Background(req); err != nil { fg = tgColors.White() bg = tgColors.White() } if fg, err = Foreground(req); err != nil { bg = tgColors.Black() fg = tgColors.Black() } return bg, fg } Loading @@ -119,7 +119,7 @@ func UserColors(req *http.Request) ([]color.RGBA, error) { for _, c := range strColors { if r, g, b, err := hexToRGB(c); err != nil { return colors, fmt.Errorf("colors: wrong input") return []color.RGBA{}, fmt.Errorf("colors: wrong input") } else { new := color.RGBA{uint8(r), uint8(g), uint8(b), uint8(255)} colors = append(colors, new) Loading extract/colors_test.go +60 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,8 @@ import ( "net/http" "net/url" "testing" tgColors "github.com/taironas/tinygraphs/colors" ) func TestUserColors(t *testing.T) { Loading Loading @@ -43,3 +45,61 @@ func TestUserColors(t *testing.T) { } } } func TestGColors(t *testing.T) { colorMap := tgColors.MapOfColorThemes() tests := []struct { title string url string gColors []color.RGBA }{ { "test wrong input", "http://www.tg.c?colors=foo&colors=bar", colorMap["base"], }, { "test no input", "http://www.tg.c", colorMap["base"], }, { "test good input", "http://www.tg.c?colors=aaaaaa&colors=bbbbbb", []color.RGBA{ color.RGBA{170, 170, 170, 255}, color.RGBA{187, 187, 187, 255}, }, }, { "test good input", "http://www.tg.c?colors=ffffff&colors=000000&colors=000000", []color.RGBA{ color.RGBA{255, 255, 255, 255}, color.RGBA{0, 0, 0, 255}, color.RGBA{0, 0, 0, 255}, }[1:3], }, { "test with theme", "http://www.tg.c?theme=frogideas", colorMap["frogideas"][1:3], }, } for _, test := range tests { t.Log(test.title) r := &http.Request{Method: "GET"} r.URL, _ = url.Parse(test.url) gColors := GColors(r) if len(gColors) != len(test.gColors) { t.Errorf("expected %d array got %d", len(test.gColors), len(gColors)) } for i := 0; i < len(test.gColors); i++ { if test.gColors[i] != gColors[i] { t.Errorf("expected %+v array got %+v", test.gColors[i], gColors[i]) } } } } Loading
extract/colors.go +3 −3 Original line number Diff line number Diff line Loading @@ -97,10 +97,10 @@ func ExtraColors(req *http.Request) (color.RGBA, color.RGBA) { var err error var bg, fg color.RGBA if bg, err = Background(req); err != nil { fg = tgColors.White() bg = tgColors.White() } if fg, err = Foreground(req); err != nil { bg = tgColors.Black() fg = tgColors.Black() } return bg, fg } Loading @@ -119,7 +119,7 @@ func UserColors(req *http.Request) ([]color.RGBA, error) { for _, c := range strColors { if r, g, b, err := hexToRGB(c); err != nil { return colors, fmt.Errorf("colors: wrong input") return []color.RGBA{}, fmt.Errorf("colors: wrong input") } else { new := color.RGBA{uint8(r), uint8(g), uint8(b), uint8(255)} colors = append(colors, new) Loading
extract/colors_test.go +60 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,8 @@ import ( "net/http" "net/url" "testing" tgColors "github.com/taironas/tinygraphs/colors" ) func TestUserColors(t *testing.T) { Loading Loading @@ -43,3 +45,61 @@ func TestUserColors(t *testing.T) { } } } func TestGColors(t *testing.T) { colorMap := tgColors.MapOfColorThemes() tests := []struct { title string url string gColors []color.RGBA }{ { "test wrong input", "http://www.tg.c?colors=foo&colors=bar", colorMap["base"], }, { "test no input", "http://www.tg.c", colorMap["base"], }, { "test good input", "http://www.tg.c?colors=aaaaaa&colors=bbbbbb", []color.RGBA{ color.RGBA{170, 170, 170, 255}, color.RGBA{187, 187, 187, 255}, }, }, { "test good input", "http://www.tg.c?colors=ffffff&colors=000000&colors=000000", []color.RGBA{ color.RGBA{255, 255, 255, 255}, color.RGBA{0, 0, 0, 255}, color.RGBA{0, 0, 0, 255}, }[1:3], }, { "test with theme", "http://www.tg.c?theme=frogideas", colorMap["frogideas"][1:3], }, } for _, test := range tests { t.Log(test.title) r := &http.Request{Method: "GET"} r.URL, _ = url.Parse(test.url) gColors := GColors(r) if len(gColors) != len(test.gColors) { t.Errorf("expected %d array got %d", len(test.gColors), len(gColors)) } for i := 0; i < len(test.gColors); i++ { if test.gColors[i] != gColors[i] { t.Errorf("expected %+v array got %+v", test.gColors[i], gColors[i]) } } } }