<commit_before>package factory

import (
	"testing"
)

func TestFactory(t *testing.T) {
	type User struct {
		ID         int
		Name       string
		Location   string
		unexported string
	}

	userFactory := NewFactory(&User{Location: "Tokyo"}).
		SeqInt("ID", func(n int) (interface{}, error) {
			return n, nil
		}).
		Attr("Name", func(args Args) (interface{}, error) {
			return "bluele", nil
		})

	iuser, err := userFactory.Create()
	if err != nil {
		t.Error(err)
	}
	user, ok := iuser.(*User)
	if !ok {
		t.Error("It should be *User type.")
		return
	}
	if user.ID != 1 {
		t.Error("user.ID should be 1.")
		return
	}
	if user.Name != "bluele" {
		t.Error(`user.Name should be "bluele".`)
		return
	}
	if user.Location != "Tokyo" {
		t.Error(`user.Location should be "Tokyo".`)
		return
	}
}

func TestSubFactory(t *testing.T) {
	type Group struct {
		ID int
	}
	type User struct {
		ID    int
		Name  string
		Group *Group
	}

	groupFactory := NewFactory(&Group{}).
		SeqInt("ID", func(n int) (interface{}, error) {
			return n, nil
		})
<commit_msg>add map attribute tests.<commit_after>package factory

import (
	"testing"
)

func TestFactory(t *testing.T) {
	type User struct {
		ID         int
		Name       string
		Location   string
		unexported string
	}

	userFactory := NewFactory(&User{Location: "Tokyo"}).
		SeqInt("ID", func(n int) (interface{}, error) {
			return n, nil
		}).
		Attr("Name", func(args Args) (interface{}, error) {
			return "bluele", nil
		})

	iuser, err := userFactory.Create()
	if err != nil {
		t.Error(err)
	}
	user, ok := iuser.(*User)
	if !ok {
		t.Error("It should be *User type.")
		return
	}
	if user.ID != 1 {
		t.Error("user.ID should be 1.")
		return
	}
	if user.Name != "bluele" {
		t.Error(`user.Name should be "bluele".`)
		return
	}
	if user.Location != "Tokyo" {
		t.Error(`user.Location should be "Tokyo".`)
		return
	}
}

func TestMapAttrFactory(t *testing.T) {
	type User struct {
		ID  int
		Ext map[string]string
	}
	var userFactory = NewFactory(&User{}).
		SeqInt("ID", func(n int) (interface{}, error) {
			return n, nil
		}).
		Attr("Ext", func(args Args) (interface{}, error) {
			return map[string]string{"test": "ok"}, nil
		})
	user := &User{}
	if err := userFactory.Construct(user); err != nil {
		t.Error(err)
		return
	}
	if user.ID == 0 {
		t.Error("user.ID should not be 0.")
	}
	if v, ok := user.Ext["test"]; !ok {
		t.Error("user.Ext[\"test\"] should not be empty.")
	} else if v != "ok" {
		t.Error("user.Ext[\"test\"] should be ok.")
	}
}

func TestSubFactory(t *testing.T) {
	type Group struct {
		ID int
	}
	type User struct {
		ID    int
		Name  string
		Group *Group
	}

	groupFactory := NewFactory(&Group{}).
		SeqInt("ID", func(n int) (interface{}, error) {
			return n, nil
		})

{'fraction_non_alphanumeric': 0.1681159420289855, 'fraction_numerical': 0.002173913043478261, 'mean_word_length': 3.0365497076023393, 'pattern_counts': {'":': 1, '<': 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': '885717', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1029, 'n_words': 280}