diff --git a/test/enum_test.dart b/test/enum_test.dart index f4c31033c0..f3621bfbfa 100644 --- a/test/enum_test.dart +++ b/test/enum_test.dart @@ -17,204 +17,154 @@ void main() { }); } -// TODO(srawlins): Sort members after a code review for the -// test_reflective_loader migration. - @reflectiveTest -class EnumTest extends DartdocTestBase { +class EnhancedEnumTest extends DartdocTestBase { @override String get libraryName => 'enums'; - void test_publicEnums() async { - var library = await bootPackageWithLibrary('enum E { one, two, three }'); - expect(library.publicEnums, isNotEmpty); - } - - void test_fullyQualifiedName() async { - var library = await bootPackageWithLibrary('enum E { one, two, three }'); - var eEnum = library.enums.named('E'); - - expect(eEnum.fullyQualifiedName, equals('enums.E')); - } + @override + String get sdkConstraint => '>=2.17.0 <3.0.0'; - void test_linkedName() async { - var library = await bootPackageWithLibrary('enum E { one, two, three }'); - var eEnum = library.enums.named('E'); + void test_constructorsAreDocumented() async { + // TODO(srawlins): As all supported Dart is >=2.15.0, this test can just + // be a "constructors" test rather than an "enum" test. + var library = await bootPackageWithLibrary(''' +enum E { + one.named(1), + two.named(2); - expect(eEnum.linkedName, equals('E')); - } + final int x; - void test_enclosingElement() async { - var library = await bootPackageWithLibrary('enum E { one, two, three }'); - var eEnum = library.enums.named('E'); + /// A named constructor. + const E.named(this.x); +} +'''); + var namedConstructor = + library.enums.named('E').constructors.named('E.named'); - expect(eEnum.enclosingElement.name, 'enums'); + expect(namedConstructor.isFactory, false); + expect(namedConstructor.fullyQualifiedName, 'enums.E.named'); + expect(namedConstructor.nameWithGenerics, 'E.named'); + expect(namedConstructor.documentationComment, '/// A named constructor.'); } - void test_publicEnumValues() async { - var library = await bootPackageWithLibrary('enum E { one, two, three }'); - var eEnum = library.enums.named('E'); + void test_instanceFieldsAreDocumented() async { + // TODO(srawlins): As all supported Dart is >=2.15.0, this test can just + // be a "fields" test rather than an "enum" test. + var library = await bootPackageWithLibrary(''' +enum E { + one, two, three; - expect(eEnum.publicEnumValues, hasLength(3)); - } + /// Doc comment. + final int field1 = 1; +} +'''); + var field1 = library.enums.named('E').instanceFields.named('field1'); - void test_valuesConstant() async { - var library = await bootPackageWithLibrary('enum E { one, two, three }'); - var valuesField = library.enums.named('E').constantFields.named('values'); - expect(valuesField.documentation, startsWith('A constant List')); + expect(field1.isInherited, false); + expect(field1.isStatic, false); + expect(field1.isDocumented, true); + expect( + field1.linkedName, + 'field1', + ); + expect(field1.documentationComment, '/// Doc comment.'); } - void test_valuesConstant_canBeReferenced() async { + void test_instanceGettersCanBeReferenced() async { + // TODO(srawlins): As all supported Dart is >=2.15.0, this test can just + // be a "getters" test rather than an "enum" test. var library = await bootPackageWithLibrary(''' -enum E { one, two, three } +enum E { + one, two; -/// Reference to [E.values]. + /// A getter. + int get x => 1; +} + +/// Reference to [E.x]. class C {} '''); var cClass = library.classes.named('C'); expect( cClass.documentationAsHtml, - '

Reference to ' - 'E.values.

', + '

Reference to E.x.

