package go_kv

import (
	"errors"
	"fmt"
	"testing"
)

func TestErrorTypes(t *testing.T) {
	allErrors := []error{
		ErrCommitUnknown,
		ErrWriteStopped,
		ErrSequenceExhausted,
		ErrWALCorrupted,
		ErrInvalidConfig,
	}

	// Each error must match itself via errors.Is.
	for _, err := range allErrors {
		if !errors.Is(err, err) {
			t.Errorf("errors.Is(%v, %v) = false, want true", err, err)
		}
	}

	// Each error must NOT match any other error.
	for i, a := range allErrors {
		for j, b := range allErrors {
			if i == j {
				continue
			}
			if errors.Is(a, b) {
				t.Errorf("errors.Is(%v, %v) = true, want false (distinct errors)", a, b)
			}
		}
	}

	// Wrapped errors must still be identifiable via errors.Is.
	wrapped := fmt.Errorf("operation failed: %w", ErrCommitUnknown)
	if !errors.Is(wrapped, ErrCommitUnknown) {
		t.Errorf("errors.Is(wrapped ErrCommitUnknown, ErrCommitUnknown) = false, want true")
	}
}
