mirror of
https://github.com/charmbracelet/lipgloss.git
synced 2024-09-11 22:17:12 +03:00
test: add RGBA tests
This commit is contained in:
parent
09292df479
commit
cabfd38a13
144
color_test.go
144
color_test.go
@ -7,8 +7,6 @@ import (
|
||||
)
|
||||
|
||||
func TestSetColorProfile(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tt := []struct {
|
||||
profile termenv.Profile
|
||||
input string
|
||||
@ -85,3 +83,145 @@ func TestHexToColor(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRGBA(t *testing.T) {
|
||||
tt := []struct {
|
||||
profile termenv.Profile
|
||||
darkBg bool
|
||||
input TerminalColor
|
||||
expected uint
|
||||
}{
|
||||
// lipgloss.Color
|
||||
{
|
||||
termenv.TrueColor,
|
||||
true,
|
||||
Color("#FF0000"),
|
||||
0xFF0000,
|
||||
},
|
||||
{
|
||||
termenv.TrueColor,
|
||||
true,
|
||||
Color("9"),
|
||||
0xFF0000,
|
||||
},
|
||||
{
|
||||
termenv.TrueColor,
|
||||
true,
|
||||
Color("21"),
|
||||
0x0000FF,
|
||||
},
|
||||
// lipgloss.AdaptiveColor
|
||||
{
|
||||
termenv.TrueColor,
|
||||
true,
|
||||
AdaptiveColor{Dark: "#FF0000", Light: "#0000FF"},
|
||||
0xFF0000,
|
||||
},
|
||||
{
|
||||
termenv.TrueColor,
|
||||
false,
|
||||
AdaptiveColor{Dark: "#FF0000", Light: "#0000FF"},
|
||||
0x0000FF,
|
||||
},
|
||||
{
|
||||
termenv.TrueColor,
|
||||
true,
|
||||
AdaptiveColor{Dark: "9", Light: "21"},
|
||||
0xFF0000,
|
||||
},
|
||||
{
|
||||
termenv.TrueColor,
|
||||
false,
|
||||
AdaptiveColor{Dark: "9", Light: "21"},
|
||||
0x0000FF,
|
||||
},
|
||||
// lipgloss.CompleteColor
|
||||
{
|
||||
termenv.TrueColor,
|
||||
true,
|
||||
CompleteColor{TrueColor: "#FF0000", ANSI256: "231", ANSI: "12"},
|
||||
0xFF0000,
|
||||
},
|
||||
{
|
||||
termenv.ANSI256,
|
||||
true,
|
||||
CompleteColor{TrueColor: "#FF0000", ANSI256: "231", ANSI: "12"},
|
||||
0xFFFFFF,
|
||||
},
|
||||
{
|
||||
termenv.ANSI,
|
||||
true,
|
||||
CompleteColor{TrueColor: "#FF0000", ANSI256: "231", ANSI: "12"},
|
||||
0x0000FF,
|
||||
},
|
||||
// lipgloss.CompleteAdaptiveColor
|
||||
// dark
|
||||
{
|
||||
termenv.TrueColor,
|
||||
true,
|
||||
CompleteAdaptiveColor{
|
||||
Dark: CompleteColor{TrueColor: "#FF0000", ANSI256: "231", ANSI: "12"},
|
||||
Light: CompleteColor{TrueColor: "#0000FF", ANSI256: "231", ANSI: "12"},
|
||||
},
|
||||
0xFF0000,
|
||||
},
|
||||
{
|
||||
termenv.ANSI256,
|
||||
true,
|
||||
CompleteAdaptiveColor{
|
||||
Dark: CompleteColor{TrueColor: "#FF0000", ANSI256: "231", ANSI: "12"},
|
||||
Light: CompleteColor{TrueColor: "#FF0000", ANSI256: "21", ANSI: "12"},
|
||||
},
|
||||
0xFFFFFF,
|
||||
},
|
||||
{
|
||||
termenv.ANSI,
|
||||
true,
|
||||
CompleteAdaptiveColor{
|
||||
Dark: CompleteColor{TrueColor: "#FF0000", ANSI256: "231", ANSI: "12"},
|
||||
Light: CompleteColor{TrueColor: "#FF0000", ANSI256: "231", ANSI: "9"},
|
||||
},
|
||||
0x0000FF,
|
||||
},
|
||||
// light
|
||||
{
|
||||
termenv.TrueColor,
|
||||
false,
|
||||
CompleteAdaptiveColor{
|
||||
Dark: CompleteColor{TrueColor: "#FF0000", ANSI256: "231", ANSI: "12"},
|
||||
Light: CompleteColor{TrueColor: "#0000FF", ANSI256: "231", ANSI: "12"},
|
||||
},
|
||||
0x0000FF,
|
||||
},
|
||||
{
|
||||
termenv.ANSI256,
|
||||
false,
|
||||
CompleteAdaptiveColor{
|
||||
Dark: CompleteColor{TrueColor: "#FF0000", ANSI256: "231", ANSI: "12"},
|
||||
Light: CompleteColor{TrueColor: "#FF0000", ANSI256: "21", ANSI: "12"},
|
||||
},
|
||||
0x0000FF,
|
||||
},
|
||||
{
|
||||
termenv.ANSI,
|
||||
false,
|
||||
CompleteAdaptiveColor{
|
||||
Dark: CompleteColor{TrueColor: "#FF0000", ANSI256: "231", ANSI: "12"},
|
||||
Light: CompleteColor{TrueColor: "#FF0000", ANSI256: "231", ANSI: "9"},
|
||||
},
|
||||
0xFF0000,
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range tt {
|
||||
SetColorProfile(tc.profile)
|
||||
SetHasDarkBackground(tc.darkBg)
|
||||
|
||||
r, g, b, _ := tc.input.RGBA()
|
||||
o := uint(r/256)<<16 + uint(g/256)<<8 + uint(b/256)
|
||||
|
||||
if o != tc.expected {
|
||||
t.Errorf("expected %X, got %X (test #%d)", tc.expected, o, i+1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user