2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- import 'package:analyzer/file_system/memory_file_system.dart' ;
6
- import 'package:path/path.dart' as path;
7
5
import 'package:test/test.dart' ;
8
6
import 'package:test_reflective_loader/test_reflective_loader.dart' ;
9
7
10
- import '../dartdoc_test_base.dart' ;
11
- import '../src/test_descriptor_utils.dart' as d;
12
8
import '../src/utils.dart' ;
9
+ import 'template_test_base.dart' ;
13
10
14
11
void main () async {
15
12
defineReflectiveSuite (() {
@@ -18,57 +15,19 @@ void main() async {
18
15
}
19
16
20
17
@reflectiveTest
21
- class ClassTest extends DartdocTestBase {
22
- static const packageName = 'class_test' ;
18
+ class ClassTest extends TemplateTestBase {
19
+ @override
20
+ String get packageName => 'class_test' ;
23
21
24
22
@override
25
23
String get libraryName => 'class' ;
26
24
27
- Future <void > createPackage ({
28
- List <d.Descriptor > libFiles = const [],
29
- }) async {
30
- packagePath = await d.createPackage (
31
- packageName,
32
- pubspec: '''
33
- name: class_test
34
- version: 0.0.1
35
- environment:
36
- sdk: '>=3.3.0-0 <4.0.0'
37
- ''' ,
38
- dartdocOptions: '''
39
- dartdoc:
40
- linkToSource:
41
- root: '.'
42
- uriTemplate: 'https://github.com/dart-lang/TEST_PKG/%f%#L%l%'
43
- ''' ,
44
- libFiles: libFiles,
45
- resourceProvider: resourceProvider,
46
- );
47
- await writeDartdocResources (resourceProvider);
48
- packageConfigProvider.addPackageToConfigFor (
49
- packagePath, packageName, Uri .file ('$packagePath /' ));
50
- }
51
-
52
- Future <List <String >> createPackageAndReadLines ({
53
- required List <d.Descriptor > libFiles,
54
- required List <String > filePath,
55
- }) async {
56
- await createPackage (libFiles: libFiles);
57
- await (await buildDartdoc ()).generateDocs ();
58
-
59
- return resourceProvider.readLines ([packagePath, 'doc' , ...filePath]);
60
- }
61
-
62
- void test_class_extends () async {
63
- var baseLines = await createPackageAndReadLines (
64
- libFiles: [
65
- d.file ('lib.dart' , '''
25
+ void test_implementers_class_extends () async {
26
+ await createPackageWithLibrary ('''
66
27
class Base {}
67
28
class Foo extends Base {}
68
- ''' ),
69
- ],
70
- filePath: ['lib' , 'Base-class.html' ],
71
- );
29
+ ''' );
30
+ var baseLines = readLines (['lib' , 'Base-class.html' ]);
72
31
73
32
baseLines.expectMainContentContainsAllInOrder ([
74
33
matches ('<dt>Implementers</dt>' ),
@@ -78,16 +37,12 @@ class Foo extends Base {}
78
37
]);
79
38
}
80
39
81
- void test_class_implements () async {
82
- var baseLines = await createPackageAndReadLines (
83
- libFiles: [
84
- d.file ('lib.dart' , '''
40
+ void test_implementers_class_implements () async {
41
+ await createPackageWithLibrary ('''
85
42
class Base {}
86
43
class Foo implements Base {}
87
- ''' ),
88
- ],
89
- filePath: ['lib' , 'Base-class.html' ],
90
- );
44
+ ''' );
45
+ var baseLines = readLines (['lib' , 'Base-class.html' ]);
91
46
92
47
baseLines.expectMainContentContainsAllInOrder ([
93
48
matches ('<dt>Implementers</dt>' ),
@@ -97,16 +52,12 @@ class Foo implements Base {}
97
52
]);
98
53
}
99
54
100
- void test_class_implements_withGenericType () async {
101
- var baseLines = await createPackageAndReadLines (
102
- libFiles: [
103
- d.file ('lib.dart' , '''
55
+ void test_implementers_class_implements_withGenericType () async {
56
+ await createPackageWithLibrary ('''
104
57
class Base<E> {}
105
58
class Foo<E> implements Base<E> {}
106
- ''' ),
107
- ],
108
- filePath: ['lib' , 'Base-class.html' ],
109
- );
59
+ ''' );
60
+ var baseLines = readLines (['lib' , 'Base-class.html' ]);
110
61
111
62
baseLines.expectMainContentContainsAllInOrder ([
112
63
matches ('<dt>Implementers</dt>' ),
@@ -116,16 +67,12 @@ class Foo<E> implements Base<E> {}
116
67
]);
117
68
}
118
69
119
- void test_class_implements_withInstantiatedType () async {
120
- var baseLines = await createPackageAndReadLines (
121
- libFiles: [
122
- d.file ('lib.dart' , '''
70
+ void test_implementers_class_implements_withInstantiatedType () async {
71
+ await createPackageWithLibrary ('''
123
72
class Base<E> {}
124
73
class Foo implements Base<int> {}
125
- ''' ),
126
- ],
127
- filePath: ['lib' , 'Base-class.html' ],
128
- );
74
+ ''' );
75
+ var baseLines = readLines (['lib' , 'Base-class.html' ]);
129
76
130
77
baseLines.expectMainContentContainsAllInOrder ([
131
78
matches ('<dt>Implementers</dt>' ),
@@ -135,17 +82,13 @@ class Foo implements Base<int> {}
135
82
]);
136
83
}
137
84
138
- void test_extensionType_implements () async {
139
- var base1Lines = await createPackageAndReadLines (
140
- libFiles: [
141
- d.file ('lib.dart' , '''
85
+ void test_implementers_extensionType_implements () async {
86
+ await createPackageWithLibrary ('''
142
87
class Base1 {}
143
88
class Base2 extends Base1 {}
144
89
extension type ET(Base2 base) implements Base1 {}
145
- ''' ),
146
- ],
147
- filePath: ['lib' , 'Base1-class.html' ],
148
- );
90
+ ''' );
91
+ var base1Lines = readLines (['lib' , 'Base1-class.html' ]);
149
92
150
93
base1Lines.expectMainContentContainsAllInOrder ([
151
94
matches ('<dt>Implementers</dt>' ),
@@ -156,16 +99,12 @@ extension type ET(Base2 base) implements Base1 {}
156
99
]);
157
100
}
158
101
159
- void test_mixin_implements () async {
160
- var baseLines = await createPackageAndReadLines (
161
- libFiles: [
162
- d.file ('lib.dart' , '''
102
+ void test_implementers_mixin_implements () async {
103
+ await createPackageWithLibrary ('''
163
104
class Base {}
164
105
mixin M implements Base {}
165
- ''' ),
166
- ],
167
- filePath: ['lib' , 'Base-class.html' ],
168
- );
106
+ ''' );
107
+ var baseLines = readLines (['lib' , 'Base-class.html' ]);
169
108
170
109
baseLines.expectMainContentContainsAllInOrder ([
171
110
matches ('<dt>Implementers</dt>' ),
@@ -176,16 +115,12 @@ mixin M implements Base {}
176
115
}
177
116
178
117
@FailingTest (reason: 'Not implemented yet; should be?' )
179
- void test_mixin_superclassConstraint () async {
180
- var baseLines = await createPackageAndReadLines (
181
- libFiles: [
182
- d.file ('lib.dart' , '''
118
+ void test_implementers_mixin_superclassConstraint () async {
119
+ await createPackageWithLibrary ('''
183
120
class Base {}
184
121
mixin M on Base {}
185
- ''' ),
186
- ],
187
- filePath: ['lib' , 'Base-class.html' ],
188
- );
122
+ ''' );
123
+ var baseLines = readLines (['lib' , 'Base-class.html' ]);
189
124
190
125
baseLines.expectMainContentContainsAllInOrder ([
191
126
matches ('<dt>Implementers</dt>' ),
@@ -194,9 +129,70 @@ mixin M on Base {}
194
129
matches ('</ul></dd>' ),
195
130
]);
196
131
}
132
+
133
+ void test_constructor_named () async {
134
+ await createPackageWithLibrary ('''
135
+ class C {
136
+ /// A named constructor.
137
+ C.named();
138
+ }
139
+ ''' );
140
+ var htmlLines = readLines (['lib' , 'C-class.html' ]);
141
+
142
+ htmlLines.expectMainContentContainsAllInOrder ([
143
+ matches ('<h2>Constructors</h2>' ),
144
+ matches ('<a href="../lib/C/C.named.html">C.named</a>' ),
145
+ matches ('A named constructor.' ),
146
+ ]);
147
+ }
148
+
149
+ void test_constructor_unnamed () async {
150
+ await createPackageWithLibrary ('''
151
+ class C {
152
+ /// An unnamed constructor.
153
+ C();
197
154
}
155
+ ''' );
156
+ var htmlLines = readLines (['lib' , 'C-class.html' ]);
157
+
158
+ htmlLines.expectMainContentContainsAllInOrder ([
159
+ matches ('<h2>Constructors</h2>' ),
160
+ matches ('<a href="../lib/C/C.html">C</a>' ),
161
+ matches ('An unnamed constructor.' ),
162
+ ]);
163
+ }
198
164
199
- extension on MemoryResourceProvider {
200
- List <String > readLines (List <String > pathParts) =>
201
- getFile (path.joinAll (pathParts)).readAsStringSync ().split ('\n ' );
165
+ void test_instanceMethod () async {
166
+ await createPackageWithLibrary ('''
167
+ class C {
168
+ /// An instance method.
169
+ void m1() {}
170
+ }
171
+ ''' );
172
+ var htmlLines = readLines (['lib' , 'C-class.html' ]);
173
+
174
+ htmlLines.expectMainContentContainsAllInOrder ([
175
+ matches ('<h2>Methods</h2>' ),
176
+ matches ('<dt id="m1" class="callable">' ),
177
+ matches ('<a href="../lib/C/m1.html">m1</a>' ),
178
+ matches ('An instance method.' ),
179
+ ]);
180
+ }
181
+
182
+ void test_instanceMethod_generic () async {
183
+ await createPackageWithLibrary ('''
184
+ abstract class C {
185
+ /// An instance method.
186
+ T m1<T extends num>(T a);
187
+ }
188
+ ''' );
189
+ var htmlLines = readLines (['lib' , 'C-class.html' ]);
190
+
191
+ htmlLines.expectMainContentContainsAllInOrder ([
192
+ matches ('<h2>Methods</h2>' ),
193
+ matches ('<dt id="m1" class="callable">' ),
194
+ matches ('<a href="../lib/C/m1.html">m1</a>' ),
195
+ matches ('An instance method.' ),
196
+ ]);
197
+ }
202
198
}
0 commit comments