44 lines
825 B
Go
Raw Normal View History

2024-03-05 16:47:02 +00:00
package color_test
import (
2024-03-05 18:10:27 +00:00
"io"
2024-03-05 16:47:02 +00:00
"testing"
"git.akyoto.dev/go/assert"
"git.akyoto.dev/go/color"
)
func TestColors(t *testing.T) {
2024-03-05 18:10:27 +00:00
color.Terminal = true
testColors(t)
}
func TestNoColors(t *testing.T) {
color.Terminal = false
testColors(t)
}
func testColors(t *testing.T) {
2024-03-05 16:47:02 +00:00
colors := map[string]color.Color{
"black": color.RGB(0.0, 0.0, 0.0),
"white": color.RGB(1.0, 1.0, 1.0),
"red": color.RGB(1.0, 0.0, 0.0),
"green": color.RGB(0.0, 1.0, 0.0),
"blue": color.RGB(0.0, 0.0, 1.0),
}
for name, value := range colors {
assert.True(t, value.R >= 0.0)
assert.True(t, value.G >= 0.0)
assert.True(t, value.B >= 0.0)
assert.True(t, value.R <= 1.0)
assert.True(t, value.G <= 1.0)
assert.True(t, value.B <= 1.0)
2024-03-05 18:10:27 +00:00
value.Fprint(io.Discard, name)
2024-03-05 16:47:02 +00:00
value.Print(name)
value.Println(name)
}
}