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