22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5- import 'package:analyzer/file_system/memory_file_system.dart' ;
6- import 'package:path/path.dart' as path;
75import 'package:test/test.dart' ;
86import 'package:test_reflective_loader/test_reflective_loader.dart' ;
97
10- import '../dartdoc_test_base.dart' ;
11- import '../src/test_descriptor_utils.dart' as d;
128import '../src/utils.dart' ;
9+ import 'template_test_base.dart' ;
1310
1411void main () async {
1512 defineReflectiveSuite (() {
@@ -18,57 +15,19 @@ void main() async {
1815}
1916
2017@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' ;
2321
2422 @override
2523 String get libraryName => 'class' ;
2624
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 ('''
6627class Base {}
6728class Foo extends Base {}
68- ''' ),
69- ],
70- filePath: ['lib' , 'Base-class.html' ],
71- );
29+ ''' );
30+ var baseLines = readLines (['lib' , 'Base-class.html' ]);
7231
7332 baseLines.expectMainContentContainsAllInOrder ([
7433 matches ('<dt>Implementers</dt>' ),
@@ -78,16 +37,12 @@ class Foo extends Base {}
7837 ]);
7938 }
8039
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 ('''
8542class Base {}
8643class Foo implements Base {}
87- ''' ),
88- ],
89- filePath: ['lib' , 'Base-class.html' ],
90- );
44+ ''' );
45+ var baseLines = readLines (['lib' , 'Base-class.html' ]);
9146
9247 baseLines.expectMainContentContainsAllInOrder ([
9348 matches ('<dt>Implementers</dt>' ),
@@ -97,16 +52,12 @@ class Foo implements Base {}
9752 ]);
9853 }
9954
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 ('''
10457class Base<E> {}
10558class Foo<E> implements Base<E> {}
106- ''' ),
107- ],
108- filePath: ['lib' , 'Base-class.html' ],
109- );
59+ ''' );
60+ var baseLines = readLines (['lib' , 'Base-class.html' ]);
11061
11162 baseLines.expectMainContentContainsAllInOrder ([
11263 matches ('<dt>Implementers</dt>' ),
@@ -116,16 +67,12 @@ class Foo<E> implements Base<E> {}
11667 ]);
11768 }
11869
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 ('''
12372class Base<E> {}
12473class Foo implements Base<int> {}
125- ''' ),
126- ],
127- filePath: ['lib' , 'Base-class.html' ],
128- );
74+ ''' );
75+ var baseLines = readLines (['lib' , 'Base-class.html' ]);
12976
13077 baseLines.expectMainContentContainsAllInOrder ([
13178 matches ('<dt>Implementers</dt>' ),
@@ -135,17 +82,13 @@ class Foo implements Base<int> {}
13582 ]);
13683 }
13784
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 ('''
14287class Base1 {}
14388class Base2 extends Base1 {}
14489extension type ET(Base2 base) implements Base1 {}
145- ''' ),
146- ],
147- filePath: ['lib' , 'Base1-class.html' ],
148- );
90+ ''' );
91+ var base1Lines = readLines (['lib' , 'Base1-class.html' ]);
14992
15093 base1Lines.expectMainContentContainsAllInOrder ([
15194 matches ('<dt>Implementers</dt>' ),
@@ -156,16 +99,12 @@ extension type ET(Base2 base) implements Base1 {}
15699 ]);
157100 }
158101
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 ('''
163104class Base {}
164105mixin M implements Base {}
165- ''' ),
166- ],
167- filePath: ['lib' , 'Base-class.html' ],
168- );
106+ ''' );
107+ var baseLines = readLines (['lib' , 'Base-class.html' ]);
169108
170109 baseLines.expectMainContentContainsAllInOrder ([
171110 matches ('<dt>Implementers</dt>' ),
@@ -176,16 +115,12 @@ mixin M implements Base {}
176115 }
177116
178117 @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 ('''
183120class Base {}
184121mixin M on Base {}
185- ''' ),
186- ],
187- filePath: ['lib' , 'Base-class.html' ],
188- );
122+ ''' );
123+ var baseLines = readLines (['lib' , 'Base-class.html' ]);
189124
190125 baseLines.expectMainContentContainsAllInOrder ([
191126 matches ('<dt>Implementers</dt>' ),
@@ -194,9 +129,70 @@ mixin M on Base {}
194129 matches ('</ul></dd>' ),
195130 ]);
196131 }
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();
197154}
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+ }
198164
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+ }
202198}
0 commit comments