From 500fe46e6c0df7827d56c7cd07741533422e7743 Mon Sep 17 00:00:00 2001 From: Emil Lauridsen Date: Wed, 25 Dec 2019 17:34:51 +0100 Subject: Remove cargo watch supporting code and tests from vscode extension --- .../src/test/utils/diagnotics/SuggestedFix.test.ts | 134 ------------ .../diagnotics/SuggestedFixCollection.test.ts | 127 ----------- .../code/src/test/utils/diagnotics/rust.test.ts | 236 --------------------- .../code/src/test/utils/diagnotics/vscode.test.ts | 98 --------- 4 files changed, 595 deletions(-) delete mode 100644 editors/code/src/test/utils/diagnotics/SuggestedFix.test.ts delete mode 100644 editors/code/src/test/utils/diagnotics/SuggestedFixCollection.test.ts delete mode 100644 editors/code/src/test/utils/diagnotics/rust.test.ts delete mode 100644 editors/code/src/test/utils/diagnotics/vscode.test.ts (limited to 'editors/code/src/test/utils/diagnotics') diff --git a/editors/code/src/test/utils/diagnotics/SuggestedFix.test.ts b/editors/code/src/test/utils/diagnotics/SuggestedFix.test.ts deleted file mode 100644 index 2b25eb705..000000000 --- a/editors/code/src/test/utils/diagnotics/SuggestedFix.test.ts +++ /dev/null @@ -1,134 +0,0 @@ -import * as assert from 'assert'; -import * as vscode from 'vscode'; - -import { SuggestionApplicability } from '../../../utils/diagnostics/rust'; -import SuggestedFix from '../../../utils/diagnostics/SuggestedFix'; - -const location1 = new vscode.Location( - vscode.Uri.file('/file/1'), - new vscode.Range(new vscode.Position(1, 2), new vscode.Position(3, 4)), -); - -const location2 = new vscode.Location( - vscode.Uri.file('/file/2'), - new vscode.Range(new vscode.Position(5, 6), new vscode.Position(7, 8)), -); - -describe('SuggestedFix', () => { - describe('isEqual', () => { - it('should treat identical instances as equal', () => { - const suggestion1 = new SuggestedFix( - 'Replace me!', - location1, - 'With this!', - ); - - const suggestion2 = new SuggestedFix( - 'Replace me!', - location1, - 'With this!', - ); - - assert(suggestion1.isEqual(suggestion2)); - }); - - it('should treat instances with different titles as inequal', () => { - const suggestion1 = new SuggestedFix( - 'Replace me!', - location1, - 'With this!', - ); - - const suggestion2 = new SuggestedFix( - 'Not the same title!', - location1, - 'With this!', - ); - - assert(!suggestion1.isEqual(suggestion2)); - }); - - it('should treat instances with different replacements as inequal', () => { - const suggestion1 = new SuggestedFix( - 'Replace me!', - location1, - 'With this!', - ); - - const suggestion2 = new SuggestedFix( - 'Replace me!', - location1, - 'With something else!', - ); - - assert(!suggestion1.isEqual(suggestion2)); - }); - - it('should treat instances with different locations as inequal', () => { - const suggestion1 = new SuggestedFix( - 'Replace me!', - location1, - 'With this!', - ); - - const suggestion2 = new SuggestedFix( - 'Replace me!', - location2, - 'With this!', - ); - - assert(!suggestion1.isEqual(suggestion2)); - }); - - it('should treat instances with different applicability as inequal', () => { - const suggestion1 = new SuggestedFix( - 'Replace me!', - location1, - 'With this!', - SuggestionApplicability.MachineApplicable, - ); - - const suggestion2 = new SuggestedFix( - 'Replace me!', - location2, - 'With this!', - SuggestionApplicability.HasPlaceholders, - ); - - assert(!suggestion1.isEqual(suggestion2)); - }); - }); - - describe('toCodeAction', () => { - it('should map a simple suggestion', () => { - const suggestion = new SuggestedFix( - 'Replace me!', - location1, - 'With this!', - ); - - const codeAction = suggestion.toCodeAction(); - assert.strictEqual(codeAction.kind, vscode.CodeActionKind.QuickFix); - assert.strictEqual(codeAction.title, 'Replace me!'); - assert.strictEqual(codeAction.isPreferred, false); - - const edit = codeAction.edit; - if (!edit) { - assert.fail('Code Action edit unexpectedly missing'); - return; - } - - const editEntries = edit.entries(); - assert.strictEqual(editEntries.length, 1); - - const [[editUri, textEdits]] = editEntries; - assert.strictEqual(editUri.toString(), location1.uri.toString()); - - assert.strictEqual(textEdits.length, 1); - const [textEdit] = textEdits; - - assert(textEdit.range.isEqual(location1.range)); - assert.strictEqual(textEdit.newText, 'With this!'); - }); - }); -}); 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 @@ -import * as assert from 'assert'; -import * as vscode from 'vscode'; - -import SuggestedFix from '../../../utils/diagnostics/SuggestedFix'; -import SuggestedFixCollection from '../../../utils/diagnostics/SuggestedFixCollection'; - -const uri1 = vscode.Uri.file('/file/1'); -const uri2 = vscode.Uri.file('/file/2'); - -const mockDocument1 = ({ - uri: uri1, -} as unknown) as vscode.TextDocument; - -const mockDocument2 = ({ - uri: uri2, -} as unknown) as vscode.TextDocument; - -const range1 = new vscode.Range( - new vscode.Position(1, 2), - new vscode.Position(3, 4), -); -const range2 = new vscode.Range( - new vscode.Position(5, 6), - new vscode.Position(7, 8), -); - -const diagnostic1 = new vscode.Diagnostic(range1, 'First diagnostic'); -const diagnostic2 = new vscode.Diagnostic(range2, 'Second diagnostic'); - -// This is a mutable object so return a fresh instance every time -function suggestion1(): SuggestedFix { - return new SuggestedFix( - 'Replace me!', - new vscode.Location(uri1, range1), - 'With this!', - ); -} - -describe('SuggestedFixCollection', () => { - it('should add a suggestion then return it as a code action', () => { - const suggestedFixes = new SuggestedFixCollection(); - suggestedFixes.addSuggestedFixForDiagnostic(suggestion1(), diagnostic1); - - // Specify the document and range that exactly matches - const codeActions = suggestedFixes.provideCodeActions( - mockDocument1, - range1, - ); - - assert.strictEqual(codeActions.length, 1); - const [codeAction] = codeActions; - assert.strictEqual(codeAction.title, suggestion1().title); - - const { diagnostics } = codeAction; - if (!diagnostics) { - assert.fail('Diagnostics unexpectedly missing'); - return; - } - - assert.strictEqual(diagnostics.length, 1); - assert.strictEqual(diagnostics[0], diagnostic1); - }); - - it('should not return code actions for different ranges', () => { - const suggestedFixes = new SuggestedFixCollection(); - suggestedFixes.addSuggestedFixForDiagnostic(suggestion1(), diagnostic1); - - const codeActions = suggestedFixes.provideCodeActions( - mockDocument1, - range2, - ); - - assert(!codeActions || codeActions.length === 0); - }); - - it('should not return code actions for different documents', () => { - const suggestedFixes = new SuggestedFixCollection(); - suggestedFixes.addSuggestedFixForDiagnostic(suggestion1(), diagnostic1); - - const codeActions = suggestedFixes.provideCodeActions( - mockDocument2, - range1, - ); - - assert(!codeActions || codeActions.length === 0); - }); - - it('should not return code actions that have been cleared', () => { - const suggestedFixes = new SuggestedFixCollection(); - suggestedFixes.addSuggestedFixForDiagnostic(suggestion1(), diagnostic1); - suggestedFixes.clear(); - - const codeActions = suggestedFixes.provideCodeActions( - mockDocument1, - range1, - ); - - assert(!codeActions || codeActions.length === 0); - }); - - it('should merge identical suggestions together', () => { - const suggestedFixes = new SuggestedFixCollection(); - - // Add the same suggestion for two diagnostics - suggestedFixes.addSuggestedFixForDiagnostic(suggestion1(), diagnostic1); - suggestedFixes.addSuggestedFixForDiagnostic(suggestion1(), diagnostic2); - - const codeActions = suggestedFixes.provideCodeActions( - mockDocument1, - range1, - ); - - assert.strictEqual(codeActions.length, 1); - const [codeAction] = codeActions; - const { diagnostics } = codeAction; - - if (!diagnostics) { - assert.fail('Diagnostics unexpectedly missing'); - return; - } - - // We should be associated with both diagnostics - assert.strictEqual(diagnostics.length, 2); - assert.strictEqual(diagnostics[0], diagnostic1); - assert.strictEqual(diagnostics[1], diagnostic2); - }); -}); diff --git a/editors/code/src/test/utils/diagnotics/rust.test.ts b/editors/code/src/test/utils/diagnotics/rust.test.ts deleted file mode 100644 index 358325cc8..000000000 --- a/editors/code/src/test/utils/diagnotics/rust.test.ts +++ /dev/null @@ -1,236 +0,0 @@ -import * as assert from 'assert'; -import * as fs from 'fs'; -import * as vscode from 'vscode'; - -import { - MappedRustDiagnostic, - mapRustDiagnosticToVsCode, - RustDiagnostic, - SuggestionApplicability, -} from '../../../utils/diagnostics/rust'; - -function loadDiagnosticFixture(name: string): RustDiagnostic { - const jsonText = fs - .readFileSync( - // We're actually in our JavaScript output directory, climb out - `${__dirname}/../../../../src/test/fixtures/rust-diagnostics/${name}.json`, - ) - .toString(); - - return JSON.parse(jsonText); -} - -function mapFixtureToVsCode(name: string): MappedRustDiagnostic { - const rd = loadDiagnosticFixture(name); - const mapResult = mapRustDiagnosticToVsCode(rd); - - if (!mapResult) { - return assert.fail('Mapping unexpectedly failed'); - } - return mapResult; -} - -describe('mapRustDiagnosticToVsCode', () => { - it('should map an incompatible type for trait error', () => { - const { diagnostic, suggestedFixes } = mapFixtureToVsCode( - 'error/E0053', - ); - - assert.strictEqual( - diagnostic.severity, - vscode.DiagnosticSeverity.Error, - ); - assert.strictEqual(diagnostic.source, 'rustc'); - assert.strictEqual( - diagnostic.message, - [ - `method \`next\` has an incompatible type for trait`, - `expected type \`fn(&mut ty::list_iter::ListIterator<'list, M>) -> std::option::Option<&ty::Ref>\``, - ` found type \`fn(&ty::list_iter::ListIterator<'list, M>) -> std::option::Option<&'list ty::Ref>\``, - ].join('\n'), - ); - assert.strictEqual(diagnostic.code, 'E0053'); - assert.deepStrictEqual(diagnostic.tags, []); - - // No related information - assert.deepStrictEqual(diagnostic.relatedInformation, []); - - // There are no suggested fixes - assert.strictEqual(suggestedFixes.length, 0); - }); - - it('should map an unused variable warning', () => { - const { diagnostic, suggestedFixes } = mapFixtureToVsCode( - 'warning/unused_variables', - ); - - assert.strictEqual( - diagnostic.severity, - vscode.DiagnosticSeverity.Warning, - ); - assert.strictEqual( - diagnostic.message, - [ - 'unused variable: `foo`', - '#[warn(unused_variables)] on by default', - ].join('\n'), - ); - assert.strictEqual(diagnostic.code, 'unused_variables'); - assert.strictEqual(diagnostic.source, 'rustc'); - assert.deepStrictEqual(diagnostic.tags, [ - vscode.DiagnosticTag.Unnecessary, - ]); - - // No related information - assert.deepStrictEqual(diagnostic.relatedInformation, []); - - // One suggested fix available to prefix the variable - assert.strictEqual(suggestedFixes.length, 1); - const [suggestedFix] = suggestedFixes; - assert.strictEqual( - suggestedFix.title, - 'consider prefixing with an underscore: `_foo`', - ); - assert.strictEqual( - suggestedFix.applicability, - SuggestionApplicability.MachineApplicable, - ); - }); - - it('should map a wrong number of parameters error', () => { - const { diagnostic, suggestedFixes } = mapFixtureToVsCode( - 'error/E0061', - ); - - assert.strictEqual( - diagnostic.severity, - vscode.DiagnosticSeverity.Error, - ); - assert.strictEqual( - diagnostic.message, - [ - 'this function takes 2 parameters but 3 parameters were supplied', - 'expected 2 parameters', - ].join('\n'), - ); - assert.strictEqual(diagnostic.code, 'E0061'); - assert.strictEqual(diagnostic.source, 'rustc'); - assert.deepStrictEqual(diagnostic.tags, []); - - // One related information for the original definition - const relatedInformation = diagnostic.relatedInformation; - if (!relatedInformation) { - assert.fail('Related information unexpectedly undefined'); - return; - } - assert.strictEqual(relatedInformation.length, 1); - const [related] = relatedInformation; - assert.strictEqual(related.message, 'defined here'); - - // There are no suggested fixes - assert.strictEqual(suggestedFixes.length, 0); - }); - - it('should map a Clippy copy pass by ref warning', () => { - const { diagnostic, suggestedFixes } = mapFixtureToVsCode( - 'clippy/trivially_copy_pass_by_ref', - ); - - assert.strictEqual( - diagnostic.severity, - vscode.DiagnosticSeverity.Warning, - ); - assert.strictEqual(diagnostic.source, 'clippy'); - assert.strictEqual( - diagnostic.message, - [ - 'this argument is passed by reference, but would be more efficient if passed by value', - '#[warn(clippy::trivially_copy_pass_by_ref)] implied by #[warn(clippy::all)]', - 'for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref', - ].join('\n'), - ); - assert.strictEqual(diagnostic.code, 'trivially_copy_pass_by_ref'); - assert.deepStrictEqual(diagnostic.tags, []); - - // One related information for the lint definition - const relatedInformation = diagnostic.relatedInformation; - if (!relatedInformation) { - assert.fail('Related information unexpectedly undefined'); - return; - } - assert.strictEqual(relatedInformation.length, 1); - const [related] = relatedInformation; - assert.strictEqual(related.message, 'lint level defined here'); - - // One suggested fix to pass by value - assert.strictEqual(suggestedFixes.length, 1); - const [suggestedFix] = suggestedFixes; - assert.strictEqual( - suggestedFix.title, - 'consider passing by value instead: `self`', - ); - // Clippy does not mark this with any applicability - assert.strictEqual( - suggestedFix.applicability, - SuggestionApplicability.Unspecified, - ); - }); - - it('should map a mismatched type error', () => { - const { diagnostic, suggestedFixes } = mapFixtureToVsCode( - 'error/E0308', - ); - - assert.strictEqual( - diagnostic.severity, - vscode.DiagnosticSeverity.Error, - ); - assert.strictEqual( - diagnostic.message, - ['mismatched types', 'expected usize, found u32'].join('\n'), - ); - assert.strictEqual(diagnostic.code, 'E0308'); - assert.strictEqual(diagnostic.source, 'rustc'); - assert.deepStrictEqual(diagnostic.tags, []); - - // No related information - assert.deepStrictEqual(diagnostic.relatedInformation, []); - - // There are no suggested fixes - assert.strictEqual(suggestedFixes.length, 0); - }); - - it('should map a macro invocation location to normal file path', () => { - const { location, diagnostic, suggestedFixes } = mapFixtureToVsCode( - 'error/E0277', - ); - - assert.strictEqual( - diagnostic.severity, - vscode.DiagnosticSeverity.Error, - ); - assert.strictEqual( - diagnostic.message, - [ - "can't compare `{integer}` with `&str`", - 'the trait `std::cmp::PartialEq<&str>` is not implemented for `{integer}`', - ].join('\n'), - ); - assert.strictEqual(diagnostic.code, 'E0277'); - assert.strictEqual(diagnostic.source, 'rustc'); - assert.deepStrictEqual(diagnostic.tags, []); - - // No related information - assert.deepStrictEqual(diagnostic.relatedInformation, []); - - // There are no suggested fixes - assert.strictEqual(suggestedFixes.length, 0); - - // The file url should be normal file - // Ignore the first part because it depends on vs workspace location - assert.strictEqual( - location.uri.path.substr(-'src/main.rs'.length), - 'src/main.rs', - ); - }); -}); diff --git a/editors/code/src/test/utils/diagnotics/vscode.test.ts b/editors/code/src/test/utils/diagnotics/vscode.test.ts deleted file mode 100644 index 4944dd032..000000000 --- a/editors/code/src/test/utils/diagnotics/vscode.test.ts +++ /dev/null @@ -1,98 +0,0 @@ -import * as assert from 'assert'; -import * as vscode from 'vscode'; - -import { areDiagnosticsEqual } from '../../../utils/diagnostics/vscode'; - -const range1 = new vscode.Range( - new vscode.Position(1, 2), - new vscode.Position(3, 4), -); - -const range2 = new vscode.Range( - new vscode.Position(5, 6), - new vscode.Position(7, 8), -); - -describe('areDiagnosticsEqual', () => { - it('should treat identical diagnostics as equal', () => { - const diagnostic1 = new vscode.Diagnostic( - range1, - 'Hello, world!', - vscode.DiagnosticSeverity.Error, - ); - - const diagnostic2 = new vscode.Diagnostic( - range1, - 'Hello, world!', - vscode.DiagnosticSeverity.Error, - ); - - assert(areDiagnosticsEqual(diagnostic1, diagnostic2)); - }); - - it('should treat diagnostics with different sources as inequal', () => { - const diagnostic1 = new vscode.Diagnostic( - range1, - 'Hello, world!', - vscode.DiagnosticSeverity.Error, - ); - diagnostic1.source = 'rustc'; - - const diagnostic2 = new vscode.Diagnostic( - range1, - 'Hello, world!', - vscode.DiagnosticSeverity.Error, - ); - diagnostic2.source = 'clippy'; - - assert(!areDiagnosticsEqual(diagnostic1, diagnostic2)); - }); - - it('should treat diagnostics with different ranges as inequal', () => { - const diagnostic1 = new vscode.Diagnostic( - range1, - 'Hello, world!', - vscode.DiagnosticSeverity.Error, - ); - - const diagnostic2 = new vscode.Diagnostic( - range2, - 'Hello, world!', - vscode.DiagnosticSeverity.Error, - ); - - assert(!areDiagnosticsEqual(diagnostic1, diagnostic2)); - }); - - it('should treat diagnostics with different messages as inequal', () => { - const diagnostic1 = new vscode.Diagnostic( - range1, - 'Hello, world!', - vscode.DiagnosticSeverity.Error, - ); - - const diagnostic2 = new vscode.Diagnostic( - range1, - 'Goodbye!, world!', - vscode.DiagnosticSeverity.Error, - ); - - assert(!areDiagnosticsEqual(diagnostic1, diagnostic2)); - }); - - it('should treat diagnostics with different severities as inequal', () => { - const diagnostic1 = new vscode.Diagnostic( - range1, - 'Hello, world!', - vscode.DiagnosticSeverity.Warning, - ); - - const diagnostic2 = new vscode.Diagnostic( - range1, - 'Hello, world!', - vscode.DiagnosticSeverity.Error, - ); - - assert(!areDiagnosticsEqual(diagnostic1, diagnostic2)); - }); -}); -- cgit v1.2.3