Skip to content

Commit

Permalink
Merge pull request #806 from leitzler/master
Browse files Browse the repository at this point in the history
Ensure generated imports doesn't start with digit
  • Loading branch information
LandonTClipp authored Aug 16, 2024
2 parents c6d2a9e + 4bee898 commit 910874a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/fixtures/12345678/http/http.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package http

type MyStruct struct{}
2 changes: 2 additions & 0 deletions pkg/fixtures/same_name_imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package test
import (
"net/http"

number_dir_http "github.com/vektra/mockery/v2/pkg/fixtures/12345678/http"
my_http "github.com/vektra/mockery/v2/pkg/fixtures/http"
)

// Example is an example
type Example interface {
A() http.Flusher
B(fixtureshttp string) my_http.MyStruct
C(fixtureshttp string) number_dir_http.MyStruct
}
2 changes: 1 addition & 1 deletion pkg/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

const mockConstructorParamTypeNamePrefix = "mockConstructorTestingT"

var invalidIdentifierChar = regexp.MustCompile("[^[:digit:][:alpha:]_]")
var invalidIdentifierChar = regexp.MustCompile("^[[:digit:]]|[^[:digit:][:alpha:]_]")

func DetermineOutputPackageName(
interfaceFileName string,
Expand Down
1 change: 1 addition & 0 deletions pkg/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ func (s *GeneratorSuite) TestGeneratorPrologueWithMultipleImportsSameName() {

expected := `package mocks
import _2345678http "github.com/vektra/mockery/v2/pkg/fixtures/12345678/http"
import fixtureshttp "github.com/vektra/mockery/v2/pkg/fixtures/http"
import http "net/http"
import mock "github.com/stretchr/testify/mock"
Expand Down

0 comments on commit 910874a

Please sign in to comment.