forked from dart-code-checker/dart-code-metrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
format_comment_test.dart
127 lines (116 loc) · 4.53 KB
/
format_comment_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
import 'package:dart_code_metrics/src/analyzers/lint_analyzer/models/severity.dart';
import 'package:dart_code_metrics/src/analyzers/lint_analyzer/rules/rules_list/format_comment/format_comment_rule.dart';
import 'package:test/test.dart';
import '../../../../../helpers/rule_test_helper.dart';
const _examplePath = 'format_comment/examples/example.dart';
const _withoutIssuePath = 'format_comment/examples/example_without_issue.dart';
const _multiline = 'format_comment/examples/example_documentation.dart';
void main() {
group('FormatCommentRule', () {
test('initialization', () async {
final unit = await RuleTestHelper.resolveFromFile(_examplePath);
final issues = FormatCommentRule().check(unit);
RuleTestHelper.verifyInitialization(
issues: issues,
ruleId: 'format-comment',
severity: Severity.style,
);
});
test('reports about found issues', () async {
final unit = await RuleTestHelper.resolveFromFile(_examplePath);
final issues = FormatCommentRule().check(unit);
RuleTestHelper.verifyIssues(
issues: issues,
startLines: [1, 3, 5, 8, 10],
startColumns: [1, 3, 5, 3, 5],
locationTexts: [
'// With start space without dot',
'//Without start space without dot',
'// with start space with dot.',
'/// With start space without dot',
'/// with start space with dot.',
],
messages: [
'Prefer formatting comments like sentences.',
'Prefer formatting comments like sentences.',
'Prefer formatting comments like sentences.',
'Prefer formatting comments like sentences.',
'Prefer formatting comments like sentences.',
],
replacements: [
'// With start space without dot.',
'// Without start space without dot.',
'// With start space with dot.',
'/// With start space without dot.',
'/// With start space with dot.',
],
);
});
test('reports about found issues in cases from documentation', () async {
final unit = await RuleTestHelper.resolveFromFile(_multiline);
final issues = FormatCommentRule().check(unit);
RuleTestHelper.verifyIssues(
issues: issues,
startLines: [2, 5, 9, 13, 17],
startColumns: [3, 3, 1, 3, 1],
locationTexts: [
'/// The value this wraps',
'/// true if this box contains a value.',
'//not if there is nothing before it',
'// assume we have a valid name.',
'/// deletes the file at [path] from the file system.',
],
messages: [
'Prefer formatting comments like sentences.',
'Prefer formatting comments like sentences.',
'Prefer formatting comments like sentences.',
'Prefer formatting comments like sentences.',
'Prefer formatting comments like sentences.',
],
replacements: [
'/// The value this wraps.',
'/// True if this box contains a value.',
'// Not if there is nothing before it.',
'// Assume we have a valid name.',
'/// Deletes the file at [path] from the file system.',
],
);
});
test('reports no issues', () async {
final unit = await RuleTestHelper.resolveFromFile(_withoutIssuePath);
RuleTestHelper.verifyNoIssues(FormatCommentRule().check(unit));
});
test('ignores the given patterns', () async {
final unit = await RuleTestHelper.resolveFromFile(_examplePath);
final issues = FormatCommentRule(const {
'ignored-patterns': [
// Ignores all the comments that start with 'Without'.
r'^Without.*$',
],
}).check(unit);
RuleTestHelper.verifyIssues(
issues: issues,
startLines: [1, 5, 8, 10],
startColumns: [1, 5, 3, 5],
locationTexts: [
'// With start space without dot',
'// with start space with dot.',
'/// With start space without dot',
'/// with start space with dot.',
],
messages: [
'Prefer formatting comments like sentences.',
'Prefer formatting comments like sentences.',
'Prefer formatting comments like sentences.',
'Prefer formatting comments like sentences.',
],
replacements: [
'// With start space without dot.',
'// With start space with dot.',
'/// With start space without dot.',
'/// With start space with dot.',
],
);
});
});
}