/* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is Ajax.org Code Editor (ACE). * * The Initial Developer of the Original Code is * Ajax.org B.V. * Portions created by the Initial Developer are Copyright (C) 2010 * the Initial Developer. All Rights Reserved. * * Contributor(s): * Fabian Jakobs * Julian Viereck * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ if (typeof process !== "undefined") { require("amd-loader"); require("./test/mockdom"); } define(function(require, exports, module) { "use strict"; var lang = require("./lib/lang"); var EditSession = require("./edit_session").EditSession; var Editor = require("./editor").Editor; var UndoManager = require("./undomanager").UndoManager; var MockRenderer = require("./test/mockrenderer").MockRenderer; var Range = require("./range").Range; var assert = require("./test/assertions"); var JavaScriptMode = require("./mode/javascript").Mode; function createFoldTestSession() { var lines = [ "function foo(items) {", " for (var i=0; i>", [1, 2], 1); }, "test get longest line" : function() { var session = new EditSession(["12"]); session.setTabSize(4); assert.equal(session.getScreenWidth(), 2); session.doc.insertNewLine({row: 0, column: Infinity}); session.doc.insertLines(1, ["123"]); assert.equal(session.getScreenWidth(), 3); session.doc.insertNewLine({row: 0, column: Infinity}); session.doc.insertLines(1, ["\t\t"]); assert.equal(session.getScreenWidth(), 8); session.setTabSize(2); assert.equal(session.getScreenWidth(), 4); }, "test getDisplayString": function() { var session = new EditSession(["12"]); session.setTabSize(4); assert.equal(session.$getDisplayTokens("\t").length, 4); assert.equal(session.$getDisplayTokens("abc").length, 3); assert.equal(session.$getDisplayTokens("abc\t").length, 4); }, "test issue 83": function() { var session = new EditSession(""); var editor = new Editor(new MockRenderer(), session); var document = session.getDocument(); session.setUseWrapMode(true); document.insertLines(0, ["a", "b"]); document.insertLines(2, ["c", "d"]); document.removeLines(1, 2); }, "test wrapMode init has to create wrapData array": function() { var session = new EditSession("foo bar\nfoo bar"); var editor = new Editor(new MockRenderer(), session); var document = session.getDocument(); session.setUseWrapMode(true); session.setWrapLimitRange(3, 3); session.adjustWrapLimit(80); // Test if wrapData is there and was computed. assert.equal(session.$wrapData.length, 2); assert.equal(session.$wrapData[0].length, 1); assert.equal(session.$wrapData[1].length, 1); }, "test first line blank with wrap": function() { var session = new EditSession("\nfoo"); session.setUseWrapMode(true); assert.equal(session.doc.getValue(), ["", "foo"].join("\n")); }, "test first line blank with wrap 2" : function() { var session = new EditSession(""); session.setUseWrapMode(true); session.setValue("\nfoo"); assert.equal(session.doc.getValue(), ["", "foo"].join("\n")); }, "test fold getFoldDisplayLine": function() { var session = createFoldTestSession(); function assertDisplayLine(foldLine, str) { var line = session.getLine(foldLine.end.row); var displayLine = session.getFoldDisplayLine(foldLine, foldLine.end.row, line.length); assert.equal(displayLine, str); } assertDisplayLine(session.$foldData[0], "function foo(args...) {") assertDisplayLine(session.$foldData[1], " for (vfoo...ert(items[bar...\"juhu\");"); }, "test foldLine idxToPosition": function() { var session = createFoldTestSession(); function assertIdx2Pos(foldLineIdx, idx, row, column) { var foldLine = session.$foldData[foldLineIdx]; assert.position(foldLine.idxToPosition(idx), row, column); } // "function foo(items) {", // " for (var i=0; i