Skip to content

Commit 36432c6

Browse files
authored
Merge pull request #1178 from eseidelGoogle/enum_index
Fix enums to use the correct index value in documentation
2 parents 5b93362 + c8488ea commit 36432c6

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/src/model.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,9 @@ class Enum extends Class {
695695
List<EnumField> get constants {
696696
if (_constants != null) return _constants;
697697

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;
700701

701702
_constants = _cls.fields
702703
.where(isPublic)

test/model_test.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,16 @@ void main() {
733733
var dog = animal.constants.firstWhere((f) => f.name == 'DOG');
734734
expect(dog.linkedName, equals('DOG'));
735735
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)'));
737746
});
738747

739748
test('has a single `index` property', () {

0 commit comments

Comments
 (0)