1 import * as assert from 'assert';
2 import * as vscode from 'vscode';
4 import { SuggestionApplicability } from '../../../utils/diagnostics/rust';
5 import SuggestedFix from '../../../utils/diagnostics/SuggestedFix';
7 const location1 = new vscode.Location(
8 vscode.Uri.file('/file/1'),
9 new vscode.Range(new vscode.Position(1, 2), new vscode.Position(3, 4)),
12 const location2 = new vscode.Location(
13 vscode.Uri.file('/file/2'),
14 new vscode.Range(new vscode.Position(5, 6), new vscode.Position(7, 8)),
17 describe('SuggestedFix', () => {
18 describe('isEqual', () => {
19 it('should treat identical instances as equal', () => {
20 const suggestion1 = new SuggestedFix(
26 const suggestion2 = new SuggestedFix(
32 assert(suggestion1.isEqual(suggestion2));
35 it('should treat instances with different titles as inequal', () => {
36 const suggestion1 = new SuggestedFix(
42 const suggestion2 = new SuggestedFix(
43 'Not the same title!',
48 assert(!suggestion1.isEqual(suggestion2));
51 it('should treat instances with different replacements as inequal', () => {
52 const suggestion1 = new SuggestedFix(
58 const suggestion2 = new SuggestedFix(
61 'With something else!',
64 assert(!suggestion1.isEqual(suggestion2));
67 it('should treat instances with different locations as inequal', () => {
68 const suggestion1 = new SuggestedFix(
74 const suggestion2 = new SuggestedFix(
80 assert(!suggestion1.isEqual(suggestion2));
83 it('should treat instances with different applicability as inequal', () => {
84 const suggestion1 = new SuggestedFix(
88 SuggestionApplicability.MachineApplicable,
91 const suggestion2 = new SuggestedFix(
95 SuggestionApplicability.HasPlaceholders,
98 assert(!suggestion1.isEqual(suggestion2));
102 describe('toCodeAction', () => {
103 it('should map a simple suggestion', () => {
104 const suggestion = new SuggestedFix(
110 const codeAction = suggestion.toCodeAction();
111 assert.strictEqual(codeAction.kind, vscode.CodeActionKind.QuickFix);
112 assert.strictEqual(codeAction.title, 'Replace me!');
113 assert.strictEqual(codeAction.isPreferred, false);
115 const edit = codeAction.edit;
117 assert.fail('Code Action edit unexpectedly missing');
121 const editEntries = edit.entries();
122 assert.strictEqual(editEntries.length, 1);
124 const [[editUri, textEdits]] = editEntries;
125 assert.strictEqual(editUri.toString(), location1.uri.toString());
127 assert.strictEqual(textEdits.length, 1);
128 const [textEdit] = textEdits;
130 assert(textEdit.range.isEqual(location1.range));
131 assert.strictEqual(textEdit.newText, 'With this!');