<commit_before>package mockery

import (
	"go/format"
	"io/ioutil"
	"path/filepath"
	"testing"

	"strings"

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

const pkg = "test"

type GeneratorSuite struct {
	suite.Suite
	parser *Parser
}

func (s *GeneratorSuite) SetupTest() {
	s.parser = NewParser()
}

func (s *GeneratorSuite) getInterfaceFromFile(interfacePath, interfaceName string) *Interface {
	if !strings.Contains(interfacePath, fixturePath) {
		interfacePath = filepath.Join(fixturePath, interfacePath)
	}
	s.NoError(
		s.parser.Parse(interfacePath), "The parser is able to parse the given file.",
	)

	s.NoError(
		s.parser.Load(), "The parser is able to load the config.",
	)

	iface, err := s.parser.Find(interfaceName)
	s.NoError(err, "The requested interface was found.")
	return iface
}

func (s *GeneratorSuite) getGenerator(
	filepath, interfaceName string, inPackage bool,
) *Generator {
	return NewGenerator(
		s.getInterfaceFromFile(filepath, interfaceName), pkg, inPackage,
	)
}

func (s *GeneratorSuite) checkGeneration(
	filepath, interfaceName string, inPackage bool, expected string,
) *Generator {
	generator := s.getGenerator(filepath, interfaceName, inPackage)
	s.NoError(generator.Generate(), "The generator ran without errors.")

	// Mirror the formatting done by normally done by golang.org/x/tools/imports in Generator.Write
	//
	// While we could possibly reuse Generator.Write here in addition to Generator.Generate,
	// it would require changing Write's signature to accept custom options, specifically to
	// allow the fragmeents already used in test cases. It's assumed that this approximation,
	// just formatting the source, is sufficient for the needs of the current test styles.
	var actual []byte<commit_msg>Update generator_test.go<commit_after>package mockery

import (
	"go/format"
	"io/ioutil"
	"path/filepath"
	"testing"

	"strings"

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

const pkg = "test"

type GeneratorSuite struct {
	suite.Suite
	parser *Parser
}

func (s *GeneratorSuite) SetupTest() {
	s.parser = NewParser()
}

func (s *GeneratorSuite) getInterfaceFromFile(interfacePath, interfaceName string) *Interface {
	if !strings.Contains(interfacePath, fixturePath) {
		interfacePath = filepath.Join(fixturePath, interfacePath)
	}
	s.NoError(
		s.parser.Parse(interfacePath), "The parser is able to parse the given file.",
	)

	s.NoError(
		s.parser.Load(), "The parser is able to load the config.",
	)

	iface, err := s.parser.Find(interfaceName)
	s.NoError(err, "The requested interface was found.")
	return iface
}

func (s *GeneratorSuite) getGenerator(
	filepath, interfaceName string, inPackage bool,
) *Generator {
	return NewGenerator(
		s.getInterfaceFromFile(filepath, interfaceName), pkg, inPackage,
	)
}

func (s *GeneratorSuite) checkGeneration(
	filepath, interfaceName string, inPackage bool, expected string,
) *Generator {
	generator := s.getGenerator(filepath, interfaceName, inPackage)
	s.NoError(generator.Generate(), "The generator ran without errors.")

	// Mirror the formatting done by normally done by golang.org/x/tools/imports in Generator.Write.
	//
	// While we could possibly reuse Generator.Write here in addition to Generator.Generate,
	// it would require changing Write's signature to accept custom options, specifically to
	// allow the fragments in preexisting cases. It's assumed that this approximation,
	// just formatting the source, is sufficient for the needs of the current test styles.
	var actual []byte
{'fraction_non_alphanumeric': 0.10266704903928879, 'fraction_numerical': 0.0, 'mean_word_length': 4.8133333333333335, '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': '3917849', 'n_tokens_mistral': 1078, 'n_tokens_neox': 1045, 'n_words': 340}