package version_test

import (
	"testing"

	"github.com/leonmika/wails-release/internal/version"
)

func TestResolve(t *testing.T) {
	cases := []struct {
		name     string
		override string
		ref      string
		sha      string
		want     string
	}{
		{"override wins", "9.9.9", "refs/tags/v1.2.3", "abcdefg1234", "9.9.9"},
		{"clean tag strips v", "", "refs/tags/v1.2.3", "abcdefg1234", "1.2.3"},
		{"prerelease tag falls back to sha", "", "refs/tags/v1.2.3-rc1", "abcdefg1234", "abcdefg"},
		{"non-tag ref falls back to sha", "", "refs/heads/main", "abcdefg1234", "abcdefg"},
		{"empty ref falls back to sha", "", "", "abcdefg1234", "abcdefg"},
		{"short sha shorter than 7 returned verbatim", "", "", "abc", "abc"},
	}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			got := version.Resolve(c.override, c.ref, c.sha)
			if got != c.want {
				t.Fatalf("got %q, want %q", got, c.want)
			}
		})
	}
}
