package builder

import (
	"os"
	"path/filepath"
	"strings"
	"testing"
)

func TestWriteIconAndVersionWinresJSON(t *testing.T) {
	dir := t.TempDir()
	full := filepath.Join(dir, "winres.json")
	if err := os.WriteFile(full, []byte(`{
  "RT_GROUP_ICON": {
    "#1": { "0409": "a.ico" }
  },
  "RT_VERSION": { "#1": { "0409": {} } }
}`), 0644); err != nil {
		t.Fatal(err)
	}
	out, err := writeIconAndVersionWinresJSON(full)
	if err != nil {
		t.Fatal(err)
	}
	raw, err := os.ReadFile(out)
	if err != nil {
		t.Fatal(err)
	}
	s := string(raw)
	if !strings.Contains(s, "RT_GROUP_ICON") || !strings.Contains(s, "a.ico") {
		t.Fatalf("unexpected icons-only json: %s", raw)
	}
	if !strings.Contains(s, "RT_VERSION") {
		t.Fatalf("version info should be preserved: %s", raw)
	}
}
