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
|
import * as assert from 'assert';
import * as vscode from 'vscode';
import {
areCodeActionsEqual,
areDiagnosticsEqual
} from '../utils/vscode_diagnostics';
const uri = vscode.Uri.file('/file/1');
const range1 = new vscode.Range(
new vscode.Position(1, 2),
new vscode.Position(3, 4)
);
const range2 = new vscode.Range(
new vscode.Position(5, 6),
new vscode.Position(7, 8)
);
describe('areDiagnosticsEqual', () => {
it('should treat identical diagnostics as equal', () => {
const diagnostic1 = new vscode.Diagnostic(
range1,
'Hello, world!',
vscode.DiagnosticSeverity.Error
);
const diagnostic2 = new vscode.Diagnostic(
range1,
'Hello, world!',
vscode.DiagnosticSeverity.Error
);
assert(areDiagnosticsEqual(diagnostic1, diagnostic2));
});
it('should treat diagnostics with different sources as inequal', () => {
const diagnostic1 = new vscode.Diagnostic(
range1,
'Hello, world!',
vscode.DiagnosticSeverity.Error
);
diagnostic1.source = 'rustc';
const diagnostic2 = new vscode.Diagnostic(
range1,
'Hello, world!',
vscode.DiagnosticSeverity.Error
);
diagnostic2.source = 'clippy';
assert(!areDiagnosticsEqual(diagnostic1, diagnostic2));
});
it('should treat diagnostics with different ranges as inequal', () => {
const diagnostic1 = new vscode.Diagnostic(
range1,
'Hello, world!',
vscode.DiagnosticSeverity.Error
);
const diagnostic2 = new vscode.Diagnostic(
range2,
'Hello, world!',
vscode.DiagnosticSeverity.Error
);
assert(!areDiagnosticsEqual(diagnostic1, diagnostic2));
});
it('should treat diagnostics with different messages as inequal', () => {
const diagnostic1 = new vscode.Diagnostic(
range1,
'Hello, world!',
vscode.DiagnosticSeverity.Error
);
const diagnostic2 = new vscode.Diagnostic(
range1,
'Goodbye!, world!',
vscode.DiagnosticSeverity.Error
);
assert(!areDiagnosticsEqual(diagnostic1, diagnostic2));
});
it('should treat diagnostics with different severities as inequal', () => {
const diagnostic1 = new vscode.Diagnostic(
range1,
'Hello, world!',
vscode.DiagnosticSeverity.Warning
);
const diagnostic2 = new vscode.Diagnostic(
range1,
'Hello, world!',
vscode.DiagnosticSeverity.Error
);
assert(!areDiagnosticsEqual(diagnostic1, diagnostic2));
});
});
describe('areCodeActionsEqual', () => {
it('should treat identical actions as equal', () => {
const codeAction1 = new vscode.CodeAction(
'Fix me!',
vscode.CodeActionKind.QuickFix
);
const codeAction2 = new vscode.CodeAction(
'Fix me!',
vscode.CodeActionKind.QuickFix
);
const edit = new vscode.WorkspaceEdit();
edit.replace(uri, range1, 'Replace with this');
codeAction1.edit = edit;
codeAction2.edit = edit;
assert(areCodeActionsEqual(codeAction1, codeAction2));
});
it('should treat actions with different types as inequal', () => {
const codeAction1 = new vscode.CodeAction(
'Fix me!',
vscode.CodeActionKind.Refactor
);
const codeAction2 = new vscode.CodeAction(
'Fix me!',
vscode.CodeActionKind.QuickFix
);
const edit = new vscode.WorkspaceEdit();
edit.replace(uri, range1, 'Replace with this');
codeAction1.edit = edit;
codeAction2.edit = edit;
assert(!areCodeActionsEqual(codeAction1, codeAction2));
});
it('should treat actions with different titles as inequal', () => {
const codeAction1 = new vscode.CodeAction(
'Fix me!',
vscode.CodeActionKind.Refactor
);
const codeAction2 = new vscode.CodeAction(
'Do something different!',
vscode.CodeActionKind.Refactor
);
const edit = new vscode.WorkspaceEdit();
edit.replace(uri, range1, 'Replace with this');
codeAction1.edit = edit;
codeAction2.edit = edit;
assert(!areCodeActionsEqual(codeAction1, codeAction2));
});
it('should treat actions with different edits as inequal', () => {
const codeAction1 = new vscode.CodeAction(
'Fix me!',
vscode.CodeActionKind.Refactor
);
const edit1 = new vscode.WorkspaceEdit();
edit1.replace(uri, range1, 'Replace with this');
codeAction1.edit = edit1;
const codeAction2 = new vscode.CodeAction(
'Fix me!',
vscode.CodeActionKind.Refactor
);
const edit2 = new vscode.WorkspaceEdit();
edit2.replace(uri, range1, 'Replace with this other thing');
codeAction2.edit = edit2;
assert(!areCodeActionsEqual(codeAction1, codeAction2));
});
});
|