package erf

import (
	"bytes"
	"testing"
)

func TestArchiveRoundTrip(t *testing.T) {
	archive := New("MOD ", []Resource{
		{Name: "module", Type: 0x07DE, Data: []byte("ifo")},
		{Name: "start", Type: 0x07DC, Data: []byte("are")},
	})

	var buf bytes.Buffer
	if err := Write(&buf, archive); err != nil {
		t.Fatalf("write: %v", err)
	}

	decoded, err := Read(bytes.NewReader(buf.Bytes()))
	if err != nil {
		t.Fatalf("read: %v", err)
	}

	if len(decoded.Resources) != 2 {
		t.Fatalf("expected 2 resources, got %d", len(decoded.Resources))
	}
	if decoded.Resources[0].Name != "module" || string(decoded.Resources[0].Data) != "ifo" {
		t.Fatalf("unexpected first resource: %#v", decoded.Resources[0])
	}
}
