83 lines
1.7 KiB
Go
Raw Normal View History

2024-03-05 16:47:02 +00:00
package color_test
import (
"testing"
"git.akyoto.dev/go/assert"
"git.akyoto.dev/go/color"
)
2024-03-06 18:23:49 +00:00
func TestPrint(t *testing.T) {
2024-03-05 18:10:27 +00:00
color.Terminal = true
2024-03-06 18:23:49 +00:00
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")
2024-03-05 18:10:27 +00:00
}
2024-03-11 21:08:28 +00:00
func TestPrintf(t *testing.T) {
color.Terminal = true
color.RGB(1, 0, 0).Printf("%s\n", "red")
color.RGB(0, 1, 0).Printf("%s\n", "green")
color.RGB(0, 0, 1).Printf("%s\n", "blue")
color.Terminal = false
color.RGB(1, 0, 0).Printf("%s\n", "red")
color.RGB(0, 1, 0).Printf("%s\n", "green")
color.RGB(0, 0, 1).Printf("%s\n", "blue")
}
2024-03-06 18:23:49 +00:00
func TestPrintln(t *testing.T) {
2024-03-05 23:18:51 +00:00
color.Terminal = true
2024-03-06 18:23:49 +00:00
color.RGB(1, 0, 0).Println("red")
color.RGB(0, 1, 0).Println("green")
color.RGB(0, 0, 1).Println("blue")
2024-03-05 23:18:51 +00:00
2024-03-06 18:23:49 +00:00
color.Terminal = false
2024-03-05 23:18:51 +00:00
2024-03-06 18:23:49 +00:00
color.RGB(1, 0, 0).Println("red")
color.RGB(0, 1, 0).Println("green")
color.RGB(0, 0, 1).Println("blue")
2024-03-05 18:10:27 +00:00
}
2024-03-06 18:23:49 +00:00
func TestRGB(t *testing.T) {
color.Terminal = true
2024-03-05 23:18:51 +00:00
rgbColors := map[string]color.Color{
2024-03-06 18:23:49 +00:00
"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),
2024-03-05 16:47:02 +00:00
}
2024-03-05 23:18:51 +00:00
for name, c := range rgbColors {
2024-03-06 18:23:49 +00:00
testColorRange(t, c)
c.Println("█ " + name)
2024-03-05 23:18:51 +00:00
}
}
2024-03-05 16:47:02 +00:00
2024-03-06 18:23:49 +00:00
func testColorRange(t *testing.T, c color.Color) {
2024-03-05 23:18:51 +00:00
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)
}