package fonts

import (
	"fmt"
	"image/color"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestFont_ToColor(t *testing.T) {
	tests := []struct {
		name           string
		font           Font
		char           string
		color          color.RGBA
		wantMappedChar [][]color.RGBA
		wantError      error
	}{
		{
			name:      "it should error if char mapping doesn't exist",
			font:      Font{},
			char:      "not found",
			wantError: fmt.Errorf("%w: %s", ErrCharNotFound, "not found"),
		},
		{
			name:  "it should produce a color mapped character",
			font:  Face5x4,
			char:  "1",
			color: White,
			wantMappedChar: [][]color.RGBA{
				{{R: 255, G: 255, B: 255, A: 0}, {R: 255, G: 255, B: 255, A: 255}, {R: 255, G: 255, B: 255, A: 0}, {R: 255, G: 255, B: 255, A: 0}},
				{{R: 255, G: 255, B: 255, A: 0}, {R: 255, G: 255, B: 255, A: 255}, {R: 255, G: 255, B: 255, A: 0}, {R: 255, G: 255, B: 255, A: 0}},
				{{R: 255, G: 255, B: 255, A: 0}, {R: 255, G: 255, B: 255, A: 255}, {R: 255, G: 255, B: 255, A: 0}, {R: 255, G: 255, B: 255, A: 0}},
				{{R: 255, G: 255, B: 255, A: 0}, {R: 255, G: 255, B: 255, A: 255}, {R: 255, G: 255, B: 255, A: 0}, {R: 255, G: 255, B: 255, A: 0}},
				{{R: 255, G: 255, B: 255, A: 0}, {R: 255, G: 255, B: 255, A: 255}, {R: 255, G: 255, B: 255, A: 0}, {R: 255, G: 255, B: 255, A: 0}},
			},
		},
	}

	for _, test := range tests {
		t.Run(test.name, func(t *testing.T) {
			mappedChar, err := test.font.ToColor(test.char, test.color)

			assert.Equal(t, test.wantMappedChar, mappedChar)
			assert.Equal(t, test.wantError, err)
		})
	}
}
