refactor tests

This commit is contained in:
Fabian Jakobs 2010-10-18 19:52:31 +02:00
commit 7e2a2d3493
22 changed files with 428 additions and 190 deletions

View file

@ -2,17 +2,19 @@
server: http://localhost:4224 server: http://localhost:4224
load: load:
- src/ace/lib/core.js - demo/require.js
- src/ace/lib/*.js # - src/ace/lib/core.js
- src/ace/MEventEmitter.js # - src/ace/lib/*.js
- src/ace/mode/Text.js # - src/ace/MEventEmitter.js
- src/ace/mode/TextHighlightRules.js # - src/ace/mode/Text.js
- src/ace/mode/*.js # - src/ace/mode/TextHighlightRules.js
- src/ace/layer/*.js # - src/ace/mode/*.js
- src/ace/*.js # - src/ace/layer/*.js
# - src/ace/*.js
- src/debug/*.js # - src/debug/*.js
- src/test/ace/*.js # - src/test/ace/*.js
- src/test/ace/mode/*.js # - src/test/ace/mode/*.js
- src/test/debug/*.js # - src/test/debug/*.js
- src/ace/test/all.js

View file

@ -5,12 +5,26 @@
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt> * @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
* @author Fabian Jakobs <fabian AT ajax DOT org> * @author Fabian Jakobs <fabian AT ajax DOT org>
*/ */
var ChangeDocumentTest = new TestCase("ChangeDocumentTest", {
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() { setUp : function() {
this.doc1 = new ace.Document(["abc", "def"].join("\n")); this.doc1 = new Document(["abc", "def"].join("\n"));
this.doc2 = new ace.Document(["ghi", "jkl"].join("\n")); this.doc2 = new Document(["ghi", "jkl"].join("\n"));
this.editor = new ace.Editor(new MockRenderer()); this.editor = new Editor(new MockRenderer());
}, },
"test: change document" : function() { "test: change document" : function() {
@ -105,10 +119,12 @@ var ChangeDocumentTest = new TestCase("ChangeDocumentTest", {
this.editor.setDocument(this.doc2); this.editor.setDocument(this.doc2);
var called = false; var called = false;
this.doc1.setMode(new ace.mode.Text()); this.doc1.setMode(new Text());
assertFalse(called); assertFalse(called);
this.doc2.setMode(new ace.mode.JavaScript()); this.doc2.setMode(new JavaScriptMode());
assertTrue(called); assertTrue(called);
} }
}); });
});

View file

