Skip to content

Commit

Permalink
Merge pull request #1178 from eseidelGoogle/enum_index
Browse files Browse the repository at this point in the history
Fix enums to use the correct index value in documentation
  • Loading branch information
keertip authored Jun 20, 2016
2 parents 5b93362 + c8488ea commit 36432c6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/src/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,9 @@ class Enum extends Class {
List<EnumField> get constants {
if (_constants != null) return _constants;

// is there a better way to get the index during a map() ?
var index = 0;
// This is a hack to give 'values' an index of -1 and all other fields
// their expected indicies. https://github.com/dart-lang/dartdoc/issues/1176
var index = -1;

_constants = _cls.fields
.where(isPublic)
Expand Down
11 changes: 10 additions & 1 deletion test/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,16 @@ void main() {
var dog = animal.constants.firstWhere((f) => f.name == 'DOG');
expect(dog.linkedName, equals('DOG'));
expect(dog.isConst, isTrue);
expect(dog.constantValue, equals('const Animal(2)'));
expect(dog.constantValue, equals('const Animal(1)'));
});

test('constants have correct indicies', () {
String valueByName(var name) {
return animal.constants.firstWhere((f) => f.name == name).constantValue;
}
expect(valueByName('CAT'), equals('const Animal(0)'));
expect(valueByName('DOG'), equals('const Animal(1)'));
expect(valueByName('HORSE'), equals('const Animal(2)'));
});

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

0 comments on commit 36432c6

Please sign in to comment.