package wal

import "testing"

func TestConstantValues(t *testing.T) {
	tests := []struct {
		name     string
		got      interface{}
		expected interface{}
	}{
		{"WalBlockSize", WalBlockSize, 32 * 1024},
		{"WalFileHeaderSize", WalFileHeaderSize, 32},
		{"WalBatchHeaderSize", WalBatchHeaderSize, 18},
		{"PhysicalRecordHeaderSize", PhysicalRecordHeaderSize, 7},
		{"MaxWalBatchEntriesSize", MaxWalBatchEntriesSize, uint32(4 * 1024 * 1024)},
		{"MaxWalBatchEntryCount", MaxWalBatchEntryCount, uint32(10000)},
		{"MaxWalKeyBytes", MaxWalKeyBytes, uint32(4 * 1024)},
		{"MaxWalInlineValueBytes", MaxWalInlineValueBytes, uint32(4 * 1024)},
		{"MaxWalVarintBytes", MaxWalVarintBytes, 5},
		{"DefaultMaxWalSegmentSize", DefaultMaxWalSegmentSize, uint64(64 * 1024 * 1024)},
		{"WalMagic", WalMagic, uint32(0x57414C4B)},
		{"WalFormatVersion", WalFormatVersion, uint16(1)},
	}

	for _, tt := range tests {
		if tt.got != tt.expected {
			t.Errorf("%s = %v, want %v", tt.name, tt.got, tt.expected)
		}
	}
}

func TestFragmentTypes(t *testing.T) {
	if RecInvalid != uint8(0) {
		t.Errorf("RecInvalid = %d, want 0", RecInvalid)
	}
	if RecFull != uint8(1) {
		t.Errorf("RecFull = %d, want 1", RecFull)
	}
	if RecFirst != uint8(2) {
		t.Errorf("RecFirst = %d, want 2", RecFirst)
	}
	if RecMiddle != uint8(3) {
		t.Errorf("RecMiddle = %d, want 3", RecMiddle)
	}
	if RecLast != uint8(4) {
		t.Errorf("RecLast = %d, want 4", RecLast)
	}
}

func TestOpTypes(t *testing.T) {
	if OpInvalid != uint8(0) {
		t.Errorf("OpInvalid = %d, want 0", OpInvalid)
	}
	if OpPut != uint8(1) {
		t.Errorf("OpPut = %d, want 1", OpPut)
	}
	if OpDelete != uint8(2) {
		t.Errorf("OpDelete = %d, want 2", OpDelete)
	}
}

func TestValueKinds(t *testing.T) {
	if VKNone != uint8(0) {
		t.Errorf("VKNone = %d, want 0", VKNone)
	}
	if VKInline != uint8(1) {
		t.Errorf("VKInline = %d, want 1", VKInline)
	}
	if VKValueLogPointer != uint8(2) {
		t.Errorf("VKValueLogPointer = %d, want 2", VKValueLogPointer)
	}
}
