This repository has been archived by the owner on Jul 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 258
/
lint_console_reporter_helper_test.dart
115 lines (104 loc) · 3.32 KB
/
lint_console_reporter_helper_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
import 'package:ansicolor/ansicolor.dart';
import 'package:dart_code_metrics/src/analyzers/lint_analyzer/metrics/models/metric_value_level.dart';
import 'package:dart_code_metrics/src/analyzers/lint_analyzer/models/issue.dart';
import 'package:dart_code_metrics/src/analyzers/lint_analyzer/models/severity.dart';
import 'package:dart_code_metrics/src/analyzers/lint_analyzer/reporters/reporters_list/console/lint_console_reporter_helper.dart';
import 'package:source_span/source_span.dart';
import 'package:test/test.dart';
import '../../../../../../stubs_builders.dart';
void main() {
group('LintConsoleReporterHelper', () {
late LintConsoleReporterHelper helper;
setUp(() {
ansiColorDisabled = false;
helper = LintConsoleReporterHelper();
});
test('getIssueMessage returns formatted message', () {
final location = SourceSpan(
SourceLocation(0, line: 1, column: 2),
SourceLocation(1, line: 2, column: 3),
' ',
);
expect(
helper.getIssueMessage(
Issue(
ruleId: 'rule',
documentation: Uri.parse('https://dartcodemetrics/rules/rule'),
location: location,
severity: Severity.warning,
message: 'Issue message',
verboseMessage: 'Issue verbose message',
),
'lib/src/my_source.dart',
),
equals([
'\x1B[38;5;180mWARNING \x1B[0mIssue message',
' at \x1B[38;5;39mlib/src/my_source.dart:1:2\x1B[0m',
' rule : https://dartcodemetrics/rules/rule',
'',
]),
);
expect(
helper.getIssueMessage(
Issue(
ruleId: 'rule',
documentation: Uri.parse('https://dartcodemetrics/rules/rule'),
location: location,
severity: Severity.none,
message: 'Issue message',
verboseMessage: 'Issue verbose message',
),
'lib/src/my_source.dart',
),
equals([
'\x1B[38;5;7m \x1B[0mIssue message',
' at \x1B[38;5;39mlib/src/my_source.dart:1:2\x1B[0m',
' rule : https://dartcodemetrics/rules/rule',
'',
]),
);
});
test('getMetricMessage returns formatted message', () {
expect(
helper.getMetricMessage(MetricValueLevel.alarm, 'Class.method', []),
isEmpty,
);
expect(
helper.getMetricMessage(
MetricValueLevel.alarm,
'Class.method',
['violation1', 'violation2'],
),
equals([
'\x1B[38;5;167mALARM \x1B[0mClass.method',
' violation1',
' violation2',
'',
]),
);
expect(
helper.getMetricMessage(
MetricValueLevel.none,
'Class.method',
['violation1', 'violation2'],
),
equals([
'\x1B[38;5;7mNONE \x1B[0mClass.method',
' violation1',
' violation2',
'',
]),
);
});
test('getMetricReport returns formatted message', () {
expect(
helper.getMetricReport(buildMetricValueStub(
id: 'metricId',
value: 12,
unitType: 'units',
)),
equals('metricid: \x1B[38;5;7m12 units\x1B[0m'),
);
});
});
}