Skip to content

Commit 722e29f

Browse files
committed
Fix duplicate entries of elements in a category when re-exported.
If a package has two libraries `foo.dart` and `bar.dart` where * `foo.dart` contains `Foo` with an `/// {@category ...}` annotation, and, * `bar.dart` re-exports `foo.dart`. Then the category page shall not list `Foo` twice, which is simply a bug. This change fixes this issue.
1 parent 95105e9 commit 722e29f

File tree

4 files changed

+50
-11
lines changed

4 files changed

+50
-11
lines changed

lib/src/model/category.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,33 @@ class Category
3232
@override
3333
final DartdocOptionContext config;
3434

35-
final List<Class> _classes = [];
35+
final Set<Class> _classes = {};
3636

37-
final List<Class> _exceptions = [];
37+
final Set<Class> _exceptions = {};
3838

3939
@override
40-
final List<TopLevelVariable> constants = [];
40+
final Set<TopLevelVariable> constants = {};
4141

4242
@override
43-
final List<Extension> extensions = [];
43+
final Set<Extension> extensions = {};
4444

4545
@override
46-
final List<ExtensionType> extensionTypes = [];
46+
final Set<ExtensionType> extensionTypes = {};
4747

4848
@override
49-
final List<Enum> enums = [];
49+
final Set<Enum> enums = {};
5050

5151
@override
52-
final List<ModelFunction> functions = [];
52+
final Set<ModelFunction> functions = {};
5353

5454
@override
55-
final List<Mixin> mixins = [];
55+
final Set<Mixin> mixins = {};
5656

5757
@override
58-
final List<TopLevelVariable> properties = [];
58+
final Set<TopLevelVariable> properties = {};
5959

6060
@override
61-
final List<Typedef> typedefs = [];
61+
final Set<Typedef> typedefs = {};
6262

6363
final CategoryDefinition _categoryDefinition;
6464

test/end2end/model_special_cases_test.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,25 @@ void main() {
393393
expect(SubForDocComments.categories.first.isDocumented, isFalse);
394394
expect(SubForDocComments.displayedCategories, isEmpty);
395395
});
396+
397+
test('No duplicate entries', () {
398+
final categories = ginormousPackageGraph.localPackages
399+
.firstWhere((p) => p.name == 'test_package')
400+
.categories;
401+
for (final c in categories) {
402+
expect(c.classes.length, equals(c.classes.toSet().length));
403+
expect(c.exceptions.length, equals(c.exceptions.toSet().length));
404+
expect(c.extensions.length, equals(c.extensions.toSet().length));
405+
expect(
406+
c.extensionTypes.length, equals(c.extensionTypes.toSet().length));
407+
expect(c.enums.length, equals(c.enums.toSet().length));
408+
expect(c.mixins.length, equals(c.mixins.toSet().length));
409+
expect(c.constants.length, equals(c.constants.toSet().length));
410+
expect(c.properties.length, equals(c.properties.toSet().length));
411+
expect(c.functions.length, equals(c.functions.toSet().length));
412+
expect(c.typedefs.length, equals(c.typedefs.toSet().length));
413+
}
414+
});
396415
});
397416

398417
group('Package', () {

test/templates/category_test.dart

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ extension type ExType(int it) {}
125125
'''),
126126
d.file('other.dart', '''
127127
/// {@category Documented}
128-
library;
128+
library;
129+
130+
export 'lib.dart' show C1, E1;
129131
'''),
130132
],
131133
files: [
@@ -229,6 +231,15 @@ library;
229231
);
230232
});
231233

234+
test('classes are not duplicated', () async {
235+
expect(
236+
topicOneLines
237+
.where((l) => l.contains('<a href="../lib/C1-class.html">C1</a>')),
238+
// Once in the sidebar and once in the main body
239+
hasLength(2),
240+
);
241+
});
242+
232243
test('sidebar contains enums', () async {
233244
expect(
234245
topicOneLines,
@@ -240,6 +251,14 @@ library;
240251
);
241252
});
242253

254+
test('enums are not duplicated', () async {
255+
expect(
256+
topicOneLines.where((l) => l.contains('<a href="../lib/E1.html">E1</a>')),
257+
// Once in the sidebar and once in the main body
258+
hasLength(2),
259+
);
260+
});
261+
243262
test('sidebar contains mixins', () async {
244263
expect(
245264
topicOneLines,

testing/test_package/lib/src/somelib.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
library reexport.somelib;
22

3+
/// {@category Unreal}
34
class SomeClass {}
45

56
class SomeOtherClass {}

0 commit comments

Comments
 (0)