diff options
author | Emil Lauridsen <[email protected]> | 2019-12-25 16:34:51 +0000 |
---|---|---|
committer | Emil Lauridsen <[email protected]> | 2019-12-25 16:37:40 +0000 |
commit | 500fe46e6c0df7827d56c7cd07741533422e7743 (patch) | |
tree | 7759cb6da5faa35954d85f3a091a62bba2b4142d /editors/code/src/test/utils/diagnotics/SuggestedFixCollection.test.ts | |
parent | c21fbc3e87d1e701f29fafcdad0a73e8d69a2f29 (diff) |
Remove cargo watch supporting code and tests from vscode extension
Diffstat (limited to 'editors/code/src/test/utils/diagnotics/SuggestedFixCollection.test.ts')
-rw-r--r-- | editors/code/src/test/utils/diagnotics/SuggestedFixCollection.test.ts | 127 |
1 files changed, 0 insertions, 127 deletions
diff --git a/editors/code/src/test/utils/diagnotics/SuggestedFixCollection.test.ts b/editors/code/src/test/utils/diagnotics/SuggestedFixCollection.test.ts deleted file mode 100644 index ef09013f4..000000000 --- a/editors/code/src/test/utils/diagnotics/SuggestedFixCollection.test.ts +++ /dev/null | |||
@@ -1,127 +0,0 @@ | |||
1 | import * as assert from 'assert'; | ||
2 | import * as vscode from 'vscode'; | ||
3 | |||
4 | import SuggestedFix from '../../../utils/diagnostics/SuggestedFix'; | ||
5 | import SuggestedFixCollection from '../../../utils/diagnostics/SuggestedFixCollection'; | ||
6 | |||
7 | const uri1 = vscode.Uri.file('/file/1'); | ||
8 | const uri2 = vscode.Uri.file('/file/2'); | ||
9 | |||
10 | const mockDocument1 = ({ | ||
11 | uri: uri1, | ||
12 | } as unknown) as vscode.TextDocument; | ||
13 | |||
14 | const mockDocument2 = ({ | ||
15 | uri: uri2, | ||
16 | } as unknown) as vscode.TextDocument; | ||
17 | |||
18 | const range1 = new vscode.Range( | ||
19 | new vscode.Position(1, 2), | ||
20 | new vscode.Position(3, 4), | ||
21 | ); | ||
22 | const range2 = new vscode.Range( | ||
23 | new vscode.Position(5, 6), | ||
24 | new vscode.Position(7, 8), | ||
25 | ); | ||
26 | |||
27 | const diagnostic1 = new vscode.Diagnostic(range1, 'First diagnostic'); | ||
28 | const diagnostic2 = new vscode.Diagnostic(range2, 'Second diagnostic'); | ||
29 | |||
30 | // This is a mutable object so return a fresh instance every time | ||
31 | function suggestion1(): SuggestedFix { | ||
32 | return new SuggestedFix( | ||
33 | 'Replace me!', | ||
34 | new vscode.Location(uri1, range1), | ||
35 | 'With this!', | ||
36 | ); | ||
37 | } | ||
38 | |||
39 | describe('SuggestedFixCollection', () => { | ||
40 | it('should add a suggestion then return it as a code action', () => { | ||
41 | const suggestedFixes = new SuggestedFixCollection(); | ||
42 | suggestedFixes.addSuggestedFixForDiagnostic(suggestion1(), diagnostic1); | ||
43 | |||
44 | // Specify the document and range that exactly matches | ||
45 | const codeActions = suggestedFixes.provideCodeActions( | ||
46 | mockDocument1, | ||
47 | range1, | ||
48 | ); | ||
49 | |||
50 | assert.strictEqual(codeActions.length, 1); | ||
51 | const [codeAction] = codeActions; | ||
52 | assert.strictEqual(codeAction.title, suggestion1().title); | ||
53 | |||
54 | const { diagnostics } = codeAction; | ||
55 | if (!diagnostics) { | ||
56 | assert.fail('Diagnostics unexpectedly missing'); | ||
57 | return; | ||
58 | } | ||
59 | |||
60 | assert.strictEqual(diagnostics.length, 1); | ||
61 | assert.strictEqual(diagnostics[0], diagnostic1); | ||
62 | }); | ||
63 | |||
64 | it('should not return code actions for different ranges', () => { | ||
65 | const suggestedFixes = new SuggestedFixCollection(); | ||
66 | suggestedFixes.addSuggestedFixForDiagnostic(suggestion1(), diagnostic1); | ||
67 | |||
68 | const codeActions = suggestedFixes.provideCodeActions( | ||
69 | mockDocument1, | ||
70 | range2, | ||
71 | ); | ||
72 | |||
73 | assert(!codeActions || codeActions.length === 0); | ||
74 | }); | ||
75 | |||
76 | it('should not return code actions for different documents', () => { | ||
77 | const suggestedFixes = new SuggestedFixCollection(); | ||
78 | suggestedFixes.addSuggestedFixForDiagnostic(suggestion1(), diagnostic1); | ||
79 | |||
80 | const codeActions = suggestedFixes.provideCodeActions( | ||
81 | mockDocument2, | ||
82 | range1, | ||
83 | ); | ||
84 | |||
85 | assert(!codeActions || codeActions.length === 0); | ||
86 | }); | ||
87 | |||
88 | it('should not return code actions that have been cleared', () => { | ||
89 | const suggestedFixes = new SuggestedFixCollection(); | ||
90 | suggestedFixes.addSuggestedFixForDiagnostic(suggestion1(), diagnostic1); | ||
91 | suggestedFixes.clear(); | ||
92 | |||
93 | const codeActions = suggestedFixes.provideCodeActions( | ||
94 | mockDocument1, | ||
95 | range1, | ||
96 | ); | ||
97 | |||
98 | assert(!codeActions || codeActions.length === 0); | ||
99 | }); | ||
100 | |||
101 | it('should merge identical suggestions together', () => { | ||
102 | const suggestedFixes = new SuggestedFixCollection(); | ||
103 | |||
104 | // Add the same suggestion for two diagnostics | ||
105 | suggestedFixes.addSuggestedFixForDiagnostic(suggestion1(), diagnostic1); | ||
106 | suggestedFixes.addSuggestedFixForDiagnostic(suggestion1(), diagnostic2); | ||
107 | |||
108 | const codeActions = suggestedFixes.provideCodeActions( | ||
109 | mockDocument1, | ||
110 | range1, | ||
111 | ); | ||
112 | |||
113 | assert.strictEqual(codeActions.length, 1); | ||
114 | const [codeAction] = codeActions; | ||
115 | const { diagnostics } = codeAction; | ||
116 | |||
117 | if (!diagnostics) { | ||
118 | assert.fail('Diagnostics unexpectedly missing'); | ||
119 | return; | ||
120 | } | ||
121 | |||
122 | // We should be associated with both diagnostics | ||
123 | assert.strictEqual(diagnostics.length, 2); | ||
124 | assert.strictEqual(diagnostics[0], diagnostic1); | ||
125 | assert.strictEqual(diagnostics[1], diagnostic2); | ||
126 | }); | ||
127 | }); | ||