forked from dart-lang/dartdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomment_processable_test.dart
195 lines (161 loc) · 4.52 KB
/
comment_processable_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:io' show Directory;
import 'package:dartdoc/src/dartdoc_options.dart';
import 'package:dartdoc/src/model/model.dart';
import 'package:dartdoc/src/package_meta.dart';
import 'package:dartdoc/src/warnings.dart';
import 'package:mockito/mockito.dart';
import 'package:test/test.dart';
void main() {
_Processor processor;
setUp(() {
processor = _Processor(_FakeDartdocOptionContext());
processor.href = '/project/a.dart';
});
test('removes triple slashes', () async {
var doc = await processor.processComment('''
/// Text.
/// More text.
''');
expect(doc, equals('''
Text.
More text.'''));
});
test('removes space after triple slashes', () async {
var doc = await processor.processComment('''
/// Text.
/// More text.
''');
// TODO(srawlins): Actually, the three spaces before 'More' is perhaps not
// the best fit. Should it only be two, to match the indent from the first
// line's "Text"?
expect(doc, equals('''
Text.
More text.'''));
});
test('leaves blank lines', () async {
var doc = await processor.processComment('''
/// Text.
///
/// More text.
''');
expect(doc, equals('''
Text.
More text.'''));
});
test('processes @template', () async {
var doc = await processor.processComment('''
/// Text.
///
/// {@template abc}
/// Template text.
/// {@endtemplate}
///
/// End text.
''');
expect(doc, equals('''
Text.
{@macro abc}
End text.'''));
verify(processor.packageGraph.addMacro('abc', 'Template text.')).called(1);
});
test('processes leading @template', () async {
var doc = await processor.processComment('''
/// {@template abc}
/// Template text.
/// {@endtemplate}
///
/// End text.
''');
expect(doc, equals('''
{@macro abc}
End text.'''));
verify(processor.packageGraph.addMacro('abc', 'Template text.')).called(1);
});
test('processes trailing @template', () async {
var doc = await processor.processComment('''
/// Text.
///
/// {@template abc}
/// Template text.
/// {@endtemplate}
''');
expect(doc, equals('''
Text.
{@macro abc}'''));
verify(processor.packageGraph.addMacro('abc', 'Template text.')).called(1);
});
test('processes @template w/o blank line following', () async {
var doc = await processor.processComment('''
/// Text.
///
/// {@template abc}
/// Template text.
/// {@endtemplate}
/// End text.
''');
expect(doc, equals('''
Text.
{@macro abc}
End text.'''));
verify(processor.packageGraph.addMacro('abc', 'Template text.')).called(1);
});
test('allows whitespace around @template name', () async {
var doc = await processor.processComment('''
/// {@template abc }
/// Template text.
/// {@endtemplate}
''');
expect(doc, equals('''
{@macro abc}'''));
verify(processor.packageGraph.addMacro('abc', 'Template text.')).called(1);
});
// TODO(srawlins): More unit tests: @example, @youtube, @animation,
// @inject-html, @tool.
}
/// In order to mix in [CommentProcessable], we must first implement
/// the super-class constraints.
abstract class __Processor extends Fake
implements Documentable, Warnable, Locatable, SourceCodeMixin {}
/// A simple comment processor for testing [CommentProcessable].
class _Processor extends __Processor with CommentProcessable {
@override
final _FakeDartdocOptionContext config;
@override
final _FakePackage package;
@override
final _MockPackageGraph packageGraph;
@override
String href;
_Processor(this.config)
: package = _FakePackage(),
packageGraph = _MockPackageGraph() {
throwOnMissingStub(packageGraph);
when(packageGraph.addMacro(any, any)).thenReturn(null);
}
}
class _FakeDirectory extends Fake implements Directory {
@override
final String path;
_FakeDirectory() : path = '/project';
}
class _FakePackage extends Fake implements Package {
@override
final PackageMeta packageMeta;
_FakePackage() : packageMeta = _FakePackageMeta();
}
class _FakePackageMeta extends Fake implements PackageMeta {
@override
final Directory dir;
_FakePackageMeta() : dir = _FakeDirectory();
}
class _FakeDartdocOptionContext extends Fake implements DartdocOptionContext {
@override
final bool allowTools;
@override
final bool injectHtml;
_FakeDartdocOptionContext({this.allowTools = false, this.injectHtml = false});
}
class _MockPackageGraph extends Mock implements PackageGraph {}