Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Unit tests for new Select Line command (pull #2002)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterflynn committed Nov 6, 2012
1 parent fa3e2d4 commit 298a01a
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/editor/EditorCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ define(function (require, exports, module) {
editor._codeMirror.execCommand("indentLess");
}

function selectLine() {
var editor = EditorManager.getFocusedEditor();
function selectLine(editor) {
editor = editor || EditorManager.getFocusedEditor();
if (editor) {
var sel = editor.getSelection();
var from = {line: sel.start.line, ch: 0};
Expand Down
88 changes: 79 additions & 9 deletions test/spec/EditorCommandHandlers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,16 @@ define(function (require, exports, module) {

myEditor.focus();
}


function makeEditorWithRange(range) {
// create editor with a visible range
var mocks = SpecRunnerUtils.createMockEditor(defaultContent, "javascript", range);
myDocument = mocks.doc;
myEditor = mocks.editor;

myEditor.focus();
}

afterEach(function () {
SpecRunnerUtils.destroyMockEditor(myDocument);
myEditor = null;
Expand Down Expand Up @@ -501,6 +510,7 @@ define(function (require, exports, module) {
});
});


describe("Move Lines Up/Down", function () {
beforeEach(setupFullEditor);

Expand Down Expand Up @@ -810,6 +820,7 @@ define(function (require, exports, module) {
});
});


describe("Delete Line", function () {
beforeEach(setupFullEditor);

Expand Down Expand Up @@ -887,14 +898,6 @@ define(function (require, exports, module) {
});

describe("Delete Line - editor with visible range", function () {
function makeEditorWithRange(range) {
// create editor with a visible range
var mocks = SpecRunnerUtils.createMockEditor(defaultContent, "javascript", range);
myDocument = mocks.doc;
myEditor = mocks.editor;

myEditor.focus();
}

it("should delete the top line of the visible range", function () {
makeEditorWithRange({startLine: 1, endLine: 5});
Expand Down Expand Up @@ -945,5 +948,72 @@ define(function (require, exports, module) {
});
});


describe("Select Line", function () {
beforeEach(setupFullEditor);

it("should select the first line with IP in that line", function () {
myEditor.setSelection({line: 0, ch: 5}, {line: 0, ch: 5});
CommandManager.execute(Commands.EDIT_SELECT_LINE, myEditor);

expectSelection({start: {line: 0, ch: 0}, end: {line: 1, ch: 0}});
});

it("should select the last line with IP in that line", function () {
myEditor.setSelection({line: 7, ch: 0}, {line: 7, ch: 0});
CommandManager.execute(Commands.EDIT_SELECT_LINE, myEditor);

expectSelection({start: {line: 7, ch: 0}, end: {line: 7, ch: 1}});
});

it("should select all in one-line file", function () {
myDocument.setText("// x");
myEditor.setSelection({line: 0, ch: 0}, {line: 0, ch: 0});
CommandManager.execute(Commands.EDIT_SELECT_LINE, myEditor);

expectSelection({start: {line: 0, ch: 0}, end: {line: 0, ch: 4}});
});

it("should extend selection to whole line", function () {
myEditor.setSelection({line: 1, ch: 4}, {line: 1, ch: 8});
CommandManager.execute(Commands.EDIT_SELECT_LINE, myEditor);

expectSelection({start: {line: 1, ch: 0}, end: {line: 2, ch: 0}});
});

it("should extend whole line selection to next line", function () {
myEditor.setSelection({line: 1, ch: 0}, {line: 2, ch: 0});
CommandManager.execute(Commands.EDIT_SELECT_LINE, myEditor);

expectSelection({start: {line: 1, ch: 0}, end: {line: 3, ch: 0}});
});

it("should extend multi-line selection to full lines", function () {
myEditor.setSelection({line: 1, ch: 4}, {line: 3, ch: 9});
CommandManager.execute(Commands.EDIT_SELECT_LINE, myEditor);

expectSelection({start: {line: 1, ch: 0}, end: {line: 4, ch: 0}});
});

it("should extend full multi-line selection to one more line", function () {
myEditor.setSelection({line: 1, ch: 0}, {line: 4, ch: 0});
CommandManager.execute(Commands.EDIT_SELECT_LINE, myEditor);

expectSelection({start: {line: 1, ch: 0}, end: {line: 5, ch: 0}});
});

});

describe("Select Line - editor with visible range", function () {

it("shouldn't select past end of visible range", function () {
makeEditorWithRange({startLine: 1, endLine: 5});
myEditor.setSelection({line: 5, ch: 4}, {line: 5, ch: 4});
CommandManager.execute(Commands.EDIT_SELECT_LINE, myEditor);

expectSelection({start: {line: 5, ch: 0}, end: {line: 5, ch: 5}});
});
});

});
});

0 comments on commit 298a01a

Please sign in to comment.