Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the parser accept index list expressions #857

Merged
merged 5 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ packages:
config: *inpackage_config
github.com/vektra/mockery/v2/pkg/fixtures/example_project:
config: *inpackage_config
github.com/vektra/mockery/v2/pkg/fixtures/index_list_expr:
config: *inpackage_config
github.com/vektra/mockery/v2/pkg/fixtures/issue845:
config:
<<: *inpackage_config
Expand Down
7 changes: 7 additions & 0 deletions pkg/fixtures/index_list_expr/index_list_expression.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package index_list_expr

type GenericMultipleTypes[T1 any, T2 any, T3 any] interface {
Func(arg1 *T1, arg2 T2) T3
}

type IndexListExpr GenericMultipleTypes[int, string, bool]
35 changes: 35 additions & 0 deletions pkg/fixtures/index_list_expr/index_list_expression_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package index_list_expr_test

import (
"context"
"testing"

"github.com/vektra/mockery/v2/pkg"

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

func TestParsing(t *testing.T) {
parser := pkg.NewParser(nil)
ctx := context.Background()
require.NoError(t, parser.ParsePackages(ctx, []string{"github.com/vektra/mockery/v2/pkg/fixtures/index_list_expr"}))
require.NoError(t, parser.Load(ctx))

for _, ifaceName := range []string{"GenericMultipleTypes", "IndexListExpr"} {
iface, err := parser.Find(ifaceName)
require.NoError(t, err)
require.NotNil(t, iface)
}
}

func TestUsage(t *testing.T) {
gmt := NewMockGenericMultipleTypes[string, int, bool](t)
testString := "foo"
gmt.EXPECT().Func(&testString, 1).Return(false)
require.Equal(t, false, gmt.Func(&testString, 1))

ile := NewMockIndexListExpr(t)
testInt := 1
ile.EXPECT().Func(&testInt, "foo").Return(true)
require.Equal(t, true, ile.Func(&testInt, "foo"))
}
81 changes: 81 additions & 0 deletions pkg/fixtures/index_list_expr/mock_generic_multiple_types_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 79 additions & 0 deletions pkg/fixtures/index_list_expr/mock_index_list_expr_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func (nv *NodeVisitor) Visit(node ast.Node) ast.Visitor {
break
}
nv.add(nv.ctx, n)
case *ast.InterfaceType, *ast.IndexExpr:
case *ast.InterfaceType, *ast.IndexExpr, *ast.IndexListExpr:
nv.add(nv.ctx, n)
default:
log.Debug().Msg("Found node with unacceptable type for mocking. Rejecting.")
Expand Down
Loading