refactor tests
This commit is contained in:
parent
f381b26fd2
commit
7e2a2d3493
22 changed files with 428 additions and 190 deletions
|
|
@ -2,17 +2,19 @@
|
|||
server: http://localhost:4224
|
||||
|
||||
load:
|
||||
- src/ace/lib/core.js
|
||||
- src/ace/lib/*.js
|
||||
- src/ace/MEventEmitter.js
|
||||
- src/ace/mode/Text.js
|
||||
- src/ace/mode/TextHighlightRules.js
|
||||
- src/ace/mode/*.js
|
||||
- src/ace/layer/*.js
|
||||
- src/ace/*.js
|
||||
- demo/require.js
|
||||
# - src/ace/lib/core.js
|
||||
# - src/ace/lib/*.js
|
||||
# - src/ace/MEventEmitter.js
|
||||
# - src/ace/mode/Text.js
|
||||
# - src/ace/mode/TextHighlightRules.js
|
||||
# - src/ace/mode/*.js
|
||||
# - src/ace/layer/*.js
|
||||
# - src/ace/*.js
|
||||
|
||||
- src/debug/*.js
|
||||
# - src/debug/*.js
|
||||
|
||||
- src/test/ace/*.js
|
||||
- src/test/ace/mode/*.js
|
||||
- src/test/debug/*.js
|
||||
# - src/test/ace/*.js
|
||||
# - src/test/ace/mode/*.js
|
||||
# - src/test/debug/*.js
|
||||
- src/ace/test/all.js
|
||||
130
src/ace/test/ChangeDocumentTest.js
Normal file
130
src/ace/test/ChangeDocumentTest.js
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
/**
|
||||
* Ajax.org Code Editor (ACE)
|
||||
*
|
||||
* @copyright 2010, Ajax.org Services B.V.
|
||||
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
* @author Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*/
|
||||
|
||||
require.def([
|
||||
"ace/Document",
|
||||
"ace/Editor",
|
||||
"ace/mode/Text",
|
||||
"ace/mode/JavaScript",
|
||||
"ace/test/MockRenderer"
|
||||
], function(
|
||||
Document,
|
||||
Editor,
|
||||
TextMode,
|
||||
JavaScriptMode,
|
||||
MockRenderer
|
||||
) {
|
||||
|
||||
var ChangeDocumentTest = new TestCase("ChangeDocumentTest", {
|
||||
setUp : function() {
|
||||
this.doc1 = new Document(["abc", "def"].join("\n"));
|
||||
this.doc2 = new Document(["ghi", "jkl"].join("\n"));
|
||||
this.editor = new Editor(new MockRenderer());
|
||||
},
|
||||
|
||||
"test: change document" : function() {
|
||||
this.editor.setDocument(this.doc1);
|
||||
assertEquals(this.doc1, this.editor.getDocument());
|
||||
|
||||
this.editor.setDocument(this.doc2);
|
||||
assertEquals(this.doc2, this.editor.getDocument());
|
||||
},
|
||||
|
||||
"test: only changes to the new document should have effect" : function() {
|
||||
var called = false;
|
||||
this.editor.onDocumentChange = function() {
|
||||
called = true;
|
||||
};
|
||||
|
||||
this.editor.setDocument(this.doc1);
|
||||
this.editor.setDocument(this.doc2);
|
||||
|
||||
this.doc1.duplicateLines(0, 0);
|
||||
assertFalse(called);
|
||||
|
||||
this.doc2.duplicateLines(0, 0);
|
||||
assertTrue(called);
|
||||
},
|
||||
|
||||
"test: should use cursor of new document" : function() {
|
||||
this.doc1.getSelection().moveCursorTo(0, 1);
|
||||
this.doc2.getSelection().moveCursorTo(1, 0);
|
||||
|
||||
this.editor.setDocument(this.doc1);
|
||||
assertPosition(0, 1, this.editor.getCursorPosition());
|
||||
|
||||
this.editor.setDocument(this.doc2);
|
||||
assertPosition(1, 0, this.editor.getCursorPosition());
|
||||
},
|
||||
|
||||
"test: only changing the cursor of the new doc should not have an effect" : function() {
|
||||
this.editor.onCursorChange = function() {
|
||||
called = true;
|
||||
};
|
||||
|
||||
this.editor.setDocument(this.doc1);
|
||||
this.editor.setDocument(this.doc2);
|
||||
assertPosition(0, 0, this.editor.getCursorPosition());
|
||||
|
||||
var called = false;
|
||||
this.doc1.getSelection().moveCursorTo(0, 1);
|
||||
assertPosition(0, 0, this.editor.getCursorPosition());
|
||||
assertFalse(called);
|
||||
|
||||
this.doc2.getSelection().moveCursorTo(1, 1);
|
||||
assertPosition(1, 1, this.editor.getCursorPosition());
|
||||
assertTrue(called);
|
||||
},
|
||||
|
||||
"test: should use selection of new document" : function() {
|
||||
this.doc1.getSelection().selectTo(0, 1);
|
||||
this.doc2.getSelection().selectTo(1, 0);
|
||||
|
||||
this.editor.setDocument(this.doc1);
|
||||
assertPosition(0, 1, this.editor.getSelection().getSelectionLead());
|
||||
|
||||
this.editor.setDocument(this.doc2);
|
||||
assertPosition(1, 0, this.editor.getSelection().getSelectionLead());
|
||||
},
|
||||
|
||||
"test: only changing the selection of the new doc should not have an effect" : function() {
|
||||
this.editor.onSelectionChange = function() {
|
||||
called = true;
|
||||
};
|
||||
|
||||
this.editor.setDocument(this.doc1);
|
||||
this.editor.setDocument(this.doc2);
|
||||
assertPosition(0, 0, this.editor.getSelection().getSelectionLead());
|
||||
|
||||
var called = false;
|
||||
this.doc1.getSelection().selectTo(0, 1);
|
||||
assertPosition(0, 0, this.editor.getSelection().getSelectionLead());
|
||||
assertFalse(called);
|
||||
|
||||
this.doc2.getSelection().selectTo(1, 1);
|
||||
assertPosition(1, 1, this.editor.getSelection().getSelectionLead());
|
||||
assertTrue(called);
|
||||
},
|
||||
|
||||
"test: should use mode of new document" : function() {
|
||||
this.editor.onDocumentModeChange = function() {
|
||||
called = true;
|
||||
};
|
||||
this.editor.setDocument(this.doc1);
|
||||
this.editor.setDocument(this.doc2);
|
||||
|
||||
var called = false;
|
||||
this.doc1.setMode(new Text());
|
||||
assertFalse(called);
|
||||
|
||||
this.doc2.setMode(new JavaScriptMode());
|
||||
assertTrue(called);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
234
src/ace/test/DocumentTest.js
Normal file
234
src/ace/test/DocumentTest.js
Normal file
|
|
@ -0,0 +1,234 @@
|
|||
/**
|
||||
* Ajax.org Code Editor (ACE)
|
||||
*
|
||||
* @copyright 2010, Ajax.org Services B.V.
|
||||
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
* @author Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*/
|
||||
|
||||
require.def([
|
||||
"ace/Document",
|
||||
"ace/UndoManager",
|
||||
"ace/Editor",
|
||||
"ace/test/MockRenderer"
|
||||
], function(
|
||||
Document,
|
||||
UndoManager,
|
||||
Editor,
|
||||
MockRenderer
|
||||
) {
|
||||
|
||||
var TextDocumentTest = new TestCase("TextDocumentTest", {
|
||||
|
||||
"test: find matching opening bracket" : function() {
|
||||
var doc = new Document(["(()(", "())))"]);
|
||||
|
||||
assertPosition(0, 1, doc.findMatchingBracket({row: 0, column: 3}));
|
||||
assertPosition(1, 0, doc.findMatchingBracket({row: 1, column: 2}));
|
||||
assertPosition(0, 3, doc.findMatchingBracket({row: 1, column: 3}));
|
||||
assertPosition(0, 0, doc.findMatchingBracket({row: 1, column: 4}));
|
||||
assertEquals(null, doc.findMatchingBracket({row: 1, column: 5}));
|
||||
},
|
||||
|
||||
"test: find matching closing bracket" : function() {
|
||||
var doc = new Document(["(()(", "())))"]);
|
||||
|
||||
assertPosition(1, 1, doc.findMatchingBracket({row: 1, column: 1}));
|
||||
assertPosition(1, 1, doc.findMatchingBracket({row: 1, column: 1}));
|
||||
assertPosition(1, 2, doc.findMatchingBracket({row: 0, column: 4}));
|
||||
assertPosition(0, 2, doc.findMatchingBracket({row: 0, column: 2}));
|
||||
assertPosition(1, 3, doc.findMatchingBracket({row: 0, column: 1}));
|
||||
assertEquals(null, doc.findMatchingBracket({row: 0, column: 0}));
|
||||
},
|
||||
|
||||
"test: match different bracket types" : function() {
|
||||
var doc = new Document(["({[", ")]}"]);
|
||||
|
||||
assertPosition(1, 0, doc.findMatchingBracket({row: 0, column: 1}));
|
||||
assertPosition(1, 2, doc.findMatchingBracket({row: 0, column: 2}));
|
||||
assertPosition(1, 1, doc.findMatchingBracket({row: 0, column: 3}));
|
||||
|
||||
assertPosition(0, 0, doc.findMatchingBracket({row: 1, column: 1}));
|
||||
assertPosition(0, 2, doc.findMatchingBracket({row: 1, column: 2}));
|
||||
assertPosition(0, 1, doc.findMatchingBracket({row: 1, column: 3}));
|
||||
},
|
||||
|
||||
"test: move lines down" : function() {
|
||||
var doc = new Document(["1", "2", "3", "4"]);
|
||||
|
||||
doc.moveLinesDown(0, 1);
|
||||
assertEquals(["3", "1", "2", "4"].join("\n"), doc.toString());
|
||||
|
||||
doc.moveLinesDown(1, 2);
|
||||
assertEquals(["3", "4", "1", "2"].join("\n"), doc.toString());
|
||||
|
||||
doc.moveLinesDown(2, 3);
|
||||
assertEquals(["3", "4", "1", "2"].join("\n"), doc.toString());
|
||||
|
||||
doc.moveLinesDown(2, 2);
|
||||
assertEquals(["3", "4", "2", "1"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: move lines up" : function() {
|
||||
var doc = new Document(["1", "2", "3", "4"]);
|
||||
|
||||
doc.moveLinesUp(2, 3);
|
||||
assertEquals(["1", "3", "4", "2"].join("\n"), doc.toString());
|
||||
|
||||
doc.moveLinesUp(1, 2);
|
||||
assertEquals(["3", "4", "1", "2"].join("\n"), doc.toString());
|
||||
|
||||
doc.moveLinesUp(0, 1);
|
||||
assertEquals(["3", "4", "1", "2"].join("\n"), doc.toString());
|
||||
|
||||
doc.moveLinesUp(2, 2);
|
||||
assertEquals(["3", "1", "4", "2"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: duplicate lines" : function() {
|
||||
var doc = new Document(["1", "2", "3", "4"]);
|
||||
|
||||
doc.duplicateLines(1, 2);
|
||||
assertEquals(["1", "2", "3", "2", "3", "4"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: duplicate last line" : function() {
|
||||
var doc = new Document(["1", "2", "3"]);
|
||||
|
||||
doc.duplicateLines(2, 2);
|
||||
assertEquals(["1", "2", "3", "3"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: duplicate first line" : function() {
|
||||
var doc = new Document(["1", "2", "3"]);
|
||||
|
||||
doc.duplicateLines(0, 0);
|
||||
assertEquals(["1", "1", "2", "3"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: should handle unix style new lines" : function() {
|
||||
var doc = new Document(["1", "2", "3"]);
|
||||
assertEquals(["1", "2", "3"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: should handle windows style new lines" : function() {
|
||||
var doc = new Document(["1", "2", "3"].join("\r\n"));
|
||||
doc.setNewLineMode("unix");
|
||||
assertEquals(["1", "2", "3"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: set new line mode to 'windows' should use '\r\n' as new lines": function() {
|
||||
var doc = new Document(["1", "2", "3"].join("\n"));
|
||||
doc.setNewLineMode("windows");
|
||||
assertEquals(["1", "2", "3"].join("\r\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: set new line mode to 'unix' should use '\n' as new lines": function() {
|
||||
var doc = new Document(["1", "2", "3"].join("\r\n"));
|
||||
doc.setNewLineMode("unix");
|
||||
assertEquals(["1", "2", "3"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: set new line mode to 'auto' should use detect the incoming nl type": function() {
|
||||
var doc = new Document(["1", "2", "3"].join("\n"));
|
||||
doc.setNewLineMode("auto");
|
||||
assertEquals(["1", "2", "3"].join("\n"), doc.toString());
|
||||
|
||||
var doc = new Document(["1", "2", "3"].join("\r\n"));
|
||||
doc.setNewLineMode("auto");
|
||||
assertEquals(["1", "2", "3"].join("\r\n"), doc.toString());
|
||||
|
||||
doc.replace(new Range(0, 0, 2, 1), ["4", "5", "6"].join("\n"));
|
||||
assertEquals(["4", "5", "6"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: undo/redo for delete line" : function() {
|
||||
var doc = new Document(["111", "222", "333"]);
|
||||
var undoManager = new UndoManager();
|
||||
doc.setUndoManager(undoManager);
|
||||
|
||||
var initialText = doc.toString();
|
||||
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.removeLines();
|
||||
var step1 = doc.toString();
|
||||
assertEquals("222\n333", step1);
|
||||
doc.$informUndoManager.call();
|
||||
|
||||
editor.removeLines();
|
||||
var step2 = doc.toString();
|
||||
assertEquals("333", step2);
|
||||
doc.$informUndoManager.call();
|
||||
|
||||
editor.removeLines();
|
||||
var step3 = doc.toString();
|
||||
assertEquals("", step3);
|
||||
doc.$informUndoManager.call();
|
||||
|
||||
|
||||
undoManager.undo();
|
||||
doc.$informUndoManager.call();
|
||||
assertEquals(step2, doc.toString());
|
||||
|
||||
undoManager.undo();
|
||||
doc.$informUndoManager.call();
|
||||
assertEquals(step1, doc.toString());
|
||||
|
||||
undoManager.undo();
|
||||
doc.$informUndoManager.call();
|
||||
assertEquals(initialText, doc.toString());
|
||||
|
||||
undoManager.undo();
|
||||
doc.$informUndoManager.call();
|
||||
assertEquals(initialText, doc.toString());
|
||||
},
|
||||
|
||||
"test: convert document to screen coordinates" : function() {
|
||||
var doc = new Document("01234\t567890\t1234");
|
||||
doc.setTabSize(4);
|
||||
|
||||
assertEquals(0, doc.documentToScreenColumn(0, 0));
|
||||
assertEquals(4, doc.documentToScreenColumn(0, 4));
|
||||
assertEquals(5, doc.documentToScreenColumn(0, 5));
|
||||
assertEquals(9, doc.documentToScreenColumn(0, 6));
|
||||
assertEquals(15, doc.documentToScreenColumn(0, 12));
|
||||
assertEquals(19, doc.documentToScreenColumn(0, 13));
|
||||
|
||||
doc.setTabSize(2);
|
||||
|
||||
assertEquals(0, doc.documentToScreenColumn(0, 0));
|
||||
assertEquals(4, doc.documentToScreenColumn(0, 4));
|
||||
assertEquals(5, doc.documentToScreenColumn(0, 5));
|
||||
assertEquals(7, doc.documentToScreenColumn(0, 6));
|
||||
assertEquals(13, doc.documentToScreenColumn(0, 12));
|
||||
assertEquals(15, doc.documentToScreenColumn(0, 13));
|
||||
},
|
||||
|
||||
"test: convert document to scrren coordinates with leading tabs": function() {
|
||||
var doc = new Document("\t\t123");
|
||||
doc.setTabSize(4);
|
||||
|
||||
assertEquals(0, doc.documentToScreenColumn(0, 0));
|
||||
assertEquals(4, doc.documentToScreenColumn(0, 1));
|
||||
assertEquals(8, doc.documentToScreenColumn(0, 2));
|
||||
assertEquals(9, doc.documentToScreenColumn(0, 3));
|
||||
},
|
||||
|
||||
"test: convert screen to document coordinates" : function() {
|
||||
var doc = new Document("01234\t567890\t1234");
|
||||
doc.setTabSize(4);
|
||||
|
||||
assertEquals(0, doc.screenToDocumentColumn(0, 0));
|
||||
assertEquals(4, doc.screenToDocumentColumn(0, 4));
|
||||
assertEquals(5, doc.screenToDocumentColumn(0, 5));
|
||||
assertEquals(5, doc.screenToDocumentColumn(0, 6));
|
||||
assertEquals(5, doc.screenToDocumentColumn(0, 7));
|
||||
assertEquals(5, doc.screenToDocumentColumn(0, 8));
|
||||
assertEquals(6, doc.screenToDocumentColumn(0, 9));
|
||||
assertEquals(12, doc.screenToDocumentColumn(0, 15));
|
||||
assertEquals(13, doc.screenToDocumentColumn(0, 19));
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
36
src/ace/test/EventEmitterTest.js
Normal file
36
src/ace/test/EventEmitterTest.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
* Ajax.org Code Editor (ACE)
|
||||
*
|
||||
* @copyright 2010, Ajax.org Services B.V.
|
||||
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
* @author Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*/
|
||||
|
||||
require.def([
|
||||
"ace/lib/oop",
|
||||
"ace/MEventEmitter"
|
||||
], function(
|
||||
oop,
|
||||
MEventEmitter
|
||||
) {
|
||||
|
||||
var EventEmitter = function() {};
|
||||
|
||||
oop.implement(EventEmitter.prototype, MEventEmitter);
|
||||
|
||||
var EventEmitterTest = new TestCase("EventEmitterTest", {
|
||||
"test: dispatch event with no data" : function() {
|
||||
var emitter = new EventEmitter();
|
||||
|
||||
var called = false;
|
||||
emitter.addEventListener("juhu", function(e) {
|
||||
called = true;
|
||||
assertEquals("juhu", e.type);
|
||||
});
|
||||
|
||||
emitter.$dispatchEvent("juhu");
|
||||
assertTrue(called);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
88
src/ace/test/MockRenderer.js
Normal file
88
src/ace/test/MockRenderer.js
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
/**
|
||||
* Ajax.org Code Editor (ACE)
|
||||
*
|
||||
* @copyright 2010, Ajax.org Services B.V.
|
||||
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
* @author Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*/
|
||||
|
||||
require.def([], function() {
|
||||
|
||||
MockRenderer = function(visibleRowCount) {
|
||||
this.container = document.createElement("div");
|
||||
this.cursor = {
|
||||
row : 0,
|
||||
column : 0
|
||||
};
|
||||
|
||||
this.visibleRowCount = visibleRowCount || 20;
|
||||
|
||||
this.layerConfig = {
|
||||
firstVisibleRow : 0,
|
||||
lastVisibleRow : this.visibleRowCount
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
MockRenderer.prototype.getFirstVisibleRow = function() {
|
||||
return this.layerConfig.firstVisibleRow;
|
||||
};
|
||||
|
||||
MockRenderer.prototype.getLastVisibleRow = function() {
|
||||
return this.layerConfig.lastVisibleRow;
|
||||
};
|
||||
|
||||
MockRenderer.prototype.getContainerElement = function() {
|
||||
return this.container;
|
||||
};
|
||||
|
||||
MockRenderer.prototype.getMouseEventTarget = function() {
|
||||
return this.container;
|
||||
};
|
||||
|
||||
MockRenderer.prototype.setDocument = function(doc) {
|
||||
this.lines = doc.lines;
|
||||
};
|
||||
|
||||
MockRenderer.prototype.setTokenizer = function() {
|
||||
};
|
||||
|
||||
MockRenderer.prototype.updateCursor = function(position) {
|
||||
this.cursor.row = position.row;
|
||||
this.cursor.column = position.column;
|
||||
};
|
||||
|
||||
MockRenderer.prototype.scrollCursorIntoView = function() {
|
||||
if (this.cursor.row < this.layerConfig.firstVisibleRow) {
|
||||
this.scrollToRow(this.cursor.row);
|
||||
}
|
||||
else if (this.cursor.row > this.layerConfig.lastVisibleRow) {
|
||||
this.scrollToRow(this.cursor.row);
|
||||
}
|
||||
};
|
||||
|
||||
MockRenderer.prototype.scrollToRow = function(row) {
|
||||
var row = Math.min(this.lines.length - this.visibleRowCount, Math.max(0,
|
||||
row));
|
||||
this.layerConfig.firstVisibleRow = row;
|
||||
this.layerConfig.lastVisibleRow = row + this.visibleRowCount;
|
||||
};
|
||||
|
||||
MockRenderer.prototype.getScrollTopRow = function() {
|
||||
return this.layerConfig.firstVisibleRow;
|
||||
};
|
||||
|
||||
MockRenderer.prototype.draw = function() {
|
||||
};
|
||||
|
||||
MockRenderer.prototype.updateLines = function(startRow, endRow) {
|
||||
};
|
||||
|
||||
MockRenderer.prototype.addMarker = function() {
|
||||
};
|
||||
|
||||
MockRenderer.prototype.setBreakpoints = function() {
|
||||
};
|
||||
|
||||
return MockRenderer;
|
||||
});
|
||||
126
src/ace/test/NavigationTest.js
Normal file
126
src/ace/test/NavigationTest.js
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
/**
|
||||
* Ajax.org Code Editor (ACE)
|
||||
*
|
||||
* @copyright 2010, Ajax.org Services B.V.
|
||||
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
* @author Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*/
|
||||
|
||||
require.def([
|
||||
"ace/Document",
|
||||
"ace/Editor",
|
||||
"ace/test/MockRenderer"
|
||||
], function(
|
||||
Document,
|
||||
Editor,
|
||||
MockRenderer
|
||||
) {
|
||||
|
||||
var NavigationTest = TestCase("NavigationTest",
|
||||
{
|
||||
createTextDocument : function(rows, cols) {
|
||||
var line = new Array(cols + 1).join("a");
|
||||
var text = new Array(rows).join(line + "\n") + line;
|
||||
return new Document(text);
|
||||
},
|
||||
|
||||
"test: navigate to end of file should scroll the last line into view" : function() {
|
||||
var doc = this.createTextDocument(200, 10);
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.navigateFileEnd();
|
||||
var cursor = editor.getCursorPosition();
|
||||
|
||||
assertTrue(editor.getFirstVisibleRow() <= cursor.row);
|
||||
assertTrue(editor.getLastVisibleRow() >= cursor.row);
|
||||
},
|
||||
|
||||
"test: navigate to start of file should scroll the first row into view" : function() {
|
||||
var doc = this.createTextDocument(200, 10);
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(editor.getLastVisibleRow() + 20);
|
||||
editor.navigateFileStart();
|
||||
|
||||
assertEquals(0, editor.getFirstVisibleRow());
|
||||
},
|
||||
|
||||
"test: goto hidden line should scroll the line into the middle of the viewport" : function() {
|
||||
var editor = new Editor(new MockRenderer(), this.createTextDocument(200, 5));
|
||||
|
||||
editor.navigateTo(0, 0);
|
||||
editor.gotoLine(101);
|
||||
assertPosition(100, 0, editor.getCursorPosition());
|
||||
assertEquals(90, editor.getFirstVisibleRow());
|
||||
|
||||
editor.navigateTo(100, 0);
|
||||
editor.gotoLine(11);
|
||||
assertPosition(10, 0, editor.getCursorPosition());
|
||||
assertEquals(0, editor.getFirstVisibleRow());
|
||||
|
||||
editor.navigateTo(100, 0);
|
||||
editor.gotoLine(6);
|
||||
assertPosition(5, 0, editor.getCursorPosition());
|
||||
assertEquals(0, editor.getFirstVisibleRow());
|
||||
|
||||
editor.navigateTo(100, 0);
|
||||
editor.gotoLine(1);
|
||||
assertPosition(0, 0, editor.getCursorPosition());
|
||||
assertEquals(0, editor.getFirstVisibleRow());
|
||||
|
||||
editor.navigateTo(0, 0);
|
||||
editor.gotoLine(191);
|
||||
assertPosition(190, 0, editor.getCursorPosition());
|
||||
assertEquals(180, editor.getFirstVisibleRow());
|
||||
|
||||
editor.navigateTo(0, 0);
|
||||
editor.gotoLine(196);
|
||||
assertPosition(195, 0, editor.getCursorPosition());
|
||||
assertEquals(180, editor.getFirstVisibleRow());
|
||||
},
|
||||
|
||||
"test: goto visible line should only move the cursor and not scroll": function() {
|
||||
var editor = new Editor(new MockRenderer(), this.createTextDocument(200, 5));
|
||||
|
||||
editor.navigateTo(0, 0);
|
||||
editor.gotoLine(12);
|
||||
assertPosition(11, 0, editor.getCursorPosition());
|
||||
assertEquals(0, editor.getFirstVisibleRow());
|
||||
|
||||
editor.navigateTo(30, 0);
|
||||
editor.gotoLine(33);
|
||||
assertPosition(32, 0, editor.getCursorPosition());
|
||||
assertEquals(30, editor.getFirstVisibleRow());
|
||||
},
|
||||
|
||||
"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 Document(["123456", "1"]));
|
||||
|
||||
editor.navigateTo(0, 6);
|
||||
assertPosition(0, 6, editor.getCursorPosition());
|
||||
|
||||
editor.navigateDown();
|
||||
assertPosition(1, 1, editor.getCursorPosition());
|
||||
|
||||
editor.navigateUp();
|
||||
assertPosition(0, 6, editor.getCursorPosition());
|
||||
},
|
||||
|
||||
"test: reset desired column on navigate left or right": function() {
|
||||
var editor = new Editor(new MockRenderer(), new Document(["123456", "12"]));
|
||||
|
||||
editor.navigateTo(0, 6);
|
||||
assertPosition(0, 6, editor.getCursorPosition());
|
||||
|
||||
editor.navigateDown();
|
||||
assertPosition(1, 2, editor.getCursorPosition());
|
||||
|
||||
editor.navigateLeft();
|
||||
assertPosition(1, 1, editor.getCursorPosition());
|
||||
|
||||
editor.navigateUp();
|
||||
assertPosition(0, 1, editor.getCursorPosition());
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
123
src/ace/test/RangeTest.js
Normal file
123
src/ace/test/RangeTest.js
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
/**
|
||||
* Ajax.org Code Editor (ACE)
|
||||
*
|
||||
* @copyright 2010, Ajax.org Services B.V.
|
||||
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
* @author Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*/
|
||||
|
||||
require.def([
|
||||
"ace/Range"
|
||||
], function(
|
||||
Range
|
||||
) {
|
||||
|
||||
RangeTest = new TestCase("RangeTest", {
|
||||
|
||||
"test: create range": function() {
|
||||
var range = new Range(1,2,3,4);
|
||||
|
||||
assertEquals(1, range.start.row);
|
||||
assertEquals(2, range.start.column);
|
||||
assertEquals(3, range.end.row);
|
||||
assertEquals(4, range.end.column);
|
||||
},
|
||||
|
||||
"test: create from points": function() {
|
||||
var range = Range.fromPoints({row: 1, column: 2}, {row:3, column:4});
|
||||
|
||||
assertEquals(1, range.start.row);
|
||||
assertEquals(2, range.start.column);
|
||||
assertEquals(3, range.end.row);
|
||||
assertEquals(4, range.end.column);
|
||||
},
|
||||
|
||||
"test: clip to rows": function() {
|
||||
assertRange(10, 0, 31, 0, new Range(0, 20, 100, 30).clipRows(10, 30));
|
||||
assertRange(10, 0, 30, 10, new Range(0, 20, 30, 10).clipRows(10, 30));
|
||||
|
||||
var range = new Range(0, 20, 3, 10);
|
||||
var range = range.clipRows(10, 30);
|
||||
|
||||
assertTrue(range.isEmpty());
|
||||
assertRange(10, 0, 10, 0, range);
|
||||
},
|
||||
|
||||
"test: isEmpty": function() {
|
||||
var range = new Range(1, 2, 1, 2);
|
||||
assertTrue(range.isEmpty());
|
||||
|
||||
var range = new Range(1, 2, 1, 6);
|
||||
assertFalse(range.isEmpty());
|
||||
},
|
||||
|
||||
"test: is multi line": function() {
|
||||
var range = new Range(1, 2, 1, 6);
|
||||
assertFalse(range.isMultiLine());
|
||||
|
||||
var range = new Range(1, 2, 2, 6);
|
||||
assertTrue(range.isMultiLine());
|
||||
},
|
||||
|
||||
"test: clone": function() {
|
||||
var range = new Range(1, 2, 3, 4);
|
||||
var clone = range.clone();
|
||||
|
||||
assertPosition(1, 2, clone.start);
|
||||
assertPosition(3, 4, clone.end);
|
||||
|
||||
clone.start.column = 20;
|
||||
assertPosition(1, 2, range.start);
|
||||
|
||||
clone.end.column = 20;
|
||||
assertPosition(3, 4, range.end);
|
||||
},
|
||||
|
||||
"test: contains for multi line ranges": function() {
|
||||
var range = new Range(1, 10, 5, 20);
|
||||
|
||||
assertTrue(range.contains(1, 10));
|
||||
assertTrue(range.contains(2, 0));
|
||||
assertTrue(range.contains(3, 100));
|
||||
assertTrue(range.contains(5, 19));
|
||||
assertTrue(range.contains(5, 20));
|
||||
|
||||
assertFalse(range.contains(1, 9));
|
||||
assertFalse(range.contains(0, 0));
|
||||
assertFalse(range.contains(5, 21));
|
||||
},
|
||||
|
||||
"test: contains for single line ranges": function() {
|
||||
var range = new Range(1, 10, 1, 20);
|
||||
|
||||
assertTrue(range.contains(1, 10));
|
||||
assertTrue(range.contains(1, 15));
|
||||
assertTrue(range.contains(1, 20));
|
||||
|
||||
assertFalse(range.contains(0, 9));
|
||||
assertFalse(range.contains(2, 9));
|
||||
assertFalse(range.contains(1, 9));
|
||||
assertFalse(range.contains(1, 21));
|
||||
},
|
||||
|
||||
"test: extend range": function() {
|
||||
var range = new Range(2, 10, 2, 30);
|
||||
|
||||
var range = range.extend(2, 5);
|
||||
assertRange(2, 5, 2, 30, range);
|
||||
|
||||
var range = range.extend(2, 35);
|
||||
assertRange(2, 5, 2, 35, range);
|
||||
|
||||
var range = range.extend(2, 15);
|
||||
assertRange(2, 5, 2, 35, range);
|
||||
|
||||
var range = range.extend(1, 4);
|
||||
assertRange(1, 4, 2, 35, range);
|
||||
|
||||
var range = range.extend(6, 10);
|
||||
assertRange(1, 4, 6, 10, range);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
322
src/ace/test/SearchTest.js
Normal file
322
src/ace/test/SearchTest.js
Normal file
|
|
@ -0,0 +1,322 @@
|
|||
/**
|
||||
* Ajax.org Code Editor (ACE)
|
||||
*
|
||||
* @copyright 2010, Ajax.org Services B.V.
|
||||
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
* @author Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*/
|
||||
|
||||
require.def([
|
||||
"ace/Document",
|
||||
"ace/Search"
|
||||
], function(
|
||||
Document,
|
||||
Search
|
||||
) {
|
||||
|
||||
var SearchTest = new TestCase("SearchTest", {
|
||||
|
||||
"test: configure the search object" : function() {
|
||||
var search = new Search();
|
||||
search.set({
|
||||
needle: "juhu",
|
||||
scope: Search.ALL
|
||||
});
|
||||
},
|
||||
|
||||
"test: find simple text in document" : function() {
|
||||
var doc = new Document(["juhu kinners 123", "456"]);
|
||||
var search = new Search().set({
|
||||
needle: "kinners"
|
||||
});
|
||||
|
||||
var range = search.find(doc);
|
||||
assertPosition(0, 5, range.start);
|
||||
assertPosition(0, 12, range.end);
|
||||
},
|
||||
|
||||
"test: find simple text in next line" : function() {
|
||||
var doc = new Document(["abc", "juhu kinners 123", "456"]);
|
||||
var search = new Search().set({
|
||||
needle: "kinners"
|
||||
});
|
||||
|
||||
var range = search.find(doc);
|
||||
assertPosition(1, 5, range.start);
|
||||
assertPosition(1, 12, range.end);
|
||||
},
|
||||
|
||||
"test: find text starting at cursor position" : function() {
|
||||
var doc = new Document(["juhu kinners", "juhu kinners 123"]);
|
||||
doc.getSelection().moveCursorTo(0, 6);
|
||||
var search = new Search().set({
|
||||
needle: "kinners"
|
||||
});
|
||||
|
||||
var range = search.find(doc);
|
||||
assertPosition(1, 5, range.start);
|
||||
assertPosition(1, 12, range.end);
|
||||
},
|
||||
|
||||
"test: wrap search is off by default" : function() {
|
||||
var doc = new Document(["abc", "juhu kinners 123", "456"]);
|
||||
doc.getSelection().moveCursorTo(2, 1);
|
||||
|
||||
var search = new Search().set({
|
||||
needle: "kinners"
|
||||
});
|
||||
|
||||
assertEquals(null, search.find(doc));
|
||||
},
|
||||
|
||||
"test: wrap search should wrap at file end" : function() {
|
||||
var doc = new Document(["abc", "juhu kinners 123", "456"]);
|
||||
doc.getSelection().moveCursorTo(2, 1);
|
||||
|
||||
var search = new Search().set({
|
||||
needle: "kinners",
|
||||
wrap: true
|
||||
});
|
||||
|
||||
var range = search.find(doc);
|
||||
assertPosition(1, 5, range.start);
|
||||
assertPosition(1, 12, range.end);
|
||||
},
|
||||
|
||||
"test: wrap search with no match should return 'null'": function() {
|
||||
var doc = new Document(["abc", "juhu kinners 123", "456"]);
|
||||
doc.getSelection().moveCursorTo(2, 1);
|
||||
|
||||
var search = new Search().set({
|
||||
needle: "xyz",
|
||||
wrap: true
|
||||
});
|
||||
|
||||
assertEquals(null, search.find(doc));
|
||||
},
|
||||
|
||||
"test: case sensitive is by default off": function() {
|
||||
var doc = new Document(["abc", "juhu kinners 123", "456"]);
|
||||
|
||||
var search = new Search().set({
|
||||
needle: "JUHU"
|
||||
});
|
||||
|
||||
assertEquals(null, search.find(doc));
|
||||
},
|
||||
|
||||
"test: case sensitive search": function() {
|
||||
var doc = new Document(["abc", "juhu kinners 123", "456"]);
|
||||
|
||||
var search = new Search().set({
|
||||
needle: "KINNERS",
|
||||
caseSensitive: true
|
||||
});
|
||||
|
||||
var range = search.find(doc);
|
||||
assertPosition(1, 5, range.start);
|
||||
assertPosition(1, 12, range.end);
|
||||
},
|
||||
|
||||
"test: whole word search should not match inside of words": function() {
|
||||
var doc = new Document(["juhukinners", "juhu kinners 123", "456"]);
|
||||
|
||||
var search = new Search().set({
|
||||
needle: "kinners",
|
||||
wholeWord: true
|
||||
});
|
||||
|
||||
var range = search.find(doc);
|
||||
assertPosition(1, 5, range.start);
|
||||
assertPosition(1, 12, range.end);
|
||||
},
|
||||
|
||||
"test: find backwards": function() {
|
||||
var doc = new Document(["juhu juhu juhu juhu"]);
|
||||
doc.getSelection().moveCursorTo(0, 10);
|
||||
var search = new Search().set({
|
||||
needle: "juhu",
|
||||
backwards: true
|
||||
});
|
||||
|
||||
var range = search.find(doc);
|
||||
assertPosition(0, 5, range.start);
|
||||
assertPosition(0, 9, range.end);
|
||||
},
|
||||
|
||||
"test: find in selection": function() {
|
||||
var doc = new Document(["juhu", "juhu", "juhu", "juhu"]);
|
||||
doc.getSelection().setSelectionAnchor(1, 0);
|
||||
doc.getSelection().selectTo(3, 5);
|
||||
|
||||
var search = new Search().set({
|
||||
needle: "juhu",
|
||||
wrap: true,
|
||||
scope: Search.SELECTION
|
||||
});
|
||||
|
||||
var range = search.find(doc);
|
||||
assertPosition(1, 0, range.start);
|
||||
assertPosition(1, 4, range.end);
|
||||
|
||||
doc.getSelection().setSelectionAnchor(0, 2);
|
||||
doc.getSelection().selectTo(3, 2);
|
||||
|
||||
var range = search.find(doc);
|
||||
assertPosition(1, 0, range.start);
|
||||
assertPosition(1, 4, range.end);
|
||||
},
|
||||
|
||||
"test: find backwards in selection": function() {
|
||||
var doc = new Document(["juhu", "juhu", "juhu", "juhu"]);
|
||||
|
||||
var search = new Search().set({
|
||||
needle: "juhu",
|
||||
wrap: true,
|
||||
backwards: true,
|
||||
scope: Search.SELECTION
|
||||
});
|
||||
|
||||
doc.getSelection().setSelectionAnchor(0, 2);
|
||||
doc.getSelection().selectTo(3, 2);
|
||||
|
||||
var range = search.find(doc);
|
||||
assertPosition(2, 0, range.start);
|
||||
assertPosition(2, 4, range.end);
|
||||
|
||||
doc.getSelection().setSelectionAnchor(0, 2);
|
||||
doc.getSelection().selectTo(1, 2);
|
||||
|
||||
assertEquals(null, search.find(doc));
|
||||
},
|
||||
|
||||
"test: edge case - match directly before the cursor" : function() {
|
||||
var doc = new Document(["123", "123", "juhu"]);
|
||||
|
||||
var search = new Search().set({
|
||||
needle: "juhu",
|
||||
wrap: true
|
||||
});
|
||||
|
||||
doc.getSelection().moveCursorTo(2, 5);
|
||||
|
||||
var range = search.find(doc);
|
||||
assertPosition(2, 0, range.start);
|
||||
assertPosition(2, 4, range.end);
|
||||
},
|
||||
|
||||
"test: edge case - match backwards directly after the cursor" : function() {
|
||||
var doc = new Document(["123", "123", "juhu"]);
|
||||
|
||||
var search = new Search().set({
|
||||
needle: "juhu",
|
||||
wrap: true,
|
||||
backwards: true
|
||||
});
|
||||
|
||||
doc.getSelection().moveCursorTo(2, 0);
|
||||
|
||||
var range = search.find(doc);
|
||||
assertPosition(2, 0, range.start);
|
||||
assertPosition(2, 4, range.end);
|
||||
},
|
||||
|
||||
"test: find using a regular expression" : function() {
|
||||
var doc = new Document(["abc123 123 cd", "abc"]);
|
||||
|
||||
var search = new Search().set({
|
||||
needle: "\\d+",
|
||||
regExp: true
|
||||
});
|
||||
|
||||
var range = search.find(doc);
|
||||
assertPosition(0, 3, range.start);
|
||||
assertPosition(0, 6, range.end);
|
||||
},
|
||||
|
||||
"test: find using a regular expression and whole word" : function() {
|
||||
var doc = new Document(["abc123 123 cd", "abc"]);
|
||||
|
||||
var search = new Search().set({
|
||||
needle: "\\d+\\b",
|
||||
regExp: true,
|
||||
wholeWord: true
|
||||
});
|
||||
|
||||
var range = search.find(doc);
|
||||
assertPosition(0, 7, range.start);
|
||||
assertPosition(0, 10, range.end);
|
||||
},
|
||||
|
||||
"test: use regular expressions with capture groups": function() {
|
||||
var doc = new Document([" ab: 12px", " <h1 abc"]);
|
||||
|
||||
var search = new Search().set({
|
||||
needle: "(\\d+)",
|
||||
regExp: true
|
||||
});
|
||||
|
||||
var range = search.find(doc);
|
||||
assertPosition(0, 6, range.start);
|
||||
assertPosition(0, 8, range.end);
|
||||
},
|
||||
|
||||
"test: find all matches in selection" : function() {
|
||||
var doc = new Document(["juhu", "juhu", "juhu", "juhu"]);
|
||||
|
||||
var search = new Search().set({
|
||||
needle: "uh",
|
||||
wrap: true,
|
||||
scope: Search.SELECTION
|
||||
});
|
||||
|
||||
doc.getSelection().setSelectionAnchor(0, 2);
|
||||
doc.getSelection().selectTo(3, 2);
|
||||
|
||||
var ranges = search.findAll(doc);
|
||||
|
||||
assertEquals(2, ranges.length);
|
||||
assertPosition(1, 1, ranges[0].start);
|
||||
assertPosition(1, 3, ranges[0].end);
|
||||
assertPosition(2, 1, ranges[1].start);
|
||||
assertPosition(2, 3, ranges[1].end);
|
||||
},
|
||||
|
||||
"test: replace() should return the replacement if the input matches the needle" : function() {
|
||||
var search = new Search().set({
|
||||
needle: "juhu"
|
||||
});
|
||||
|
||||
assertEquals("kinners", search.replace("juhu", "kinners"));
|
||||
assertEquals(null, search.replace("", "kinners"));
|
||||
assertEquals(null, search.replace(" juhu", "kinners"));
|
||||
|
||||
// regexp replacement
|
||||
},
|
||||
|
||||
"test: replace with a RegExp search" : function() {
|
||||
var search = new Search().set({
|
||||
needle: "\\d+",
|
||||
regExp: true
|
||||
});
|
||||
|
||||
assertEquals("kinners", search.replace("123", "kinners"));
|
||||
assertEquals("kinners", search.replace("01234", "kinners"));
|
||||
assertEquals(null, search.replace("", "kinners"));
|
||||
assertEquals(null, search.replace("a12", "kinners"));
|
||||
assertEquals(null, search.replace("12a", "kinners"));
|
||||
},
|
||||
|
||||
"test: replace with RegExp match and capture groups" : function() {
|
||||
var search = new Search().set({
|
||||
needle: "ab(\\d\\d)",
|
||||
regExp: true
|
||||
});
|
||||
|
||||
assertEquals("cd12", search.replace("ab12", "cd$1"));
|
||||
assertEquals("-ab12-", search.replace("ab12", "-$&-"));
|
||||
assertEquals("$", search.replace("ab12", "$$"));
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
266
src/ace/test/SelectionTest.js
Normal file
266
src/ace/test/SelectionTest.js
Normal file
|
|
@ -0,0 +1,266 @@
|
|||
/**
|
||||
* Ajax.org Code Editor (ACE)
|
||||
*
|
||||
* @copyright 2010, Ajax.org Services B.V.
|
||||
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
* @author Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*/
|
||||
|
||||
require.def([
|
||||
"ace/Document"
|
||||
], function(
|
||||
Document
|
||||
) {
|
||||
|
||||
var SelectionTest = TestCase("SelectionTest",
|
||||
{
|
||||
createTextDocument : function(rows, cols) {
|
||||
var line = new Array(cols + 1).join("a");
|
||||
var text = new Array(rows).join(line + "\n") + line;
|
||||
return new Document(text);
|
||||
},
|
||||
|
||||
"test: move cursor to end of file should place the cursor on last row and column" : function() {
|
||||
var doc = this.createTextDocument(200, 10);
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorFileEnd();
|
||||
assertPosition(199, 10, selection.getCursor());
|
||||
},
|
||||
|
||||
"test: moveCursor to start of file should place the cursor on the first row and column" : function() {
|
||||
var doc = this.createTextDocument(200, 10);
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorFileStart();
|
||||
assertPosition(0, 0, selection.getCursor());
|
||||
},
|
||||
|
||||
"test: move selection lead to end of file" : function() {
|
||||
var doc = this.createTextDocument(200, 10);
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorTo(100, 5);
|
||||
selection.selectFileEnd();
|
||||
|
||||
var range = selection.getRange();
|
||||
|
||||
assertPosition(100, 5, range.start);
|
||||
assertPosition(199, 10, range.end);
|
||||
},
|
||||
|
||||
"test: move selection lead to start of file" : function() {
|
||||
var doc = this.createTextDocument(200, 10);
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorTo(100, 5);
|
||||
selection.selectFileStart();
|
||||
|
||||
var range = selection.getRange();
|
||||
|
||||
assertPosition(0, 0, range.start);
|
||||
assertPosition(100, 5, range.end);
|
||||
},
|
||||
|
||||
"test: move cursor word right" : function() {
|
||||
var doc = new Document( ["ab",
|
||||
" Juhu Kinners (abc, 12)", " cde"].join("\n"));
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorDown();
|
||||
assertPosition(1, 0, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assertPosition(1, 1, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assertPosition(1, 5, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assertPosition(1, 6, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assertPosition(1, 13, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assertPosition(1, 15, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assertPosition(1, 18, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assertPosition(1, 20, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assertPosition(1, 22, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assertPosition(1, 23, selection.getCursor());
|
||||
|
||||
// wrap line
|
||||
selection.moveCursorWordRight();
|
||||
assertPosition(2, 0, selection.getCursor());
|
||||
},
|
||||
|
||||
"test: select word right if cursor in word" : function() {
|
||||
var doc = new Document("Juhu Kinners");
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 2);
|
||||
selection.moveCursorWordRight();
|
||||
|
||||
assertPosition(0, 4, selection.getCursor());
|
||||
},
|
||||
|
||||
"test: moveCursor word left" : function() {
|
||||
var doc = new Document( ["ab",
|
||||
" Juhu Kinners (abc, 12)", " cde"].join("\n"));
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorDown();
|
||||
selection.moveCursorLineEnd();
|
||||
assertPosition(1, 23, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assertPosition(1, 22, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assertPosition(1, 20, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assertPosition(1, 18, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assertPosition(1, 15, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assertPosition(1, 13, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assertPosition(1, 6, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assertPosition(1, 5, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assertPosition(1, 1, selection.getCursor());
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assertPosition(1, 0, selection.getCursor());
|
||||
|
||||
// wrap line
|
||||
selection.moveCursorWordLeft();
|
||||
assertPosition(0, 2, selection.getCursor());
|
||||
},
|
||||
|
||||
"test: select word left if cursor in word" : function() {
|
||||
var doc = new Document("Juhu Kinners");
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 8);
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assertPosition(0, 5, selection.getCursor());
|
||||
},
|
||||
|
||||
"test: select word right and select" : function() {
|
||||
var doc = new Document("Juhu Kinners");
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 0);
|
||||
selection.selectWordRight();
|
||||
|
||||
var range = selection.getRange();
|
||||
|
||||
assertPosition(0, 0, range.start);
|
||||
assertPosition(0, 4, range.end);
|
||||
},
|
||||
|
||||
"test: select word left and select" : function() {
|
||||
var doc = new Document("Juhu Kinners");
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 3);
|
||||
selection.selectWordLeft();
|
||||
|
||||
var range = selection.getRange();
|
||||
|
||||
assertPosition(0, 0, range.start);
|
||||
assertPosition(0, 3, range.end);
|
||||
},
|
||||
|
||||
"test: select word with cursor in word should select the word" : function() {
|
||||
var doc = new Document("Juhu Kinners 123");
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 8);
|
||||
selection.selectWord();
|
||||
|
||||
var range = selection.getRange();
|
||||
assertPosition(0, 5, range.start);
|
||||
assertPosition(0, 12, range.end);
|
||||
},
|
||||
|
||||
"test: select word with cursor betwen white space and word should select the word" : function() {
|
||||
var doc = new Document("Juhu Kinners");
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 4);
|
||||
selection.selectWord();
|
||||
|
||||
var range = selection.getRange();
|
||||
assertPosition(0, 0, range.start);
|
||||
assertPosition(0, 4, range.end);
|
||||
|
||||
selection.moveCursorTo(0, 5);
|
||||
selection.selectWord();
|
||||
|
||||
var range = selection.getRange();
|
||||
assertPosition(0, 5, range.start);
|
||||
assertPosition(0, 12, range.end);
|
||||
},
|
||||
|
||||
"test: select word with cursor in white space should select white space" : function() {
|
||||
var doc = new Document("Juhu Kinners");
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 5);
|
||||
selection.selectWord();
|
||||
|
||||
var range = selection.getRange();
|
||||
assertPosition(0, 4, range.start);
|
||||
assertPosition(0, 6, range.end);
|
||||
},
|
||||
|
||||
"test: moving cursor should fire a 'changeCursor' event" : function() {
|
||||
var doc = new Document("Juhu Kinners");
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 5);
|
||||
|
||||
var called = false;
|
||||
selection.addEventListener("changeCursor", function() {
|
||||
called = true;
|
||||
});
|
||||
|
||||
selection.moveCursorTo(0, 6);
|
||||
assertTrue(called);
|
||||
},
|
||||
|
||||
"test: calling setCursor with the same position should not fire an event": function() {
|
||||
var doc = new Document("Juhu Kinners");
|
||||
var selection = doc.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 5);
|
||||
|
||||
var called = false;
|
||||
selection.addEventListener("changeCursor", function() {
|
||||
called = true;
|
||||
});
|
||||
|
||||
selection.moveCursorTo(0, 5);
|
||||
assertFalse(called);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
315
src/ace/test/TextEditTest.js
Normal file
315
src/ace/test/TextEditTest.js
Normal file
|
|
@ -0,0 +1,315 @@
|
|||
/**
|
||||
* Ajax.org Code Editor (ACE)
|
||||
*
|
||||
* @copyright 2010, Ajax.org Services B.V.
|
||||
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
* @author Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*/
|
||||
|
||||
require.def([
|
||||
"ace/Document",
|
||||
"ace/Editor",
|
||||
"ace/mode/JavaScript",
|
||||
"ace/test/MockRenderer"
|
||||
], function(
|
||||
Document,
|
||||
Editor,
|
||||
JavaScriptMode,
|
||||
MockRenderer
|
||||
) {
|
||||
|
||||
var TextEditTest = TestCase("TextEditTest",
|
||||
{
|
||||
"test: delete line from the middle" : function() {
|
||||
var doc = new Document(["a", "b", "c", "d"].join("\n"));
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.removeLines();
|
||||
|
||||
assertEquals("a\nc\nd", doc.toString());
|
||||
assertPosition(1, 0, editor.getCursorPosition());
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
assertEquals("a\nd", doc.toString());
|
||||
assertPosition(1, 0, editor.getCursorPosition());
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
assertEquals("a\n", doc.toString());
|
||||
assertPosition(1, 0, editor.getCursorPosition());
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
assertEquals("a\n", doc.toString());
|
||||
assertPosition(1, 0, editor.getCursorPosition());
|
||||
},
|
||||
|
||||
"test: delete multiple selected lines" : function() {
|
||||
var doc = new Document(["a", "b", "c", "d"].join("\n"));
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.removeLines();
|
||||
assertEquals("a\nd", doc.toString());
|
||||
assertPosition(1, 0, editor.getCursorPosition());
|
||||
},
|
||||
|
||||
"test: delete first line" : function() {
|
||||
var doc = new Document(["a", "b", "c"].join("\n"));
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
assertEquals("b\nc", doc.toString());
|
||||
assertPosition(0, 0, editor.getCursorPosition());
|
||||
},
|
||||
|
||||
"test: delete last" : function() {
|
||||
var doc = new Document(["a", "b", "c"].join("\n"));
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(2, 1);
|
||||
editor.removeLines();
|
||||
|
||||
assertEquals("a\nb\n", doc.toString());
|
||||
assertPosition(2, 0, editor.getCursorPosition());
|
||||
},
|
||||
|
||||
"test: indent block" : function() {
|
||||
var doc = new Document(["a12345", "b12345", "c12345"].join("\n"));
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(1, 3);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.blockIndent(" ");
|
||||
|
||||
assertEquals(["a12345", " b12345", " c12345"].join("\n"),
|
||||
doc.toString());
|
||||
|
||||
assertPosition(2, 7, editor.getCursorPosition());
|
||||
|
||||
var range = editor.getSelectionRange();
|
||||
assertPosition(1, 7, range.start);
|
||||
assertPosition(2, 7, range.end);
|
||||
},
|
||||
|
||||
"test: outdent block" : function() {
|
||||
var doc = new Document([" a12345", " b12345", " c12345"].join("\n"));
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(0, 3);
|
||||
editor.getSelection().selectDown();
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.blockOutdent(" ");
|
||||
assertEquals([" a12345", "b12345", " c12345"].join("\n"),
|
||||
doc.toString());
|
||||
|
||||
assertPosition(2, 1, editor.getCursorPosition());
|
||||
|
||||
var range = editor.getSelectionRange();
|
||||
assertPosition(0, 1, range.start);
|
||||
assertPosition(2, 1, range.end);
|
||||
|
||||
|
||||
editor.blockOutdent(" ");
|
||||
assertEquals([" a12345", "b12345", " c12345"].join("\n"),
|
||||
doc.toString());
|
||||
|
||||
var range = editor.getSelectionRange();
|
||||
assertPosition(0, 1, range.start);
|
||||
assertPosition(2, 1, range.end);
|
||||
},
|
||||
|
||||
"test: outent without a selection should update cursor" : function() {
|
||||
var doc = new Document(" 12");
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(0, 3);
|
||||
editor.blockOutdent(" ");
|
||||
|
||||
assertEquals(" 12", doc.toString());
|
||||
assertPosition(0, 1, editor.getCursorPosition());
|
||||
},
|
||||
|
||||
"test: comment lines should perserve selection" : function() {
|
||||
var doc = new Document([" abc", "cde"].join("\n"), new JavaScriptMode());
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(0, 2);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.toggleCommentLines();
|
||||
|
||||
assertEquals(["// abc", "//cde"].join("\n"), doc.toString());
|
||||
|
||||
var selection = editor.getSelectionRange();
|
||||
assertPosition(0, 4, selection.start);
|
||||
assertPosition(1, 4, selection.end);
|
||||
},
|
||||
|
||||
"test: uncomment lines should perserve selection" : function() {
|
||||
var doc = new Document(["// abc", "//cde"].join("\n"), new JavaScriptMode());
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(0, 1);
|
||||
editor.getSelection().selectDown();
|
||||
editor.getSelection().selectRight();
|
||||
editor.getSelection().selectRight();
|
||||
|
||||
editor.toggleCommentLines();
|
||||
|
||||
assertEquals([" abc", "cde"].join("\n"), doc.toString());
|
||||
assertRange(0, 0, 1, 1, editor.getSelectionRange());
|
||||
},
|
||||
|
||||
"test: comment lines - if the selection end is at the line start it should stay there": function() {
|
||||
//select down
|
||||
var doc = new Document(["abc", "cde"].join("\n"), new JavaScriptMode());
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(0, 0);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.toggleCommentLines();
|
||||
assertRange(0, 2, 1, 0, editor.getSelectionRange());
|
||||
|
||||
// select up
|
||||
var doc = new Document(["abc", "cde"].join("\n"), new JavaScriptMode());
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.getSelection().selectUp();
|
||||
|
||||
editor.toggleCommentLines();
|
||||
assertRange(0, 2, 1, 0, editor.getSelectionRange());
|
||||
},
|
||||
|
||||
"test: move lines down should select moved lines" : function() {
|
||||
var doc = new Document(["11", "22", "33", "44"].join("\n"));
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(0, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.moveLinesDown();
|
||||
assertEquals(["33", "11", "22", "44"].join("\n"), doc.toString());
|
||||
assertPosition(1, 0, editor.getCursorPosition());
|
||||
assertPosition(3, 0, editor.getSelection().getSelectionAnchor());
|
||||
assertPosition(1, 0, editor.getSelection().getSelectionLead());
|
||||
|
||||
editor.moveLinesDown();
|
||||
assertEquals(["33", "44", "11", "22"].join("\n"), doc.toString());
|
||||
assertPosition(2, 0, editor.getCursorPosition());
|
||||
assertPosition(3, 2, editor.getSelection().getSelectionAnchor());
|
||||
assertPosition(2, 0, editor.getSelection().getSelectionLead());
|
||||
|
||||
// moving again should have no effect
|
||||
editor.moveLinesDown();
|
||||
assertEquals(["33", "44", "11", "22"].join("\n"), doc.toString());
|
||||
assertPosition(2, 0, editor.getCursorPosition());
|
||||
assertPosition(3, 2, editor.getSelection().getSelectionAnchor());
|
||||
assertPosition(2, 0, editor.getSelection().getSelectionLead());
|
||||
},
|
||||
|
||||
"test: move lines up should select moved lines" : function() {
|
||||
var doc = new Document(["11", "22", "33", "44"].join("\n"));
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(2, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.moveLinesUp();
|
||||
assertEquals(["11", "33", "44", "22"].join("\n"), doc.toString());
|
||||
assertPosition(1, 0, editor.getCursorPosition());
|
||||
assertPosition(3, 0, editor.getSelection().getSelectionAnchor());
|
||||
assertPosition(1, 0, editor.getSelection().getSelectionLead());
|
||||
|
||||
editor.moveLinesUp();
|
||||
assertEquals(["33", "44", "11", "22"].join("\n"), doc.toString());
|
||||
assertPosition(0, 0, editor.getCursorPosition());
|
||||
assertPosition(2, 0, editor.getSelection().getSelectionAnchor());
|
||||
assertPosition(0, 0, editor.getSelection().getSelectionLead());
|
||||
},
|
||||
|
||||
"test: move line without active selection should move cursor to start of the moved line" : function()
|
||||
{
|
||||
var doc = new Document(["11", "22", "33", "44"].join("\n"));
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.clearSelection();
|
||||
|
||||
editor.moveLinesDown();
|
||||
assertEquals(["11", "33", "22", "44"].join("\n"), doc.toString());
|
||||
assertPosition(2, 0, editor.getCursorPosition());
|
||||
|
||||
editor.clearSelection();
|
||||
|
||||
editor.moveLinesUp();
|
||||
assertEquals(["11", "22", "33", "44"].join("\n"), doc.toString());
|
||||
assertPosition(1, 0, editor.getCursorPosition());
|
||||
},
|
||||
|
||||
"test: copy lines down should select lines and place cursor at the selection start" : function() {
|
||||
var doc = new Document(["11", "22", "33", "44"].join("\n"));
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.copyLinesDown();
|
||||
assertEquals(["11", "22", "33", "22", "33", "44"].join("\n"), doc.toString());
|
||||
|
||||
assertPosition(3, 0, editor.getCursorPosition());
|
||||
assertPosition(5, 0, editor.getSelection().getSelectionAnchor());
|
||||
assertPosition(3, 0, editor.getSelection().getSelectionLead());
|
||||
},
|
||||
|
||||
"test: copy lines up should select lines and place cursor at the selection start" : function() {
|
||||
var doc = new Document(["11", "22", "33", "44"].join("\n"));
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.copyLinesUp();
|
||||
assertEquals(["11", "22", "33", "22", "33", "44"].join("\n"), doc.toString());
|
||||
|
||||
assertPosition(1, 0, editor.getCursorPosition());
|
||||
assertPosition(3, 0, editor.getSelection().getSelectionAnchor());
|
||||
assertPosition(1, 0, editor.getSelection().getSelectionLead());
|
||||
},
|
||||
|
||||
"test: input a tab with soft tab should convert it to spaces" : function() {
|
||||
var doc = new Document("");
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
doc.setTabSize(2);
|
||||
doc.setUseSoftTabs(true);
|
||||
|
||||
editor.onTextInput("\t");
|
||||
assertEquals(" ", doc.toString());
|
||||
|
||||
doc.setTabSize(5);
|
||||
editor.onTextInput("\t");
|
||||
assertEquals(" ", doc.toString());
|
||||
},
|
||||
|
||||
"test: input tab without soft tabs should keep the tab character" : function() {
|
||||
var doc = new Document("");
|
||||
var editor = new Editor(new MockRenderer(), doc);
|
||||
|
||||
doc.setUseSoftTabs(false);
|
||||
|
||||
editor.onTextInput("\t");
|
||||
assertEquals("\t", doc.toString());
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
48
src/ace/test/VirtualRendererTest.js
Normal file
48
src/ace/test/VirtualRendererTest.js
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* Ajax.org Code Editor (ACE)
|
||||
*
|
||||
* @copyright 2010, Ajax.org Services B.V.
|
||||
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
* @author Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*/
|
||||
|
||||
require.def([
|
||||
"ace/Document",
|
||||
"ace/VirtualRenderer"
|
||||
], function(
|
||||
Document,
|
||||
VirtualRenderer
|
||||
) {
|
||||
|
||||
var VirtualRendererTest = new TestCase("VirtualRendererTest", {
|
||||
|
||||
"test: screen2text the column should be rounded to the next character edge" : function() {
|
||||
var el = document.createElement("div");
|
||||
el.style.left = "0px";
|
||||
el.style.top = "0px";
|
||||
el.style.width = "100px";
|
||||
el.style.height = "100px";
|
||||
document.body.style.margin = "0px";
|
||||
document.body.style.padding = "0px";
|
||||
document.body.appendChild(el);
|
||||
|
||||
var renderer = new VirtualRenderer(el);
|
||||
renderer.setDocument(new Document("1234"));
|
||||
|
||||
renderer.characterWidth = 10;
|
||||
renderer.lineHeight = 15;
|
||||
|
||||
assertPosition(0, 0, renderer.screenToTextCoordinates(0, 0));
|
||||
assertPosition(0, 0, renderer.screenToTextCoordinates(4, 0));
|
||||
assertPosition(0, 1, renderer.screenToTextCoordinates(5, 0));
|
||||
assertPosition(0, 1, renderer.screenToTextCoordinates(9, 0));
|
||||
assertPosition(0, 1, renderer.screenToTextCoordinates(10, 0));
|
||||
assertPosition(0, 1, renderer.screenToTextCoordinates(14, 0));
|
||||
assertPosition(0, 2, renderer.screenToTextCoordinates(15, 0));
|
||||
document.body.removeChild(el);
|
||||
}
|
||||
|
||||
// change tab size after setDocument (for text layer)
|
||||
});
|
||||
|
||||
});
|
||||
11
src/ace/test/all.js
Normal file
11
src/ace/test/all.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
require({
|
||||
paths: {
|
||||
"ace": "../src/ace"
|
||||
}},
|
||||
["ace/test/assertions", "ace/test/ChangeDocumentTest"],
|
||||
function(a) {
|
||||
console.log(a)
|
||||
alert("a " + a)
|
||||
}
|
||||
);
|
||||
|
||||
25
src/ace/test/assertions.js
Normal file
25
src/ace/test/assertions.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/**
|
||||
* Ajax.org Code Editor (ACE)
|
||||
*
|
||||
* @copyright 2010, Ajax.org Services B.V.
|
||||
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
* @author Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*/
|
||||
|
||||
require.def([], function() {
|
||||
|
||||
window.assertPosition = function(row, column, cursor) {
|
||||
assertEquals(row, cursor.row);
|
||||
assertEquals(column, cursor.column);
|
||||
};
|
||||
|
||||
window.assertRange = function(startRow, startColumn, endRow, endColumn, range) {
|
||||
assertPosition(startRow, startColumn, range.start);
|
||||
assertPosition(endRow, endColumn, range.end);
|
||||
};
|
||||
|
||||
window.assertJsonEquals = function(expectedJson, foundJson) {
|
||||
assertEquals(JSON.stringify(expectedJson), JSON.stringify(foundJson));
|
||||
};
|
||||
|
||||
});
|
||||
50
src/ace/test/mode/CssTest.js
Normal file
50
src/ace/test/mode/CssTest.js
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* Ajax.org Code Editor (ACE)
|
||||
*
|
||||
* @copyright 2010, Ajax.org Services B.V.
|
||||
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
* @author Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*/
|
||||
|
||||
require.def([
|
||||
"ace/Document",
|
||||
"ace/Range",
|
||||
"ace/mode/Css"
|
||||
], function(
|
||||
Document,
|
||||
Range,
|
||||
CssMode
|
||||
) {
|
||||
|
||||
var CssTest = new TestCase("mode.CssTest", {
|
||||
|
||||
setUp : function() {
|
||||
this.mode = new CssMode();
|
||||
},
|
||||
|
||||
"test: toggle comment lines should not do anything" : function() {
|
||||
var doc = new Document([" abc", "cde", "fg"].join("\n"));
|
||||
|
||||
var range = new Range(0, 3, 1, 1);
|
||||
var comment = this.mode.toggleCommentLines("start", doc, range);
|
||||
assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
|
||||
"test: lines should keep indentation" : function() {
|
||||
assertEquals(" ", this.mode.getNextLineIndent("start", " abc", " "));
|
||||
assertEquals("\t", this.mode.getNextLineIndent("start", "\tabc", " "));
|
||||
},
|
||||
|
||||
"test: new line after { should increase indent" : function() {
|
||||
assertEquals(" ", this.mode.getNextLineIndent("start", " abc{", " "));
|
||||
assertEquals("\t ", this.mode.getNextLineIndent("start", "\tabc { ", " "));
|
||||
},
|
||||
|
||||
"test: no indent increase after { in a comment" : function() {
|
||||
assertEquals(" ", this.mode.getNextLineIndent("start", " /*{", " "));
|
||||
assertEquals(" ", this.mode.getNextLineIndent("start", " /*{ ", " "));
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
53
src/ace/test/mode/CssTokenizerTest.js
Normal file
53
src/ace/test/mode/CssTokenizerTest.js
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* Ajax.org Code Editor (ACE)
|
||||
*
|
||||
* @copyright 2010, Ajax.org Services B.V.
|
||||
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
* @author Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*/
|
||||
|
||||
require.def([
|
||||
"ace/mode/Css"
|
||||
], function(
|
||||
CssMode
|
||||
) {
|
||||
|
||||
var CssTest = new TestCase("mode.CssTest", {
|
||||
|
||||
setUp : function() {
|
||||
this.tokenizer = new CssMode().getTokenizer();
|
||||
},
|
||||
|
||||
"test: tokenize pixel number" : function() {
|
||||
var line = "-12px";
|
||||
var tokens = this.tokenizer.getLineTokens(line, "start").tokens;
|
||||
|
||||
assertEquals(1, tokens.length);
|
||||
assertEquals("number", tokens[0].type);
|
||||
},
|
||||
|
||||
"test: tokenize hex3 color" : function() {
|
||||
var tokens = this.tokenizer.getLineTokens("#abc", "start").tokens;
|
||||
|
||||
assertEquals(1, tokens.length);
|
||||
assertEquals("number", tokens[0].type);
|
||||
},
|
||||
|
||||
"test: tokenize hex6 color" : function() {
|
||||
var tokens = this.tokenizer.getLineTokens("#abc012", "start").tokens;
|
||||
|
||||
assertEquals(1, tokens.length);
|
||||
assertEquals("number", tokens[0].type);
|
||||
},
|
||||
|
||||
"test: tokenize parens" : function() {
|
||||
var tokens = this.tokenizer.getLineTokens("{()}", "start").tokens;
|
||||
|
||||
assertEquals(3, tokens.length);
|
||||
assertEquals("lparen", tokens[0].type);
|
||||
assertEquals("text", tokens[1].type);
|
||||
assertEquals("rparen", tokens[2].type);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
40
src/ace/test/mode/HtmlTest.js
Normal file
40
src/ace/test/mode/HtmlTest.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/**
|
||||
* Ajax.org Code Editor (ACE)
|
||||
*
|
||||
* @copyright 2010, Ajax.org Services B.V.
|
||||
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
* @author Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*/
|
||||
|
||||
require.def([
|
||||
"ace/Document",
|
||||
"ace/Range",
|
||||
"ace/mode/Html"
|
||||
], function(
|
||||
Document,
|
||||
Range,
|
||||
HtmlMode
|
||||
) {
|
||||
|
||||
var HtmlTest = new TestCase("mode.HtmlTest", {
|
||||
|
||||
setUp : function() {
|
||||
this.mode = new HtmlMode();
|
||||
},
|
||||
|
||||
"test: toggle comment lines should not do anything" : function() {
|
||||
var doc = new Document([" abc", "cde", "fg"]);
|
||||
|
||||
var range = new Range(0, 3, 1, 1);
|
||||
var comment = this.mode.toggleCommentLines("start", doc, range);
|
||||
assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: next line indent should be the same as the current line indent" : function() {
|
||||
assertEquals(" ", this.mode.getNextLineIndent("start", " abc"));
|
||||
assertEquals("", this.mode.getNextLineIndent("start", "abc"));
|
||||
assertEquals("\t", this.mode.getNextLineIndent("start", "\tabc"));
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
41
src/ace/test/mode/HtmlTokenizerTest.js
Normal file
41
src/ace/test/mode/HtmlTokenizerTest.js
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/**
|
||||
* Ajax.org Code Editor (ACE)
|
||||
*
|
||||
* @copyright 2010, Ajax.org Services B.V.
|
||||
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
* @author Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*/
|
||||
|
||||
require.def([
|
||||
"ace/mode/Html"
|
||||
], function(
|
||||
HtmlMode
|
||||
) {
|
||||
|
||||
var HtmlTest = new TestCase("mode.HtmlTest", {
|
||||
|
||||
setUp : function() {
|
||||
this.tokenizer = new HtmlMode().getTokenizer();
|
||||
},
|
||||
|
||||
"test: tokenize embedded script" : function() {
|
||||
|
||||
var line = "<script a='a'>var</script>'123'";
|
||||
var tokens = this.tokenizer.getLineTokens(line, "start").tokens;
|
||||
|
||||
//assertEquals(10, tokens.length);
|
||||
assertEquals("text", tokens[0].type);
|
||||
assertEquals("keyword", tokens[1].type);
|
||||
assertEquals("text", tokens[2].type);
|
||||
assertEquals("keyword", tokens[3].type);
|
||||
assertEquals("text", tokens[4].type);
|
||||
assertEquals("string", tokens[5].type);
|
||||
assertEquals("text", tokens[6].type);
|
||||
assertEquals("keyword", tokens[7].type);
|
||||
assertEquals("text", tokens[8].type);
|
||||
assertEquals("keyword", tokens[9].type);
|
||||
assertEquals("text", tokens[10].type);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
121
src/ace/test/mode/JavaScriptTest.js
Normal file
121
src/ace/test/mode/JavaScriptTest.js
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
/**
|
||||
* Ajax.org Code Editor (ACE)
|
||||
*
|
||||
* @copyright 2010, Ajax.org Services B.V.
|
||||
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
* @author Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*/
|
||||
|
||||
require.def([
|
||||
"ace/Document",
|
||||
"ace/Range",
|
||||
"ace/Tokenizer",
|
||||
"ace/mode/JavaScript"
|
||||
], function(
|
||||
Document,
|
||||
Range,
|
||||
Tokenizer,
|
||||
JavaScriptMode
|
||||
) {
|
||||
|
||||
var JavaScriptTest = new TestCase("mode.JavaScriptTest", {
|
||||
|
||||
setUp : function() {
|
||||
this.mode = new JavaScriptMode();
|
||||
},
|
||||
|
||||
"test: getTokenizer() (smoke test)" : function() {
|
||||
var tokenizer = this.mode.getTokenizer();
|
||||
|
||||
assertTrue(tokenizer instanceof Tokenizer);
|
||||
|
||||
var tokens = tokenizer.getLineTokens("'juhu'", "start").tokens;
|
||||
assertEquals("string", tokens[0].type);
|
||||
},
|
||||
|
||||
"test: toggle comment lines should prepend '//' to each line" : function() {
|
||||
var doc = new Document([" abc", "cde", "fg"]);
|
||||
|
||||
var range = new Range(0, 3, 1, 1);
|
||||
var comment = this.mode.toggleCommentLines("start", doc, range);
|
||||
assertEquals(["// abc", "//cde", "fg"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: toggle comment on commented lines should remove leading '//' chars" : function() {
|
||||
var doc = new Document(["// abc", "//cde", "fg"]);
|
||||
|
||||
var range = new Range(0, 3, 1, 1);
|
||||
var comment = this.mode.toggleCommentLines("start", doc, range);
|
||||
assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: toggle comment on multiple lines with one commented line prepend '//' to each line" : function() {
|
||||
var doc = new Document(["// abc", "//cde", "fg"]);
|
||||
|
||||
var range = new Range(0, 3, 2, 1);
|
||||
var comment = this.mode.toggleCommentLines("start", doc, range);
|
||||
assertEquals(["//// abc", "////cde", "//fg"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: toggle comment on a comment line with leading white space": function() {
|
||||
var doc = new Document(["//cde", " //fg"]);
|
||||
|
||||
var range = new Range(0, 3, 1, 1);
|
||||
var comment = this.mode.toggleCommentLines("start", doc, range);
|
||||
assertEquals(["cde", " fg"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: auto indent after opening brace" : function() {
|
||||
assertEquals(" ", this.mode.getNextLineIndent("start", "if () {", " "));
|
||||
},
|
||||
|
||||
"test: no auto indent after opening brace in multi line comment" : function() {
|
||||
assertEquals("", this.mode.getNextLineIndent("start", "/*if () {", " "));
|
||||
assertEquals(" ", this.mode.getNextLineIndent("comment", " abcd", " "));
|
||||
},
|
||||
|
||||
"test: no auto indent after opening brace in single line comment" : function() {
|
||||
assertEquals("", this.mode.getNextLineIndent("start", "//if () {", " "));
|
||||
assertEquals(" ", this.mode.getNextLineIndent("start", " //if () {", " "));
|
||||
},
|
||||
|
||||
"test: no auto indent should add to existing indent" : function() {
|
||||
assertEquals(" ", this.mode.getNextLineIndent("start", " if () {", " "));
|
||||
assertEquals(" ", this.mode.getNextLineIndent("start", " cde", " "));
|
||||
},
|
||||
|
||||
"test: special indent in doc comments" : function() {
|
||||
assertEquals(" * ", this.mode.getNextLineIndent("doc-start", "/**", " "));
|
||||
assertEquals(" * ", this.mode.getNextLineIndent("doc-start", " /**", " "));
|
||||
assertEquals(" * ", this.mode.getNextLineIndent("doc-start", " *", " "));
|
||||
assertEquals(" * ", this.mode.getNextLineIndent("doc-start", " *", " "));
|
||||
assertEquals(" ", this.mode.getNextLineIndent("doc-start", " abc", " "));
|
||||
},
|
||||
|
||||
"test: no indent after doc comments" : function() {
|
||||
assertEquals("", this.mode.getNextLineIndent("doc-start", " */", " "));
|
||||
},
|
||||
|
||||
"test: trigger outdent if line is space and new text starts with closing brace" : function() {
|
||||
assertTrue(this.mode.checkOutdent("start", " ", " }"));
|
||||
assertFalse(this.mode.checkOutdent("start", " a ", " }"));
|
||||
assertFalse(this.mode.checkOutdent("start", "", "}"));
|
||||
assertFalse(this.mode.checkOutdent("start", " ", "a }"));
|
||||
assertFalse(this.mode.checkOutdent("start", " }", "}"));
|
||||
},
|
||||
|
||||
"test: auto outdent should indent the line with the same indent as the line with the matching opening brace" : function() {
|
||||
var doc = new Document([" function foo() {", " bla", " }"]);
|
||||
this.mode.autoOutdent("start", doc, 2);
|
||||
assertEquals(" }", doc.getLine(2));
|
||||
},
|
||||
|
||||
"test: no auto outdent if no matching brace is found" : function() {
|
||||
var doc = new Document([" function foo()", " bla", " }"]);
|
||||
this.mode.autoOutdent("start", doc, 2);
|
||||
assertEquals(" }", doc.getLine(2));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
68
src/ace/test/mode/JavaScriptTokenizerTest.js
Normal file
68
src/ace/test/mode/JavaScriptTokenizerTest.js
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
* Ajax.org Code Editor (ACE)
|
||||
*
|
||||
* @copyright 2010, Ajax.org Services B.V.
|
||||
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
* @author Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*/
|
||||
|
||||
require.def([
|
||||
"ace/mode/JavaScript"
|
||||
], function(
|
||||
JavaScriptMode
|
||||
) {
|
||||
|
||||
var JavaScriptTokenizerTest = new TestCase("mode.JavaScriptTokenizerTest", {
|
||||
|
||||
setUp : function() {
|
||||
this.tokenizer = new JavaScriptMode().getTokenizer();
|
||||
},
|
||||
|
||||
"test: tokenize1" : function() {
|
||||
var line = "foo = function";
|
||||
|
||||
var tokens = this.tokenizer.getLineTokens(line, "start").tokens;
|
||||
|
||||
assertEquals(3, tokens.length);
|
||||
assertEquals("identifier", tokens[0].type);
|
||||
assertEquals("text", tokens[1].type);
|
||||
assertEquals("keyword", tokens[2].type);
|
||||
},
|
||||
|
||||
"test: tokenize doc comment" : function() {
|
||||
var line = "abc /** de */ fg";
|
||||
|
||||
var tokens = this.tokenizer.getLineTokens(line, "start").tokens;
|
||||
|
||||
assertEquals(5, tokens.length);
|
||||
assertEquals("identifier", tokens[0].type);
|
||||
assertEquals("text", tokens[1].type);
|
||||
assertEquals("doc-comment", tokens[2].type);
|
||||
assertEquals("text", tokens[3].type);
|
||||
assertEquals("identifier", tokens[4].type);
|
||||
},
|
||||
|
||||
"test: tokenize doc comment with tag" : function() {
|
||||
var line = "/** @param {} */";
|
||||
|
||||
var tokens = this.tokenizer.getLineTokens(line, "start").tokens;
|
||||
|
||||
assertEquals(3, tokens.length);
|
||||
assertEquals("doc-comment", tokens[0].type);
|
||||
assertEquals("doc-comment-tag", tokens[1].type);
|
||||
assertEquals("doc-comment", tokens[2].type);
|
||||
},
|
||||
|
||||
"test: tokenize parens" : function() {
|
||||
var line = "[{( )}]";
|
||||
|
||||
var tokens = this.tokenizer.getLineTokens(line, "start").tokens;
|
||||
|
||||
assertEquals(3, tokens.length);
|
||||
assertEquals("lparen", tokens[0].type);
|
||||
assertEquals("text", tokens[1].type);
|
||||
assertEquals("rparen", tokens[2].type);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
39
src/ace/test/mode/TextTest.js
Normal file
39
src/ace/test/mode/TextTest.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* Ajax.org Code Editor (ACE)
|
||||
*
|
||||
* @copyright 2010, Ajax.org Services B.V.
|
||||
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
|
||||
* @author Fabian Jakobs <fabian AT ajax DOT org>
|
||||
*/
|
||||
|
||||
require.def([
|
||||
"ace/Document",
|
||||
"ace/Range",
|
||||
"ace/mode/Text"
|
||||
], function(
|
||||
Document,
|
||||
Range,
|
||||
TextMode
|
||||
) {
|
||||
|
||||
var TextTest = new TestCase("mode.TextTest", {
|
||||
|
||||
setUp : function() {
|
||||
this.mode = new TextMode();
|
||||
},
|
||||
|
||||
"test: toggle comment lines should not do anything" : function() {
|
||||
var doc = new Document([" abc", "cde", "fg"]);
|
||||
|
||||
var range = new Range(0, 3, 1, 1);
|
||||
var comment = this.mode.toggleCommentLines("start", doc, range);
|
||||
assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
|
||||
"text: lines should not be indented" : function() {
|
||||
assertEquals("", this.mode.getNextLineIndent("start", " abc", " "));
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue