Skip to content

Commit

Permalink
Remove Class assert for ClassTypedef. (#3595)
Browse files Browse the repository at this point in the history
  • Loading branch information
kallentu committed Dec 8, 2023
1 parent 2244cf0 commit 337f40f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 31 deletions.
3 changes: 2 additions & 1 deletion lib/src/model/typedef.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ class GeneralizedTypedef extends Typedef {
class ClassTypedef extends Typedef {
ClassTypedef(super.element, super.library, super.packageGraph) {
assert(!isCallable);
assert(modelType.modelElement is Class);
// TODO(kallentu): Make sure typedef testing is covered for each interface
// element.
}

@override
Expand Down
96 changes: 66 additions & 30 deletions test/typedef_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,38 @@ void main() {

@reflectiveTest
class TypedefTest extends DartdocTestBase {
@override
List<String> get experiments => ['inline-class'];

@override
String get libraryName => 'typedefs';

@override
String get sdkConstraint => '>=3.0.0 <4.0.0';
String get sdkConstraint => '>=3.3.0 <4.0.0';

void test_class_basic() async {
var library = await bootPackageWithLibrary('''
class C {}
typedef T = C;
''');
final tTypedef = library.typedefs.named('T');
expect(tTypedef.nameWithGenerics, 'T');
expect(tTypedef.genericParameters, '');
expect(tTypedef.aliasedType, isA<InterfaceType>());
}

void test_extensionType_basic() async {
var library = await bootPackageWithLibrary('''
extension type E(int i) {}
typedef T = E;
''');
final tTypedef = library.typedefs.named('T');
expect(tTypedef.nameWithGenerics, 'T');
expect(tTypedef.genericParameters, '');
expect(tTypedef.aliasedType, isA<InterfaceType>());
}

void test_basicFunctionTypedef() async {
void test_function_basic() async {
var library = await bootPackageWithLibrary('''
/// Line _one_.
///
Expand All @@ -52,7 +77,7 @@ Line _two_.''');
<p>Line <em>two</em>.</p>''');
}

void test_genericFunctionTypedef() async {
void test_function_generic() async {
var library = await bootPackageWithLibrary('''
typedef Cb2<T> = T Function(T);
''');
Expand All @@ -69,7 +94,7 @@ typedef Cb2<T> = T Function(T);
expect(cb2Typedef.aliasedType, isA<FunctionType>());
}

void test_genericFunctionTypedefReferringToGenericTypedef() async {
void test_function_generic_referringToGenericTypedef() async {
var library = await bootPackageWithLibrary('''
typedef Cb2<T> = T Function(T);
Expand All @@ -92,7 +117,7 @@ typedef Cb3<T> = Cb2<List<T>>;
// TODO(srawlins): Dramatically improve typedef testing.
}

void test_typedefInDocCommentReference() async {
void test_inDocCommentReference() async {
var library = await bootPackageWithLibrary('''
typedef Cb2<T> = T Function(T);
Expand All @@ -111,7 +136,39 @@ typedef Cb3<T> = Cb2<List<T>>;
);
}

void test_basicRecordTypedef() async {
void test_inDocCommentReference2() async {
var library = await bootPackageWithLibrary('''
typedef R2<T> = (T, String);
/// Not unlike [R2].
typedef R3<T> = R2<List<T>>;
''');
final r3Typedef = library.typedefs.named('R3');

expect(r3Typedef.isDocumented, isTrue);

expect(r3Typedef.documentation, 'Not unlike [R2].');

expect(
r3Typedef.documentationAsHtml,
'<p>Not unlike '
'<a href="%%__HTMLBASE_dartdoc_internal__%%typedefs/R2.html">R2</a>.'
'</p>',
);
}

void test_mixin_basic() async {
var library = await bootPackageWithLibrary('''
mixin M {}
typedef T = M;
''');
final tTypedef = library.typedefs.named('T');
expect(tTypedef.nameWithGenerics, 'T');
expect(tTypedef.genericParameters, '');
expect(tTypedef.aliasedType, isA<InterfaceType>());
}

void test_record_basic() async {
var library = await bootPackageWithLibrary('''
/// Line _one_.
///
Expand All @@ -137,7 +194,7 @@ Line _two_.''');
<p>Line <em>two</em>.</p>''');
}

void test_genericRecordTypedef() async {
void test_record_generic() async {
var library = await bootPackageWithLibrary('''
typedef R2<T> = (T, String);
''');
Expand All @@ -154,7 +211,7 @@ typedef R2<T> = (T, String);
expect(r2Typedef.aliasedType, isA<RecordType>());
}

void test_genericRecordTypedefReferringToGenericTypedef() async {
void test_record_generic_referringToGenericTypedef() async {
var library = await bootPackageWithLibrary('''
typedef R2<T> = (T, String);
Expand All @@ -174,28 +231,7 @@ typedef R3<T> = R2<List<T>>;
expect(r3Typedef.aliasedType, isA<RecordType>());
}

void test_typedefInDocCommentReference2() async {
var library = await bootPackageWithLibrary('''
typedef R2<T> = (T, String);
/// Not unlike [R2].
typedef R3<T> = R2<List<T>>;
''');
final r3Typedef = library.typedefs.named('R3');

expect(r3Typedef.isDocumented, isTrue);

expect(r3Typedef.documentation, 'Not unlike [R2].');

expect(
r3Typedef.documentationAsHtml,
'<p>Not unlike '
'<a href="%%__HTMLBASE_dartdoc_internal__%%typedefs/R2.html">R2</a>.'
'</p>',
);
}

void test_typedefRetainsAliasWhenUsed() async {
void test_retainsAliasWhenUsed() async {
var library = await bootPackageWithLibrary('''
typedef R<T> = (T, String);
Expand Down

0 comments on commit 337f40f

Please sign in to comment.