aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/test/vscode_diagnostics.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/test/vscode_diagnostics.test.ts')
-rw-r--r--editors/code/src/test/vscode_diagnostics.test.ts164
1 files changed, 164 insertions, 0 deletions
diff --git a/editors/code/src/test/vscode_diagnostics.test.ts b/editors/code/src/test/vscode_diagnostics.test.ts
new file mode 100644
index 000000000..ca4345626
--- /dev/null
+++ b/editors/code/src/test/vscode_diagnostics.test.ts
@@ -0,0 +1,164 @@
1import * as assert from 'assert';
2import * as vscode from 'vscode';
3
4import {
5 areCodeActionsEqual,
6 areDiagnosticsEqual
7} from '../utils/vscode_diagnostics';
8
9const uri = vscode.Uri.file('/file/1');
10
11const range1 = new vscode.Range(
12 new vscode.Position(1, 2),
13 new vscode.Position(3, 4)
14);
15
16const range2 = new vscode.Range(
17 new vscode.Position(5, 6),
18 new vscode.Position(7, 8)
19);
20
21describe('areDiagnosticsEqual', () => {
22 it('should treat identical diagnostics as equal', () => {
23 const diagnostic1 = new vscode.Diagnostic(
24 range1,
25 'Hello, world!',
26 vscode.DiagnosticSeverity.Error
27 );
28
29 const diagnostic2 = new vscode.Diagnostic(
30 range1,
31 'Hello, world!',
32 vscode.DiagnosticSeverity.Error
33 );
34
35 assert(areDiagnosticsEqual(diagnostic1, diagnostic2));
36 });
37
38 it('should treat diagnostics with different ranges as inequal', () => {
39 const diagnostic1 = new vscode.Diagnostic(
40 range1,
41 'Hello, world!',
42 vscode.DiagnosticSeverity.Error
43 );
44
45 const diagnostic2 = new vscode.Diagnostic(
46 range2,
47 'Hello, world!',
48 vscode.DiagnosticSeverity.Error
49 );
50
51 assert(!areDiagnosticsEqual(diagnostic1, diagnostic2));
52 });
53
54 it('should treat diagnostics with different messages as inequal', () => {
55 const diagnostic1 = new vscode.Diagnostic(
56 range1,
57 'Hello, world!',
58 vscode.DiagnosticSeverity.Error
59 );
60
61 const diagnostic2 = new vscode.Diagnostic(
62 range1,
63 'Goodbye!, world!',
64 vscode.DiagnosticSeverity.Error
65 );
66
67 assert(!areDiagnosticsEqual(diagnostic1, diagnostic2));
68 });
69
70 it('should treat diagnostics with different severities as inequal', () => {
71 const diagnostic1 = new vscode.Diagnostic(
72 range1,
73 'Hello, world!',
74 vscode.DiagnosticSeverity.Warning
75 );
76
77 const diagnostic2 = new vscode.Diagnostic(
78 range1,
79 'Hello, world!',
80 vscode.DiagnosticSeverity.Error
81 );
82
83 assert(!areDiagnosticsEqual(diagnostic1, diagnostic2));
84 });
85});
86
87describe('areCodeActionsEqual', () => {
88 it('should treat identical actions as equal', () => {
89 const codeAction1 = new vscode.CodeAction(
90 'Fix me!',
91 vscode.CodeActionKind.QuickFix
92 );
93
94 const codeAction2 = new vscode.CodeAction(
95 'Fix me!',
96 vscode.CodeActionKind.QuickFix
97 );
98
99 const edit = new vscode.WorkspaceEdit();
100 edit.replace(uri, range1, 'Replace with this');
101 codeAction1.edit = edit;
102 codeAction2.edit = edit;
103
104 assert(areCodeActionsEqual(codeAction1, codeAction2));
105 });
106
107 it('should treat actions with different types as inequal', () => {
108 const codeAction1 = new vscode.CodeAction(
109 'Fix me!',
110 vscode.CodeActionKind.Refactor
111 );
112
113 const codeAction2 = new vscode.CodeAction(
114 'Fix me!',
115 vscode.CodeActionKind.QuickFix
116 );
117
118 const edit = new vscode.WorkspaceEdit();
119 edit.replace(uri, range1, 'Replace with this');
120 codeAction1.edit = edit;
121 codeAction2.edit = edit;
122
123 assert(!areCodeActionsEqual(codeAction1, codeAction2));
124 });
125
126 it('should treat actions with different titles as inequal', () => {
127 const codeAction1 = new vscode.CodeAction(
128 'Fix me!',
129 vscode.CodeActionKind.Refactor
130 );
131
132 const codeAction2 = new vscode.CodeAction(
133 'Do something different!',
134 vscode.CodeActionKind.Refactor
135 );
136
137 const edit = new vscode.WorkspaceEdit();
138 edit.replace(uri, range1, 'Replace with this');
139 codeAction1.edit = edit;
140 codeAction2.edit = edit;
141
142 assert(!areCodeActionsEqual(codeAction1, codeAction2));
143 });
144
145 it('should treat actions with different edits as inequal', () => {
146 const codeAction1 = new vscode.CodeAction(
147 'Fix me!',
148 vscode.CodeActionKind.Refactor
149 );
150 const edit1 = new vscode.WorkspaceEdit();
151 edit1.replace(uri, range1, 'Replace with this');
152 codeAction1.edit = edit1;
153
154 const codeAction2 = new vscode.CodeAction(
155 'Fix me!',
156 vscode.CodeActionKind.Refactor
157 );
158 const edit2 = new vscode.WorkspaceEdit();
159 edit2.replace(uri, range1, 'Replace with this other thing');
160 codeAction2.edit = edit2;
161
162 assert(!areCodeActionsEqual(codeAction1, codeAction2));
163 });
164});