func TestAgainstJSONEncodingEmbeddedTime(t *testing.T) {
	timeLeafFn := func(t reflect.Type) bool {
		return t == reflect.TypeOf(time.Time{})
	}
	now := time.Now().UTC()
	myt := Time{
		now,
	}
	var want Time
	jsonRoundTrip(t, myt, &want)
	var got Time
	fields, err := NewCache(nil, nil, timeLeafFn).Fields(reflect.TypeOf(got))
	if err != nil {
		t.Fatal(err)
	}
	setFields(fields, &got, myt)
	if !reflect.DeepEqual(got, want) {
		t.Errorf("got\n%+v\nwant\n%+v", got, want)
	}
}
Tests use of LeafTypes parameter to NewCache
package fields
import (
	"encoding/json"
	"errors"
	"fmt"
	"reflect"
	"strings"
	"testing"
	"time"
)
type embed1 struct {
	Em1    int
	Dup    int  
	Shadow int
	embed3
}
type embed2 struct {
	Dup int
	embed3
	embed4
}
type embed3 struct {
	Em3 int  
	embed5
}
type embed4 struct {
	Em4     int
	Dup     int  
	*embed1      
}
type embed5 struct {
	x int
}
type Anonymous int
type S1 struct {
	Exported   int
	unexported int
	Shadow     int  
	embed1
	*embed2
	Anonymous
}
type Time struct {
	time.Time
}
var intType = reflect.TypeOf(int(0))
func field(name string, tval interface{}, index ...int) *Field {
	return &Field{
		Name:  name,
		Type:  reflect.TypeOf(tval),
		Index: index,
	}
}
func tfield(name string, tval interface{}, index ...int) *Field {
	return &Field{
		Name:        name,
		Type:        reflect.TypeOf(tval),
		Index:       index,
		NameFromTag: true,
	}
}
func TestFieldsNoTags(t *testing.T) {
	c := NewCache(nil, nil, nil)
	got, err := c.Fields(reflect.TypeOf(S1{}))
	if err != nil {
		t.Fatal(err)
	}
	want := []*Field{
		field("Exported", int(0), 0),
		field("Shadow", int(0), 2),
		field("Em1", int(0), 3, 0),
		field("Em4", int(0), 4, 2, 0),
		field("Anonymous", Anonymous(0), 5),
	}
	if msg, ok := compareFields(got, want); !ok {
		t.Error(msg)
	}
}
func TestAgainstJSONEncodingNoTags(t *testing.T) {
	s1 := S1{
		Exported:   1,
		unexported: 2,
		Shadow:     3,
		embed1: embed1{
			Em1:    4,
			Dup:    5,
			Shadow: 6,
			embed3: embed3{
				Em3:    7,
				embed5: embed5{x: 8},
			},
		},
		embed2: &embed2{
			Dup: 9,
			embed3: embed3{
				Em3:    10,
				embed5: embed5{x: 11},
			},
			embed4: embed4{
				Em4:    12,
				Dup:    13,
				embed1: &embed1{Em1: 14},
			},
		},
		Anonymous: Anonymous(15),
	}
	var want S1
	jsonRoundTrip(t, s1, &want)
	var got S1
	got.embed2 = &embed2{}  
	fields, err := NewCache(nil, nil, nil).Fields(reflect.TypeOf(got))
	if err != nil {
		t.Fatal(err)
	}
	setFields(fields, &got, s1)
	if !reflect.DeepEqual(got, want) {
		t.Errorf("got\n%+v\nwant\n%+v", got, want)
	}
}