Added a test specifically to cover the NRGBA interface handling, so that I could get 100% coverage.
This commit is contained in:
		
							
								
								
									
										5
									
								
								oklab.go
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								oklab.go
									
									
									
									
									
								
							| @ -194,5 +194,8 @@ var ( | ||||
| 	Model = color.ModelFunc(okLabModel) | ||||
|  | ||||
| 	// Type assertions. | ||||
| 	_ NRGBAColor = Color{} | ||||
| 	_ interface { | ||||
| 		color.Color | ||||
| 		NRGBAColor | ||||
| 	} = Color{} | ||||
| ) | ||||
|  | ||||
| @ -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) { | ||||
|  | ||||
		Reference in New Issue
	
	Block a user