-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
139a0c5
commit 00c9a71
Showing
1 changed file
with
29 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,39 @@ | ||
package type_alias_test | ||
|
||
import ( | ||
"context" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/chigopher/pathlib" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/vektra/mockery/v2/pkg" | ||
"golang.org/x/tools/go/packages" | ||
) | ||
|
||
func TestTypeAliasResolved(t *testing.T) { | ||
parser := pkg.NewParser([]string{}) | ||
require.NoError(t, parser.ParsePackages(context.Background(), []string{"github.com/vektra/mockery/v2/fixtures/type_alias"})) | ||
var config packages.Config | ||
config.Mode = packages.NeedTypes | | ||
packages.NeedTypesSizes | | ||
packages.NeedSyntax | | ||
packages.NeedTypesInfo | | ||
packages.NeedImports | | ||
packages.NeedName | | ||
packages.NeedFiles | | ||
packages.NeedCompiledGoFiles | ||
config.Tests = true | ||
packageList, err := packages.Load(&config, "github.com/vektra/mockery/v2/pkg/fixtures/type_alias") | ||
require.NoError(t, err) | ||
require.Equal(t, 3, len(packageList)) | ||
|
||
//var pkg *packages.Package | ||
|
||
for _, pkgElem := range packageList { | ||
t.Log(pkgElem.ID) | ||
func TestTypeAlias(t *testing.T) { | ||
for _, tt := range []struct { | ||
name string | ||
filepath string | ||
expectedRegex string | ||
}{ | ||
{ | ||
name: "With alias resolved", | ||
filepath: "./mock_InterfaceWithResolvedAlias_test.go", | ||
expectedRegex: `func \((_?[a-zA-Z]*)+ \*InterfaceWithResolvedAlias\) Foo\(\) int {`, | ||
}, | ||
{ | ||
name: "With alias unresolved", | ||
filepath: "./mock_InterfaceWithUnresolvedAlias_test.go", | ||
expectedRegex: `func \((_?[a-zA-Z]*)+ \*InterfaceWithUnresolvedAlias\) Foo\(\) type_alias.Type {`, | ||
}, | ||
} { | ||
t.Run(tt.name, func(t *testing.T) { | ||
regex, err := regexp.Compile(tt.expectedRegex) | ||
require.NoError(t, err) | ||
path := pathlib.NewPath(tt.filepath) | ||
bytes, err := path.ReadFile() | ||
require.NoError(t, err) | ||
|
||
assert.True(t, regex.Match(bytes), "expected regex was not found in file") | ||
}) | ||
} | ||
|
||
//pkg := packageList[0] | ||
//for _, file := range pkg.Syntax { | ||
// t.Log("FOUND FILE") | ||
// t.Log(file.Name.Name) | ||
// for _, decl := range file.Decls { | ||
// t.Logf("%v", decl) | ||
// } | ||
//} | ||
t.Fail() | ||
|
||
} | ||
|
||
//func TestTypeAliasUnResolved(t *testing.T) { | ||
// expectedReturn := Type(1) | ||
// mockInterface := NewInterfaceWithUnresolvedAlias(t) | ||
// mockInterface.EXPECT().Foo().Return(expectedReturn) | ||
// | ||
// actualReturn := mockInterface.Foo() | ||
// assert.Equal(t, "foo", reflect.TypeOf(actualReturn).String()) | ||
// assert.Equal(t, expectedReturn, actualReturn) | ||
// | ||
//} |