|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | + *--------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import * as vscode from 'vscode'; |
| 7 | +import * as path from 'path'; |
| 8 | +import testAssetWorkspace from './testAssets/testAssetWorkspace'; |
| 9 | +import { |
| 10 | + activateCSharpExtension, |
| 11 | + closeAllEditorsAsync, |
| 12 | + openFileInWorkspaceAsync, |
| 13 | + sortLocations, |
| 14 | +} from './integrationHelpers'; |
| 15 | +import { describe, beforeAll, beforeEach, afterAll, test, expect, afterEach } from '@jest/globals'; |
| 16 | + |
| 17 | +describe(`[${testAssetWorkspace.description}] Test Go To Implementation`, () => { |
| 18 | + beforeAll(async () => { |
| 19 | + await activateCSharpExtension(); |
| 20 | + }); |
| 21 | + |
| 22 | + beforeEach(async () => { |
| 23 | + await openFileInWorkspaceAsync(path.join('src', 'app', 'implementation.cs')); |
| 24 | + }); |
| 25 | + |
| 26 | + afterAll(async () => { |
| 27 | + await testAssetWorkspace.cleanupWorkspace(); |
| 28 | + }); |
| 29 | + |
| 30 | + afterEach(async () => { |
| 31 | + await closeAllEditorsAsync(); |
| 32 | + }); |
| 33 | + |
| 34 | + test('Finds implementations', async () => { |
| 35 | + const requestPosition = new vscode.Position(4, 22); |
| 36 | + const implementationList = await getImplementations(requestPosition); |
| 37 | + |
| 38 | + expect(implementationList).toHaveLength(3); |
| 39 | + |
| 40 | + expect(implementationList[0].uri.path).toContain('BaseClassImplementation.cs'); |
| 41 | + expect(implementationList[0].range).toStrictEqual(new vscode.Range(2, 17, 2, 40)); |
| 42 | + |
| 43 | + expect(implementationList[1].uri.path).toContain('implementation.cs'); |
| 44 | + expect(implementationList[1].range).toStrictEqual(new vscode.Range(4, 17, 4, 26)); |
| 45 | + |
| 46 | + expect(implementationList[2].uri.path).toContain('implementation.cs'); |
| 47 | + expect(implementationList[2].range).toStrictEqual(new vscode.Range(5, 17, 5, 26)); |
| 48 | + }); |
| 49 | +}); |
| 50 | + |
| 51 | +async function getImplementations(position: vscode.Position): Promise<vscode.Location[]> { |
| 52 | + const implementationList = <vscode.Location[]>( |
| 53 | + await vscode.commands.executeCommand( |
| 54 | + 'vscode.executeImplementationProvider', |
| 55 | + vscode.window.activeTextEditor!.document.uri, |
| 56 | + position |
| 57 | + ) |
| 58 | + ); |
| 59 | + |
| 60 | + return sortLocations(implementationList); |
| 61 | +} |
0 commit comments