Skip to content

Commit

Permalink
allow duplicate typedefs
Browse files Browse the repository at this point in the history
  • Loading branch information
dickermoshe authored and srawlins committed Dec 4, 2024
1 parent 1dafb54 commit c8d036f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ $rawOutput
void addTypesFrom(analyzer.DartType type) {
// Prevent infinite recursion.
if (seenTypes.contains(type)) {
if (type.alias != null) {
// To check for duplicate typdefs that have different names
type.alias!.element.accept(typeVisitor);
}
return;
}
seenTypes.add(type);
Expand Down
31 changes: 29 additions & 2 deletions test/builder/auto_mocks_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3583,8 +3583,7 @@ void main() {
expect(mocksContent, contains('implements _i2.Baz'));
});

test(
'when a type parameter is a typedef a function which returns another type',
test('when its a type parameter of function which returns another type',
() async {
final mocksContent = await buildWithNonNullable({
...annotationsAsset,
Expand All @@ -3610,6 +3609,34 @@ void main() {
'''
});

expect(mocksContent, contains('class MockFoo extends _i1.Mock'));
expect(mocksContent, contains('implements _i2.Foo'));
});
test('when its a duplicate type parameter', () async {
final mocksContent = await buildWithNonNullable({
...annotationsAsset,
'foo|lib/foo.dart': dedent(r'''
class Bar {}
typedef BarDef = int Function();
typedef BarDef2 = int Function();
class BaseFoo<T,P> {
BaseFoo(this.t1, this.t2);
final T t1;
final P t2;
}
class Foo extends BaseFoo<BarDef, BarDef2> {
Foo() : super(() => 1, () => 2);
}
'''),
'foo|test/foo_test.dart': '''
import 'package:foo/foo.dart';
import 'package:mockito/annotations.dart';
@GenerateMocks([Foo])
void main() {}
'''
});

expect(mocksContent, contains('class MockFoo extends _i1.Mock'));
expect(mocksContent, contains('implements _i2.Foo'));
});
Expand Down

0 comments on commit c8d036f

Please sign in to comment.