Skip to content
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
6 changes: 3 additions & 3 deletions lib/src/model/enum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ class EnumField extends Field {
return canonicalModelElement?.href;
}
assert(canonicalEnclosingContainer == enclosingElement);
// TODO(jcollins-g): EnumField should not depend on enclosingElement, but
// we sort of have to while we are half-converted to [FileStructure].
return '${package.baseHref}${enclosingElement.library.dirName}/${enclosingElement.fileName}';
assert(canonicalLibrary != null);
return '${package.baseHref}${canonicalLibrary!.dirName}/'
'${enclosingElement.fileName}';
}

@override
Expand Down
18 changes: 18 additions & 0 deletions test/enums_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

import 'dartdoc_test_base.dart';
import 'src/test_descriptor_utils.dart' as d;
import 'src/utils.dart';

void main() {
Expand Down Expand Up @@ -637,6 +638,23 @@ enum E {
expect(oneValue.constantValue, equals(oneValue.renderedName));
}

void test_value_linksToItsAnchor_inExportedLib() async {
var library = (await bootPackageFromFiles([
d.file('lib/src/library.dart', '''
enum E { one, two three }
'''),
d.file('lib/enums.dart', '''
export 'src/library.dart';
'''),
]))
.libraries
.named(libraryName);
var oneValue =
library.enums.named('E').publicEnumValues.named('one') as EnumField;
expect(oneValue.linkedName, '<a href="$linkPrefix/E.html#one">one</a>');
expect(oneValue.constantValue, equals(oneValue.renderedName));
}

void test_values_haveIndices() async {
var library = await bootPackageWithLibrary('enum E { one, two, three }');
var oneValue =
Expand Down
11 changes: 10 additions & 1 deletion test/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,16 @@ bool get classModifiersAllowed =>
.allows(platformVersion);

extension ModelElementIterableExtension<T extends ModelElement> on Iterable<T> {
T named(String name) => singleWhere((e) => e.name == name);
T named(String name) {
var elements = where((e) => e.name == name).toList();
if (elements.isEmpty) {
throw StateError("No $T elements named '$name'");
}
if (elements.length > 1) {
throw StateError("Too many $T elements named '$name': $elements");
}
return elements.single;
}

T displayNamed(String displayName) =>
singleWhere((e) => e.displayName == displayName);
Expand Down
Loading