Added a test specifically to cover the NRGBA interface handling, so that I could get 100% coverage.

This commit is contained in:
Amy G. Dalin 2025-02-20 14:14:43 -05:00
parent 080e096c1d
commit 299a2b9c9d
2 changed files with 23 additions and 1 deletions

View File

@ -194,5 +194,8 @@ var (
Model = color.ModelFunc(okLabModel)
// Type assertions.
_ NRGBAColor = Color{}
_ interface {
color.Color
NRGBAColor
} = Color{}
)

View File

@ -76,6 +76,18 @@ func fixedNRGBA64Model(c color.Color) color.Color {
return color.NRGBA64Model.Convert(c)
}
type testNRGBAColor struct {
color.NRGBA64
}
func (c testNRGBAColor) NRGBA() (r, g, b, a uint32) {
return uint32(c.R), uint32(c.G), uint32(c.B), uint32(c.A)
}
func testNRGBAModel(c color.Color) color.Color {
return testNRGBAColor{fixedNRGBA64Model(c).(color.NRGBA64)}
}
func Test_Model(t *testing.T) {
// test to make sure we can reproduce some test colors.
// In particular, I want to make sure the colors can be recovered from transparent NRGBA and NRGBA64.
@ -136,6 +148,13 @@ func Test_Model(t *testing.T) {
"RGBA: invisible nothing",
color.RGBA{R: 0x0, G: 0x0, B: 0x0, A: 0x0},
color.RGBAModel,
}, {
// test the handling of the NRGBAColor interface; as
// all the types that support it have special handling
// that would take precidence.
"testNRGBAColor: invisible Floral White",
testNRGBAColor{color.NRGBA64{R: 0xff, G: 0xfa, B: 0xf0, A: 0x00}},
color.ModelFunc(testNRGBAModel),
},
} {
t.Run(tt.name, func(t *testing.T) {