This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package wpdf
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHexToColor(t *testing.T) {
|
||||
cases := []struct {
|
||||
in uint32
|
||||
want PDFColor
|
||||
}{
|
||||
{0x000000, PDFColor{R: 0, G: 0, B: 0}},
|
||||
{0xFFFFFF, PDFColor{R: 255, G: 255, B: 255}},
|
||||
{0xFF0000, PDFColor{R: 255, G: 0, B: 0}},
|
||||
{0x00FF00, PDFColor{R: 0, G: 255, B: 0}},
|
||||
{0x0000FF, PDFColor{R: 0, G: 0, B: 255}},
|
||||
{0x123456, PDFColor{R: 0x12, G: 0x34, B: 0x56}},
|
||||
{0xC0C0C0, PDFColor{R: 192, G: 192, B: 192}},
|
||||
}
|
||||
for _, c := range cases {
|
||||
got := hexToColor(c.in)
|
||||
if got != c.want {
|
||||
t.Errorf("hexToColor(%#x) = %+v, want %+v", c.in, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHexToColorIgnoresHigherBits(t *testing.T) {
|
||||
got := hexToColor(0xFF123456)
|
||||
want := PDFColor{R: 0x12, G: 0x34, B: 0x56}
|
||||
if got != want {
|
||||
t.Errorf("hexToColor(0xFF123456) = %+v, want %+v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRgbToColor(t *testing.T) {
|
||||
got := rgbToColor(10, 20, 30)
|
||||
want := PDFColor{R: 10, G: 20, B: 30}
|
||||
if got != want {
|
||||
t.Errorf("rgbToColor(10,20,30) = %+v, want %+v", got, want)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user