package changelog

import "testing"

func TestAll_NewestFirst(t *testing.T) {
	entries := All()
	if len(entries) == 0 {
		t.Fatal("expected at least one entry")
	}
	for i := 1; i < len(entries); i++ {
		if entries[i-1].Date < entries[i].Date {
			t.Fatalf("entries not sorted newest-first at index %d: %q before %q",
				i, entries[i-1].Date, entries[i].Date)
		}
	}
}

func TestAll_ReturnsCopy(t *testing.T) {
	a := All()
	if len(a) == 0 {
		t.Skip("no entries")
	}
	a[0] = Entry{Date: "1970-01-01"}
	b := All()
	if b[0].Date == "1970-01-01" {
		t.Fatal("All() should return an independent copy")
	}
}

func TestUnseenCount(t *testing.T) {
	if got := UnseenCount(""); got != len(Entries) {
		t.Fatalf("empty cutoff: want %d, got %d", len(Entries), got)
	}
	if got := UnseenCount("9999-12-31"); got != 0 {
		t.Fatalf("far-future cutoff: want 0, got %d", got)
	}
	// An ISO timestamp for the same day as an entry is lexicographically
	// greater than the bare date, so that entry counts as seen.
	entries := All()
	newest := entries[0].Date
	cutoff := newest + "T10:00:00Z"
	if got := UnseenCount(cutoff); got != 0 {
		t.Fatalf("same-day ISO timestamp after entry: want 0 unseen, got %d", got)
	}
}
