Add test for comment operator

This commit is contained in:
Kim Fiedler Vestergaard 2017-04-13 20:18:15 +02:00
parent bd780205a2
commit 5a6d305e1c
4 changed files with 60 additions and 6 deletions

View File

@ -7,7 +7,9 @@ import { ModeHandler } from '../../src/mode/modeHandler';
suite("Mode Handler", () => {
setup(setupWorkspace);
setup(async () => {
await setupWorkspace();
});
teardown(cleanUpWorkspace);

View File

@ -0,0 +1,50 @@
"use strict";
import { setupWorkspace, setTextEditorOptions, cleanUpWorkspace } 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"
],
});
});

View File

@ -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);
@ -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);

View File

@ -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);