Give better error message for describeEnum (#61581)
This commit is contained in:
committed by
GitHub
parent
293a2bf8e8
commit
1b406159f2
@@ -3032,7 +3032,10 @@ String describeIdentity(Object? object) => '${objectRuntimeType(object, '<optimi
|
||||
String describeEnum(Object enumEntry) {
|
||||
final String description = enumEntry.toString();
|
||||
final int indexOfDot = description.indexOf('.');
|
||||
assert(indexOfDot != -1 && indexOfDot < description.length - 1);
|
||||
assert(
|
||||
indexOfDot != -1 && indexOfDot < description.length - 1,
|
||||
'The provided object "$enumEntry" is not an enum.',
|
||||
);
|
||||
return description.substring(indexOfDot + 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -903,6 +903,14 @@ void main() {
|
||||
expect(describeEnum(ExampleEnum.hello), equals('hello'));
|
||||
expect(describeEnum(ExampleEnum.world), equals('world'));
|
||||
expect(describeEnum(ExampleEnum.deferToChild), equals('deferToChild'));
|
||||
expect(
|
||||
() => describeEnum('Hello World'),
|
||||
throwsA(isAssertionError.having(
|
||||
(AssertionError e) => e.message,
|
||||
'message',
|
||||
'The provided object "Hello World" is not an enum.'),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('string property test', () {
|
||||
|
||||
Reference in New Issue
Block a user