Skip to content

Commit

Permalink
Write out extension type constructor docs (#3602)
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins authored Dec 12, 2023
1 parent 7ac2a1c commit c4f304f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
9 changes: 9 additions & 0 deletions lib/src/generator/generator_frontend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ class GeneratorFrontEnd implements Generator {
_generatorBackend.generateExtensionType(
packageGraph, lib, extensionType);

for (var constructor
in filterNonDocumented(extensionType.constructors)) {
if (!constructor.isCanonical) continue;

indexAccumulator.add(constructor);
_generatorBackend.generateConstructor(
packageGraph, lib, extensionType, constructor);
}

for (var constant
in filterNonDocumented(extensionType.constantFields)) {
indexAccumulator.add(constant);
Expand Down
43 changes: 30 additions & 13 deletions test/templates/extension_type_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class FooSub extends Foo<int> {}
extension type One<E>(Foo<E> it) {
/// A named constructor.
MyIterable.named(Foo<E> e);
One.named(Foo<E> e);
/// An instance method.
void m1() {}
Expand Down Expand Up @@ -147,6 +147,28 @@ dartdoc:
]);
});

test('primary constructor page is rendered', () async {
var constructorPageLines = resourceProvider
.readLines([packagePath, 'doc', 'lib', 'One', 'One.html']);
constructorPageLines.expectMainContentContainsAllInOrder([
matches(
'<span class="kind-constructor">One&lt;<wbr>'
'<span class="type-parameter">E</span>&gt;</span> constructor',
)
]);
});

test('named constructor page is rendered', () async {
var constructorPageLines = resourceProvider
.readLines([packagePath, 'doc', 'lib', 'One', 'One.named.html']);
constructorPageLines.expectMainContentContainsAllInOrder([
matches(
'<span class="kind-constructor">One&lt;<wbr>'
'<span class="type-parameter">E</span>&gt;.named</span> constructor',
)
]);
});

test('page contains representation type', () async {
oneLines.expectMainContentContainsAllInOrder([
matches('<dt>on</dt>'),
Expand Down Expand Up @@ -209,18 +231,13 @@ dartdoc:
]);
});

test(
'page contains (static) constants',
// TODO(srawlins): Implement.
skip: true,
() async {
oneLines.expectMainContentContainsAllInOrder([
matches('<h2>Constants</h2>'),
matches('<a href="../lib/One/c1-constant.html">c1</a>'),
matches('A constant.'),
]);
},
);
test('page contains (static) constants', () async {
oneLines.expectMainContentContainsAllInOrder([
matches('<h2>Constants</h2>'),
matches('<a href="../lib/One/c1-constant.html">c1</a>'),
matches('A constant.'),
]);
});

test('page contains representation field', () async {
oneLines.expectMainContentContainsAllInOrder([
Expand Down

0 comments on commit c4f304f

Please sign in to comment.