diff --git a/src/goGenerateTests.ts b/src/goGenerateTests.ts index b662ad94d..44952d134 100644 --- a/src/goGenerateTests.ts +++ b/src/goGenerateTests.ts @@ -15,9 +15,15 @@ import { GoDocumentSymbolProvider } from './goOutline'; import { outputChannel } from './goStatus'; const generatedWord = 'Generated '; -export const FUNCTION_TYPE = 'function'; -export const FILE_TYPE = 'file'; -export const PACKAGE_TYPE = 'package'; + +/** + * This enum is the types of generation supported via the gotests tooling + */ +export enum GenerationType { + Function, + File, + Package, +} /** * If current active editor has a Go file, returns the editor. @@ -76,9 +82,9 @@ function getGoConfigObject(editor: vscode.TextEditor): vscode.WorkspaceConfigura /** * * @param type The type of tests to generate. In this case a simple string to indicate what - * type of tests we need to create, function, file, or package + * type of tests we need to create, function, file, or package. These are constants in this package. */ -export function GenerateTests(type: string): Thenable { +export function GenerateTests(type: GenerationType): Thenable { let editor = checkActiveEditor(); if (!editor) { return; @@ -87,11 +93,11 @@ export function GenerateTests(type: string): Thenable { let goConfig = getGoConfigObject(editor); switch (type) { - case PACKAGE_TYPE: + case GenerationType.Package: return generateTestCurrentPackage(editor, goConfig); - case FILE_TYPE: + case GenerationType.File: return generateTestCurrentFile(editor, goConfig); - case FUNCTION_TYPE: + case GenerationType.Function: return generateTestCurrentFunction(editor, goConfig); default: vscode.window.showErrorMessage('unknown type passed to generate tests: ' + type); diff --git a/src/goMain.ts b/src/goMain.ts index 540c0f856..d8ef67c56 100644 --- a/src/goMain.ts +++ b/src/goMain.ts @@ -329,15 +329,15 @@ export function activate(ctx: vscode.ExtensionContext): void { })); ctx.subscriptions.push(vscode.commands.registerCommand('go.test.generate.package', () => { - goGenerateTests.GenerateTests(goGenerateTests.PACKAGE_TYPE); + goGenerateTests.GenerateTests(goGenerateTests.GenerationType.Package); })); ctx.subscriptions.push(vscode.commands.registerCommand('go.test.generate.file', () => { - goGenerateTests.GenerateTests(goGenerateTests.FILE_TYPE); + goGenerateTests.GenerateTests(goGenerateTests.GenerationType.File); })); ctx.subscriptions.push(vscode.commands.registerCommand('go.test.generate.function', () => { - goGenerateTests.GenerateTests(goGenerateTests.FUNCTION_TYPE); + goGenerateTests.GenerateTests(goGenerateTests.GenerationType.Function); })); ctx.subscriptions.push(vscode.commands.registerCommand('go.toggle.test.file', () => { diff --git a/test/go.test.ts b/test/go.test.ts index 82e0a3cf4..c95bf6c43 100644 --- a/test/go.test.ts +++ b/test/go.test.ts @@ -20,7 +20,7 @@ import { testCurrentFile } from '../src/goTest'; import { getBinPath, getGoVersion, isVendorSupported } from '../src/util'; import { documentSymbols } from '../src/goOutline'; import { listPackages, getTextEditForAddImport } from '../src/goImport'; -import { GenerateTests, FUNCTION_TYPE, PACKAGE_TYPE, FILE_TYPE } from '../src/goGenerateTests'; +import { GenerateTests, GenerationType } from '../src/goGenerateTests'; import { getAllPackages } from '../src/goPackages'; import { getImportPath } from '../src/util'; import { goPlay } from '../src/goPlayground'; @@ -302,7 +302,7 @@ It returns the number of bytes written and any write error encountered. let uri = vscode.Uri.file(path.join(generateTestsSourcePath, 'generatetests.go')); return vscode.workspace.openTextDocument(uri).then(document => { return vscode.window.showTextDocument(document).then(editor => { - return GenerateTests(FILE_TYPE).then((result: boolean) => { + return GenerateTests(GenerationType.File).then((result: boolean) => { assert.equal(result, true); return Promise.resolve(); }); @@ -331,7 +331,7 @@ It returns the number of bytes written and any write error encountered. assert(vscode.window.activeTextEditor, 'No active editor'); let selection = new vscode.Selection(5, 0, 6, 0); editor.selection = selection; - return GenerateTests(FUNCTION_TYPE).then((result: boolean) => { + return GenerateTests(GenerationType.Function).then((result: boolean) => { assert.equal(result, true); return Promise.resolve(); }); @@ -357,7 +357,7 @@ It returns the number of bytes written and any write error encountered. let uri = vscode.Uri.file(path.join(generatePackageTestSourcePath, 'generatetests.go')); return vscode.workspace.openTextDocument(uri).then(document => { return vscode.window.showTextDocument(document).then(editor => { - return GenerateTests(PACKAGE_TYPE).then((result: boolean) => { + return GenerateTests(GenerationType.Package).then((result: boolean) => { assert.equal(result, true); return Promise.resolve(); });