Skip to content

Commit

Permalink
Add test for comment operator
Browse files Browse the repository at this point in the history
  • Loading branch information
kimfiedler committed Apr 13, 2017
1 parent cfac478 commit 3fbc101
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 6 deletions.
4 changes: 3 additions & 1 deletion test/mode/modeHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { ModeHandler } from '../../src/mode/modeHandler';

suite("Mode Handler", () => {

setup(setupWorkspace);
setup(async () => {
await setupWorkspace();
});

teardown(cleanUpWorkspace);

Expand Down
50 changes: 50 additions & 0 deletions test/operator/comment.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"use strict";

import { setupWorkspace, setTextEditorOptions, cleanUpWorkspace, assertEqual } from './../testUtils';
import { ModeName } from '../../src/mode/mode';
import { ModeHandler } from '../../src/mode/modeHandler';
import { getTestingFunctions } from '../testSimplifier';

suite("comment operator", () => {
let modeHandler: ModeHandler;
let {
newTest,
newTestOnly,
} = getTestingFunctions();

setup(async () => {
await setupWorkspace(".js");
setTextEditorOptions(4, false);
modeHandler = new ModeHandler();
});

teardown(cleanUpWorkspace);

newTest({
title: "gbb comments out current line",
start: [
"first| line",
"second line"
],
keysPressed: 'gbb',
end: [
"|// first line",
"second line",
],
});

newTest({
title: "gbj comments in current and next line",
start: [
"// first| line",
"// second line",
"third line"
],
keysPressed: 'gbj',
end: [
"|first line",
"second line",
"third line"
],
});
});
8 changes: 4 additions & 4 deletions test/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ function rndName() {
return Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 10);
}

async function createRandomFile(contents: string): Promise<vscode.Uri> {
const tmpFile = join(os.tmpdir(), rndName());
async function createRandomFile(contents: string, fileExtension: string): Promise<vscode.Uri> {
const tmpFile = join(os.tmpdir(), rndName() + fileExtension);

try {
fs.writeFileSync(tmpFile, contents);
Expand Down Expand Up @@ -41,8 +41,8 @@ export function assertEqual<T>(one: T, two: T, message: string = ""): void {
assert.equal(one, two, message);
}

export async function setupWorkspace(): Promise<any> {
const file = await createRandomFile("");
export async function setupWorkspace(fileExtension: string = ""): Promise<any> {
const file = await createRandomFile("", fileExtension);
const doc = await vscode.workspace.openTextDocument(file);

await vscode.window.showTextDocument(doc);
Expand Down
4 changes: 3 additions & 1 deletion test/textEditor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { TextEditor } from './../src/textEditor';
import { setupWorkspace, cleanUpWorkspace } from './testUtils';

suite("text editor", () => {
suiteSetup(setupWorkspace);
suiteSetup(async () => {
await setupWorkspace();
});

suiteTeardown(cleanUpWorkspace);

Expand Down

0 comments on commit 3fbc101

Please sign in to comment.