|
| 1 | +import 'package:dart_code_metrics/src/analyzers/lint_analyzer/models/severity.dart'; |
| 2 | +import 'package:dart_code_metrics/src/analyzers/lint_analyzer/rules/rules_list/format_comment/format_comment_rule.dart'; |
| 3 | +import 'package:test/test.dart'; |
| 4 | + |
| 5 | +import '../../../../../helpers/rule_test_helper.dart'; |
| 6 | + |
| 7 | +const _examplePath = 'format_comment/examples/example.dart'; |
| 8 | +const _withoutIssuePath = 'format_comment/examples/example_without_issue.dart'; |
| 9 | +const _multiline = 'format_comment/examples/example_documentation.dart'; |
| 10 | + |
| 11 | +void main() { |
| 12 | + group('FormatCommentRule', () { |
| 13 | + test('initialization', () async { |
| 14 | + final unit = await RuleTestHelper.resolveFromFile(_examplePath); |
| 15 | + final issues = FormatCommentRule().check(unit); |
| 16 | + |
| 17 | + RuleTestHelper.verifyInitialization( |
| 18 | + issues: issues, |
| 19 | + ruleId: 'format-comment', |
| 20 | + severity: Severity.style, |
| 21 | + ); |
| 22 | + }); |
| 23 | + |
| 24 | + test('reports about found issues', () async { |
| 25 | + final unit = await RuleTestHelper.resolveFromFile(_examplePath); |
| 26 | + final issues = FormatCommentRule().check(unit); |
| 27 | + |
| 28 | + RuleTestHelper.verifyIssues( |
| 29 | + issues: issues, |
| 30 | + startLines: [1, 3, 5, 8, 10], |
| 31 | + startColumns: [1, 3, 5, 3, 5], |
| 32 | + locationTexts: [ |
| 33 | + '// With start space without dot', |
| 34 | + '//Without start space without dot', |
| 35 | + '// with start space with dot.', |
| 36 | + '/// With start space without dot', |
| 37 | + '/// with start space with dot.', |
| 38 | + ], |
| 39 | + messages: [ |
| 40 | + 'Prefer formatting comments like sentences.', |
| 41 | + 'Prefer formatting comments like sentences.', |
| 42 | + 'Prefer formatting comments like sentences.', |
| 43 | + 'Prefer formatting comments like sentences.', |
| 44 | + 'Prefer formatting comments like sentences.', |
| 45 | + ], |
| 46 | + replacements: [ |
| 47 | + '// With start space without dot.', |
| 48 | + '// Without start space without dot.', |
| 49 | + '// With start space with dot.', |
| 50 | + '/// With start space without dot.', |
| 51 | + '/// With start space with dot.', |
| 52 | + ], |
| 53 | + ); |
| 54 | + }); |
| 55 | + |
| 56 | + test('reports about found issues in cases from documentation', () async { |
| 57 | + final unit = await RuleTestHelper.resolveFromFile(_multiline); |
| 58 | + final issues = FormatCommentRule().check(unit); |
| 59 | + |
| 60 | + RuleTestHelper.verifyIssues( |
| 61 | + issues: issues, |
| 62 | + startLines: [2, 5, 9, 13, 17], |
| 63 | + startColumns: [3, 3, 1, 3, 1], |
| 64 | + locationTexts: [ |
| 65 | + '/// The value this wraps', |
| 66 | + '/// true if this box contains a value.', |
| 67 | + '//not if there is nothing before it', |
| 68 | + '// assume we have a valid name.', |
| 69 | + '/// deletes the file at [path] from the file system.', |
| 70 | + ], |
| 71 | + messages: [ |
| 72 | + 'Prefer formatting comments like sentences.', |
| 73 | + 'Prefer formatting comments like sentences.', |
| 74 | + 'Prefer formatting comments like sentences.', |
| 75 | + 'Prefer formatting comments like sentences.', |
| 76 | + 'Prefer formatting comments like sentences.', |
| 77 | + ], |
| 78 | + replacements: [ |
| 79 | + '/// The value this wraps.', |
| 80 | + '/// True if this box contains a value.', |
| 81 | + '// Not if there is nothing before it.', |
| 82 | + '// Assume we have a valid name.', |
| 83 | + '/// Deletes the file at [path] from the file system.', |
| 84 | + ], |
| 85 | + ); |
| 86 | + }); |
| 87 | + |
| 88 | + test('reports no issues', () async { |
| 89 | + final unit = await RuleTestHelper.resolveFromFile(_withoutIssuePath); |
| 90 | + RuleTestHelper.verifyNoIssues(FormatCommentRule().check(unit)); |
| 91 | + }); |
| 92 | + }); |
| 93 | +} |
0 commit comments