@ -5,10 +5,23 @@
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt> * @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
* @author Fabian Jakobs <fabian AT ajax DOT org> * @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", { var TextDocumentTest = new TestCase("TextDocumentTest", {
"test: find matching opening bracket" : function() { "test: find matching opening bracket" : function() {
var doc = new ace.Document(["(()(", "())))"]); var doc = new Document(["(()(", "())))"]);
assertPosition(0, 1, doc.findMatchingBracket({row: 0, column: 3})); assertPosition(0, 1, doc.findMatchingBracket({row: 0, column: 3}));
assertPosition(1, 0, doc.findMatchingBracket({row: 1, column: 2})); assertPosition(1, 0, doc.findMatchingBracket({row: 1, column: 2}));
@ -18,7 +31,7 @@ var TextDocumentTest = new TestCase("TextDocumentTest", {
}, },
"test: find matching closing bracket" : function() { "test: find matching closing bracket" : function() {
var doc = new ace.Document(["(()(", "())))"]); var doc = new Document(["(()(", "())))"]);
assertPosition(1, 1, doc.findMatchingBracket({row: 1, column: 1})); assertPosition(1, 1, doc.findMatchingBracket({row: 1, column: 1}));
assertPosition(1, 1, doc.findMatchingBracket({row: 1, column: 1})); assertPosition(1, 1, doc.findMatchingBracket({row: 1, column: 1}));
@ -29,7 +42,7 @@ var TextDocumentTest = new TestCase("TextDocumentTest", {
}, },
"test: match different bracket types" : function() { "test: match different bracket types" : function() {
var doc = new ace.Document(["({[", ")]}"]); var doc = new Document(["({[", ")]}"]);
assertPosition(1, 0, doc.findMatchingBracket({row: 0, column: 1})); assertPosition(1, 0, doc.findMatchingBracket({row: 0, column: 1}));
assertPosition(1, 2, doc.findMatchingBracket({row: 0, column: 2})); assertPosition(1, 2, doc.findMatchingBracket({row: 0, column: 2}));
@ -41,7 +54,7 @@ var TextDocumentTest = new TestCase("TextDocumentTest", {
}, },
"test: move lines down" : function() { "test: move lines down" : function() {
var doc = new ace.Document(["1", "2", "3", "4"]); var doc = new Document(["1", "2", "3", "4"]);
doc.moveLinesDown(0, 1); doc.moveLinesDown(0, 1);
assertEquals(["3", "1", "2", "4"].join("\n"), doc.toString()); assertEquals(["3", "1", "2", "4"].join("\n"), doc.toString());
@ -57,7 +70,7 @@ var TextDocumentTest = new TestCase("TextDocumentTest", {
}, },
"test: move lines up" : function() { "test: move lines up" : function() {
var doc = new ace.Document(["1", "2", "3", "4"]); var doc = new Document(["1", "2", "3", "4"]);
doc.moveLinesUp(2, 3); doc.moveLinesUp(2, 3);
assertEquals(["1", "3", "4", "2"].join("\n"), doc.toString()); assertEquals(["1", "3", "4", "2"].join("\n"), doc.toString());
@ -73,70 +86,70 @@ var TextDocumentTest = new TestCase("TextDocumentTest", {
}, },
"test: duplicate lines" : function() { "test: duplicate lines" : function() {
var doc = new ace.Document(["1", "2", "3", "4"]); var doc = new Document(["1", "2", "3", "4"]);
doc.duplicateLines(1, 2); doc.duplicateLines(1, 2);
assertEquals(["1", "2", "3", "2", "3", "4"].join("\n"), doc.toString()); assertEquals(["1", "2", "3", "2", "3", "4"].join("\n"), doc.toString());
}, },
"test: duplicate last line" : function() { "test: duplicate last line" : function() {
var doc = new ace.Document(["1", "2", "3"]); var doc = new Document(["1", "2", "3"]);
doc.duplicateLines(2, 2); doc.duplicateLines(2, 2);
assertEquals(["1", "2", "3", "3"].join("\n"), doc.toString()); assertEquals(["1", "2", "3", "3"].join("\n"), doc.toString());
}, },
"test: duplicate first line" : function() { "test: duplicate first line" : function() {
var doc = new ace.Document(["1", "2", "3"]); var doc = new Document(["1", "2", "3"]);
doc.duplicateLines(0, 0); doc.duplicateLines(0, 0);
assertEquals(["1", "1", "2", "3"].join("\n"), doc.toString()); assertEquals(["1", "1", "2", "3"].join("\n"), doc.toString());
}, },
"test: should handle unix style new lines" : function() { "test: should handle unix style new lines" : function() {
var doc = new ace.Document(["1", "2", "3"]); var doc = new Document(["1", "2", "3"]);
assertEquals(["1", "2", "3"].join("\n"), doc.toString()); assertEquals(["1", "2", "3"].join("\n"), doc.toString());
}, },
"test: should handle windows style new lines" : function() { "test: should handle windows style new lines" : function() {
var doc = new ace.Document(["1", "2", "3"].join("\r\n")); var doc = new Document(["1", "2", "3"].join("\r\n"));
doc.setNewLineMode("unix"); doc.setNewLineMode("unix");
assertEquals(["1", "2", "3"].join("\n"), doc.toString()); assertEquals(["1", "2", "3"].join("\n"), doc.toString());
}, },
"test: set new line mode to 'windows' should use '\r\n' as new lines": function() { "test: set new line mode to 'windows' should use '\r\n' as new lines": function() {
var doc = new ace.Document(["1", "2", "3"].join("\n")); var doc = new Document(["1", "2", "3"].join("\n"));
doc.setNewLineMode("windows"); doc.setNewLineMode("windows");
assertEquals(["1", "2", "3"].join("\r\n"), doc.toString()); assertEquals(["1", "2", "3"].join("\r\n"), doc.toString());
}, },
"test: set new line mode to 'unix' should use '\n' as new lines": function() { "test: set new line mode to 'unix' should use '\n' as new lines": function() {
var doc = new ace.Document(["1", "2", "3"].join("\r\n")); var doc = new Document(["1", "2", "3"].join("\r\n"));
doc.setNewLineMode("unix"); doc.setNewLineMode("unix");
assertEquals(["1", "2", "3"].join("\n"), doc.toString()); assertEquals(["1", "2", "3"].join("\n"), doc.toString());
}, },
"test: set new line mode to 'auto' should use detect the incoming nl type": function() { "test: set new line mode to 'auto' should use detect the incoming nl type": function() {
var doc = new ace.Document(["1", "2", "3"].join("\n")); var doc = new Document(["1", "2", "3"].join("\n"));
doc.setNewLineMode("auto"); doc.setNewLineMode("auto");
assertEquals(["1", "2", "3"].join("\n"), doc.toString()); assertEquals(["1", "2", "3"].join("\n"), doc.toString());
var doc = new ace.Document(["1", "2", "3"].join("\r\n")); var doc = new Document(["1", "2", "3"].join("\r\n"));
doc.setNewLineMode("auto"); doc.setNewLineMode("auto");
assertEquals(["1", "2", "3"].join("\r\n"), doc.toString()); assertEquals(["1", "2", "3"].join("\r\n"), doc.toString());
doc.replace(new ace.Range(0, 0, 2, 1), ["4", "5", "6"].join("\n")); doc.replace(new Range(0, 0, 2, 1), ["4", "5", "6"].join("\n"));
assertEquals(["4", "5", "6"].join("\n"), doc.toString()); assertEquals(["4", "5", "6"].join("\n"), doc.toString());
}, },
"test: undo/redo for delete line" : function() { "test: undo/redo for delete line" : function() {
var doc = new ace.Document(["111", "222", "333"]); var doc = new Document(["111", "222", "333"]);
var undoManager = new ace.UndoManager(); var undoManager = new UndoManager();
doc.setUndoManager(undoManager); doc.setUndoManager(undoManager);
var initialText = doc.toString(); var initialText = doc.toString();
var editor = new ace.Editor(new MockRenderer(), doc); var editor = new Editor(new MockRenderer(), doc);
editor.removeLines(); editor.removeLines();
var step1 = doc.toString(); var step1 = doc.toString();
@ -172,7 +185,7 @@ var TextDocumentTest = new TestCase("TextDocumentTest", {
}, },
"test: convert document to screen coordinates" : function() { "test: convert document to screen coordinates" : function() {
var doc = new ace.Document("01234\t567890\t1234"); var doc = new Document("01234\t567890\t1234");
doc.setTabSize(4); doc.setTabSize(4);
assertEquals(0, doc.documentToScreenColumn(0, 0)); assertEquals(0, doc.documentToScreenColumn(0, 0));
@ -193,7 +206,7 @@ var TextDocumentTest = new TestCase("TextDocumentTest", {
}, },
"test: convert document to scrren coordinates with leading tabs": function() { "test: convert document to scrren coordinates with leading tabs": function() {
var doc = new ace.Document("\t\t123"); var doc = new Document("\t\t123");
doc.setTabSize(4); doc.setTabSize(4);
assertEquals(0, doc.documentToScreenColumn(0, 0)); assertEquals(0, doc.documentToScreenColumn(0, 0));
@ -203,7 +216,7 @@ var TextDocumentTest = new TestCase("TextDocumentTest", {
}, },
"test: convert screen to document coordinates" : function() { "test: convert screen to document coordinates" : function() {
var doc = new ace.Document("01234\t567890\t1234"); var doc = new Document("01234\t567890\t1234");
doc.setTabSize(4); doc.setTabSize(4);
assertEquals(0, doc.screenToDocumentColumn(0, 0)); assertEquals(0, doc.screenToDocumentColumn(0, 0));
@ -217,3 +230,5 @@ var TextDocumentTest = new TestCase("TextDocumentTest", {
assertEquals(13, doc.screenToDocumentColumn(0, 19)); assertEquals(13, doc.screenToDocumentColumn(0, 19));
} }
}); });
});

View file

@ -5,9 +5,18 @@
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt> * @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
* @author Fabian Jakobs <fabian AT ajax DOT org> * @author Fabian Jakobs <fabian AT ajax DOT org>
*/ */
require.def([
"ace/lib/oop",
"ace/MEventEmitter"
], function(
oop,
MEventEmitter
) {
var EventEmitter = function() {}; var EventEmitter = function() {};
ace.implement(EventEmitter.prototype, ace.MEventEmitter); oop.implement(EventEmitter.prototype, MEventEmitter);
var EventEmitterTest = new TestCase("EventEmitterTest", { var EventEmitterTest = new TestCase("EventEmitterTest", {
"test: dispatch event with no data" : function() { "test: dispatch event with no data" : function() {
@ -23,3 +32,5 @@ var EventEmitterTest = new TestCase("EventEmitterTest", {
assertTrue(called); assertTrue(called);
} }
}); });
});

View file

@ -5,6 +5,9 @@
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt> * @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
* @author Fabian Jakobs <fabian AT ajax DOT org> * @author Fabian Jakobs <fabian AT ajax DOT org>
*/ */
require.def([], function() {
MockRenderer = function(visibleRowCount) { MockRenderer = function(visibleRowCount) {
this.container = document.createElement("div"); this.container = document.createElement("div");
this.cursor = { this.cursor = {
@ -80,3 +83,6 @@ MockRenderer.prototype.addMarker = function() {
MockRenderer.prototype.setBreakpoints = function() { MockRenderer.prototype.setBreakpoints = function() {
}; };
return MockRenderer;
});

View file

@ -5,17 +5,28 @@
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt> * @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
* @author Fabian Jakobs <fabian AT ajax DOT org> * @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", var NavigationTest = TestCase("NavigationTest",
{ {
createTextDocument : function(rows, cols) { createTextDocument : function(rows, cols) {
var line = new Array(cols + 1).join("a"); var line = new Array(cols + 1).join("a");
var text = new Array(rows).join(line + "\n") + line; var text = new Array(rows).join(line + "\n") + line;
return new ace.Document(text); return new Document(text);
}, },
"test: navigate to end of file should scroll the last line into view" : function() { "test: navigate to end of file should scroll the last line into view" : function() {
var doc = this.createTextDocument(200, 10); var doc = this.createTextDocument(200, 10);
var editor = new ace.Editor(new MockRenderer(), doc); var editor = new Editor(new MockRenderer(), doc);
editor.navigateFileEnd(); editor.navigateFileEnd();
var cursor = editor.getCursorPosition(); var cursor = editor.getCursorPosition();
@ -26,7 +37,7 @@ var NavigationTest = TestCase("NavigationTest",
"test: navigate to start of file should scroll the first row into view" : function() { "test: navigate to start of file should scroll the first row into view" : function() {
var doc = this.createTextDocument(200, 10); var doc = this.createTextDocument(200, 10);
var editor = new ace.Editor(new MockRenderer(), doc); var editor = new Editor(new MockRenderer(), doc);
editor.moveCursorTo(editor.getLastVisibleRow() + 20); editor.moveCursorTo(editor.getLastVisibleRow() + 20);
editor.navigateFileStart(); editor.navigateFileStart();
@ -35,7 +46,7 @@ var NavigationTest = TestCase("NavigationTest",
}, },
"test: goto hidden line should scroll the line into the middle of the viewport" : function() { "test: goto hidden line should scroll the line into the middle of the viewport" : function() {
var editor = new ace.Editor(new MockRenderer(), this.createTextDocument(200, 5)); var editor = new Editor(new MockRenderer(), this.createTextDocument(200, 5));
editor.navigateTo(0, 0); editor.navigateTo(0, 0);
editor.gotoLine(101); editor.gotoLine(101);
@ -69,7 +80,7 @@ var NavigationTest = TestCase("NavigationTest",
}, },
"test: goto visible line should only move the cursor and not scroll": function() { "test: goto visible line should only move the cursor and not scroll": function() {
var editor = new ace.Editor(new MockRenderer(), this.createTextDocument(200, 5)); var editor = new Editor(new MockRenderer(), this.createTextDocument(200, 5));
editor.navigateTo(0, 0); editor.navigateTo(0, 0);
editor.gotoLine(12); editor.gotoLine(12);
@ -83,7 +94,7 @@ var NavigationTest = TestCase("NavigationTest",
}, },
"test: navigate from the end of a long line down to a short line and back should maintain the curser column": function() { "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 ace.Editor(new MockRenderer(), new ace.Document(["123456", "1"])); var editor = new Editor(new MockRenderer(), new Document(["123456", "1"]));
editor.navigateTo(0, 6); editor.navigateTo(0, 6);
assertPosition(0, 6, editor.getCursorPosition()); assertPosition(0, 6, editor.getCursorPosition());
@ -96,7 +107,7 @@ var NavigationTest = TestCase("NavigationTest",
}, },
"test: reset desired column on navigate left or right": function() { "test: reset desired column on navigate left or right": function() {
var editor = new ace.Editor(new MockRenderer(), new ace.Document(["123456", "12"])); var editor = new Editor(new MockRenderer(), new Document(["123456", "12"]));
editor.navigateTo(0, 6); editor.navigateTo(0, 6);
assertPosition(0, 6, editor.getCursorPosition()); assertPosition(0, 6, editor.getCursorPosition());
@ -111,3 +122,5 @@ var NavigationTest = TestCase("NavigationTest",
assertPosition(0, 1, editor.getCursorPosition()); assertPosition(0, 1, editor.getCursorPosition());
} }
}); });
});

View file

@ -5,10 +5,17 @@
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt> * @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
* @author Fabian Jakobs <fabian AT ajax DOT org> * @author Fabian Jakobs <fabian AT ajax DOT org>
*/ */
require.def([
"ace/Range"
], function(
Range
) {
RangeTest = new TestCase("RangeTest", { RangeTest = new TestCase("RangeTest", {
"test: create range": function() { "test: create range": function() {
var range = new ace.Range(1,2,3,4); var range = new Range(1,2,3,4);
assertEquals(1, range.start.row); assertEquals(1, range.start.row);
assertEquals(2, range.start.column); assertEquals(2, range.start.column);
@ -17,7 +24,7 @@ RangeTest = new TestCase("RangeTest", {
}, },
"test: create from points": function() { "test: create from points": function() {
var range = ace.Range.fromPoints({row: 1, column: 2}, {row:3, column:4}); var range = Range.fromPoints({row: 1, column: 2}, {row:3, column:4});
assertEquals(1, range.start.row); assertEquals(1, range.start.row);
assertEquals(2, range.start.column); assertEquals(2, range.start.column);
@ -26,10 +33,10 @@ RangeTest = new TestCase("RangeTest", {
}, },
"test: clip to rows": function() { "test: clip to rows": function() {
assertRange(10, 0, 31, 0, new ace.Range(0, 20, 100, 30).clipRows(10, 30)); assertRange(10, 0, 31, 0, new Range(0, 20, 100, 30).clipRows(10, 30));
assertRange(10, 0, 30, 10, new ace.Range(0, 20, 30, 10).clipRows(10, 30)); assertRange(10, 0, 30, 10, new Range(0, 20, 30, 10).clipRows(10, 30));
var range = new ace.Range(0, 20, 3, 10); var range = new Range(0, 20, 3, 10);
var range = range.clipRows(10, 30); var range = range.clipRows(10, 30);
assertTrue(range.isEmpty()); assertTrue(range.isEmpty());
@ -37,23 +44,23 @@ RangeTest = new TestCase("RangeTest", {
}, },
"test: isEmpty": function() { "test: isEmpty": function() {
var range = new ace.Range(1, 2, 1, 2); var range = new Range(1, 2, 1, 2);
assertTrue(range.isEmpty()); assertTrue(range.isEmpty());
var range = new ace.Range(1, 2, 1, 6); var range = new Range(1, 2, 1, 6);
assertFalse(range.isEmpty()); assertFalse(range.isEmpty());
}, },
"test: is multi line": function() { "test: is multi line": function() {
var range = new ace.Range(1, 2, 1, 6); var range = new Range(1, 2, 1, 6);
assertFalse(range.isMultiLine()); assertFalse(range.isMultiLine());
var range = new ace.Range(1, 2, 2, 6); var range = new Range(1, 2, 2, 6);
assertTrue(range.isMultiLine()); assertTrue(range.isMultiLine());
}, },
"test: clone": function() { "test: clone": function() {
var range = new ace.Range(1, 2, 3, 4); var range = new Range(1, 2, 3, 4);
var clone = range.clone(); var clone = range.clone();
assertPosition(1, 2, clone.start); assertPosition(1, 2, clone.start);
@ -67,7 +74,7 @@ RangeTest = new TestCase("RangeTest", {
}, },
"test: contains for multi line ranges": function() { "test: contains for multi line ranges": function() {
var range = new ace.Range(1, 10, 5, 20); var range = new Range(1, 10, 5, 20);
assertTrue(range.contains(1, 10)); assertTrue(range.contains(1, 10));
assertTrue(range.contains(2, 0)); assertTrue(range.contains(2, 0));
@ -81,7 +88,7 @@ RangeTest = new TestCase("RangeTest", {
}, },
"test: contains for single line ranges": function() { "test: contains for single line ranges": function() {
var range = new ace.Range(1, 10, 1, 20); var range = new Range(1, 10, 1, 20);
assertTrue(range.contains(1, 10)); assertTrue(range.contains(1, 10));
assertTrue(range.contains(1, 15)); assertTrue(range.contains(1, 15));
@ -94,7 +101,7 @@ RangeTest = new TestCase("RangeTest", {
}, },
"test: extend range": function() { "test: extend range": function() {
var range = new ace.Range(2, 10, 2, 30); var range = new Range(2, 10, 2, 30);
var range = range.extend(2, 5); var range = range.extend(2, 5);
assertRange(2, 5, 2, 30, range); assertRange(2, 5, 2, 30, range);
@ -112,3 +119,5 @@ RangeTest = new TestCase("RangeTest", {
assertRange(1, 4, 6, 10, range); assertRange(1, 4, 6, 10, range);
} }
}); });
});

View file

@ -5,19 +5,28 @@
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt> * @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
* @author Fabian Jakobs <fabian AT ajax DOT org> * @author Fabian Jakobs <fabian AT ajax DOT org>
*/ */
require.def([
"ace/Document",
"ace/Search"
], function(
Document,
Search
) {
var SearchTest = new TestCase("SearchTest", { var SearchTest = new TestCase("SearchTest", {
"test: configure the search object" : function() { "test: configure the search object" : function() {
var search = new ace.Search(); var search = new Search();
search.set({ search.set({
needle: "juhu", needle: "juhu",
scope: ace.Search.ALL scope: Search.ALL
}); });
}, },
"test: find simple text in document" : function() { "test: find simple text in document" : function() {
var doc = new ace.Document(["juhu kinners 123", "456"]); var doc = new Document(["juhu kinners 123", "456"]);
var search = new ace.Search().set({ var search = new Search().set({
needle: "kinners" needle: "kinners"
}); });
@ -27,8 +36,8 @@ var SearchTest = new TestCase("SearchTest", {
}, },
"test: find simple text in next line" : function() { "test: find simple text in next line" : function() {
var doc = new ace.Document(["abc", "juhu kinners 123", "456"]); var doc = new Document(["abc", "juhu kinners 123", "456"]);
var search = new ace.Search().set({ var search = new Search().set({
needle: "kinners" needle: "kinners"
}); });
@ -38,9 +47,9 @@ var SearchTest = new TestCase("SearchTest", {
}, },
"test: find text starting at cursor position" : function() { "test: find text starting at cursor position" : function() {
var doc = new ace.Document(["juhu kinners", "juhu kinners 123"]); var doc = new Document(["juhu kinners", "juhu kinners 123"]);
doc.getSelection().moveCursorTo(0, 6); doc.getSelection().moveCursorTo(0, 6);
var search = new ace.Search().set({ var search = new Search().set({
needle: "kinners" needle: "kinners"
}); });
@ -50,10 +59,10 @@ var SearchTest = new TestCase("SearchTest", {
}, },
"test: wrap search is off by default" : function() { "test: wrap search is off by default" : function() {
var doc = new ace.Document(["abc", "juhu kinners 123", "456"]); var doc = new Document(["abc", "juhu kinners 123", "456"]);
doc.getSelection().moveCursorTo(2, 1); doc.getSelection().moveCursorTo(2, 1);
var search = new ace.Search().set({ var search = new Search().set({
needle: "kinners" needle: "kinners"
}); });
@ -61,10 +70,10 @@ var SearchTest = new TestCase("SearchTest", {
}, },
"test: wrap search should wrap at file end" : function() { "test: wrap search should wrap at file end" : function() {
var doc = new ace.Document(["abc", "juhu kinners 123", "456"]); var doc = new Document(["abc", "juhu kinners 123", "456"]);
doc.getSelection().moveCursorTo(2, 1); doc.getSelection().moveCursorTo(2, 1);
var search = new ace.Search().set({ var search = new Search().set({
needle: "kinners", needle: "kinners",
wrap: true wrap: true
}); });
@ -75,10 +84,10 @@ var SearchTest = new TestCase("SearchTest", {
}, },
"test: wrap search with no match should return 'null'": function() { "test: wrap search with no match should return 'null'": function() {
var doc = new ace.Document(["abc", "juhu kinners 123", "456"]); var doc = new Document(["abc", "juhu kinners 123", "456"]);
doc.getSelection().moveCursorTo(2, 1); doc.getSelection().moveCursorTo(2, 1);
var search = new ace.Search().set({ var search = new Search().set({
needle: "xyz", needle: "xyz",
wrap: true wrap: true
}); });
@ -87,9 +96,9 @@ var SearchTest = new TestCase("SearchTest", {
}, },
"test: case sensitive is by default off": function() { "test: case sensitive is by default off": function() {
var doc = new ace.Document(["abc", "juhu kinners 123", "456"]); var doc = new Document(["abc", "juhu kinners 123", "456"]);
var search = new ace.Search().set({ var search = new Search().set({
needle: "JUHU" needle: "JUHU"
}); });
@ -97,9 +106,9 @@ var SearchTest = new TestCase("SearchTest", {
}, },
"test: case sensitive search": function() { "test: case sensitive search": function() {
var doc = new ace.Document(["abc", "juhu kinners 123", "456"]); var doc = new Document(["abc", "juhu kinners 123", "456"]);
var search = new ace.Search().set({ var search = new Search().set({
needle: "KINNERS", needle: "KINNERS",
caseSensitive: true caseSensitive: true
}); });
@ -110,9 +119,9 @@ var SearchTest = new TestCase("SearchTest", {
}, },
"test: whole word search should not match inside of words": function() { "test: whole word search should not match inside of words": function() {
var doc = new ace.Document(["juhukinners", "juhu kinners 123", "456"]); var doc = new Document(["juhukinners", "juhu kinners 123", "456"]);
var search = new ace.Search().set({ var search = new Search().set({
needle: "kinners", needle: "kinners",
wholeWord: true wholeWord: true
}); });
@ -123,9 +132,9 @@ var SearchTest = new TestCase("SearchTest", {
}, },
"test: find backwards": function() { "test: find backwards": function() {
var doc = new ace.Document(["juhu juhu juhu juhu"]); var doc = new Document(["juhu juhu juhu juhu"]);
doc.getSelection().moveCursorTo(0, 10); doc.getSelection().moveCursorTo(0, 10);
var search = new ace.Search().set({ var search = new Search().set({
needle: "juhu", needle: "juhu",
backwards: true backwards: true
}); });
@ -136,14 +145,14 @@ var SearchTest = new TestCase("SearchTest", {
}, },
"test: find in selection": function() { "test: find in selection": function() {
var doc = new ace.Document(["juhu", "juhu", "juhu", "juhu"]); var doc = new Document(["juhu", "juhu", "juhu", "juhu"]);
doc.getSelection().setSelectionAnchor(1, 0); doc.getSelection().setSelectionAnchor(1, 0);
doc.getSelection().selectTo(3, 5); doc.getSelection().selectTo(3, 5);
var search = new ace.Search().set({ var search = new Search().set({
needle: "juhu", needle: "juhu",
wrap: true, wrap: true,
scope: ace.Search.SELECTION scope: Search.SELECTION
}); });
var range = search.find(doc); var range = search.find(doc);
@ -159,13 +168,13 @@ var SearchTest = new TestCase("SearchTest", {
}, },
"test: find backwards in selection": function() { "test: find backwards in selection": function() {
var doc = new ace.Document(["juhu", "juhu", "juhu", "juhu"]); var doc = new Document(["juhu", "juhu", "juhu", "juhu"]);
var search = new ace.Search().set({ var search = new Search().set({
needle: "juhu", needle: "juhu",
wrap: true, wrap: true,
backwards: true, backwards: true,
scope: ace.Search.SELECTION scope: Search.SELECTION
}); });
doc.getSelection().setSelectionAnchor(0, 2); doc.getSelection().setSelectionAnchor(0, 2);
@ -182,9 +191,9 @@ var SearchTest = new TestCase("SearchTest", {
}, },
"test: edge case - match directly before the cursor" : function() { "test: edge case - match directly before the cursor" : function() {
var doc = new ace.Document(["123", "123", "juhu"]); var doc = new Document(["123", "123", "juhu"]);
var search = new ace.Search().set({ var search = new Search().set({
needle: "juhu", needle: "juhu",
wrap: true wrap: true
}); });
@ -197,9 +206,9 @@ var SearchTest = new TestCase("SearchTest", {
}, },
"test: edge case - match backwards directly after the cursor" : function() { "test: edge case - match backwards directly after the cursor" : function() {
var doc = new ace.Document(["123", "123", "juhu"]); var doc = new Document(["123", "123", "juhu"]);
var search = new ace.Search().set({ var search = new Search().set({
needle: "juhu", needle: "juhu",
wrap: true, wrap: true,
backwards: true backwards: true
@ -213,9 +222,9 @@ var SearchTest = new TestCase("SearchTest", {
}, },
"test: find using a regular expression" : function() { "test: find using a regular expression" : function() {
var doc = new ace.Document(["abc123 123 cd", "abc"]); var doc = new Document(["abc123 123 cd", "abc"]);
var search = new ace.Search().set({ var search = new Search().set({
needle: "\\d+", needle: "\\d+",
regExp: true regExp: true
}); });
@ -226,9 +235,9 @@ var SearchTest = new TestCase("SearchTest", {
}, },
"test: find using a regular expression and whole word" : function() { "test: find using a regular expression and whole word" : function() {
var doc = new ace.Document(["abc123 123 cd", "abc"]); var doc = new Document(["abc123 123 cd", "abc"]);
var search = new ace.Search().set({ var search = new Search().set({
needle: "\\d+\\b", needle: "\\d+\\b",
regExp: true, regExp: true,
wholeWord: true wholeWord: true
@ -240,9 +249,9 @@ var SearchTest = new TestCase("SearchTest", {
}, },
"test: use regular expressions with capture groups": function() { "test: use regular expressions with capture groups": function() {
var doc = new ace.Document([" ab: 12px", " <h1 abc"]); var doc = new Document([" ab: 12px", " <h1 abc"]);
var search = new ace.Search().set({ var search = new Search().set({
needle: "(\\d+)", needle: "(\\d+)",
regExp: true regExp: true
}); });
@ -253,12 +262,12 @@ var SearchTest = new TestCase("SearchTest", {
}, },
"test: find all matches in selection" : function() { "test: find all matches in selection" : function() {
var doc = new ace.Document(["juhu", "juhu", "juhu", "juhu"]); var doc = new Document(["juhu", "juhu", "juhu", "juhu"]);
var search = new ace.Search().set({ var search = new Search().set({
needle: "uh", needle: "uh",
wrap: true, wrap: true,
scope: ace.Search.SELECTION scope: Search.SELECTION
}); });
doc.getSelection().setSelectionAnchor(0, 2); doc.getSelection().setSelectionAnchor(0, 2);
@ -274,7 +283,7 @@ var SearchTest = new TestCase("SearchTest", {
}, },
"test: replace() should return the replacement if the input matches the needle" : function() { "test: replace() should return the replacement if the input matches the needle" : function() {
var search = new ace.Search().set({ var search = new Search().set({
needle: "juhu" needle: "juhu"
}); });
@ -286,7 +295,7 @@ var SearchTest = new TestCase("SearchTest", {
}, },
"test: replace with a RegExp search" : function() { "test: replace with a RegExp search" : function() {
var search = new ace.Search().set({ var search = new Search().set({
needle: "\\d+", needle: "\\d+",
regExp: true regExp: true
}); });
@ -299,7 +308,7 @@ var SearchTest = new TestCase("SearchTest", {
}, },
"test: replace with RegExp match and capture groups" : function() { "test: replace with RegExp match and capture groups" : function() {
var search = new ace.Search().set({ var search = new Search().set({
needle: "ab(\\d\\d)", needle: "ab(\\d\\d)",
regExp: true regExp: true
}); });
@ -309,3 +318,5 @@ var SearchTest = new TestCase("SearchTest", {
assertEquals("$", search.replace("ab12", "$$")); assertEquals("$", search.replace("ab12", "$$"));
} }
}); });
});

View file

@ -5,12 +5,19 @@
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt> * @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
* @author Fabian Jakobs <fabian AT ajax DOT org> * @author Fabian Jakobs <fabian AT ajax DOT org>
*/ */
require.def([
"ace/Document"
], function(
Document
) {
var SelectionTest = TestCase("SelectionTest", var SelectionTest = TestCase("SelectionTest",
{ {
createTextDocument : function(rows, cols) { createTextDocument : function(rows, cols) {
var line = new Array(cols + 1).join("a"); var line = new Array(cols + 1).join("a");
var text = new Array(rows).join(line + "\n") + line; var text = new Array(rows).join(line + "\n") + line;
return new ace.Document(text); return new Document(text);
}, },
"test: move cursor to end of file should place the cursor on last row and column" : function() { "test: move cursor to end of file should place the cursor on last row and column" : function() {
@ -56,7 +63,7 @@ var SelectionTest = TestCase("SelectionTest",
}, },
"test: move cursor word right" : function() { "test: move cursor word right" : function() {
var doc = new ace.Document( ["ab", var doc = new Document( ["ab",
" Juhu Kinners (abc, 12)", " cde"].join("\n")); " Juhu Kinners (abc, 12)", " cde"].join("\n"));
var selection = doc.getSelection(); var selection = doc.getSelection();
@ -96,7 +103,7 @@ var SelectionTest = TestCase("SelectionTest",
}, },
"test: select word right if cursor in word" : function() { "test: select word right if cursor in word" : function() {
var doc = new ace.Document("Juhu Kinners"); var doc = new Document("Juhu Kinners");
var selection = doc.getSelection(); var selection = doc.getSelection();
selection.moveCursorTo(0, 2); selection.moveCursorTo(0, 2);
@ -106,7 +113,7 @@ var SelectionTest = TestCase("SelectionTest",
}, },
"test: moveCursor word left" : function() { "test: moveCursor word left" : function() {
var doc = new ace.Document( ["ab", var doc = new Document( ["ab",
" Juhu Kinners (abc, 12)", " cde"].join("\n")); " Juhu Kinners (abc, 12)", " cde"].join("\n"));
var selection = doc.getSelection(); var selection = doc.getSelection();
@ -147,7 +154,7 @@ var SelectionTest = TestCase("SelectionTest",
}, },
"test: select word left if cursor in word" : function() { "test: select word left if cursor in word" : function() {
var doc = new ace.Document("Juhu Kinners"); var doc = new Document("Juhu Kinners");
var selection = doc.getSelection(); var selection = doc.getSelection();
selection.moveCursorTo(0, 8); selection.moveCursorTo(0, 8);
@ -157,7 +164,7 @@ var SelectionTest = TestCase("SelectionTest",
}, },
"test: select word right and select" : function() { "test: select word right and select" : function() {
var doc = new ace.Document("Juhu Kinners"); var doc = new Document("Juhu Kinners");
var selection = doc.getSelection(); var selection = doc.getSelection();
selection.moveCursorTo(0, 0); selection.moveCursorTo(0, 0);
@ -170,7 +177,7 @@ var SelectionTest = TestCase("SelectionTest",
}, },
"test: select word left and select" : function() { "test: select word left and select" : function() {
var doc = new ace.Document("Juhu Kinners"); var doc = new Document("Juhu Kinners");
var selection = doc.getSelection(); var selection = doc.getSelection();
selection.moveCursorTo(0, 3); selection.moveCursorTo(0, 3);
@ -183,7 +190,7 @@ var SelectionTest = TestCase("SelectionTest",
}, },
"test: select word with cursor in word should select the word" : function() { "test: select word with cursor in word should select the word" : function() {
var doc = new ace.Document("Juhu Kinners 123"); var doc = new Document("Juhu Kinners 123");
var selection = doc.getSelection(); var selection = doc.getSelection();
selection.moveCursorTo(0, 8); selection.moveCursorTo(0, 8);
@ -195,7 +202,7 @@ var SelectionTest = TestCase("SelectionTest",
}, },
"test: select word with cursor betwen white space and word should select the word" : function() { "test: select word with cursor betwen white space and word should select the word" : function() {
var doc = new ace.Document("Juhu Kinners"); var doc = new Document("Juhu Kinners");
var selection = doc.getSelection(); var selection = doc.getSelection();
selection.moveCursorTo(0, 4); selection.moveCursorTo(0, 4);
@ -214,7 +221,7 @@ var SelectionTest = TestCase("SelectionTest",
}, },
"test: select word with cursor in white space should select white space" : function() { "test: select word with cursor in white space should select white space" : function() {
var doc = new ace.Document("Juhu Kinners"); var doc = new Document("Juhu Kinners");
var selection = doc.getSelection(); var selection = doc.getSelection();
selection.moveCursorTo(0, 5); selection.moveCursorTo(0, 5);
@ -226,7 +233,7 @@ var SelectionTest = TestCase("SelectionTest",
}, },
"test: moving cursor should fire a 'changeCursor' event" : function() { "test: moving cursor should fire a 'changeCursor' event" : function() {
var doc = new ace.Document("Juhu Kinners"); var doc = new Document("Juhu Kinners");
var selection = doc.getSelection(); var selection = doc.getSelection();
selection.moveCursorTo(0, 5); selection.moveCursorTo(0, 5);
@ -241,7 +248,7 @@ var SelectionTest = TestCase("SelectionTest",
}, },
"test: calling setCursor with the same position should not fire an event": function() { "test: calling setCursor with the same position should not fire an event": function() {
var doc = new ace.Document("Juhu Kinners"); var doc = new Document("Juhu Kinners");
var selection = doc.getSelection(); var selection = doc.getSelection();
selection.moveCursorTo(0, 5); selection.moveCursorTo(0, 5);
@ -255,3 +262,5 @@ var SelectionTest = TestCase("SelectionTest",
assertFalse(called); assertFalse(called);
} }
}); });
});

View file

@ -5,11 +5,24 @@
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt> * @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
* @author Fabian Jakobs <fabian AT ajax DOT org> * @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", var TextEditTest = TestCase("TextEditTest",
{ {
"test: delete line from the middle" : function() { "test: delete line from the middle" : function() {
var doc = new ace.Document(["a", "b", "c", "d"].join("\n")); var doc = new Document(["a", "b", "c", "d"].join("\n"));
var editor = new ace.Editor(new MockRenderer(), doc); var editor = new Editor(new MockRenderer(), doc);
editor.moveCursorTo(1, 1); editor.moveCursorTo(1, 1);
editor.removeLines(); editor.removeLines();
@ -34,8 +47,8 @@ var TextEditTest = TestCase("TextEditTest",
}, },
"test: delete multiple selected lines" : function() { "test: delete multiple selected lines" : function() {
var doc = new ace.Document(["a", "b", "c", "d"].join("\n")); var doc = new Document(["a", "b", "c", "d"].join("\n"));
var editor = new ace.Editor(new MockRenderer(), doc); var editor = new Editor(new MockRenderer(), doc);
editor.moveCursorTo(1, 1); editor.moveCursorTo(1, 1);
editor.getSelection().selectDown(); editor.getSelection().selectDown();
@ -46,8 +59,8 @@ var TextEditTest = TestCase("TextEditTest",
}, },
"test: delete first line" : function() { "test: delete first line" : function() {
var doc = new ace.Document(["a", "b", "c"].join("\n")); var doc = new Document(["a", "b", "c"].join("\n"));
var editor = new ace.Editor(new MockRenderer(), doc); var editor = new Editor(new MockRenderer(), doc);
editor.removeLines(); editor.removeLines();
@ -56,8 +69,8 @@ var TextEditTest = TestCase("TextEditTest",
}, },
"test: delete last" : function() { "test: delete last" : function() {
var doc = new ace.Document(["a", "b", "c"].join("\n")); var doc = new Document(["a", "b", "c"].join("\n"));
var editor = new ace.Editor(new MockRenderer(), doc); var editor = new Editor(new MockRenderer(), doc);
editor.moveCursorTo(2, 1); editor.moveCursorTo(2, 1);
editor.removeLines(); editor.removeLines();
@ -67,8 +80,8 @@ var TextEditTest = TestCase("TextEditTest",
}, },
"test: indent block" : function() { "test: indent block" : function() {
var doc = new ace.Document(["a12345", "b12345", "c12345"].join("\n")); var doc = new Document(["a12345", "b12345", "c12345"].join("\n"));
var editor = new ace.Editor(new MockRenderer(), doc); var editor = new Editor(new MockRenderer(), doc);
editor.moveCursorTo(1, 3); editor.moveCursorTo(1, 3);
editor.getSelection().selectDown(); editor.getSelection().selectDown();
@ -86,8 +99,8 @@ var TextEditTest = TestCase("TextEditTest",
}, },
"test: outdent block" : function() { "test: outdent block" : function() {
var doc = new ace.Document([" a12345", " b12345", " c12345"].join("\n")); var doc = new Document([" a12345", " b12345", " c12345"].join("\n"));
var editor = new ace.Editor(new MockRenderer(), doc); var editor = new Editor(new MockRenderer(), doc);
editor.moveCursorTo(0, 3); editor.moveCursorTo(0, 3);
editor.getSelection().selectDown(); editor.getSelection().selectDown();
@ -114,8 +127,8 @@ var TextEditTest = TestCase("TextEditTest",
}, },
"test: outent without a selection should update cursor" : function() { "test: outent without a selection should update cursor" : function() {
var doc = new ace.Document(" 12"); var doc = new Document(" 12");
var editor = new ace.Editor(new MockRenderer(), doc); var editor = new Editor(new MockRenderer(), doc);
editor.moveCursorTo(0, 3); editor.moveCursorTo(0, 3);
editor.blockOutdent(" "); editor.blockOutdent(" ");
@ -125,8 +138,8 @@ var TextEditTest = TestCase("TextEditTest",
}, },
"test: comment lines should perserve selection" : function() { "test: comment lines should perserve selection" : function() {
var doc = new ace.Document([" abc", "cde"].join("\n"), new ace.mode.JavaScript()); var doc = new Document([" abc", "cde"].join("\n"), new JavaScriptMode());
var editor = new ace.Editor(new MockRenderer(), doc); var editor = new Editor(new MockRenderer(), doc);
editor.moveCursorTo(0, 2); editor.moveCursorTo(0, 2);
editor.getSelection().selectDown(); editor.getSelection().selectDown();
@ -141,8 +154,8 @@ var TextEditTest = TestCase("TextEditTest",
}, },
"test: uncomment lines should perserve selection" : function() { "test: uncomment lines should perserve selection" : function() {
var doc = new ace.Document(["// abc", "//cde"].join("\n"), new ace.mode.JavaScript()); var doc = new Document(["// abc", "//cde"].join("\n"), new JavaScriptMode());
var editor = new ace.Editor(new MockRenderer(), doc); var editor = new Editor(new MockRenderer(), doc);
editor.moveCursorTo(0, 1); editor.moveCursorTo(0, 1);
editor.getSelection().selectDown(); editor.getSelection().selectDown();
@ -157,8 +170,8 @@ var TextEditTest = TestCase("TextEditTest",
"test: comment lines - if the selection end is at the line start it should stay there": function() { "test: comment lines - if the selection end is at the line start it should stay there": function() {
//select down //select down
var doc = new ace.Document(["abc", "cde"].join("\n"), new ace.mode.JavaScript()); var doc = new Document(["abc", "cde"].join("\n"), new JavaScriptMode());
var editor = new ace.Editor(new MockRenderer(), doc); var editor = new Editor(new MockRenderer(), doc);
editor.moveCursorTo(0, 0); editor.moveCursorTo(0, 0);
editor.getSelection().selectDown(); editor.getSelection().selectDown();
@ -167,8 +180,8 @@ var TextEditTest = TestCase("TextEditTest",
assertRange(0, 2, 1, 0, editor.getSelectionRange()); assertRange(0, 2, 1, 0, editor.getSelectionRange());
// select up // select up
var doc = new ace.Document(["abc", "cde"].join("\n"), new ace.mode.JavaScript()); var doc = new Document(["abc", "cde"].join("\n"), new JavaScriptMode());
var editor = new ace.Editor(new MockRenderer(), doc); var editor = new Editor(new MockRenderer(), doc);
editor.moveCursorTo(1, 0); editor.moveCursorTo(1, 0);
editor.getSelection().selectUp(); editor.getSelection().selectUp();
@ -178,8 +191,8 @@ var TextEditTest = TestCase("TextEditTest",
}, },
"test: move lines down should select moved lines" : function() { "test: move lines down should select moved lines" : function() {
var doc = new ace.Document(["11", "22", "33", "44"].join("\n")); var doc = new Document(["11", "22", "33", "44"].join("\n"));
var editor = new ace.Editor(new MockRenderer(), doc); var editor = new Editor(new MockRenderer(), doc);
editor.moveCursorTo(0, 1); editor.moveCursorTo(0, 1);
editor.getSelection().selectDown(); editor.getSelection().selectDown();
@ -205,8 +218,8 @@ var TextEditTest = TestCase("TextEditTest",
}, },
"test: move lines up should select moved lines" : function() { "test: move lines up should select moved lines" : function() {
var doc = new ace.Document(["11", "22", "33", "44"].join("\n")); var doc = new Document(["11", "22", "33", "44"].join("\n"));
var editor = new ace.Editor(new MockRenderer(), doc); var editor = new Editor(new MockRenderer(), doc);
editor.moveCursorTo(2, 1); editor.moveCursorTo(2, 1);
editor.getSelection().selectDown(); editor.getSelection().selectDown();
@ -226,8 +239,8 @@ var TextEditTest = TestCase("TextEditTest",
"test: move line without active selection should move cursor to start of the moved line" : function() "test: move line without active selection should move cursor to start of the moved line" : function()
{ {
var doc = new ace.Document(["11", "22", "33", "44"].join("\n")); var doc = new Document(["11", "22", "33", "44"].join("\n"));
var editor = new ace.Editor(new MockRenderer(), doc); var editor = new Editor(new MockRenderer(), doc);
editor.moveCursorTo(1, 1); editor.moveCursorTo(1, 1);
editor.clearSelection(); editor.clearSelection();
@ -244,8 +257,8 @@ var TextEditTest = TestCase("TextEditTest",
}, },
"test: copy lines down should select lines and place cursor at the selection start" : function() { "test: copy lines down should select lines and place cursor at the selection start" : function() {
var doc = new ace.Document(["11", "22", "33", "44"].join("\n")); var doc = new Document(["11", "22", "33", "44"].join("\n"));
var editor = new ace.Editor(new MockRenderer(), doc); var editor = new Editor(new MockRenderer(), doc);
editor.moveCursorTo(1, 1); editor.moveCursorTo(1, 1);
editor.getSelection().selectDown(); editor.getSelection().selectDown();
@ -259,8 +272,8 @@ var TextEditTest = TestCase("TextEditTest",
}, },
"test: copy lines up should select lines and place cursor at the selection start" : function() { "test: copy lines up should select lines and place cursor at the selection start" : function() {
var doc = new ace.Document(["11", "22", "33", "44"].join("\n")); var doc = new Document(["11", "22", "33", "44"].join("\n"));
var editor = new ace.Editor(new MockRenderer(), doc); var editor = new Editor(new MockRenderer(), doc);
editor.moveCursorTo(1, 1); editor.moveCursorTo(1, 1);
editor.getSelection().selectDown(); editor.getSelection().selectDown();
@ -274,8 +287,8 @@ var TextEditTest = TestCase("TextEditTest",
}, },
"test: input a tab with soft tab should convert it to spaces" : function() { "test: input a tab with soft tab should convert it to spaces" : function() {
var doc = new ace.Document(""); var doc = new Document("");
var editor = new ace.Editor(new MockRenderer(), doc); var editor = new Editor(new MockRenderer(), doc);
doc.setTabSize(2); doc.setTabSize(2);
doc.setUseSoftTabs(true); doc.setUseSoftTabs(true);
@ -289,8 +302,8 @@ var TextEditTest = TestCase("TextEditTest",
}, },
"test: input tab without soft tabs should keep the tab character" : function() { "test: input tab without soft tabs should keep the tab character" : function() {
var doc = new ace.Document(""); var doc = new Document("");
var editor = new ace.Editor(new MockRenderer(), doc); var editor = new Editor(new MockRenderer(), doc);
doc.setUseSoftTabs(false); doc.setUseSoftTabs(false);
@ -298,3 +311,5 @@ var TextEditTest = TestCase("TextEditTest",
assertEquals("\t", doc.toString()); assertEquals("\t", doc.toString());
} }
}); });
});

View file

@ -5,6 +5,15 @@
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt> * @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
* @author Fabian Jakobs <fabian AT ajax DOT org> * @author Fabian Jakobs <fabian AT ajax DOT org>
*/ */
require.def([
"ace/Document",
"ace/VirtualRenderer"
], function(
Document,
VirtualRenderer
) {
var VirtualRendererTest = new TestCase("VirtualRendererTest", { var VirtualRendererTest = new TestCase("VirtualRendererTest", {
"test: screen2text the column should be rounded to the next character edge" : function() { "test: screen2text the column should be rounded to the next character edge" : function() {
@ -17,8 +26,8 @@ var VirtualRendererTest = new TestCase("VirtualRendererTest", {
document.body.style.padding = "0px"; document.body.style.padding = "0px";
document.body.appendChild(el); document.body.appendChild(el);
var renderer = new ace.VirtualRenderer(el); var renderer = new VirtualRenderer(el);
renderer.setDocument(new ace.Document("1234")); renderer.setDocument(new Document("1234"));
renderer.characterWidth = 10; renderer.characterWidth = 10;
renderer.lineHeight = 15; renderer.lineHeight = 15;
@ -33,6 +42,7 @@ var VirtualRendererTest = new TestCase("VirtualRendererTest", {
document.body.removeChild(el); document.body.removeChild(el);
} }
// change tab size after setDocument (for text layer) // change tab size after setDocument (for text layer)
}); });
});

11
src/ace/test/all.js Normal file
View file

@ -0,0 +1,11 @@
require({
paths: {
"ace": "../src/ace"
}},
["ace/test/assertions", "ace/test/ChangeDocumentTest"],
function(a) {
console.log(a)
alert("a " + a)
}
);

View file

@ -5,16 +5,21 @@
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt> * @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
* @author Fabian Jakobs <fabian AT ajax DOT org> * @author Fabian Jakobs <fabian AT ajax DOT org>
*/ */
assertPosition = function(row, column, cursor) {
require.def([], function() {
window.assertPosition = function(row, column, cursor) {
assertEquals(row, cursor.row); assertEquals(row, cursor.row);
assertEquals(column, cursor.column); assertEquals(column, cursor.column);
}; };
assertRange = function(startRow, startColumn, endRow, endColumn, range) { window.assertRange = function(startRow, startColumn, endRow, endColumn, range) {
assertPosition(startRow, startColumn, range.start); assertPosition(startRow, startColumn, range.start);
assertPosition(endRow, endColumn, range.end); assertPosition(endRow, endColumn, range.end);
}; };
assertJsonEquals = function(expectedJson, foundJson) { window.assertJsonEquals = function(expectedJson, foundJson) {
assertEquals(JSON.stringify(expectedJson), JSON.stringify(foundJson)); assertEquals(JSON.stringify(expectedJson), JSON.stringify(foundJson));
}; };
});

View file

@ -5,16 +5,27 @@
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt> * @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
* @author Fabian Jakobs <fabian AT ajax DOT org> * @author Fabian Jakobs <fabian AT ajax DOT org>
*/ */
var CssTest = new TestCase("mode.CssTest", {
require.def([
"ace/Document",
"ace/Range",
"ace/mode/Css"
], function(
Document,
Range,
CssMode
) {
var CssTest = new TestCase("mode.CssTest", {
setUp : function() { setUp : function() {
this.mode = new ace.mode.Css(); this.mode = new CssMode();
}, },
"test: toggle comment lines should not do anything" : function() { "test: toggle comment lines should not do anything" : function() {
var doc = new ace.Document([" abc", "cde", "fg"].join("\n")); var doc = new Document([" abc", "cde", "fg"].join("\n"));
var range = new ace.Range(0, 3, 1, 1); var range = new Range(0, 3, 1, 1);
var comment = this.mode.toggleCommentLines("start", doc, range); var comment = this.mode.toggleCommentLines("start", doc, range);
assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString()); assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString());
}, },
@ -35,3 +46,5 @@ var CssTest = new TestCase("mode.CssTest", {
assertEquals(" ", this.mode.getNextLineIndent("start", " /*{ ", " ")); assertEquals(" ", this.mode.getNextLineIndent("start", " /*{ ", " "));
} }
}); });
});

View file

@ -5,10 +5,17 @@
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt> * @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
* @author Fabian Jakobs <fabian AT ajax DOT org> * @author Fabian Jakobs <fabian AT ajax DOT org>
*/ */
require.def([
"ace/mode/Css"
], function(
CssMode
) {
var CssTest = new TestCase("mode.CssTest", { var CssTest = new TestCase("mode.CssTest", {
setUp : function() { setUp : function() {
this.tokenizer = new ace.mode.Css().getTokenizer(); this.tokenizer = new CssMode().getTokenizer();
}, },
"test: tokenize pixel number" : function() { "test: tokenize pixel number" : function() {
@ -42,3 +49,5 @@ var CssTest = new TestCase("mode.CssTest", {
assertEquals("rparen", tokens[2].type); assertEquals("rparen", tokens[2].type);
} }
}); });
});

View file

@ -5,16 +5,27 @@
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt> * @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
* @author Fabian Jakobs <fabian AT ajax DOT org> * @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", { var HtmlTest = new TestCase("mode.HtmlTest", {
setUp : function() { setUp : function() {
this.mode = new ace.mode.Html(); this.mode = new HtmlMode();
}, },
"test: toggle comment lines should not do anything" : function() { "test: toggle comment lines should not do anything" : function() {
var doc = new ace.Document([" abc", "cde", "fg"]); var doc = new Document([" abc", "cde", "fg"]);
var range = new ace.Range(0, 3, 1, 1); var range = new Range(0, 3, 1, 1);
var comment = this.mode.toggleCommentLines("start", doc, range); var comment = this.mode.toggleCommentLines("start", doc, range);
assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString()); assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString());
}, },
@ -25,3 +36,5 @@ var HtmlTest = new TestCase("mode.HtmlTest", {
assertEquals("\t", this.mode.getNextLineIndent("start", "\tabc")); assertEquals("\t", this.mode.getNextLineIndent("start", "\tabc"));
} }
}); });
});

View file

@ -5,10 +5,17 @@
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt> * @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
* @author Fabian Jakobs <fabian AT ajax DOT org> * @author Fabian Jakobs <fabian AT ajax DOT org>
*/ */
require.def([
"ace/mode/Html"
], function(
HtmlMode
) {
var HtmlTest = new TestCase("mode.HtmlTest", { var HtmlTest = new TestCase("mode.HtmlTest", {
setUp : function() { setUp : function() {
this.tokenizer = new ace.mode.Html().getTokenizer(); this.tokenizer = new HtmlMode().getTokenizer();
}, },
"test: tokenize embedded script" : function() { "test: tokenize embedded script" : function() {
@ -30,3 +37,5 @@ var HtmlTest = new TestCase("mode.HtmlTest", {
assertEquals("text", tokens[10].type); assertEquals("text", tokens[10].type);
} }
}); });
});

View file

@ -5,49 +5,62 @@
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt> * @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
* @author Fabian Jakobs <fabian AT ajax DOT org> * @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", { var JavaScriptTest = new TestCase("mode.JavaScriptTest", {
setUp : function() { setUp : function() {
this.mode = new ace.mode.JavaScript(); this.mode = new JavaScriptMode();
}, },
"test: getTokenizer() (smoke test)" : function() { "test: getTokenizer() (smoke test)" : function() {
var tokenizer = this.mode.getTokenizer(); var tokenizer = this.mode.getTokenizer();
assertTrue(tokenizer instanceof ace.Tokenizer); assertTrue(tokenizer instanceof Tokenizer);
var tokens = tokenizer.getLineTokens("'juhu'", "start").tokens; var tokens = tokenizer.getLineTokens("'juhu'", "start").tokens;
assertEquals("string", tokens[0].type); assertEquals("string", tokens[0].type);
}, },
"test: toggle comment lines should prepend '//' to each line" : function() { "test: toggle comment lines should prepend '//' to each line" : function() {
var doc = new ace.Document([" abc", "cde", "fg"]); var doc = new Document([" abc", "cde", "fg"]);
var range = new ace.Range(0, 3, 1, 1); var range = new Range(0, 3, 1, 1);
var comment = this.mode.toggleCommentLines("start", doc, range); var comment = this.mode.toggleCommentLines("start", doc, range);
assertEquals(["// abc", "//cde", "fg"].join("\n"), doc.toString()); assertEquals(["// abc", "//cde", "fg"].join("\n"), doc.toString());
}, },
"test: toggle comment on commented lines should remove leading '//' chars" : function() { "test: toggle comment on commented lines should remove leading '//' chars" : function() {
var doc = new ace.Document(["// abc", "//cde", "fg"]); var doc = new Document(["// abc", "//cde", "fg"]);
var range = new ace.Range(0, 3, 1, 1); var range = new Range(0, 3, 1, 1);
var comment = this.mode.toggleCommentLines("start", doc, range); var comment = this.mode.toggleCommentLines("start", doc, range);
assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString()); assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString());
}, },
"test: toggle comment on multiple lines with one commented line prepend '//' to each line" : function() { "test: toggle comment on multiple lines with one commented line prepend '//' to each line" : function() {
var doc = new ace.Document(["// abc", "//cde", "fg"]); var doc = new Document(["// abc", "//cde", "fg"]);
var range = new ace.Range(0, 3, 2, 1); var range = new Range(0, 3, 2, 1);
var comment = this.mode.toggleCommentLines("start", doc, range); var comment = this.mode.toggleCommentLines("start", doc, range);
assertEquals(["//// abc", "////cde", "//fg"].join("\n"), doc.toString()); assertEquals(["//// abc", "////cde", "//fg"].join("\n"), doc.toString());
}, },
"test: toggle comment on a comment line with leading white space": function() { "test: toggle comment on a comment line with leading white space": function() {
var doc = new ace.Document(["//cde", " //fg"]); var doc = new Document(["//cde", " //fg"]);
var range = new ace.Range(0, 3, 1, 1); var range = new Range(0, 3, 1, 1);
var comment = this.mode.toggleCommentLines("start", doc, range); var comment = this.mode.toggleCommentLines("start", doc, range);
assertEquals(["cde", " fg"].join("\n"), doc.toString()); assertEquals(["cde", " fg"].join("\n"), doc.toString());
}, },
@ -92,15 +105,17 @@ var JavaScriptTest = new TestCase("mode.JavaScriptTest", {
}, },
"test: auto outdent should indent the line with the same indent as the line with the matching opening brace" : function() { "test: auto outdent should indent the line with the same indent as the line with the matching opening brace" : function() {
var doc = new ace.Document([" function foo() {", " bla", " }"]); var doc = new Document([" function foo() {", " bla", " }"]);
this.mode.autoOutdent("start", doc, 2); this.mode.autoOutdent("start", doc, 2);
assertEquals(" }", doc.getLine(2)); assertEquals(" }", doc.getLine(2));
}, },
"test: no auto outdent if no matching brace is found" : function() { "test: no auto outdent if no matching brace is found" : function() {
var doc = new ace.Document([" function foo()", " bla", " }"]); var doc = new Document([" function foo()", " bla", " }"]);
this.mode.autoOutdent("start", doc, 2); this.mode.autoOutdent("start", doc, 2);
assertEquals(" }", doc.getLine(2)); assertEquals(" }", doc.getLine(2));
} }
}); });
});

View file

@ -5,10 +5,17 @@
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt> * @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
* @author Fabian Jakobs <fabian AT ajax DOT org> * @author Fabian Jakobs <fabian AT ajax DOT org>
*/ */
require.def([
"ace/mode/JavaScript"
], function(
JavaScriptMode
) {
var JavaScriptTokenizerTest = new TestCase("mode.JavaScriptTokenizerTest", { var JavaScriptTokenizerTest = new TestCase("mode.JavaScriptTokenizerTest", {
setUp : function() { setUp : function() {
this.tokenizer = new ace.mode.JavaScript().getTokenizer(); this.tokenizer = new JavaScriptMode().getTokenizer();
}, },
"test: tokenize1" : function() { "test: tokenize1" : function() {
@ -57,3 +64,5 @@ var JavaScriptTokenizerTest = new TestCase("mode.JavaScriptTokenizerTest", {
assertEquals("rparen", tokens[2].type); assertEquals("rparen", tokens[2].type);
} }
}); });
});

View file

@ -5,16 +5,27 @@
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt> * @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
* @author Fabian Jakobs <fabian AT ajax DOT org> * @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", { var TextTest = new TestCase("mode.TextTest", {
setUp : function() { setUp : function() {
this.mode = new ace.mode.Text(); this.mode = new TextMode();
}, },
"test: toggle comment lines should not do anything" : function() { "test: toggle comment lines should not do anything" : function() {
var doc = new ace.Document([" abc", "cde", "fg"]); var doc = new Document([" abc", "cde", "fg"]);
var range = new ace.Range(0, 3, 1, 1); var range = new Range(0, 3, 1, 1);
var comment = this.mode.toggleCommentLines("start", doc, range); var comment = this.mode.toggleCommentLines("start", doc, range);
assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString()); assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString());
}, },
@ -24,3 +35,5 @@ var TextTest = new TestCase("mode.TextTest", {
assertEquals("", this.mode.getNextLineIndent("start", " abc", " ")); assertEquals("", this.mode.getNextLineIndent("start", " abc", " "));
} }
}); });
});

View file

@ -5,25 +5,38 @@
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt> * @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
* @author Fabian Jakobs <fabian AT ajax DOT org> * @author Fabian Jakobs <fabian AT ajax DOT org>
*/ */
require.def([
"ace/Document",
"ace/Range",
"ace/Tokenizer",
"ace/mode/Xml"
], function(
Document,
Range,
Tokenizer,
XmlMode
) {
var XmlTest = new TestCase("mode.XmlTest", { var XmlTest = new TestCase("mode.XmlTest", {
setUp : function() { setUp : function() {
this.mode = new ace.mode.Xml(); this.mode = new XmlMode();
}, },
"test: getTokenizer() (smoke test)" : function() { "test: getTokenizer() (smoke test)" : function() {
var tokenizer = this.mode.getTokenizer(); var tokenizer = this.mode.getTokenizer();
assertTrue(tokenizer instanceof ace.Tokenizer); assertTrue(tokenizer instanceof Tokenizer);
var tokens = tokenizer.getLineTokens("<juhu>", "start").tokens; var tokens = tokenizer.getLineTokens("<juhu>", "start").tokens;
assertEquals("keyword", tokens[1].type); assertEquals("keyword", tokens[1].type);
}, },
"test: toggle comment lines should not do anything" : function() { "test: toggle comment lines should not do anything" : function() {
var doc = new ace.Document([" abc", "cde", "fg"]); var doc = new Document([" abc", "cde", "fg"]);
var range = new ace.Range(0, 3, 1, 1); var range = new Range(0, 3, 1, 1);
var comment = this.mode.toggleCommentLines("start", doc, range); var comment = this.mode.toggleCommentLines("start", doc, range);
assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString()); assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString());
}, },
@ -34,3 +47,5 @@ var XmlTest = new TestCase("mode.XmlTest", {
assertEquals("\t", this.mode.getNextLineIndent("start", "\tabc")); assertEquals("\t", this.mode.getNextLineIndent("start", "\tabc"));
} }
}); });
});

View file

@ -5,10 +5,17 @@
* @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt> * @license LGPLv3 <http://www.gnu.org/licenses/lgpl-3.0.txt>
* @author Fabian Jakobs <fabian AT ajax DOT org> * @author Fabian Jakobs <fabian AT ajax DOT org>
*/ */
require.def([
"ace/mode/Xml"
], function(
XmlMode
) {
var XmlTest = new TestCase("mode.XmlTest", { var XmlTest = new TestCase("mode.XmlTest", {
setUp : function() { setUp : function() {
this.tokenizer = new ace.mode.Xml().getTokenizer(); this.tokenizer = new XmlMode().getTokenizer();
}, },
"test: tokenize1" : function() { "test: tokenize1" : function() {
@ -24,3 +31,5 @@ var XmlTest = new TestCase("mode.XmlTest", {
assertEquals("text", tokens[4].type); assertEquals("text", tokens[4].type);
} }
}); });
});