Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Change to Enum since that's the best fit here
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffbean committed Aug 13, 2018
1 parent 2e6d332 commit a0cdf66
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
22 changes: 14 additions & 8 deletions src/goGenerateTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<boolean> {
export function GenerateTests(type: GenerationType): Thenable<boolean> {
let editor = checkActiveEditor();
if (!editor) {
return;
Expand All @@ -87,11 +93,11 @@ export function GenerateTests(type: string): Thenable<boolean> {
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);
Expand Down
6 changes: 3 additions & 3 deletions src/goMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
8 changes: 4 additions & 4 deletions test/go.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
});
Expand Down Expand Up @@ -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();
});
Expand All @@ -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();
});
Expand Down

0 comments on commit a0cdf66

Please sign in to comment.