Skip to content

Commit

Permalink
shuffling around
Browse files Browse the repository at this point in the history
  • Loading branch information
LandonTClipp committed Jan 2, 2025
1 parent 705aec3 commit 365b8eb
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 29 deletions.
5 changes: 2 additions & 3 deletions internal/template_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/chigopher/pathlib"
"github.com/rs/zerolog"
"github.com/vektra/mockery/v3/internal/stackerr"
"github.com/vektra/mockery/v3/registry"
"github.com/vektra/mockery/v3/template"
"golang.org/x/tools/go/packages"
"golang.org/x/tools/imports"
Expand Down Expand Up @@ -101,7 +100,7 @@ func findPkgPath(dirPath *pathlib.Path) (string, error) {

type TemplateGenerator struct {
templateName string
registry *registry.Registry
registry *template.Registry
formatter Formatter
pkgConfig *Config
inPackage bool
Expand Down Expand Up @@ -148,7 +147,7 @@ func NewTemplateGenerator(
log.Debug().Msg("output package detected to not be in-package of original package")
}

reg, err := registry.New(srcPkg, outPkgPath, inPackage)
reg, err := template.NewRegistry(srcPkg, outPkgPath, inPackage)
if err != nil {
return nil, fmt.Errorf("creating new registry: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion mockery-tools.env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION=v3.0.0-alpha.11
VERSION=v3.0.0-alpha.12
2 changes: 1 addition & 1 deletion registry/method_scope.go → template/method_scope.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package registry
package template

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion registry/package.go → template/package.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package registry
package template

import (
"strings"
Expand Down
4 changes: 2 additions & 2 deletions registry/registry.go → template/registry.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package registry
package template

import (
"context"
Expand Down Expand Up @@ -33,7 +33,7 @@ type Registry struct {

// New loads the source package info and returns a new instance of
// Registry.
func New(srcPkg *packages.Package, dstPkgPath string, inPackage bool) (*Registry, error) {
func NewRegistry(srcPkg *packages.Package, dstPkgPath string, inPackage bool) (*Registry, error) {
return &Registry{
dstPkgPath: dstPkgPath,
srcPkg: srcPkg,
Expand Down
5 changes: 2 additions & 3 deletions template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"text/template"

"github.com/huandu/xstrings"
"github.com/vektra/mockery/v3/registry"
)

// Template is the Moq template. It is capable of generating the Moq
Expand Down Expand Up @@ -63,13 +62,13 @@ func exported(s string) string {
}

var TemplateMockFuncs = template.FuncMap{
"importStatement": func(imprt *registry.Package) string {
"importStatement": func(imprt *Package) string {
if imprt.Alias == "" {
return `"` + imprt.Path() + `"`
}
return imprt.Alias + ` "` + imprt.Path() + `"`
},
"syncPkgQualifier": func(imports []*registry.Package) string {
"syncPkgQualifier": func(imports []*Package) string {
for _, imprt := range imports {
if imprt.Path() == "sync" {
return imprt.Qualifier()
Expand Down
11 changes: 5 additions & 6 deletions template/template_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import (
"fmt"
"go/types"
"strings"

"github.com/vektra/mockery/v3/registry"
)

// ConfigData is the data sent to the template for the config file.
type ConfigData struct {
ConfigDir string
InterfaceDir string
Expand All @@ -20,13 +19,13 @@ type ConfigData struct {
SrcPackagePath string
}

// Data is the template data used to render the Moq template.
// Data is the template data used to render the mock template.
type Data struct {
Boilerplate string
BuildTags string
PkgName string
SrcPkgQualifier string
Imports []*registry.Package
Imports []*Package
Mocks []MockData
TemplateData map[string]any
}
Expand Down Expand Up @@ -98,7 +97,7 @@ type MethodData struct {
// Scope represents the lexical scope of the method. Its primary function
// is keeping track of all names visible in the current scope, which allows
// the creation of new variables with guaranteed non-conflicting names.
Scope *registry.MethodScope
Scope *MethodScope
}

// ArgList is the string representation of method parameters, ex:
Expand Down Expand Up @@ -217,7 +216,7 @@ type TypeParamData struct {
// ParamData is the data which represents a parameter to some method of
// an interface.
type ParamData struct {
Var *registry.Var
Var *Var
Variadic bool
}

Expand Down
20 changes: 9 additions & 11 deletions template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package template
import (
"go/types"
"testing"

"github.com/vektra/mockery/v3/registry"
)

func TestTemplateMockFuncs(t *testing.T) {
Expand All @@ -19,8 +17,8 @@ func TestTemplateMockFuncs(t *testing.T) {
})

t.Run("ImportStatement", func(t *testing.T) {
f := TemplateMockFuncs["ImportStatement"].(func(*registry.Package) string)
pkg := registry.NewPackage(types.NewPackage("xyz", "xyz"))
f := TemplateMockFuncs["ImportStatement"].(func(*Package) string)
pkg := NewPackage(types.NewPackage("xyz", "xyz"))
if f(pkg) != `"xyz"` {
t.Errorf("ImportStatement(...): want: `\"xyz\"`; got: `%s`", f(pkg))
}
Expand All @@ -32,22 +30,22 @@ func TestTemplateMockFuncs(t *testing.T) {
})

t.Run("SyncPkgQualifier", func(t *testing.T) {
f := TemplateMockFuncs["SyncPkgQualifier"].(func([]*registry.Package) string)
f := TemplateMockFuncs["SyncPkgQualifier"].(func([]*Package) string)
if f(nil) != "sync" {
t.Errorf("SyncPkgQualifier(...): want: `sync`; got: `%s`", f(nil))
}
imports := []*registry.Package{
registry.NewPackage(types.NewPackage("sync", "sync")),
registry.NewPackage(types.NewPackage("github.com/some/module", "module")),
imports := []*Package{
NewPackage(types.NewPackage("sync", "sync")),
NewPackage(types.NewPackage("github.com/some/module", "module")),
}
if f(imports) != "sync" {
t.Errorf("SyncPkgQualifier(...): want: `sync`; got: `%s`", f(imports))
}

syncPkg := registry.NewPackage(types.NewPackage("sync", "sync"))
syncPkg := NewPackage(types.NewPackage("sync", "sync"))
syncPkg.Alias = "stdsync"
otherSyncPkg := registry.NewPackage(types.NewPackage("github.com/someother/sync", "sync"))
imports = []*registry.Package{otherSyncPkg, syncPkg}
otherSyncPkg := NewPackage(types.NewPackage("github.com/someother/sync", "sync"))
imports = []*Package{otherSyncPkg, syncPkg}
if f(imports) != "stdsync" {
t.Errorf("SyncPkgQualifier(...): want: `stdsync`; got: `%s`", f(imports))
}
Expand Down
2 changes: 1 addition & 1 deletion registry/var.go → template/var.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package registry
package template

import (
"go/types"
Expand Down

0 comments on commit 365b8eb

Please sign in to comment.