package drawio_test

import (
	"testing"

	"git.mousesoft.ru/ms/drawio-exporter/pkg/drawio"
	"github.com/stretchr/testify/assert"
)

func TestFormat(t *testing.T) {
	testData := []struct {
		name   string
		err    error
		format drawio.Format
		ext    string
	}{
		{
			name:   "pdf",
			err:    nil,
			format: drawio.PDF,
			ext:    ".pdf",
		},
		{
			name:   "png",
			err:    nil,
			format: drawio.PNG,
			ext:    ".png",
		},
		{
			name:   "jpg",
			err:    nil,
			format: drawio.JPG,
			ext:    ".jpg",
		},
		{
			name:   "svg",
			err:    nil,
			format: drawio.SVG,
			ext:    ".svg",
		},
		{
			name:   "vsdx",
			err:    nil,
			format: drawio.VSDX,
			ext:    ".vsdx",
		},
		{
			name:   "xml",
			err:    nil,
			format: drawio.XML,
			ext:    ".xml",
		},
		{
			name:   "svvg",
			err:    drawio.ErrUnsupportedFormat{"svvg"},
			format: drawio.Format(""),
			ext:    "",
		},
	}
	for _, test := range testData {
		t.Run(test.name, func(t *testing.T) {
			var (
				v   drawio.Format
				err error
			)
			err = (&v).Set(test.name)
			if test.err == nil {
				assert.Equal(t, test.name, test.format.String())
				assert.NoError(t, err)
			} else {
				assert.ErrorIs(t, err, test.err)
				assert.ErrorContains(t, err, test.err.Error())
			}
		})
	}
}
