Skip to content

Commit ab8d74c

Browse files
authored
Migrate the field template test to use the reflective test infra (#3843)
1 parent 4a96cf4 commit ab8d74c

File tree

1 file changed

+76
-78
lines changed

1 file changed

+76
-78
lines changed

test/templates/field_test.dart

Lines changed: 76 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2,99 +2,97 @@
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:dartdoc/src/dartdoc.dart';
7-
import 'package:dartdoc/src/model/model.dart';
8-
import 'package:path/path.dart' as path;
95
import 'package:test/test.dart';
6+
import 'package:test_reflective_loader/test_reflective_loader.dart';
107

11-
import '../src/test_descriptor_utils.dart' as d;
128
import '../src/utils.dart';
9+
import 'template_test_base.dart';
1310

1411
void main() async {
15-
const packageName = 'test_package';
12+
defineReflectiveSuite(() {
13+
defineReflectiveTests(FieldTest);
14+
});
15+
}
1616

17-
late List<String> f1Lines;
17+
@reflectiveTest
18+
class FieldTest extends TemplateTestBase {
19+
@override
20+
String get packageName => 'field_test';
1821

19-
group('methods', () {
20-
setUpAll(() async {
21-
final packageMetaProvider = testPackageMetaProvider;
22-
final resourceProvider =
23-
packageMetaProvider.resourceProvider as MemoryResourceProvider;
24-
final packagePath = await d.createPackage(
25-
packageName,
26-
pubspec: '''
27-
name: fields
28-
version: 0.0.1
29-
environment:
30-
sdk: '>=2.18.0 <3.0.0'
31-
''',
32-
libFiles: [
33-
d.file('lib.dart', '''
34-
class A {
35-
const A(String m);
22+
@override
23+
String get libraryName => 'field';
24+
25+
void test_class_fieldName() async {
26+
await createPackageWithLibrary('''
27+
class C {
28+
int f1 = 1;
3629
}
30+
''');
31+
var f1Lines = readLines(['lib', 'C', 'f1.html']);
32+
f1Lines.expectMainContentContainsAllInOrder(
33+
[
34+
matches('<h1><span class="kind-property">f1</span> property'),
35+
],
36+
);
37+
}
3738

38-
class B {
39+
void test_class_annotations() async {
40+
await createPackageWithLibrary('''
41+
class C {
3942
@deprecated
4043
@A('message')
4144
int f1 = 1;
4245
}
43-
'''),
44-
],
45-
resourceProvider: resourceProvider,
46-
);
47-
await writeDartdocResources(resourceProvider);
48-
final context = await generatorContextFromArgv([
49-
'--input',
50-
packagePath,
51-
'--output',
52-
path.join(packagePath, 'doc'),
53-
'--sdk-dir',
54-
packageMetaProvider.defaultSdkDir.path,
55-
'--no-link-to-remote',
56-
], packageMetaProvider);
5746
58-
final packageConfigProvider =
59-
getTestPackageConfigProvider(packageMetaProvider.defaultSdkDir.path);
60-
packageConfigProvider.addPackageToConfigFor(
61-
packagePath, packageName, Uri.file('$packagePath/'));
62-
final packageBuilder = PubPackageBuilder(
63-
context,
64-
packageMetaProvider,
65-
packageConfigProvider,
66-
skipUnreachableSdkLibraries: true,
67-
);
68-
await (await Dartdoc.fromContext(context, packageBuilder)).generateDocs();
69-
f1Lines = resourceProvider
70-
.getFile(path.join(packagePath, 'doc', 'lib', 'B', 'f1.html'))
71-
.readAsStringSync()
72-
.split('\n');
73-
});
47+
class A {
48+
const A(String m);
49+
}
50+
''');
51+
var f1Lines = readLines(['lib', 'C', 'f1.html']);
52+
f1Lines.expectMainContentContainsAllInOrder(
53+
[
54+
matches('<ol class="annotation-list">'),
55+
matches('<li>@deprecated</li>'),
56+
matches(
57+
r'<li>@<a href="../../lib/A-class.html">A</a>\(&#39;message&#39;\)</li>'),
58+
matches('</ol>'),
59+
],
60+
);
61+
}
7462

75-
test('field page contains method name', () async {
76-
f1Lines.expectMainContentContainsAllInOrder(
77-
[
78-
matches('<h1><span class="kind-property">f1</span> property'),
79-
],
80-
);
81-
});
63+
void test_class_docComment() async {
64+
await createPackageWithLibrary('''
65+
class C {
66+
/// Documentation text.
67+
int f1 = 1;
68+
}
69+
''');
70+
var f1Lines = readLines(['lib', 'C', 'f1.html']);
71+
f1Lines.expectMainContentContainsAllInOrder(
72+
[
73+
matches('<section class="desc markdown">'),
74+
matches('<p>Documentation text.</p>'),
75+
],
76+
);
77+
}
8278

83-
test('field page contains annotations', () async {
84-
f1Lines.expectMainContentContainsAllInOrder(
85-
[
86-
matches('<ol class="annotation-list">'),
87-
matches('<li>@deprecated</li>'),
88-
matches(
89-
r'<li>@<a href="../../lib/A-class.html">A</a>\(&#39;message&#39;\)</li>'),
90-
matches('</ol>'),
91-
],
92-
);
93-
});
79+
void test_extensionType_representationField_final() async {
80+
await createPackageWithLibrary('''
81+
extension type ET(
82+
/// Documentation text.
83+
int f1) {}
84+
''');
85+
var f1Lines = readLines(['lib', 'ET', 'f1.html']);
86+
f1Lines.expectMainContentContainsAllInOrder(
87+
[
88+
matches(
89+
'<div class="features"><span class="feature">final</span></div>'),
90+
],
91+
);
92+
}
9493

95-
// TODO(srawlins): Add rendering tests.
96-
// * how inherited fields look on subclass page ('inherited' feature)
97-
// * static fields
98-
// * linked elements in signature
99-
});
94+
// TODO(srawlins): Add rendering tests:
95+
// * how inherited fields look on subclass page ('inherited' feature)
96+
// * static fields
97+
// * linked elements in signature
10098
}

0 commit comments

Comments
 (0)