package color_test import ( "io" "testing" "git.akyoto.dev/go/assert" "git.akyoto.dev/go/color" ) func TestFprint(t *testing.T) { color.Terminal = true color.RGB(1, 0, 0).Fprint(io.Discard, "red") color.RGB(0, 1, 0).Fprint(io.Discard, "green") color.RGB(0, 0, 1).Fprint(io.Discard, "blue") color.Terminal = false color.RGB(1, 0, 0).Fprint(io.Discard, "red") color.RGB(0, 1, 0).Fprint(io.Discard, "green") color.RGB(0, 0, 1).Fprint(io.Discard, "blue") } func TestPrint(t *testing.T) { color.Terminal = true color.RGB(1, 0, 0).Print("red\n") color.RGB(0, 1, 0).Print("green\n") color.RGB(0, 0, 1).Print("blue\n") color.Terminal = false color.RGB(1, 0, 0).Print("red\n") color.RGB(0, 1, 0).Print("green\n") color.RGB(0, 0, 1).Print("blue\n") } func TestPrintln(t *testing.T) { color.Terminal = true color.RGB(1, 0, 0).Println("red") color.RGB(0, 1, 0).Println("green") color.RGB(0, 0, 1).Println("blue") color.Terminal = false color.RGB(1, 0, 0).Println("red") color.RGB(0, 1, 0).Println("green") color.RGB(0, 0, 1).Println("blue") } func TestRGB(t *testing.T) { color.Terminal = true rgbColors := map[string]color.Color{ "black": color.RGB(0, 0, 0), "white": color.RGB(1, 1, 1), "gray": color.RGB(0.5, 0.5, 0.5), "red": color.RGB(1, 0, 0), "green": color.RGB(0, 1, 0), "blue": color.RGB(0, 0, 1), "cyan": color.RGB(0, 1, 1), "yellow": color.RGB(1, 1, 0), "orange": color.RGB(1, 0.5, 0), "magenta": color.RGB(1, 0, 1), } for name, c := range rgbColors { testColorRange(t, c) c.Println("█ " + name) } } func testColorRange(t *testing.T, c color.Color) { assert.True(t, c.R >= 0.0) assert.True(t, c.G >= 0.0) assert.True(t, c.B >= 0.0) assert.True(t, c.R <= 1.0) assert.True(t, c.G <= 1.0) assert.True(t, c.B <= 1.0) }