Example #1
0
// ExtraColors returns a background and foreground color.RGBA is specified.
// returns black and white otherwise
func ExtraColors(req *http.Request) (color.RGBA, color.RGBA) {
	var err error
	var bg, fg color.RGBA
	if bg, err = Background(req); err != nil {
		bg = tgColors.White()
	}

	if fg, err = Foreground(req); err != nil {
		fg = tgColors.Black()
	}
	return bg, fg
}
Example #2
0
func TestExtraColors(t *testing.T) {
	t.Parallel()

	tests := []struct {
		title string
		url   string
		bg    color.RGBA
		fg    color.RGBA
	}{
		{
			"test wrong input",
			"http://www.tg.c?fg=foo&bg=bar",
			tgColors.White(),
			tgColors.Black(),
		},
		{
			"test no input",
			"http://www.tg.c",
			tgColors.White(),
			tgColors.Black(),
		},
		{
			"test good input",
			"http://www.tg.c?fg=aaaaaa&bg=bbbbbb",
			color.RGBA{187, 187, 187, 255},
			color.RGBA{170, 170, 170, 255},
		},
	}

	for _, test := range tests {
		t.Log(test.title)
		r := &http.Request{Method: "GET"}
		r.URL, _ = url.Parse(test.url)
		bg, fg := ExtraColors(r)
		if fg != test.fg || bg != test.bg {
			t.Errorf("expected %+v got %+v", test.fg, fg)
			t.Errorf("expected %+v got %+v", test.bg, bg)
		}
	}
}