Skip to content

Commit 910874a

Browse files
authored
Merge pull request #806 from leitzler/master
Ensure generated imports doesn't start with digit
2 parents c6d2a9e + 4bee898 commit 910874a

File tree

4 files changed

+7
-1
lines changed

4 files changed

+7
-1
lines changed

pkg/fixtures/12345678/http/http.go

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package http
2+
3+
type MyStruct struct{}

pkg/fixtures/same_name_imports.go

+2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package test
33
import (
44
"net/http"
55

6+
number_dir_http "github.com/vektra/mockery/v2/pkg/fixtures/12345678/http"
67
my_http "github.com/vektra/mockery/v2/pkg/fixtures/http"
78
)
89

910
// Example is an example
1011
type Example interface {
1112
A() http.Flusher
1213
B(fixtureshttp string) my_http.MyStruct
14+
C(fixtureshttp string) number_dir_http.MyStruct
1315
}

pkg/generator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525

2626
const mockConstructorParamTypeNamePrefix = "mockConstructorTestingT"
2727

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

3030
func DetermineOutputPackageName(
3131
interfaceFileName string,

pkg/generator_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ func (s *GeneratorSuite) TestGeneratorPrologueWithMultipleImportsSameName() {
260260

261261
expected := `package mocks
262262
263+
import _2345678http "github.com/vektra/mockery/v2/pkg/fixtures/12345678/http"
263264
import fixtureshttp "github.com/vektra/mockery/v2/pkg/fixtures/http"
264265
import http "net/http"
265266
import mock "github.com/stretchr/testify/mock"

0 commit comments

Comments
 (0)