<commit_before>package reflector

import (
	"errors"
	"fmt"
	"reflect"
	"testing"

	"github.com/stretchr/testify/assert"
)

type Address struct {
	Street string `tag:"be" tag2:"1,2,3"`
	Number int    `tag:"bi"`
}

type Person struct {
	Name string `tag:"bu"`
	Address
}

func (p Person) Add(a, b, c int) int     { return a + b + c }
func (p *Person) Substract(a, b int) int { return a - b }
func (p Person) ReturnsError(err bool) (string, *int, error) {
	i := 2
	if err {
		return "", nil, errors.New("Error here!")
	}
	return "jen", &i, nil
}

type CustomType int

func (ct CustomType) Method1() string { return "yep" }
func (ct *CustomType) Method2() int   { return 7 }

func (p Person) Hi(name string) string {
	return fmt.Sprintf("Hi %s my name is %s", name, p.Name)
}

type Company struct {
	Address
	Number int `tag:"bi"`
}

// TestDoubleFields checks that there are no "double" fields (or fields shadowing)
func TestDoubleFields(t *testing.T) {
	structs := []interface{}{
		Obj{},
		ObjField{},
		ObjMethod{},
		ObjMetadata{},
		ObjFieldMetadata{},
		ObjMethodMetadata{},
	}
	for _, s := range structs {
		double := New(s).FindDoubleFields()
		assert.Equal(t, 0, len(double))
	}
}

func TestString(t *testing.T) {
	assert.Equal(t, "reflector.Person", New(Person{}).String())
	assert.Equal(t, "*reflector.Person", New(&Person{}).String())
	assert.Equal(t, "nil", New(nil).String())
	assert.Equal(t, "int", New(1).String())
	var i int
	assert.Equal(t, "*int", New(&i).String())

	// Check that when we twice get a field, the metadata field is cached only once:
	assert.Equal(t, New(Person{}).Field("bu").ObjFieldMetadata, New(Person{}).Field("bu").ObjFieldMetadata)
	assert.Equal(t, New(&Person{}).Field("bu").ObjFieldMetadata, New(&Person{}).Field("bu").ObjFieldMetadata)
	assert.Equal(t, New(Person{}).Field("Address").ObjFieldMetadata, New(Person{}).Field("Address").ObjFieldMetadata)
	assert.Equal(t, New(&Person{}).Field("bu").ObjFieldMetadata, New(&Person{}).Field("bu").ObjFieldMetadata)
}

func _TestNilStringPtr(t *testing.T) {
	assert.Equal(t, "*string", New((*string)(nil)).String())
	assert.Equal(t, 0, len(New((*string)(nil)).Fields()))
	assert.Equal(t, 0, len(New((*string)(nil)).Methods()))

	v, err := New((*string)(nil)).Field("Bu").Get()
	assert.Nil(t, v)
	assert.NotNil(t, err)
}

func TestNilStructPtr(t *testing.T) {
	assert.Equal(t, "*reflector.Person", New((*Person)(nil)).String())
	assert.Equal(t, 2, len(New((*Person)(nil)).Fields()))
	assert.Equal(t, 4, len(New((*Person)(nil)).Methods()))

	err := New((*Person)(nil)).Field("Number").Set(17)
	assert.NotNil(t, err)<commit_msg>Unignore test<commit_after>package reflector

import (
	"errors"
	"fmt"
	"reflect"
	"testing"

	"github.com/stretchr/testify/assert"
)

type Address struct {
	Street string `tag:"be" tag2:"1,2,3"`
	Number int    `tag:"bi"`
}

type Person struct {
	Name string `tag:"bu"`
	Address
}

func (p Person) Add(a, b, c int) int     { return a + b + c }
func (p *Person) Substract(a, b int) int { return a - b }
func (p Person) ReturnsError(err bool) (string, *int, error) {
	i := 2
	if err {
		return "", nil, errors.New("Error here!")
	}
	return "jen", &i, nil
}

type CustomType int

func (ct CustomType) Method1() string { return "yep" }
func (ct *CustomType) Method2() int   { return 7 }

func (p Person) Hi(name string) string {
	return fmt.Sprintf("Hi %s my name is %s", name, p.Name)
}

type Company struct {
	Address
	Number int `tag:"bi"`
}

// TestDoubleFields checks that there are no "double" fields (or fields shadowing)
func TestDoubleFields(t *testing.T) {
	structs := []interface{}{
		Obj{},
		ObjField{},
		ObjMethod{},
		ObjMetadata{},
		ObjFieldMetadata{},
		ObjMethodMetadata{},
	}
	for _, s := range structs {
		double := New(s).FindDoubleFields()
		assert.Equal(t, 0, len(double))
	}
}

func TestString(t *testing.T) {
	assert.Equal(t, "reflector.Person", New(Person{}).String())
	assert.Equal(t, "*reflector.Person", New(&Person{}).String())
	assert.Equal(t, "nil", New(nil).String())
	assert.Equal(t, "int", New(1).String())
	var i int
	assert.Equal(t, "*int", New(&i).String())

	// Check that when we twice get a field, the metadata field is cached only once:
	assert.Equal(t, New(Person{}).Field("bu").ObjFieldMetadata, New(Person{}).Field("bu").ObjFieldMetadata)
	assert.Equal(t, New(&Person{}).Field("bu").ObjFieldMetadata, New(&Person{}).Field("bu").ObjFieldMetadata)
	assert.Equal(t, New(Person{}).Field("Address").ObjFieldMetadata, New(Person{}).Field("Address").ObjFieldMetadata)
	assert.Equal(t, New(&Person{}).Field("bu").ObjFieldMetadata, New(&Person{}).Field("bu").ObjFieldMetadata)
}

func TestNilStringPtr(t *testing.T) {
	assert.Equal(t, "*string", New((*string)(nil)).String())
	assert.Equal(t, 0, len(New((*string)(nil)).Fields()))
	assert.Equal(t, 0, len(New((*string)(nil)).Methods()))

	v, err := New((*string)(nil)).Field("Bu").Get()
	assert.Nil(t, v)
	assert.NotNil(t, err)
}

func TestNilStructPtr(t *testing.T) {
	assert.Equal(t, "*reflector.Person", New((*Person)(nil)).String())
	assert.Equal(t, 2, len(New((*Person)(nil)).Fields()))
	assert.Equal(t, 4, len(New((*Person)(nil)).Methods()))

	err := New((*Person)(nil)).Field("Number").Set(17)
	assert.NotNil(t, err)
{'fraction_non_alphanumeric': 0.20471535365152385, 'fraction_numerical': 0.006133793367835921, 'mean_word_length': 5.211904761904762, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6482825', 'n_tokens_mistral': 1912, 'n_tokens_neox': 1866, 'n_words': 440}