|
| 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 { expect, should } from 'chai'; |
| 7 | +import * as vscode from 'vscode'; |
| 8 | +import * as path from 'path'; |
| 9 | +import { isRazorWorkspace } from './integrationHelpers'; |
| 10 | +import testAssetWorkspace from './testAssets/testAssetWorkspace'; |
| 11 | + |
| 12 | +const onTypeFormatProviderCommand = 'vscode.executeFormatOnTypeProvider'; |
| 13 | + |
| 14 | +function normalizeNewlines(original: string): string { |
| 15 | + while (original.indexOf('\r\n') != -1) { |
| 16 | + original = original.replace('\r\n', '\n'); |
| 17 | + } |
| 18 | + |
| 19 | + return original; |
| 20 | +} |
| 21 | + |
| 22 | +suite(`Documentation Comment Auto Formatting: ${testAssetWorkspace.description}`, function () { |
| 23 | + let fileUri: vscode.Uri; |
| 24 | + |
| 25 | + suiteSetup(async function () { |
| 26 | + should(); |
| 27 | + |
| 28 | + if (isRazorWorkspace(vscode.workspace)) { |
| 29 | + // The format-on-type provider does not run for razor files. |
| 30 | + this.skip(); |
| 31 | + } |
| 32 | + |
| 33 | + const projectDirectory = testAssetWorkspace.projects[0].projectDirectoryPath; |
| 34 | + const filePath = path.join(projectDirectory, 'DocComments.cs'); |
| 35 | + fileUri = vscode.Uri.file(filePath); |
| 36 | + |
| 37 | + await vscode.commands.executeCommand('vscode.open', fileUri); |
| 38 | + }); |
| 39 | + |
| 40 | + suiteTeardown(async () => { |
| 41 | + await testAssetWorkspace.cleanupWorkspace(); |
| 42 | + }); |
| 43 | + |
| 44 | + test('Triple slash inserts doc comment snippet', async () => { |
| 45 | + const commentPosition = new vscode.Position(2, 7); |
| 46 | + const formatEdits = <vscode.TextEdit[]>(await vscode.commands.executeCommand(onTypeFormatProviderCommand, fileUri, commentPosition, '/')); |
| 47 | + expect(formatEdits).ofSize(1); |
| 48 | + expect(normalizeNewlines(formatEdits[0].newText)).eq(" <summary>\n /// \n /// </summary>\n /// <param name=\"param1\"></param>\n /// <param name=\"param2\"></param>\n /// <returns></returns>"); |
| 49 | + expect(formatEdits[0].range.start.line).eq(commentPosition.line); |
| 50 | + expect(formatEdits[0].range.start.character).eq(commentPosition.character); |
| 51 | + expect(formatEdits[0].range.end.line).eq(commentPosition.line); |
| 52 | + expect(formatEdits[0].range.end.character).eq(commentPosition.character); |
| 53 | + }); |
| 54 | + |
| 55 | + test('Enter in comment inserts triple-slashes preceding', async () => { |
| 56 | + const commentPosition = new vscode.Position(9, 0); |
| 57 | + const formatEdits = <vscode.TextEdit[]>(await vscode.commands.executeCommand(onTypeFormatProviderCommand, fileUri, commentPosition, '\n')); |
| 58 | + expect(formatEdits).ofSize(1); |
| 59 | + expect(formatEdits[0].newText).eq(" /// "); |
| 60 | + expect(formatEdits[0].range.start.line).eq(commentPosition.line); |
| 61 | + expect(formatEdits[0].range.start.character).eq(commentPosition.character); |
| 62 | + expect(formatEdits[0].range.end.line).eq(commentPosition.line); |
| 63 | + expect(formatEdits[0].range.end.character).eq(commentPosition.character); |
| 64 | + }); |
| 65 | +}); |
0 commit comments