Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
aioutecism committed Sep 17, 2016
1 parent 3a74e78 commit 3780bf8
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 9 deletions.
58 changes: 58 additions & 0 deletions test/Actions/Delete.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import * as assert from 'assert';
import * as TestUtil from '../Util';
import {window, Selection} from 'vscode';

import {Configuration} from '../../src/Configuration';
import {ActionDelete} from '../../src/Actions/Delete';
import {MotionWord} from '../../src/Motions/Word';

export function run() {

Configuration.init();

test('ActionDelete.byMotions', (done) => {

const testCases = [
{
message: 'MotionWord.nextStart at line end',
motions: [MotionWord.nextStart()],
in: 'Foo end\nBar end',
selection: new Selection(0, 6, 0, 6),
out: 'Foo en\nBar end',
},
{
message: 'MotionWord.prevStart at line start',
motions: [MotionWord.prevStart()],
in: 'Foo end\nBar end',
selection: new Selection(1, 0, 1, 0),
out: 'Foo end\nBar end',
}
];

let promise = Promise.resolve();

while (testCases.length > 0) {
const testCase = testCases.shift();
promise = promise.then(() => {

return TestUtil.createTempDocument(testCase.in).then(() => {
TestUtil.setSelection(testCase.selection);

return ActionDelete.byMotions({
motions: testCase.motions
}).then(() => {
assert.equal(TestUtil.getDocument().getText(), testCase.out, testCase.message);
});
});

});
}

promise.then(() => {
done();
}, (error) => {
done(error);
});

});
};
16 changes: 8 additions & 8 deletions test/Motions/Word.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function run() {

Configuration.init();

test('MotionWordPosition.NEXT_START', (done) => {
test('MotionWord: Next start', (done) => {
TestUtil.createTempDocument(' foo bar baz fum-nom').then(() => {

let apply = (fromCharacter) => {
Expand Down Expand Up @@ -142,7 +142,7 @@ export function run() {
});
});

test('MotionWordPosition.NEXT_END', (done) => {
test('MotionWord: Next end', (done) => {
TestUtil.createTempDocument(' foo bar baz fum-nom').then(() => {

let apply = (fromCharacter) => {
Expand Down Expand Up @@ -275,7 +275,7 @@ export function run() {
});
});

test('MotionWordPosition.PREV_START', (done) => {
test('MotionWord: Prev start', (done) => {
TestUtil.createTempDocument(' foo bar baz fum-nom').then(() => {

let apply = (fromCharacter) => {
Expand Down Expand Up @@ -408,7 +408,7 @@ export function run() {
});
});

test('MotionWordPosition.PREV_END', (done) => {
test('MotionWord: Prev end', (done) => {
TestUtil.createTempDocument(' foo bar baz fum-nom').then(() => {

let apply = (fromCharacter) => {
Expand Down Expand Up @@ -541,7 +541,7 @@ export function run() {
});
});

test('MotionWordPosition.NEXT_START with blankSeparators', (done) => {
test('MotionWord: Next start with blank separated style', (done) => {
TestUtil.createTempDocument(' <foo-bar> (baz$foo) bar').then(() => {

let apply = (fromCharacter) => {
Expand Down Expand Up @@ -674,7 +674,7 @@ export function run() {
});
});

test('MotionWordPosition.NEXT_END with blankSeparators', (done) => {
test('MotionWord: Next end with blank separated style', (done) => {
TestUtil.createTempDocument(' <foo-bar> (baz$foo) bar').then(() => {

let apply = (fromCharacter) => {
Expand Down Expand Up @@ -807,7 +807,7 @@ export function run() {
});
});

test('MotionWordPosition.PREV_START with blankSeparators', (done) => {
test('MotionWord: Prev start with blank separated style', (done) => {
TestUtil.createTempDocument(' <foo-bar> (baz$foo) bar').then(() => {

let apply = (fromCharacter) => {
Expand Down Expand Up @@ -945,7 +945,7 @@ export function run() {
});
});

test('MotionWordPosition.PREV_END with blankSeparators', (done) => {
test('MotionWord: Prev end with blank separated style', (done) => {
TestUtil.createTempDocument(' <foo-bar> (baz$foo) bar').then(() => {

let apply = (fromCharacter) => {
Expand Down
6 changes: 5 additions & 1 deletion test/Util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {workspace, window, Uri, Position, Selection} from 'vscode';
import {workspace, window, Uri, TextDocument, Position, Selection} from 'vscode';

export function createTempDocument(content?: string): Thenable<boolean> {
const uri = Uri.parse(`untitled:${__dirname}.${Math.random()}.tmp`);
Expand All @@ -16,6 +16,10 @@ export function createTempDocument(content?: string): Thenable<boolean> {
});
}

export function getDocument(): TextDocument {
return window.activeTextEditor.document;
}

export function setPosition(position: Position): void {
setPositions([position]);
}
Expand Down
2 changes: 2 additions & 0 deletions test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import * as MotionWordTest from './Motions/Word.test';
import * as MotionIntegrationTest from './Motions/Integration.test';
import * as TextObjectWordTest from './TextObjects/Word.test';
import * as ActionSelectionTest from './Actions/Selection.test';
import * as ActionDeleteTest from './Actions/Delete.test';

// Defines a Mocha test suite to group tests of similar kind together
suite('Extension Tests', () => {
MotionWordTest.run();
MotionIntegrationTest.run();

ActionSelectionTest.run();
ActionDeleteTest.run();

TextObjectWordTest.run();
});

0 comments on commit 3780bf8

Please sign in to comment.