', ); } - void test_annotatedValue() async { + void test_instanceMethodsCanBeReferenced() async { + // TODO(srawlins): As all supported Dart is >=2.15.0, this test can just + // be a "methods" test rather than an "enum" test. var library = await bootPackageWithLibrary(''' enum E { - @deprecated - one, - two, three + one, two; + + /// Doc comment. + static int method1(String p) => 7; } +/// Reference to [E.method1]. +class C {} '''); - var one = library.enums.named('E').publicEnumValues.named('one'); - expect(one.hasAnnotations, true); - expect(one.annotations, hasLength(1)); - expect(one.isDeprecated, true); + var cClass = library.classes.named('C'); + expect( + cClass.documentationAsHtml, + '

Reference to E.method1.

', + ); } - void test_value_canBeReferenced() async { + void test_instanceSettersAreDocumented() async { + // TODO(srawlins): As all supported Dart is >=2.15.0, this test can just + // be a "setters" test rather than an "enum" test. var library = await bootPackageWithLibrary(''' -enum E { one, two, three } +enum E { + one, two; -/// Reference to [E.one]. -class C {} + /// A setter. + set x(int value) {} +} '''); - var cClass = library.classes.named('C'); - expect(cClass.documentationAsHtml, - '

Reference to E.one.

'); + var xSetter = library.enums.named('E').instanceAccessors.named('x='); + + expect(xSetter.isGetter, false); + expect(xSetter.isSetter, true); + expect(xSetter.isPublic, true); + expect(xSetter.documentationComment, 'A setter.'); } - void test_index_canBeReferenced() async { + void test_instanceSettersCanBeReferenced() async { + // TODO(srawlins): As all supported Dart is >=2.15.0, this test can just + // be a "setters" test rather than an "enum" test. var library = await bootPackageWithLibrary(''' -enum E { one, two, three } +enum E { + one, two; -/// Reference to [E.index]. + /// A setter. + set x(int value) {} +} + +/// Reference to [E.x]. class C {} '''); var cClass = library.classes.named('C'); expect( cClass.documentationAsHtml, - '

Reference to ' - 'E.index.

', - ); - } - - void test_index_isLinked() async { - var library = await bootPackageWithLibrary('enum E { one, two, three }'); - var eEnum = library.enums.named('E'); - - expect(eEnum.instanceFields.map((f) => f.name), contains('index')); - expect( - eEnum.instanceFields.named('index').linkedName, - 'index', + '

Reference to E.x.

', ); } - void test_toString() async { - var library = await bootPackageWithLibrary('enum E { one, two, three }'); - var eEnum = library.enums.named('E'); - var toStringMethod = eEnum.instanceMethods.named('toString'); - expect(toStringMethod.characterLocation, isNotNull); - expect(toStringMethod.characterLocation.toString(), - equals(eEnum.characterLocation.toString())); - } - - void test_value_linksToItsAnchor() async { - var library = await bootPackageWithLibrary('enum E { one, two, three }'); - var oneValue = - library.enums.named('E').publicEnumValues.named('one') as EnumField; - expect(oneValue.linkedName, 'one'); - expect(oneValue.constantValue, - equals(EnumFieldRendererHtml().renderValue(oneValue))); - } - - void test_values_haveIndices() async { - var library = await bootPackageWithLibrary('enum E { one, two, three }'); - var oneValue = - library.enums.named('E').publicEnumValues.named('one') as EnumField; - var twoValue = - library.enums.named('E').publicEnumValues.named('two') as EnumField; - var threeValue = - library.enums.named('E').publicEnumValues.named('three') as EnumField; - - expect(oneValue.constantValue, equals('const E(0)')); - expect(twoValue.constantValue, equals('const E(1)')); - expect(threeValue.constantValue, equals('const E(2)')); - } - - void test_hasAnnotations() async { + void test_interfacesAreLinked() async { var library = await bootPackageWithLibrary(''' -class C { - const C(); -} - -@C() -enum E { one, two, three } -'''); - var eEnum = library.enums.named('E'); - - expect(eEnum.hasAnnotations, true); - expect(eEnum.annotations, hasLength(1)); - expect(eEnum.annotations.single.linkedName, - 'C'); - } +class C {} +class D {} - void test_hasDocComment() async { - var library = await bootPackageWithLibrary(''' -/// Doc comment for [E]. -enum E { one, two, three } +enum E implements C, D { one, two, three; } '''); var eEnum = library.enums.named('E'); - expect(eEnum.hasDocumentationComment, true); - expect(eEnum.documentationComment, '/// Doc comment for [E].'); - } - - void test_value_hasDocComment() async { - var library = await bootPackageWithLibrary(''' -enum E { - /// Doc comment for [E.one]. - one, - two, - three -} -'''); - var one = library.enums.named('E').publicEnumValues.named('one'); - - expect(one.hasDocumentationComment, true); - expect(one.documentationComment, '/// Doc comment for [E.one].'); + expect(eEnum.interfaces, hasLength(2)); + expect(eEnum.interfaces.map((i) => i.name), equals(['C', 'D'])); } -} - -@reflectiveTest -class EnhancedEnumTest extends DartdocTestBase { - @override - String get libraryName => 'enums'; - - @override - String get sdkConstraint => '>=2.17.0 <3.0.0'; void test_linkedGenericParameters() async { var library = await bootPackageWithLibrary(''' @@ -255,21 +205,55 @@ enum E { expect(method1.documentationComment, '/// Doc comment.'); } - void test_operatorsAreDocumented() async { - // TODO(srawlins): As all supported Dart is >=2.15.0, this test can just - // be an "operator" test rather than an "enum" test. + void test_mixedInTypesAreLinked() async { var library = await bootPackageWithLibrary(''' -enum E { - one, two, three; - - /// Greater than. - bool operator >(E other) => index > other.index; +mixin M {} +mixin N {} - /// Less than. - bool operator <(E other) => index < other.index; -} +enum E with M, N { one, two, three; } '''); - var greaterThan = + var eEnum = library.enums.named('E'); + + expect(eEnum.mixedInTypes, hasLength(2)); + expect(eEnum.mixedInTypes.map((i) => i.name), equals(['M', 'N'])); + } + + void test_namedConstructorCanBeReferenced() async { + // TODO(srawlins): As all supported Dart is >=2.15.0, this test can just + // be a "constructors" test rather than an "enum" test. + var library = await bootPackageWithLibrary(''' +enum E { + one.named(1), + two.named(2); + + const E.named(int x); +} + +/// Reference to [E.named]. +class C {} +'''); + var cClass = library.classes.named('C'); + expect( + cClass.documentationAsHtml, + '

Reference to E.named.

', + ); + } + + void test_operatorsAreDocumented() async { + // TODO(srawlins): As all supported Dart is >=2.15.0, this test can just + // be an "operator" test rather than an "enum" test. + var library = await bootPackageWithLibrary(''' +enum E { + one, two, three; + + /// Greater than. + bool operator >(E other) => index > other.index; + + /// Less than. + bool operator <(E other) => index < other.index; +} +'''); + var greaterThan = library.enums.named('E').instanceOperators.named('operator >'); expect(greaterThan.isInherited, false); @@ -299,78 +283,47 @@ enum E { expect(lessThan.documentationComment, '/// Less than.'); } - void test_interfacesAreLinked() async { - var library = await bootPackageWithLibrary(''' -class C {} -class D {} - -enum E implements C, D { one, two, three; } -'''); - var eEnum = library.enums.named('E'); - - expect(eEnum.interfaces, hasLength(2)); - expect(eEnum.interfaces.map((i) => i.name), equals(['C', 'D'])); - } - - void test_mixedInTypesAreLinked() async { - var library = await bootPackageWithLibrary(''' -mixin M {} -mixin N {} - -enum E with M, N { one, two, three; } -'''); - var eEnum = library.enums.named('E'); - - expect(eEnum.mixedInTypes, hasLength(2)); - expect(eEnum.mixedInTypes.map((i) => i.name), equals(['M', 'N'])); - } - - void test_staticMethodsAreDocumented() async { + void test_staticFieldsAreDocumented() async { // TODO(srawlins): As all supported Dart is >=2.15.0, this test can just - // be a "static method" test rather than an "enum" test. + // be a "static field" test rather than an "enum" test. var library = await bootPackageWithLibrary(''' enum E { one, two, three; /// Doc comment. - static int method1(String p) => 7; + static int field1 = 1; } '''); - var method1 = library.enums.named('E').staticMethods.named('method1'); + var method1 = library.enums.named('E').staticFields.named('field1'); expect(method1.isInherited, false); - expect(method1.isOperator, false); expect(method1.isStatic, true); - expect(method1.isCallable, true); expect(method1.isDocumented, true); expect( method1.linkedName, - 'method1', + 'field1', ); expect(method1.documentationComment, '/// Doc comment.'); } - void test_staticFieldsAreDocumented() async { + void test_staticFieldsCanBeReferenced() async { // TODO(srawlins): As all supported Dart is >=2.15.0, this test can just - // be a "static field" test rather than an "enum" test. + // be a "static fields" test rather than an "enum" test. var library = await bootPackageWithLibrary(''' enum E { - one, two, three; + one, two; - /// Doc comment. - static int field1 = 1; + static int f = 1; } -'''); - var method1 = library.enums.named('E').staticFields.named('field1'); - expect(method1.isInherited, false); - expect(method1.isStatic, true); - expect(method1.isDocumented, true); +/// Reference to [E.f]. +class C {} +'''); + var cClass = library.classes.named('C'); expect( - method1.linkedName, - 'field1', + cClass.documentationAsHtml, + '

Reference to E.f.

', ); - expect(method1.documentationComment, '/// Doc comment.'); } void test_staticGettersAreDocumented() async { @@ -396,69 +349,49 @@ enum E { expect(method1.documentationComment, 'Doc comment.'); } - void test_instanceFieldsAreDocumented() async { + void test_staticMethodsAreDocumented() async { // TODO(srawlins): As all supported Dart is >=2.15.0, this test can just - // be a "fields" test rather than an "enum" test. + // be a "static method" test rather than an "enum" test. var library = await bootPackageWithLibrary(''' enum E { one, two, three; /// Doc comment. - final int field1 = 1; + static int method1(String p) => 7; } '''); - var field1 = library.enums.named('E').instanceFields.named('field1'); + var method1 = library.enums.named('E').staticMethods.named('method1'); - expect(field1.isInherited, false); - expect(field1.isStatic, false); - expect(field1.isDocumented, true); + expect(method1.isInherited, false); + expect(method1.isOperator, false); + expect(method1.isStatic, true); + expect(method1.isCallable, true); + expect(method1.isDocumented, true); expect( - field1.linkedName, - 'field1', + method1.linkedName, + 'method1', ); - expect(field1.documentationComment, '/// Doc comment.'); + expect(method1.documentationComment, '/// Doc comment.'); } - void test_instanceSettersAreDocumented() async { + void test_staticMethodsCanBeReferenced() async { // TODO(srawlins): As all supported Dart is >=2.15.0, this test can just - // be a "setters" test rather than an "enum" test. + // be a "static methods" test rather than an "enum" test. var library = await bootPackageWithLibrary(''' enum E { one, two; - /// A setter. - set x(int value) {} + static void m() {} } -'''); - var xSetter = library.enums.named('E').instanceAccessors.named('x='); - - expect(xSetter.isGetter, false); - expect(xSetter.isSetter, true); - expect(xSetter.isPublic, true); - expect(xSetter.documentationComment, 'A setter.'); - } - - void test_constructorsAreDocumented() async { - // TODO(srawlins): As all supported Dart is >=2.15.0, this test can just - // be a "constructors" test rather than an "enum" test. - var library = await bootPackageWithLibrary(''' -enum E { - one.named(1), - two.named(2); - - final int x; - /// A named constructor. - const E.named(this.x); -} +/// Reference to [E.m]. +class C {} '''); - var namedConstructor = - library.enums.named('E').constructors.named('E.named'); - - expect(namedConstructor.isFactory, false); - expect(namedConstructor.fullyQualifiedName, 'enums.E.named'); - expect(namedConstructor.nameWithGenerics, 'E.named'); - expect(namedConstructor.documentationComment, '/// A named constructor.'); + var cClass = library.classes.named('C'); + expect( + cClass.documentationAsHtml, + '

Reference to E.m.

', + ); } void test_valuesHaveAConstantValueImplementation() async { @@ -487,128 +420,192 @@ enum F { one, two } var fTwoValue = library.enums.named('F').publicEnumValues.named('two'); expect(fTwoValue.constantValueTruncated, 'F()'); } +} - void test_namedConstructorCanBeReferenced() async { - // TODO(srawlins): As all supported Dart is >=2.15.0, this test can just - // be a "constructors" test rather than an "enum" test. +@reflectiveTest +class EnumTest extends DartdocTestBase { + @override + String get libraryName => 'enums'; + + void test_annotatedValue() async { var library = await bootPackageWithLibrary(''' enum E { - one.named(1), - two.named(2); - - const E.named(int x); + @deprecated + one, + two, three } -/// Reference to [E.named]. -class C {} '''); - var cClass = library.classes.named('C'); - expect( - cClass.documentationAsHtml, - '

Reference to E.named.

', - ); + var one = library.enums.named('E').publicEnumValues.named('one'); + expect(one.hasAnnotations, true); + expect(one.annotations, hasLength(1)); + expect(one.isDeprecated, true); } - void test_instanceMethodsCanBeReferenced() async { - // TODO(srawlins): As all supported Dart is >=2.15.0, this test can just - // be a "methods" test rather than an "enum" test. - var library = await bootPackageWithLibrary(''' -enum E { - one, two; + void test_enclosingElement() async { + var library = await bootPackageWithLibrary('enum E { one, two, three }'); + var eEnum = library.enums.named('E'); - /// Doc comment. - static int method1(String p) => 7; + expect(eEnum.enclosingElement.name, 'enums'); + } + + void test_fullyQualifiedName() async { + var library = await bootPackageWithLibrary('enum E { one, two, three }'); + var eEnum = library.enums.named('E'); + + expect(eEnum.fullyQualifiedName, equals('enums.E')); + } + + void test_hasAnnotations() async { + var library = await bootPackageWithLibrary(''' +class C { + const C(); } -/// Reference to [E.method1]. -class C {} +@C() +enum E { one, two, three } '''); - var cClass = library.classes.named('C'); - expect( - cClass.documentationAsHtml, - '

Reference to E.method1.

', - ); + var eEnum = library.enums.named('E'); + + expect(eEnum.hasAnnotations, true); + expect(eEnum.annotations, hasLength(1)); + expect(eEnum.annotations.single.linkedName, + 'C'); } - void test_instanceGettersCanBeReferenced() async { - // TODO(srawlins): As all supported Dart is >=2.15.0, this test can just - // be a "getters" test rather than an "enum" test. + void test_hasDocComment() async { var library = await bootPackageWithLibrary(''' -enum E { - one, two; +/// Doc comment for [E]. +enum E { one, two, three } +'''); + var eEnum = library.enums.named('E'); - /// A getter. - int get x => 1; -} + expect(eEnum.hasDocumentationComment, true); + expect(eEnum.documentationComment, '/// Doc comment for [E].'); + } -/// Reference to [E.x]. + void test_index_canBeReferenced() async { + var library = await bootPackageWithLibrary(''' +enum E { one, two, three } + +/// Reference to [E.index]. class C {} '''); var cClass = library.classes.named('C'); expect( cClass.documentationAsHtml, - '

Reference to E.x.

', + '

Reference to ' + 'E.index.

', ); } - void test_instanceSettersCanBeReferenced() async { - // TODO(srawlins): As all supported Dart is >=2.15.0, this test can just - // be a "setters" test rather than an "enum" test. - var library = await bootPackageWithLibrary(''' -enum E { - one, two; - - /// A setter. - set x(int value) {} -} + void test_index_isLinked() async { + var library = await bootPackageWithLibrary('enum E { one, two, three }'); + var eEnum = library.enums.named('E'); -/// Reference to [E.x]. -class C {} -'''); - var cClass = library.classes.named('C'); + expect(eEnum.instanceFields.map((f) => f.name), contains('index')); expect( - cClass.documentationAsHtml, - '

Reference to E.x.

', + eEnum.instanceFields.named('index').linkedName, + 'index', ); } - void test_staticMethodsCanBeReferenced() async { - // TODO(srawlins): As all supported Dart is >=2.15.0, this test can just - // be a "static methods" test rather than an "enum" test. - var library = await bootPackageWithLibrary(''' -enum E { - one, two; + void test_linkedName() async { + var library = await bootPackageWithLibrary('enum E { one, two, three }'); + var eEnum = library.enums.named('E'); - static void m() {} -} + expect(eEnum.linkedName, equals('E')); + } -/// Reference to [E.m]. + void test_publicEnums() async { + var library = await bootPackageWithLibrary('enum E { one, two, three }'); + expect(library.publicEnums, isNotEmpty); + } + + void test_publicEnumValues() async { + var library = await bootPackageWithLibrary('enum E { one, two, three }'); + var eEnum = library.enums.named('E'); + + expect(eEnum.publicEnumValues, hasLength(3)); + } + + void test_toString() async { + var library = await bootPackageWithLibrary('enum E { one, two, three }'); + var eEnum = library.enums.named('E'); + var toStringMethod = eEnum.instanceMethods.named('toString'); + expect(toStringMethod.characterLocation, isNotNull); + expect(toStringMethod.characterLocation.toString(), + equals(eEnum.characterLocation.toString())); + } + + void test_value_canBeReferenced() async { + var library = await bootPackageWithLibrary(''' +enum E { one, two, three } + +/// Reference to [E.one]. class C {} '''); var cClass = library.classes.named('C'); - expect( - cClass.documentationAsHtml, - '

Reference to E.m.

', - ); + expect(cClass.documentationAsHtml, + '

Reference to E.one.

'); } - void test_staticFieldsCanBeReferenced() async { - // TODO(srawlins): As all supported Dart is >=2.15.0, this test can just - // be a "static fields" test rather than an "enum" test. + void test_value_hasDocComment() async { var library = await bootPackageWithLibrary(''' enum E { - one, two; - - static int f = 1; + /// Doc comment for [E.one]. + one, + two, + three } +'''); + var one = library.enums.named('E').publicEnumValues.named('one'); -/// Reference to [E.f]. + expect(one.hasDocumentationComment, true); + expect(one.documentationComment, '/// Doc comment for [E.one].'); + } + + void test_value_linksToItsAnchor() async { + var library = await bootPackageWithLibrary('enum E { one, two, three }'); + var oneValue = + library.enums.named('E').publicEnumValues.named('one') as EnumField; + expect(oneValue.linkedName, 'one'); + expect(oneValue.constantValue, + equals(EnumFieldRendererHtml().renderValue(oneValue))); + } + + void test_values_haveIndices() async { + var library = await bootPackageWithLibrary('enum E { one, two, three }'); + var oneValue = + library.enums.named('E').publicEnumValues.named('one') as EnumField; + var twoValue = + library.enums.named('E').publicEnumValues.named('two') as EnumField; + var threeValue = + library.enums.named('E').publicEnumValues.named('three') as EnumField; + + expect(oneValue.constantValue, equals('const E(0)')); + expect(twoValue.constantValue, equals('const E(1)')); + expect(threeValue.constantValue, equals('const E(2)')); + } + + void test_valuesConstant() async { + var library = await bootPackageWithLibrary('enum E { one, two, three }'); + var valuesField = library.enums.named('E').constantFields.named('values'); + expect(valuesField.documentation, startsWith('A constant List')); + } + + void test_valuesConstant_canBeReferenced() async { + var library = await bootPackageWithLibrary(''' +enum E { one, two, three } + +/// Reference to [E.values]. class C {} '''); var cClass = library.classes.named('C'); expect( cClass.documentationAsHtml, - '

Reference to E.f.

', + '

Reference to ' + 'E.values.

', ); } }