"test: delete line from the middle" : function() { var session = new EditSession(["a", "b", "c", "d"].join("\n")); var editor = new Editor(new MockRenderer(), session); editor.moveCursorTo(1, 1); editor.removeLines(); assert.equal(session.toString(), "a\nc\nd"); assert.position(editor.getCursorPosition(), 1, 0); editor.removeLines(); assert.equal(session.toString(), "a\nd"); assert.position(editor.getCursorPosition(), 1, 0); editor.removeLines(); assert.equal(session.toString(), "a\n"); assert.position(editor.getCursorPosition(), 1, 0); editor.removeLines(); assert.equal(session.toString(), "a\n"); assert.position(editor.getCursorPosition(), 1, 0); },
"test: find matching opening bracket" : function() { var session = new EditSession(["(()(", "())))"]); assert.position(session.findMatchingBracket({row: 0, column: 3}), 0, 1); assert.position(session.findMatchingBracket({row: 1, column: 2}), 1, 0); assert.position(session.findMatchingBracket({row: 1, column: 3}), 0, 3); assert.position(session.findMatchingBracket({row: 1, column: 4}), 0, 0); assert.equal(session.findMatchingBracket({row: 1, column: 5}), null); },
"test: documentToScreen with soft wrap": function() { var session = new EditSession(["foo bar foo bar"]); session.setUseWrapMode(true); session.setWrapLimitRange(12, 12); session.adjustWrapLimit(80); assert.position(session.documentToScreenPosition(0, 11), 0, 11); assert.position(session.documentToScreenPosition(0, 12), 1, 0); },
"test: should use selection of new document" : function() { this.session1.getSelection().selectTo(0, 1); this.session2.getSelection().selectTo(1, 0); this.editor.setSession(this.session1); assert.position(this.editor.getSelection().getSelectionLead(), 0, 1); this.editor.setSession(this.session2); assert.position(this.editor.getSelection().getSelectionLead(), 1, 0); },
"test: should use cursor of new document" : function() { this.session1.getSelection().moveCursorTo(0, 1); this.session2.getSelection().moveCursorTo(1, 0); this.editor.setSession(this.session1); assert.position(this.editor.getCursorPosition(), 0, 1); this.editor.setSession(this.session2); assert.position(this.editor.getCursorPosition(), 1, 0); },
"test: find simple text in next line" : function() { var session = new EditSession(["abc", "juhu kinners 123", "456"]); var search = new Search().set({ needle: "kinners" }); var range = search.find(session); assert.position(range.start, 1, 5); assert.position(range.end, 1, 12); },
"test: move lines down should select moved lines" : function() { var session = new EditSession(["11", "22", "33", "44"].join("\n")); var editor = new Editor(new MockRenderer(), session); editor.moveCursorTo(0, 1); editor.getSelection().selectDown(); editor.moveLinesDown(); assert.equal(["33", "11", "22", "44"].join("\n"), session.toString()); assert.position(editor.getCursorPosition(), 1, 0); assert.position(editor.getSelection().getSelectionAnchor(), 3, 0); assert.position(editor.getSelection().getSelectionLead(), 1, 0); editor.moveLinesDown(); assert.equal(["33", "44", "11", "22"].join("\n"), session.toString()); assert.position(editor.getCursorPosition(), 2, 0); assert.position(editor.getSelection().getSelectionAnchor(), 3, 2); assert.position(editor.getSelection().getSelectionLead(), 2, 0); // moving again should have no effect editor.moveLinesDown(); assert.equal(["33", "44", "11", "22"].join("\n"), session.toString()); assert.position(editor.getCursorPosition(), 2, 0); assert.position(editor.getSelection().getSelectionAnchor(), 3, 2); assert.position(editor.getSelection().getSelectionLead(), 2, 0); },
"test: moveCursor word left" : function() { var session = new EditSession(" Fuß Füße"); var selection = session.getSelection(); selection.moveCursorTo(0, 9) selection.moveCursorWordLeft(); assert.position(selection.getCursor(), 0, 5); selection.moveCursorWordLeft(); assert.position(selection.getCursor(), 0, 4); },
"test: select word with cursor in word should select the word" : function() { var session = new EditSession("Juhu Kinners 123"); var selection = session.getSelection(); selection.moveCursorTo(0, 8); selection.selectWord(); var range = selection.getRange(); assert.position(range.start, 0, 5); assert.position(range.end, 0, 12); },
"test: select word with cursor in white space should select white space" : function() { var session = new EditSession("Juhu Kinners"); var selection = session.getSelection(); selection.moveCursorTo(0, 5); selection.selectWord(); var range = selection.getRange(); assert.position(range.start, 0, 4); assert.position(range.end, 0, 6); },
"test: screenToDocument with soft wrap and multi byte characters": function() { session = new EditSession(["ぁ a"]); session.setUseWrapMode(true); session.adjustWrapLimit(80); assert.position(session.screenToDocumentPosition(0, 1), 0, 0); assert.position(session.screenToDocumentPosition(0, 2), 0, 1); assert.position(session.screenToDocumentPosition(0, 3), 0, 2); assert.position(session.screenToDocumentPosition(0, 4), 0, 3); assert.position(session.screenToDocumentPosition(0, 5), 0, 3); },
"test: documentToScreen with soft wrap and multibyte characters": function() { session = new EditSession(["ぁぁa"]); session.setUseWrapMode(true); session.setWrapLimitRange(2, 2); session.adjustWrapLimit(80); assert.position(session.documentToScreenPosition(0, 1), 1, 0); assert.position(session.documentToScreenPosition(0, 2), 2, 0); assert.position(session.documentToScreenPosition(0, 4), 2, 1); },
"test: find text starting at cursor position" : function() { var session = new EditSession(["juhu kinners", "juhu kinners 123"]); session.getSelection().moveCursorTo(0, 6); var search = new Search().set({ needle: "kinners" }); var range = search.find(session); assert.position(range.start, 1, 5); assert.position(range.end, 1, 12); },
"test: documentToScreen without soft wrap": function() { var session = new EditSession([ "juhu", "12\t\t34", "ぁぁa" ]); assert.position(session.documentToScreenPosition(0, 3), 0, 3); assert.position(session.documentToScreenPosition(1, 3), 1, 4); assert.position(session.documentToScreenPosition(1, 4), 1, 8); assert.position(session.documentToScreenPosition(2, 2), 2, 4); },
"test: find backwards": function() { var session = new EditSession(["juhu juhu juhu juhu"]); session.getSelection().moveCursorTo(0, 10); var search = new Search().set({ needle: "juhu", backwards: true }); var range = search.find(session); assert.position(range.start, 0, 5); assert.position(range.end, 0, 9); },
"test: whole word search should not match inside of words": function() { var session = new EditSession(["juhukinners", "juhu kinners 123", "456"]); var search = new Search().set({ needle: "kinners", wholeWord: true }); var range = search.find(session); assert.position(range.start, 1, 5); assert.position(range.end, 1, 12); },
"test: screenToDocument with soft wrap": function() { var session = new EditSession(["foo bar foo bar"]); session.setUseWrapMode(true); session.setWrapLimitRange(12, 12); session.adjustWrapLimit(80); assert.position(session.screenToDocumentPosition(1, 0), 0, 12); assert.position(session.screenToDocumentPosition(0, 11), 0, 11); // Check if the position is clamped the right way. assert.position(session.screenToDocumentPosition(0, 12), 0, 11); assert.position(session.screenToDocumentPosition(0, 20), 0, 11); },
"test: navigate from the end of a long line down to a short line and back should maintain the curser column": function() { var editor = new Editor(new MockRenderer(), new EditSession(["123456", "1"])); editor.navigateTo(0, 6); assert.position(editor.getCursorPosition(), 0, 6); editor.navigateDown(); assert.position(editor.getCursorPosition(), 1, 1); editor.navigateUp(); assert.position(editor.getCursorPosition(), 0, 6); },
"test: use regular expressions with capture groups": function() { var session = new EditSession([" ab: 12px", " <h1 abc"]); var search = new Search().set({ needle: "(\\d+)", regExp: true }); var range = search.find(session); assert.position(range.start, 0, 6); assert.position(range.end, 0, 8); },
"test: find using a regular expression" : function() { var session = new EditSession(["abc123 123 cd", "abc"]); var search = new Search().set({ needle: "\\d+", regExp: true }); var range = search.find(session); assert.position(range.start, 0, 3); assert.position(range.end, 0, 6); },
"test: move selection lead to start of file" : function() { var session = this.createSession(200, 10); var selection = session.getSelection(); selection.moveCursorTo(100, 5); selection.selectFileStart(); var range = selection.getRange(); assert.position(range.start, 0, 0); assert.position(range.end, 100, 5); },
"test: select word left and select" : function() { var session = new EditSession("Juhu Kinners"); var selection = session.getSelection(); selection.moveCursorTo(0, 3); selection.selectWordLeft(); var range = selection.getRange(); assert.position(range.start, 0, 0); assert.position(range.end, 0, 3); },
"test: goto visible line should only move the cursor and not scroll": function() { var editor = new Editor(new MockRenderer(), this.createEditSession(200, 5)); editor.navigateTo(0, 0); editor.gotoLine(12); assert.position(editor.getCursorPosition(), 11, 0); assert.equal(editor.getFirstVisibleRow(), 0); editor.navigateTo(30, 0); editor.gotoLine(33); assert.position(editor.getCursorPosition(), 32, 0); assert.equal(editor.getFirstVisibleRow(), 30); },
"test: wrap search should wrap at file end" : function() { var session = new EditSession(["abc", "juhu kinners 123", "456"]); session.getSelection().moveCursorTo(2, 1); var search = new Search().set({ needle: "kinners", wrap: true }); var range = search.find(session); assert.position(range.start, 1, 5); assert.position(range.end, 1, 12); },
"test: find using a regular expression and whole word" : function() { var session = new EditSession(["abc123 123 cd", "abc"]); var search = new Search().set({ needle: "\\d+\\b", regExp: true, wholeWord: true }); var range = search.find(session); assert.position(range.start, 0, 7); assert.position(range.end, 0, 10); },
"test: clone": function() { var range = new Range(1, 2, 3, 4); var clone = range.clone(); assert.position(clone.start, 1, 2); assert.position(clone.end, 3, 4); clone.start.column = 20; assert.position(range.start, 1, 2); clone.end.column = 20; assert.position(range.end, 3, 4); },
"test: copy lines up should select lines and place cursor at the selection start" : function() { var session = new EditSession(["11", "22", "33", "44"].join("\n")); var editor = new Editor(new MockRenderer(), session); editor.moveCursorTo(1, 1); editor.getSelection().selectDown(); editor.copyLinesUp(); assert.equal(["11", "22", "33", "22", "33", "44"].join("\n"), session.toString()); assert.position(editor.getCursorPosition(), 1, 0); assert.position(editor.getSelection().getSelectionAnchor(), 3, 0); assert.position(editor.getSelection().getSelectionLead(), 1, 0); },
"test: comment lines should perserve selection" : function() { var session = new EditSession([" abc", "cde"].join("\n"), new JavaScriptMode()); var editor = new Editor(new MockRenderer(), session); editor.moveCursorTo(0, 2); editor.getSelection().selectDown(); editor.toggleCommentLines(); assert.equal(["// abc", "//cde"].join("\n"), session.toString()); var selection = editor.getSelectionRange(); assert.position(selection.start, 0, 4); assert.position(selection.end, 1, 4); },
"test: edge case - match directly before the cursor" : function() { var session = new EditSession(["123", "123", "juhu"]); var search = new Search().set({ needle: "juhu", wrap: true }); session.getSelection().moveCursorTo(2, 5); var range = search.find(session); assert.position(range.start, 2, 0); assert.position(range.end, 2, 4); },
"test: reset desired column on navigate left or right": function() { var editor = new Editor(new MockRenderer(), new EditSession(["123456", "12"])); editor.navigateTo(0, 6); assert.position(editor.getCursorPosition(), 0, 6); editor.navigateDown(); assert.position(editor.getCursorPosition(), 1, 2); editor.navigateLeft(); assert.position(editor.getCursorPosition(), 1, 1); editor.navigateUp(); assert.position(editor.getCursorPosition(), 0, 1); }