func TestFreelist_read(t *testing.T) {
	var buf [4096]byte
	page := (*page)(unsafe.Pointer(&buf[0]))
	page.flags = freelistPageFlag
	page.count = 2
	ids := (*[3]pgid)(unsafe.Pointer(&page.ptr))
	ids[0] = 23
	ids[1] = 50
	f := &freelist{pending: make(map[txid][]pgid)}
	f.read(page)
	assert.Equal(t, len(f.ids), 2)
	assert.Equal(t, f.ids[0], pgid(23))
	assert.Equal(t, f.ids[1], pgid(50))
}
Ensure that a freelist can deserialize from a freelist page.
package bolt
import (
	"testing"
	"unsafe"
	"github.com/stretchr/testify/assert"
)
func TestFreelist_free(t *testing.T) {
	f := &freelist{pending: make(map[txid][]pgid)}
	f.free(100, &page{id: 12})
	assert.Equal(t, f.pending[100], []pgid{12})
}
func TestFreelist_free_overflow(t *testing.T) {
	f := &freelist{pending: make(map[txid][]pgid)}
	f.free(100, &page{id: 12, overflow: 3})
	assert.Equal(t, f.pending[100], []pgid{12, 13, 14, 15})
}
func TestFreelist_release(t *testing.T) {
	f := &freelist{pending: make(map[txid][]pgid)}
	f.free(100, &page{id: 12, overflow: 1})
	f.free(100, &page{id: 9})
	f.free(102, &page{id: 39})
	f.release(100)
	f.release(101)
	assert.Equal(t, f.ids, []pgid{13, 12, 9})
	f.release(102)
	assert.Equal(t, f.ids, []pgid{39, 13, 12, 9})
}
func TestFreelist_allocate(t *testing.T) {
	f := &freelist{ids: []pgid{18, 13, 12, 9, 7, 6, 5, 4, 3}}
	assert.Equal(t, f.allocate(2), pgid(12))
	assert.Equal(t, f.allocate(1), pgid(18))
	assert.Equal(t, f.allocate(3), pgid(5))
	assert.Equal(t, f.allocate(3), pgid(0))
	assert.Equal(t, f.allocate(2), pgid(3))
	assert.Equal(t, f.allocate(1), pgid(9))
	assert.Equal(t, f.allocate(0), pgid(0))
	assert.Equal(t, f.ids, []pgid{})
}