|
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:dartdoc/src/dartdoc.dart'; |
7 |
| -import 'package:dartdoc/src/model/model.dart'; |
8 |
| -import 'package:path/path.dart' as path; |
9 | 5 | import 'package:test/test.dart';
|
| 6 | +import 'package:test_reflective_loader/test_reflective_loader.dart'; |
10 | 7 |
|
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 |
| - const packageName = 'test_package'; |
| 12 | + defineReflectiveSuite(() { |
| 13 | + defineReflectiveTests(FieldTest); |
| 14 | + }); |
| 15 | +} |
16 | 16 |
|
17 |
| - late List<String> f1Lines; |
| 17 | +@reflectiveTest |
| 18 | +class FieldTest extends TemplateTestBase { |
| 19 | + @override |
| 20 | + String get packageName => 'field_test'; |
18 | 21 |
|
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; |
36 | 29 | }
|
| 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 | + } |
37 | 38 |
|
38 |
| -class B { |
| 39 | + void test_class_annotations() async { |
| 40 | + await createPackageWithLibrary(''' |
| 41 | +class C { |
39 | 42 | @deprecated
|
40 | 43 | @A('message')
|
41 | 44 | int f1 = 1;
|
42 | 45 | }
|
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); |
57 | 46 |
|
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>\('message'\)</li>'), |
| 58 | + matches('</ol>'), |
| 59 | + ], |
| 60 | + ); |
| 61 | + } |
74 | 62 |
|
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 | + } |
82 | 78 |
|
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>\('message'\)</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 | + } |
94 | 93 |
|
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 |
100 | 98 | }
|
0 commit comments