File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -695,8 +695,9 @@ class Enum extends Class {
695
695
List <EnumField > get constants {
696
696
if (_constants != null ) return _constants;
697
697
698
- // is there a better way to get the index during a map() ?
699
- var index = 0 ;
698
+ // This is a hack to give 'values' an index of -1 and all other fields
699
+ // their expected indicies. https://github.com/dart-lang/dartdoc/issues/1176
700
+ var index = - 1 ;
700
701
701
702
_constants = _cls.fields
702
703
.where (isPublic)
Original file line number Diff line number Diff line change @@ -733,7 +733,16 @@ void main() {
733
733
var dog = animal.constants.firstWhere ((f) => f.name == 'DOG' );
734
734
expect (dog.linkedName, equals ('DOG' ));
735
735
expect (dog.isConst, isTrue);
736
- expect (dog.constantValue, equals ('const Animal(2)' ));
736
+ expect (dog.constantValue, equals ('const Animal(1)' ));
737
+ });
738
+
739
+ test ('constants have correct indicies' , () {
740
+ String valueByName (var name) {
741
+ return animal.constants.firstWhere ((f) => f.name == name).constantValue;
742
+ }
743
+ expect (valueByName ('CAT' ), equals ('const Animal(0)' ));
744
+ expect (valueByName ('DOG' ), equals ('const Animal(1)' ));
745
+ expect (valueByName ('HORSE' ), equals ('const Animal(2)' ));
737
746
});
738
747
739
748
test ('has a single `index` property' , () {
You can’t perform that action at this time.
0 commit comments