@@ -11,7 +11,7 @@ import 'src/test_descriptor_utils.dart' as d;
11
11
import 'src/utils.dart' ;
12
12
13
13
void main () {
14
- group ('typedefs' , () {
14
+ group ('typedefs of function types ' , () {
15
15
late Library library;
16
16
17
17
// It is expensive (~10s) to compute a package graph, even skipping
@@ -33,6 +33,7 @@ typedef Cb1 = void Function();
33
33
34
34
typedef Cb2<T> = T Function(T);
35
35
36
+ /// Not unlike [Cb2].
36
37
typedef Cb3<T> = Cb2<List<T>>;
37
38
''' ),
38
39
],
@@ -52,12 +53,12 @@ typedef Cb3<T> = Cb2<List<T>>;
52
53
library = packageGraph.libraries.named (libraryName);
53
54
});
54
55
55
- test ('basic typedef' , () async {
56
+ test ('basic function typedef' , () async {
56
57
final cb1Typedef = library.typedefs.named ('Cb1' );
57
58
58
59
expect (cb1Typedef.nameWithGenerics, 'Cb1' );
59
60
expect (cb1Typedef.genericParameters, '' );
60
- expect (cb1Typedef.aliasedType is FunctionType , isTrue );
61
+ expect (cb1Typedef.aliasedType, isA < FunctionType >() );
61
62
expect (cb1Typedef.documentationComment, '''
62
63
/// Line _one_.
63
64
///
@@ -72,7 +73,7 @@ Line _two_.''');
72
73
<p>Line <em>two</em>.</p>''' );
73
74
});
74
75
75
- test ('generic typedef' , () async {
76
+ test ('generic function typedef' , () async {
76
77
final cb2Typedef = library.typedefs.named ('Cb2' );
77
78
78
79
expect (
@@ -83,10 +84,10 @@ Line _two_.''');
83
84
cb2Typedef.genericParameters,
84
85
'<<wbr><span class="type-parameter">T</span>>' ,
85
86
);
86
- expect (cb2Typedef.aliasedType is FunctionType , isTrue );
87
+ expect (cb2Typedef.aliasedType, isA < FunctionType >() );
87
88
});
88
89
89
- test ('generic typedef referring to a generic typedef' , () async {
90
+ test ('generic function typedef referring to a generic typedef' , () async {
90
91
final cb3Typedef = library.typedefs.named ('Cb3' );
91
92
92
93
expect (
@@ -97,11 +98,132 @@ Line _two_.''');
97
98
cb3Typedef.genericParameters,
98
99
'<<wbr><span class="type-parameter">T</span>>' ,
99
100
);
100
- expect (cb3Typedef.aliasedType is FunctionType , isTrue );
101
+ expect (cb3Typedef.aliasedType, isA < FunctionType >() );
101
102
102
103
expect (cb3Typedef.parameters, hasLength (1 ));
103
104
104
105
// TODO(srawlins): Dramatically improve typedef testing.
105
106
});
107
+
108
+ test ('typedef in a doc comment reference' , () {
109
+ final cb3Typedef = library.typedefs.named ('Cb3' );
110
+
111
+ expect (cb3Typedef.isDocumented, isTrue);
112
+
113
+ expect (cb3Typedef.documentation, 'Not unlike [Cb2].' );
114
+
115
+ expect (
116
+ cb3Typedef.documentationAsHtml,
117
+ '<p>Not unlike '
118
+ '<a href="%%__HTMLBASE_dartdoc_internal__%%typedefs/Cb2.html">Cb2</a>.'
119
+ '</p>' ,
120
+ );
121
+ });
122
+ });
123
+
124
+ group ('typedefs of record types' , skip: ! recordsAllowed, () {
125
+ late Library library;
126
+
127
+ // It is expensive (~10s) to compute a package graph, even skipping
128
+ // unreachable Dart SDK libraries, so we set up this package once.
129
+ setUpAll (() async {
130
+ const libraryName = 'typedefs' ;
131
+ final packageMetaProvider = testPackageMetaProvider;
132
+
133
+ final packagePath = await d.createPackage (
134
+ libraryName,
135
+ libFiles: [
136
+ d.file ('lib.dart' , '''
137
+ library $libraryName ;
138
+
139
+ /// Line _one_.
140
+ ///
141
+ /// Line _two_.
142
+ typedef R1 = (int, String);
143
+
144
+ typedef R2<T> = (T, String);
145
+
146
+ /// Not unlike [R2].
147
+ typedef R3<T> = R2<List<T>>;
148
+ ''' ),
149
+ ],
150
+ resourceProvider:
151
+ packageMetaProvider.resourceProvider as MemoryResourceProvider ,
152
+ );
153
+ final packageConfigProvider =
154
+ getTestPackageConfigProvider (packageMetaProvider.defaultSdkDir.path);
155
+ packageConfigProvider.addPackageToConfigFor (
156
+ packagePath, libraryName, Uri .file ('$packagePath /' ));
157
+
158
+ final packageGraph = await bootBasicPackage (
159
+ packagePath,
160
+ packageMetaProvider,
161
+ packageConfigProvider,
162
+ );
163
+ library = packageGraph.libraries.named (libraryName);
164
+ });
165
+
166
+ test ('basic record typedef' , () async {
167
+ final r1Typedef = library.typedefs.named ('R1' );
168
+
169
+ expect (r1Typedef.nameWithGenerics, 'R1' );
170
+ expect (r1Typedef.genericParameters, '' );
171
+ expect (r1Typedef.aliasedType, isA <RecordType >());
172
+ expect (r1Typedef.documentationComment, '''
173
+ /// Line _one_.
174
+ ///
175
+ /// Line _two_.''' );
176
+ expect (r1Typedef.documentation, '''
177
+ Line _one_.
178
+
179
+ Line _two_.''' );
180
+ expect (r1Typedef.oneLineDoc, 'Line <em>one</em>.' );
181
+ expect (r1Typedef.documentationAsHtml, '''
182
+ <p>Line <em>one</em>.</p>
183
+ <p>Line <em>two</em>.</p>''' );
184
+ });
185
+
186
+ test ('generic record typedef' , () async {
187
+ final r2Typedef = library.typedefs.named ('R2' );
188
+
189
+ expect (
190
+ r2Typedef.nameWithGenerics,
191
+ 'R2<<wbr><span class="type-parameter">T</span>>' ,
192
+ );
193
+ expect (
194
+ r2Typedef.genericParameters,
195
+ '<<wbr><span class="type-parameter">T</span>>' ,
196
+ );
197
+ expect (r2Typedef.aliasedType, isA <RecordType >());
198
+ });
199
+
200
+ test ('generic record typedef referring to a generic typedef' , () async {
201
+ final r3Typedef = library.typedefs.named ('R3' );
202
+
203
+ expect (
204
+ r3Typedef.nameWithGenerics,
205
+ 'R3<<wbr><span class="type-parameter">T</span>>' ,
206
+ );
207
+ expect (
208
+ r3Typedef.genericParameters,
209
+ '<<wbr><span class="type-parameter">T</span>>' ,
210
+ );
211
+ expect (r3Typedef.aliasedType, isA <RecordType >());
212
+ });
213
+
214
+ test ('typedef in a doc comment reference' , () {
215
+ final r3Typedef = library.typedefs.named ('R3' );
216
+
217
+ expect (r3Typedef.isDocumented, isTrue);
218
+
219
+ expect (r3Typedef.documentation, 'Not unlike [R2].' );
220
+
221
+ expect (
222
+ r3Typedef.documentationAsHtml,
223
+ '<p>Not unlike '
224
+ '<a href="%%__HTMLBASE_dartdoc_internal__%%typedefs/R2.html">R2</a>.'
225
+ '</p>' ,
226
+ );
227
+ });
106
228
});
107
229
}
0 commit comments