Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promisify #92

Merged
merged 2 commits into from
Dec 4, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
tests: fixes #88
  • Loading branch information
jpoon committed Dec 4, 2015
commit 0ad4f1089b0a953485f11c051f791fad14acbe6d
66 changes: 32 additions & 34 deletions test/mode/modeInsert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ModeInsert from '../../src/mode/modeInsert';
import {ModeName} from '../../src/mode/mode';
import {Cursor} from '../../src/motion/motion';
import TextEditor from '../../src/textEditor';
import * as testUtils from '../testUtils';
import TestHelpers from '../testHelpers';

let modeHandler: ModeInsert = null;

Expand All @@ -29,69 +29,69 @@ suite("Mode Insert", () => {
});

test("can handle key events", (done) => {
let expected = "!";

modeHandler.HandleKeyEvent("!")
.then(() => {
return testUtils.assertTextEditorText(expected);
return TestHelpers.assertEqualLines(["!"]);
}).then(done, done);
});

test("Can handle 'o'", (done) => {
let expected = "text\n";

TextEditor.insert("text")
.then(() => {
return modeHandler.HandleActivation("o");
}).then(() => {
return testUtils.assertTextEditorText(expected);
}).then(done, done);
})
.then(() => {
return TestHelpers.assertEqualLines(["text", ""]);
})
.then(done, done);
});

test("Can handle 'O'", (done) => {
let expected = "\ntext";

TextEditor.insert("text")
.then(() => {
return modeHandler.HandleActivation("O");
}).then(() => {
return testUtils.assertTextEditorText(expected);
}).then(done, done);
})
.then(() => {
return TestHelpers.assertEqualLines(["", "text"]);
})
.then(done, done);
});

test("Can handle 'i'", (done) => {
let expected = "text!text";

TextEditor.insert("texttext")
.then(() => {
new Cursor(0, 4).move();
}).then(() => {
})
.then(() => {
return modeHandler.HandleActivation("i");
}).then(() => {
})
.then(() => {
return modeHandler.HandleKeyEvent("!");
}).then(() => {
return testUtils.assertTextEditorText(expected);
}).then(done, done);
})
.then(() => {
return TestHelpers.assertEqualLines(["text!text"]);
})
.then(done, done);
});

test("Can handle 'I'", (done) => {
let expected = "!text";

TextEditor.insert("text")
.then(() => {
new Cursor(0, 4).move();
}).then(() => {
})
.then(() => {
return modeHandler.HandleActivation("I");
}).then(() => {
})
.then(() => {
return modeHandler.HandleKeyEvent("!");
}).then(() => {
return testUtils.assertTextEditorText(expected);
}).then(done, done);
})
.then(() => {
return TestHelpers.assertEqualLines(["!text"]);
})
.then(done, done);
});

test("Can handle 'a'", (done) => {
let expected = "textt!ext";

TextEditor.insert("texttext")
.then(() => {
new Cursor(0, 4).move();
Expand All @@ -100,13 +100,11 @@ suite("Mode Insert", () => {
}).then(() => {
return modeHandler.HandleKeyEvent("!");
}).then(() => {
return testUtils.assertTextEditorText(expected);
return TestHelpers.assertEqualLines(["textt!ext"]);
}).then(done, done);
});

test("Can handle 'A'", (done) => {
let expected = "text!";

TextEditor.insert("text")
.then(() => {
new Cursor(0, 0).move();
Expand All @@ -115,7 +113,7 @@ suite("Mode Insert", () => {
}).then(() => {
return modeHandler.HandleKeyEvent("!");
}).then(() => {
return testUtils.assertTextEditorText(expected);
return TestHelpers.assertEqualLines(["text!"]);
}).then(done, done);
});
});
14 changes: 14 additions & 0 deletions test/testHelpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import TextEditor from '../src/textEditor';
import * as assert from 'assert';

export default class TestHelpers {

public static assertEqualLines(expectedLines : string[]) {
assert.equal(TextEditor.getLineCount(), expectedLines.length);

for (let i = 0; i < expectedLines.length; i++) {
assert.equal(TextEditor.readLine(i), expectedLines[i]);
}
}

}
13 changes: 0 additions & 13 deletions test/testUtils.ts

This file was deleted.