File tree 3 files changed +31
-4
lines changed
3 files changed +31
-4
lines changed Original file line number Diff line number Diff line change @@ -117,9 +117,9 @@ class EnumField extends Field {
117
117
return canonicalModelElement? .href;
118
118
}
119
119
assert (canonicalEnclosingContainer == enclosingElement);
120
- // TODO(jcollins-g): EnumField should not depend on enclosingElement, but
121
- // we sort of have to while we are half-converted to [FileStructure].
122
- return '${ package . baseHref }${ enclosingElement . library . dirName }/ ${enclosingElement .fileName }' ;
120
+ assert (canonicalLibrary != null );
121
+ return '${ package . baseHref }${ canonicalLibrary !. dirName }/'
122
+ ' ${enclosingElement .fileName }' ;
123
123
}
124
124
125
125
@override
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import 'package:test/test.dart';
8
8
import 'package:test_reflective_loader/test_reflective_loader.dart' ;
9
9
10
10
import 'dartdoc_test_base.dart' ;
11
+ import 'src/test_descriptor_utils.dart' as d;
11
12
import 'src/utils.dart' ;
12
13
13
14
void main () {
@@ -637,6 +638,23 @@ enum E {
637
638
expect (oneValue.constantValue, equals (oneValue.renderedName));
638
639
}
639
640
641
+ void test_value_linksToItsAnchor_inExportedLib () async {
642
+ var library = (await bootPackageFromFiles ([
643
+ d.file ('lib/src/library.dart' , '''
644
+ enum E { one, two three }
645
+ ''' ),
646
+ d.file ('lib/enums.dart' , '''
647
+ export 'src/library.dart';
648
+ ''' ),
649
+ ]))
650
+ .libraries
651
+ .named (libraryName);
652
+ var oneValue =
653
+ library.enums.named ('E' ).publicEnumValues.named ('one' ) as EnumField ;
654
+ expect (oneValue.linkedName, '<a href="$linkPrefix /E.html#one">one</a>' );
655
+ expect (oneValue.constantValue, equals (oneValue.renderedName));
656
+ }
657
+
640
658
void test_values_haveIndices () async {
641
659
var library = await bootPackageWithLibrary ('enum E { one, two, three }' );
642
660
var oneValue =
Original file line number Diff line number Diff line change @@ -355,7 +355,16 @@ bool get classModifiersAllowed =>
355
355
.allows (platformVersion);
356
356
357
357
extension ModelElementIterableExtension <T extends ModelElement > on Iterable <T > {
358
- T named (String name) => singleWhere ((e) => e.name == name);
358
+ T named (String name) {
359
+ var elements = where ((e) => e.name == name).toList ();
360
+ if (elements.isEmpty) {
361
+ throw StateError ("No $T elements named '$name '" );
362
+ }
363
+ if (elements.length > 1 ) {
364
+ throw StateError ("Too many $T elements named '$name ': $elements " );
365
+ }
366
+ return elements.single;
367
+ }
359
368
360
369
T displayNamed (String displayName) =>
361
370
singleWhere ((e) => e.displayName == displayName);
You can’t perform that action at this time.
0 commit comments