aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/test
diff options
context:
space:
mode:
authorSeivan Heidari <[email protected]>2019-12-23 14:35:31 +0000
committerSeivan Heidari <[email protected]>2019-12-23 14:35:31 +0000
commitb21d9337d9200e2cfdc90b386591c72c302dc03e (patch)
treef81f5c08f821115cee26fa4d3ceaae88c7807fd5 /editors/code/src/test
parent18a0937585b836ec5ed054b9ae48e0156ab6d9ef (diff)
parentce07a2daa9e53aa86a769f8641b14c2878444fbc (diff)
Merge branch 'master' into feature/themes
Diffstat (limited to 'editors/code/src/test')
-rw-r--r--editors/code/src/test/fixtures/rust-diagnostics/error/E0277.json261
-rw-r--r--editors/code/src/test/utils/diagnotics/SuggestedFix.test.ts29
-rw-r--r--editors/code/src/test/utils/diagnotics/SuggestedFixCollection.test.ts26
-rw-r--r--editors/code/src/test/utils/diagnotics/rust.test.ts92
-rw-r--r--editors/code/src/test/utils/diagnotics/vscode.test.ts24
-rw-r--r--editors/code/src/test/utils/index.ts2
6 files changed, 367 insertions, 67 deletions
diff --git a/editors/code/src/test/fixtures/rust-diagnostics/error/E0277.json b/editors/code/src/test/fixtures/rust-diagnostics/error/E0277.json
new file mode 100644
index 000000000..bfef33c7d
--- /dev/null
+++ b/editors/code/src/test/fixtures/rust-diagnostics/error/E0277.json
@@ -0,0 +1,261 @@
1{
2 "rendered": "error[E0277]: can't compare `{integer}` with `&str`\n --> src/main.rs:2:5\n |\n2 | assert_eq!(1, \"love\");\n | ^^^^^^^^^^^^^^^^^^^^^^ no implementation for `{integer} == &str`\n |\n = help: the trait `std::cmp::PartialEq<&str>` is not implemented for `{integer}`\n = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)\n\n",
3 "children": [
4 {
5 "children": [],
6 "code": null,
7 "level": "help",
8 "message": "the trait `std::cmp::PartialEq<&str>` is not implemented for `{integer}`",
9 "rendered": null,
10 "spans": []
11 }
12 ],
13 "code": {
14 "code": "E0277",
15 "explanation": "\nYou tried to use a type which doesn't implement some trait in a place which\nexpected that trait. Erroneous code example:\n\n```compile_fail,E0277\n// here we declare the Foo trait with a bar method\ntrait Foo {\n fn bar(&self);\n}\n\n// we now declare a function which takes an object implementing the Foo trait\nfn some_func<T: Foo>(foo: T) {\n foo.bar();\n}\n\nfn main() {\n // we now call the method with the i32 type, which doesn't implement\n // the Foo trait\n some_func(5i32); // error: the trait bound `i32 : Foo` is not satisfied\n}\n```\n\nIn order to fix this error, verify that the type you're using does implement\nthe trait. Example:\n\n```\ntrait Foo {\n fn bar(&self);\n}\n\nfn some_func<T: Foo>(foo: T) {\n foo.bar(); // we can now use this method since i32 implements the\n // Foo trait\n}\n\n// we implement the trait on the i32 type\nimpl Foo for i32 {\n fn bar(&self) {}\n}\n\nfn main() {\n some_func(5i32); // ok!\n}\n```\n\nOr in a generic context, an erroneous code example would look like:\n\n```compile_fail,E0277\nfn some_func<T>(foo: T) {\n println!(\"{:?}\", foo); // error: the trait `core::fmt::Debug` is not\n // implemented for the type `T`\n}\n\nfn main() {\n // We now call the method with the i32 type,\n // which *does* implement the Debug trait.\n some_func(5i32);\n}\n```\n\nNote that the error here is in the definition of the generic function: Although\nwe only call it with a parameter that does implement `Debug`, the compiler\nstill rejects the function: It must work with all possible input types. In\norder to make this example compile, we need to restrict the generic type we're\naccepting:\n\n```\nuse std::fmt;\n\n// Restrict the input type to types that implement Debug.\nfn some_func<T: fmt::Debug>(foo: T) {\n println!(\"{:?}\", foo);\n}\n\nfn main() {\n // Calling the method is still fine, as i32 implements Debug.\n some_func(5i32);\n\n // This would fail to compile now:\n // struct WithoutDebug;\n // some_func(WithoutDebug);\n}\n```\n\nRust only looks at the signature of the called function, as such it must\nalready specify all requirements that will be used for every type parameter.\n"
16 },
17 "level": "error",
18 "message": "can't compare `{integer}` with `&str`",
19 "spans": [
20 {
21 "byte_end": 155,
22 "byte_start": 153,
23 "column_end": 33,
24 "column_start": 31,
25 "expansion": {
26 "def_site_span": {
27 "byte_end": 940,
28 "byte_start": 0,
29 "column_end": 6,
30 "column_start": 1,
31 "expansion": null,
32 "file_name": "<::core::macros::assert_eq macros>",
33 "is_primary": false,
34 "label": null,
35 "line_end": 36,
36 "line_start": 1,
37 "suggested_replacement": null,
38 "suggestion_applicability": null,
39 "text": [
40 {
41 "highlight_end": 35,
42 "highlight_start": 1,
43 "text": "($ left : expr, $ right : expr) =>"
44 },
45 {
46 "highlight_end": 3,
47 "highlight_start": 1,
48 "text": "({"
49 },
50 {
51 "highlight_end": 33,
52 "highlight_start": 1,
53 "text": " match (& $ left, & $ right)"
54 },
55 {
56 "highlight_end": 7,
57 "highlight_start": 1,
58 "text": " {"
59 },
60 {
61 "highlight_end": 34,
62 "highlight_start": 1,
63 "text": " (left_val, right_val) =>"
64 },
65 {
66 "highlight_end": 11,
67 "highlight_start": 1,
68 "text": " {"
69 },
70 {
71 "highlight_end": 46,
72 "highlight_start": 1,
73 "text": " if ! (* left_val == * right_val)"
74 },
75 {
76 "highlight_end": 15,
77 "highlight_start": 1,
78 "text": " {"
79 },
80 {
81 "highlight_end": 25,
82 "highlight_start": 1,
83 "text": " panic !"
84 },
85 {
86 "highlight_end": 57,
87 "highlight_start": 1,
88 "text": " (r#\"assertion failed: `(left == right)`"
89 },
90 {
91 "highlight_end": 16,
92 "highlight_start": 1,
93 "text": " left: `{:?}`,"
94 },
95 {
96 "highlight_end": 18,
97 "highlight_start": 1,
98 "text": " right: `{:?}`\"#,"
99 },
100 {
101 "highlight_end": 47,
102 "highlight_start": 1,
103 "text": " & * left_val, & * right_val)"
104 },
105 {
106 "highlight_end": 15,
107 "highlight_start": 1,
108 "text": " }"
109 },
110 {
111 "highlight_end": 11,
112 "highlight_start": 1,
113 "text": " }"
114 },
115 {
116 "highlight_end": 7,
117 "highlight_start": 1,
118 "text": " }"
119 },
120 {
121 "highlight_end": 42,
122 "highlight_start": 1,
123 "text": " }) ; ($ left : expr, $ right : expr,) =>"
124 },
125 {
126 "highlight_end": 49,
127 "highlight_start": 1,
128 "text": "({ $ crate :: assert_eq ! ($ left, $ right) }) ;"
129 },
130 {
131 "highlight_end": 53,
132 "highlight_start": 1,
133 "text": "($ left : expr, $ right : expr, $ ($ arg : tt) +) =>"
134 },
135 {
136 "highlight_end": 3,
137 "highlight_start": 1,
138 "text": "({"
139 },
140 {
141 "highlight_end": 37,
142 "highlight_start": 1,
143 "text": " match (& ($ left), & ($ right))"
144 },
145 {
146 "highlight_end": 7,
147 "highlight_start": 1,
148 "text": " {"
149 },
150 {
151 "highlight_end": 34,
152 "highlight_start": 1,
153 "text": " (left_val, right_val) =>"
154 },
155 {
156 "highlight_end": 11,
157 "highlight_start": 1,
158 "text": " {"
159 },
160 {
161 "highlight_end": 46,
162 "highlight_start": 1,
163 "text": " if ! (* left_val == * right_val)"
164 },
165 {
166 "highlight_end": 15,
167 "highlight_start": 1,
168 "text": " {"
169 },
170 {
171 "highlight_end": 25,
172 "highlight_start": 1,
173 "text": " panic !"
174 },
175 {
176 "highlight_end": 57,
177 "highlight_start": 1,
178 "text": " (r#\"assertion failed: `(left == right)`"
179 },
180 {
181 "highlight_end": 16,
182 "highlight_start": 1,
183 "text": " left: `{:?}`,"
184 },
185 {
186 "highlight_end": 22,
187 "highlight_start": 1,
188 "text": " right: `{:?}`: {}\"#,"
189 },
190 {
191 "highlight_end": 72,
192 "highlight_start": 1,
193 "text": " & * left_val, & * right_val, $ crate :: format_args !"
194 },
195 {
196 "highlight_end": 33,
197 "highlight_start": 1,
198 "text": " ($ ($ arg) +))"
199 },
200 {
201 "highlight_end": 15,
202 "highlight_start": 1,
203 "text": " }"
204 },
205 {
206 "highlight_end": 11,
207 "highlight_start": 1,
208 "text": " }"
209 },
210 {
211 "highlight_end": 7,
212 "highlight_start": 1,
213 "text": " }"
214 },
215 {
216 "highlight_end": 6,
217 "highlight_start": 1,
218 "text": " }) ;"
219 }
220 ]
221 },
222 "macro_decl_name": "assert_eq!",
223 "span": {
224 "byte_end": 38,
225 "byte_start": 16,
226 "column_end": 27,
227 "column_start": 5,
228 "expansion": null,
229 "file_name": "src/main.rs",
230 "is_primary": false,
231 "label": null,
232 "line_end": 2,
233 "line_start": 2,
234 "suggested_replacement": null,
235 "suggestion_applicability": null,
236 "text": [
237 {
238 "highlight_end": 27,
239 "highlight_start": 5,
240 "text": " assert_eq!(1, \"love\");"
241 }
242 ]
243 }
244 },
245 "file_name": "<::core::macros::assert_eq macros>",
246 "is_primary": true,
247 "label": "no implementation for `{integer} == &str`",
248 "line_end": 7,
249 "line_start": 7,
250 "suggested_replacement": null,
251 "suggestion_applicability": null,
252 "text": [
253 {
254 "highlight_end": 33,
255 "highlight_start": 31,
256 "text": " if ! (* left_val == * right_val)"
257 }
258 ]
259 }
260 ]
261}
diff --git a/editors/code/src/test/utils/diagnotics/SuggestedFix.test.ts b/editors/code/src/test/utils/diagnotics/SuggestedFix.test.ts
index 6c7f436f3..2b25eb705 100644
--- a/editors/code/src/test/utils/diagnotics/SuggestedFix.test.ts
+++ b/editors/code/src/test/utils/diagnotics/SuggestedFix.test.ts
@@ -6,12 +6,12 @@ import SuggestedFix from '../../../utils/diagnostics/SuggestedFix';
6 6
7const location1 = new vscode.Location( 7const location1 = new vscode.Location(
8 vscode.Uri.file('/file/1'), 8 vscode.Uri.file('/file/1'),
9 new vscode.Range(new vscode.Position(1, 2), new vscode.Position(3, 4)) 9 new vscode.Range(new vscode.Position(1, 2), new vscode.Position(3, 4)),
10); 10);
11 11
12const location2 = new vscode.Location( 12const location2 = new vscode.Location(
13 vscode.Uri.file('/file/2'), 13 vscode.Uri.file('/file/2'),
14 new vscode.Range(new vscode.Position(5, 6), new vscode.Position(7, 8)) 14 new vscode.Range(new vscode.Position(5, 6), new vscode.Position(7, 8)),
15); 15);
16 16
17describe('SuggestedFix', () => { 17describe('SuggestedFix', () => {
@@ -20,13 +20,13 @@ describe('SuggestedFix', () => {
20 const suggestion1 = new SuggestedFix( 20 const suggestion1 = new SuggestedFix(
21 'Replace me!', 21 'Replace me!',
22 location1, 22 location1,
23 'With this!' 23 'With this!',
24 ); 24 );
25 25
26 const suggestion2 = new SuggestedFix( 26 const suggestion2 = new SuggestedFix(
27 'Replace me!', 27 'Replace me!',
28 location1, 28 location1,
29 'With this!' 29 'With this!',
30 ); 30 );
31 31
32 assert(suggestion1.isEqual(suggestion2)); 32 assert(suggestion1.isEqual(suggestion2));
@@ -36,13 +36,13 @@ describe('SuggestedFix', () => {
36 const suggestion1 = new SuggestedFix( 36 const suggestion1 = new SuggestedFix(
37 'Replace me!', 37 'Replace me!',
38 location1, 38 location1,
39 'With this!' 39 'With this!',
40 ); 40 );
41 41
42 const suggestion2 = new SuggestedFix( 42 const suggestion2 = new SuggestedFix(
43 'Not the same title!', 43 'Not the same title!',
44 location1, 44 location1,
45 'With this!' 45 'With this!',
46 ); 46 );
47 47
48 assert(!suggestion1.isEqual(suggestion2)); 48 assert(!suggestion1.isEqual(suggestion2));
@@ -52,13 +52,13 @@ describe('SuggestedFix', () => {
52 const suggestion1 = new SuggestedFix( 52 const suggestion1 = new SuggestedFix(
53 'Replace me!', 53 'Replace me!',
54 location1, 54 location1,
55 'With this!' 55 'With this!',
56 ); 56 );
57 57
58 const suggestion2 = new SuggestedFix( 58 const suggestion2 = new SuggestedFix(
59 'Replace me!', 59 'Replace me!',
60 location1, 60 location1,
61 'With something else!' 61 'With something else!',
62 ); 62 );
63 63
64 assert(!suggestion1.isEqual(suggestion2)); 64 assert(!suggestion1.isEqual(suggestion2));
@@ -68,13 +68,13 @@ describe('SuggestedFix', () => {
68 const suggestion1 = new SuggestedFix( 68 const suggestion1 = new SuggestedFix(
69 'Replace me!', 69 'Replace me!',
70 location1, 70 location1,
71 'With this!' 71 'With this!',
72 ); 72 );
73 73
74 const suggestion2 = new SuggestedFix( 74 const suggestion2 = new SuggestedFix(
75 'Replace me!', 75 'Replace me!',
76 location2, 76 location2,
77 'With this!' 77 'With this!',
78 ); 78 );
79 79
80 assert(!suggestion1.isEqual(suggestion2)); 80 assert(!suggestion1.isEqual(suggestion2));
@@ -85,14 +85,14 @@ describe('SuggestedFix', () => {
85 'Replace me!', 85 'Replace me!',
86 location1, 86 location1,
87 'With this!', 87 'With this!',
88 SuggestionApplicability.MachineApplicable 88 SuggestionApplicability.MachineApplicable,
89 ); 89 );
90 90
91 const suggestion2 = new SuggestedFix( 91 const suggestion2 = new SuggestedFix(
92 'Replace me!', 92 'Replace me!',
93 location2, 93 location2,
94 'With this!', 94 'With this!',
95 SuggestionApplicability.HasPlaceholders 95 SuggestionApplicability.HasPlaceholders,
96 ); 96 );
97 97
98 assert(!suggestion1.isEqual(suggestion2)); 98 assert(!suggestion1.isEqual(suggestion2));
@@ -104,7 +104,7 @@ describe('SuggestedFix', () => {
104 const suggestion = new SuggestedFix( 104 const suggestion = new SuggestedFix(
105 'Replace me!', 105 'Replace me!',
106 location1, 106 location1,
107 'With this!' 107 'With this!',
108 ); 108 );
109 109
110 const codeAction = suggestion.toCodeAction(); 110 const codeAction = suggestion.toCodeAction();
@@ -114,7 +114,8 @@ describe('SuggestedFix', () => {
114 114
115 const edit = codeAction.edit; 115 const edit = codeAction.edit;
116 if (!edit) { 116 if (!edit) {
117 return assert.fail('Code Action edit unexpectedly missing'); 117 assert.fail('Code Action edit unexpectedly missing');
118 return;
118 } 119 }
119 120
120 const editEntries = edit.entries(); 121 const editEntries = edit.entries();
diff --git a/editors/code/src/test/utils/diagnotics/SuggestedFixCollection.test.ts b/editors/code/src/test/utils/diagnotics/SuggestedFixCollection.test.ts
index f0328893e..ef09013f4 100644
--- a/editors/code/src/test/utils/diagnotics/SuggestedFixCollection.test.ts
+++ b/editors/code/src/test/utils/diagnotics/SuggestedFixCollection.test.ts
@@ -8,20 +8,20 @@ const uri1 = vscode.Uri.file('/file/1');
8const uri2 = vscode.Uri.file('/file/2'); 8const uri2 = vscode.Uri.file('/file/2');
9 9
10const mockDocument1 = ({ 10const mockDocument1 = ({
11 uri: uri1 11 uri: uri1,
12} as unknown) as vscode.TextDocument; 12} as unknown) as vscode.TextDocument;
13 13
14const mockDocument2 = ({ 14const mockDocument2 = ({
15 uri: uri2 15 uri: uri2,
16} as unknown) as vscode.TextDocument; 16} as unknown) as vscode.TextDocument;
17 17
18const range1 = new vscode.Range( 18const range1 = new vscode.Range(
19 new vscode.Position(1, 2), 19 new vscode.Position(1, 2),
20 new vscode.Position(3, 4) 20 new vscode.Position(3, 4),
21); 21);
22const range2 = new vscode.Range( 22const range2 = new vscode.Range(
23 new vscode.Position(5, 6), 23 new vscode.Position(5, 6),
24 new vscode.Position(7, 8) 24 new vscode.Position(7, 8),
25); 25);
26 26
27const diagnostic1 = new vscode.Diagnostic(range1, 'First diagnostic'); 27const diagnostic1 = new vscode.Diagnostic(range1, 'First diagnostic');
@@ -32,7 +32,7 @@ function suggestion1(): SuggestedFix {
32 return new SuggestedFix( 32 return new SuggestedFix(
33 'Replace me!', 33 'Replace me!',
34 new vscode.Location(uri1, range1), 34 new vscode.Location(uri1, range1),
35 'With this!' 35 'With this!',
36 ); 36 );
37} 37}
38 38
@@ -44,7 +44,7 @@ describe('SuggestedFixCollection', () => {
44 // Specify the document and range that exactly matches 44 // Specify the document and range that exactly matches
45 const codeActions = suggestedFixes.provideCodeActions( 45 const codeActions = suggestedFixes.provideCodeActions(
46 mockDocument1, 46 mockDocument1,
47 range1 47 range1,
48 ); 48 );
49 49
50 assert.strictEqual(codeActions.length, 1); 50 assert.strictEqual(codeActions.length, 1);
@@ -53,7 +53,8 @@ describe('SuggestedFixCollection', () => {
53 53
54 const { diagnostics } = codeAction; 54 const { diagnostics } = codeAction;
55 if (!diagnostics) { 55 if (!diagnostics) {
56 return assert.fail('Diagnostics unexpectedly missing'); 56 assert.fail('Diagnostics unexpectedly missing');
57 return;
57 } 58 }
58 59
59 assert.strictEqual(diagnostics.length, 1); 60 assert.strictEqual(diagnostics.length, 1);
@@ -66,7 +67,7 @@ describe('SuggestedFixCollection', () => {
66 67
67 const codeActions = suggestedFixes.provideCodeActions( 68 const codeActions = suggestedFixes.provideCodeActions(
68 mockDocument1, 69 mockDocument1,
69 range2 70 range2,
70 ); 71 );
71 72
72 assert(!codeActions || codeActions.length === 0); 73 assert(!codeActions || codeActions.length === 0);
@@ -78,7 +79,7 @@ describe('SuggestedFixCollection', () => {
78 79
79 const codeActions = suggestedFixes.provideCodeActions( 80 const codeActions = suggestedFixes.provideCodeActions(
80 mockDocument2, 81 mockDocument2,
81 range1 82 range1,
82 ); 83 );
83 84
84 assert(!codeActions || codeActions.length === 0); 85 assert(!codeActions || codeActions.length === 0);
@@ -91,7 +92,7 @@ describe('SuggestedFixCollection', () => {
91 92
92 const codeActions = suggestedFixes.provideCodeActions( 93 const codeActions = suggestedFixes.provideCodeActions(
93 mockDocument1, 94 mockDocument1,
94 range1 95 range1,
95 ); 96 );
96 97
97 assert(!codeActions || codeActions.length === 0); 98 assert(!codeActions || codeActions.length === 0);
@@ -106,7 +107,7 @@ describe('SuggestedFixCollection', () => {
106 107
107 const codeActions = suggestedFixes.provideCodeActions( 108 const codeActions = suggestedFixes.provideCodeActions(
108 mockDocument1, 109 mockDocument1,
109 range1 110 range1,
110 ); 111 );
111 112
112 assert.strictEqual(codeActions.length, 1); 113 assert.strictEqual(codeActions.length, 1);
@@ -114,7 +115,8 @@ describe('SuggestedFixCollection', () => {
114 const { diagnostics } = codeAction; 115 const { diagnostics } = codeAction;
115 116
116 if (!diagnostics) { 117 if (!diagnostics) {
117 return assert.fail('Diagnostics unexpectedly missing'); 118 assert.fail('Diagnostics unexpectedly missing');
119 return;
118 } 120 }
119 121
120 // We should be associated with both diagnostics 122 // We should be associated with both diagnostics
diff --git a/editors/code/src/test/utils/diagnotics/rust.test.ts b/editors/code/src/test/utils/diagnotics/rust.test.ts
index 327d15046..358325cc8 100644
--- a/editors/code/src/test/utils/diagnotics/rust.test.ts
+++ b/editors/code/src/test/utils/diagnotics/rust.test.ts
@@ -6,14 +6,14 @@ import {
6 MappedRustDiagnostic, 6 MappedRustDiagnostic,
7 mapRustDiagnosticToVsCode, 7 mapRustDiagnosticToVsCode,
8 RustDiagnostic, 8 RustDiagnostic,
9 SuggestionApplicability 9 SuggestionApplicability,
10} from '../../../utils/diagnostics/rust'; 10} from '../../../utils/diagnostics/rust';
11 11
12function loadDiagnosticFixture(name: string): RustDiagnostic { 12function loadDiagnosticFixture(name: string): RustDiagnostic {
13 const jsonText = fs 13 const jsonText = fs
14 .readFileSync( 14 .readFileSync(
15 // We're actually in our JavaScript output directory, climb out 15 // We're actually in our JavaScript output directory, climb out
16 `${__dirname}/../../../../src/test/fixtures/rust-diagnostics/${name}.json` 16 `${__dirname}/../../../../src/test/fixtures/rust-diagnostics/${name}.json`,
17 ) 17 )
18 .toString(); 18 .toString();
19 19
@@ -33,12 +33,12 @@ function mapFixtureToVsCode(name: string): MappedRustDiagnostic {
33describe('mapRustDiagnosticToVsCode', () => { 33describe('mapRustDiagnosticToVsCode', () => {
34 it('should map an incompatible type for trait error', () => { 34 it('should map an incompatible type for trait error', () => {
35 const { diagnostic, suggestedFixes } = mapFixtureToVsCode( 35 const { diagnostic, suggestedFixes } = mapFixtureToVsCode(
36 'error/E0053' 36 'error/E0053',
37 ); 37 );
38 38
39 assert.strictEqual( 39 assert.strictEqual(
40 diagnostic.severity, 40 diagnostic.severity,
41 vscode.DiagnosticSeverity.Error 41 vscode.DiagnosticSeverity.Error,
42 ); 42 );
43 assert.strictEqual(diagnostic.source, 'rustc'); 43 assert.strictEqual(diagnostic.source, 'rustc');
44 assert.strictEqual( 44 assert.strictEqual(
@@ -46,8 +46,8 @@ describe('mapRustDiagnosticToVsCode', () => {
46 [ 46 [
47 `method \`next\` has an incompatible type for trait`, 47 `method \`next\` has an incompatible type for trait`,
48 `expected type \`fn(&mut ty::list_iter::ListIterator<'list, M>) -> std::option::Option<&ty::Ref<M>>\``, 48 `expected type \`fn(&mut ty::list_iter::ListIterator<'list, M>) -> std::option::Option<&ty::Ref<M>>\``,
49 ` found type \`fn(&ty::list_iter::ListIterator<'list, M>) -> std::option::Option<&'list ty::Ref<M>>\`` 49 ` found type \`fn(&ty::list_iter::ListIterator<'list, M>) -> std::option::Option<&'list ty::Ref<M>>\``,
50 ].join('\n') 50 ].join('\n'),
51 ); 51 );
52 assert.strictEqual(diagnostic.code, 'E0053'); 52 assert.strictEqual(diagnostic.code, 'E0053');
53 assert.deepStrictEqual(diagnostic.tags, []); 53 assert.deepStrictEqual(diagnostic.tags, []);
@@ -61,24 +61,24 @@ describe('mapRustDiagnosticToVsCode', () => {
61 61
62 it('should map an unused variable warning', () => { 62 it('should map an unused variable warning', () => {
63 const { diagnostic, suggestedFixes } = mapFixtureToVsCode( 63 const { diagnostic, suggestedFixes } = mapFixtureToVsCode(
64 'warning/unused_variables' 64 'warning/unused_variables',
65 ); 65 );
66 66
67 assert.strictEqual( 67 assert.strictEqual(
68 diagnostic.severity, 68 diagnostic.severity,
69 vscode.DiagnosticSeverity.Warning 69 vscode.DiagnosticSeverity.Warning,
70 ); 70 );
71 assert.strictEqual( 71 assert.strictEqual(
72 diagnostic.message, 72 diagnostic.message,
73 [ 73 [
74 'unused variable: `foo`', 74 'unused variable: `foo`',
75 '#[warn(unused_variables)] on by default' 75 '#[warn(unused_variables)] on by default',
76 ].join('\n') 76 ].join('\n'),
77 ); 77 );
78 assert.strictEqual(diagnostic.code, 'unused_variables'); 78 assert.strictEqual(diagnostic.code, 'unused_variables');
79 assert.strictEqual(diagnostic.source, 'rustc'); 79 assert.strictEqual(diagnostic.source, 'rustc');
80 assert.deepStrictEqual(diagnostic.tags, [ 80 assert.deepStrictEqual(diagnostic.tags, [
81 vscode.DiagnosticTag.Unnecessary 81 vscode.DiagnosticTag.Unnecessary,
82 ]); 82 ]);
83 83
84 // No related information 84 // No related information
@@ -89,29 +89,29 @@ describe('mapRustDiagnosticToVsCode', () => {
89 const [suggestedFix] = suggestedFixes; 89 const [suggestedFix] = suggestedFixes;
90 assert.strictEqual( 90 assert.strictEqual(
91 suggestedFix.title, 91 suggestedFix.title,
92 'consider prefixing with an underscore: `_foo`' 92 'consider prefixing with an underscore: `_foo`',
93 ); 93 );
94 assert.strictEqual( 94 assert.strictEqual(
95 suggestedFix.applicability, 95 suggestedFix.applicability,
96 SuggestionApplicability.MachineApplicable 96 SuggestionApplicability.MachineApplicable,
97 ); 97 );
98 }); 98 });
99 99
100 it('should map a wrong number of parameters error', () => { 100 it('should map a wrong number of parameters error', () => {
101 const { diagnostic, suggestedFixes } = mapFixtureToVsCode( 101 const { diagnostic, suggestedFixes } = mapFixtureToVsCode(
102 'error/E0061' 102 'error/E0061',
103 ); 103 );
104 104
105 assert.strictEqual( 105 assert.strictEqual(
106 diagnostic.severity, 106 diagnostic.severity,
107 vscode.DiagnosticSeverity.Error 107 vscode.DiagnosticSeverity.Error,
108 ); 108 );
109 assert.strictEqual( 109 assert.strictEqual(
110 diagnostic.message, 110 diagnostic.message,
111 [ 111 [
112 'this function takes 2 parameters but 3 parameters were supplied', 112 'this function takes 2 parameters but 3 parameters were supplied',
113 'expected 2 parameters' 113 'expected 2 parameters',
114 ].join('\n') 114 ].join('\n'),
115 ); 115 );
116 assert.strictEqual(diagnostic.code, 'E0061'); 116 assert.strictEqual(diagnostic.code, 'E0061');
117 assert.strictEqual(diagnostic.source, 'rustc'); 117 assert.strictEqual(diagnostic.source, 'rustc');
@@ -120,7 +120,8 @@ describe('mapRustDiagnosticToVsCode', () => {
120 // One related information for the original definition 120 // One related information for the original definition
121 const relatedInformation = diagnostic.relatedInformation; 121 const relatedInformation = diagnostic.relatedInformation;
122 if (!relatedInformation) { 122 if (!relatedInformation) {
123 return assert.fail('Related information unexpectedly undefined'); 123 assert.fail('Related information unexpectedly undefined');
124 return;
124 } 125 }
125 assert.strictEqual(relatedInformation.length, 1); 126 assert.strictEqual(relatedInformation.length, 1);
126 const [related] = relatedInformation; 127 const [related] = relatedInformation;
@@ -132,12 +133,12 @@ describe('mapRustDiagnosticToVsCode', () => {
132 133
133 it('should map a Clippy copy pass by ref warning', () => { 134 it('should map a Clippy copy pass by ref warning', () => {
134 const { diagnostic, suggestedFixes } = mapFixtureToVsCode( 135 const { diagnostic, suggestedFixes } = mapFixtureToVsCode(
135 'clippy/trivially_copy_pass_by_ref' 136 'clippy/trivially_copy_pass_by_ref',
136 ); 137 );
137 138
138 assert.strictEqual( 139 assert.strictEqual(
139 diagnostic.severity, 140 diagnostic.severity,
140 vscode.DiagnosticSeverity.Warning 141 vscode.DiagnosticSeverity.Warning,
141 ); 142 );
142 assert.strictEqual(diagnostic.source, 'clippy'); 143 assert.strictEqual(diagnostic.source, 'clippy');
143 assert.strictEqual( 144 assert.strictEqual(
@@ -145,8 +146,8 @@ describe('mapRustDiagnosticToVsCode', () => {
145 [ 146 [
146 'this argument is passed by reference, but would be more efficient if passed by value', 147 'this argument is passed by reference, but would be more efficient if passed by value',
147 '#[warn(clippy::trivially_copy_pass_by_ref)] implied by #[warn(clippy::all)]', 148 '#[warn(clippy::trivially_copy_pass_by_ref)] implied by #[warn(clippy::all)]',
148 'for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref' 149 'for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref',
149 ].join('\n') 150 ].join('\n'),
150 ); 151 );
151 assert.strictEqual(diagnostic.code, 'trivially_copy_pass_by_ref'); 152 assert.strictEqual(diagnostic.code, 'trivially_copy_pass_by_ref');
152 assert.deepStrictEqual(diagnostic.tags, []); 153 assert.deepStrictEqual(diagnostic.tags, []);
@@ -154,7 +155,8 @@ describe('mapRustDiagnosticToVsCode', () => {
154 // One related information for the lint definition 155 // One related information for the lint definition
155 const relatedInformation = diagnostic.relatedInformation; 156 const relatedInformation = diagnostic.relatedInformation;
156 if (!relatedInformation) { 157 if (!relatedInformation) {
157 return assert.fail('Related information unexpectedly undefined'); 158 assert.fail('Related information unexpectedly undefined');
159 return;
158 } 160 }
159 assert.strictEqual(relatedInformation.length, 1); 161 assert.strictEqual(relatedInformation.length, 1);
160 const [related] = relatedInformation; 162 const [related] = relatedInformation;
@@ -165,27 +167,27 @@ describe('mapRustDiagnosticToVsCode', () => {
165 const [suggestedFix] = suggestedFixes; 167 const [suggestedFix] = suggestedFixes;
166 assert.strictEqual( 168 assert.strictEqual(
167 suggestedFix.title, 169 suggestedFix.title,
168 'consider passing by value instead: `self`' 170 'consider passing by value instead: `self`',
169 ); 171 );
170 // Clippy does not mark this with any applicability 172 // Clippy does not mark this with any applicability
171 assert.strictEqual( 173 assert.strictEqual(
172 suggestedFix.applicability, 174 suggestedFix.applicability,
173 SuggestionApplicability.Unspecified 175 SuggestionApplicability.Unspecified,
174 ); 176 );
175 }); 177 });
176 178
177 it('should map a mismatched type error', () => { 179 it('should map a mismatched type error', () => {
178 const { diagnostic, suggestedFixes } = mapFixtureToVsCode( 180 const { diagnostic, suggestedFixes } = mapFixtureToVsCode(
179 'error/E0308' 181 'error/E0308',
180 ); 182 );
181 183
182 assert.strictEqual( 184 assert.strictEqual(
183 diagnostic.severity, 185 diagnostic.severity,
184 vscode.DiagnosticSeverity.Error 186 vscode.DiagnosticSeverity.Error,
185 ); 187 );
186 assert.strictEqual( 188 assert.strictEqual(
187 diagnostic.message, 189 diagnostic.message,
188 ['mismatched types', 'expected usize, found u32'].join('\n') 190 ['mismatched types', 'expected usize, found u32'].join('\n'),
189 ); 191 );
190 assert.strictEqual(diagnostic.code, 'E0308'); 192 assert.strictEqual(diagnostic.code, 'E0308');
191 assert.strictEqual(diagnostic.source, 'rustc'); 193 assert.strictEqual(diagnostic.source, 'rustc');
@@ -197,4 +199,38 @@ describe('mapRustDiagnosticToVsCode', () => {
197 // There are no suggested fixes 199 // There are no suggested fixes
198 assert.strictEqual(suggestedFixes.length, 0); 200 assert.strictEqual(suggestedFixes.length, 0);
199 }); 201 });
202
203 it('should map a macro invocation location to normal file path', () => {
204 const { location, diagnostic, suggestedFixes } = mapFixtureToVsCode(
205 'error/E0277',
206 );
207
208 assert.strictEqual(
209 diagnostic.severity,
210 vscode.DiagnosticSeverity.Error,
211 );
212 assert.strictEqual(
213 diagnostic.message,
214 [
215 "can't compare `{integer}` with `&str`",
216 'the trait `std::cmp::PartialEq<&str>` is not implemented for `{integer}`',
217 ].join('\n'),
218 );
219 assert.strictEqual(diagnostic.code, 'E0277');
220 assert.strictEqual(diagnostic.source, 'rustc');
221 assert.deepStrictEqual(diagnostic.tags, []);
222
223 // No related information
224 assert.deepStrictEqual(diagnostic.relatedInformation, []);
225
226 // There are no suggested fixes
227 assert.strictEqual(suggestedFixes.length, 0);
228
229 // The file url should be normal file
230 // Ignore the first part because it depends on vs workspace location
231 assert.strictEqual(
232 location.uri.path.substr(-'src/main.rs'.length),
233 'src/main.rs',
234 );
235 });
200}); 236});
diff --git a/editors/code/src/test/utils/diagnotics/vscode.test.ts b/editors/code/src/test/utils/diagnotics/vscode.test.ts
index 542dec1f5..4944dd032 100644
--- a/editors/code/src/test/utils/diagnotics/vscode.test.ts
+++ b/editors/code/src/test/utils/diagnotics/vscode.test.ts
@@ -5,12 +5,12 @@ import { areDiagnosticsEqual } from '../../../utils/diagnostics/vscode';
5 5
6const range1 = new vscode.Range( 6const range1 = new vscode.Range(
7 new vscode.Position(1, 2), 7 new vscode.Position(1, 2),
8 new vscode.Position(3, 4) 8 new vscode.Position(3, 4),
9); 9);
10 10
11const range2 = new vscode.Range( 11const range2 = new vscode.Range(
12 new vscode.Position(5, 6), 12 new vscode.Position(5, 6),
13 new vscode.Position(7, 8) 13 new vscode.Position(7, 8),
14); 14);
15 15
16describe('areDiagnosticsEqual', () => { 16describe('areDiagnosticsEqual', () => {
@@ -18,13 +18,13 @@ describe('areDiagnosticsEqual', () => {
18 const diagnostic1 = new vscode.Diagnostic( 18 const diagnostic1 = new vscode.Diagnostic(
19 range1, 19 range1,
20 'Hello, world!', 20 'Hello, world!',
21 vscode.DiagnosticSeverity.Error 21 vscode.DiagnosticSeverity.Error,
22 ); 22 );
23 23
24 const diagnostic2 = new vscode.Diagnostic( 24 const diagnostic2 = new vscode.Diagnostic(
25 range1, 25 range1,
26 'Hello, world!', 26 'Hello, world!',
27 vscode.DiagnosticSeverity.Error 27 vscode.DiagnosticSeverity.Error,
28 ); 28 );
29 29
30 assert(areDiagnosticsEqual(diagnostic1, diagnostic2)); 30 assert(areDiagnosticsEqual(diagnostic1, diagnostic2));
@@ -34,14 +34,14 @@ describe('areDiagnosticsEqual', () => {
34 const diagnostic1 = new vscode.Diagnostic( 34 const diagnostic1 = new vscode.Diagnostic(
35 range1, 35 range1,
36 'Hello, world!', 36 'Hello, world!',
37 vscode.DiagnosticSeverity.Error 37 vscode.DiagnosticSeverity.Error,
38 ); 38 );
39 diagnostic1.source = 'rustc'; 39 diagnostic1.source = 'rustc';
40 40
41 const diagnostic2 = new vscode.Diagnostic( 41 const diagnostic2 = new vscode.Diagnostic(
42 range1, 42 range1,
43 'Hello, world!', 43 'Hello, world!',
44 vscode.DiagnosticSeverity.Error 44 vscode.DiagnosticSeverity.Error,
45 ); 45 );
46 diagnostic2.source = 'clippy'; 46 diagnostic2.source = 'clippy';
47 47
@@ -52,13 +52,13 @@ describe('areDiagnosticsEqual', () => {
52 const diagnostic1 = new vscode.Diagnostic( 52 const diagnostic1 = new vscode.Diagnostic(
53 range1, 53 range1,
54 'Hello, world!', 54 'Hello, world!',
55 vscode.DiagnosticSeverity.Error 55 vscode.DiagnosticSeverity.Error,
56 ); 56 );
57 57
58 const diagnostic2 = new vscode.Diagnostic( 58 const diagnostic2 = new vscode.Diagnostic(
59 range2, 59 range2,
60 'Hello, world!', 60 'Hello, world!',
61 vscode.DiagnosticSeverity.Error 61 vscode.DiagnosticSeverity.Error,
62 ); 62 );
63 63
64 assert(!areDiagnosticsEqual(diagnostic1, diagnostic2)); 64 assert(!areDiagnosticsEqual(diagnostic1, diagnostic2));
@@ -68,13 +68,13 @@ describe('areDiagnosticsEqual', () => {
68 const diagnostic1 = new vscode.Diagnostic( 68 const diagnostic1 = new vscode.Diagnostic(
69 range1, 69 range1,
70 'Hello, world!', 70 'Hello, world!',
71 vscode.DiagnosticSeverity.Error 71 vscode.DiagnosticSeverity.Error,
72 ); 72 );
73 73
74 const diagnostic2 = new vscode.Diagnostic( 74 const diagnostic2 = new vscode.Diagnostic(
75 range1, 75 range1,
76 'Goodbye!, world!', 76 'Goodbye!, world!',
77 vscode.DiagnosticSeverity.Error 77 vscode.DiagnosticSeverity.Error,
78 ); 78 );
79 79
80 assert(!areDiagnosticsEqual(diagnostic1, diagnostic2)); 80 assert(!areDiagnosticsEqual(diagnostic1, diagnostic2));
@@ -84,13 +84,13 @@ describe('areDiagnosticsEqual', () => {
84 const diagnostic1 = new vscode.Diagnostic( 84 const diagnostic1 = new vscode.Diagnostic(
85 range1, 85 range1,
86 'Hello, world!', 86 'Hello, world!',
87 vscode.DiagnosticSeverity.Warning 87 vscode.DiagnosticSeverity.Warning,
88 ); 88 );
89 89
90 const diagnostic2 = new vscode.Diagnostic( 90 const diagnostic2 = new vscode.Diagnostic(
91 range1, 91 range1,
92 'Hello, world!', 92 'Hello, world!',
93 vscode.DiagnosticSeverity.Error 93 vscode.DiagnosticSeverity.Error,
94 ); 94 );
95 95
96 assert(!areDiagnosticsEqual(diagnostic1, diagnostic2)); 96 assert(!areDiagnosticsEqual(diagnostic1, diagnostic2));
diff --git a/editors/code/src/test/utils/index.ts b/editors/code/src/test/utils/index.ts
index 16715a286..9927daaf6 100644
--- a/editors/code/src/test/utils/index.ts
+++ b/editors/code/src/test/utils/index.ts
@@ -17,7 +17,7 @@ import * as path from 'path';
17export function run(): Promise<void> { 17export function run(): Promise<void> {
18 // Create the mocha test 18 // Create the mocha test
19 const mocha = new Mocha({ 19 const mocha = new Mocha({
20 ui: 'bdd' 20 ui: 'bdd',
21 }); 21 });
22 mocha.useColors(true); 22 mocha.useColors(true);
23 23