move unit tests into the source folder
This commit is contained in:
parent
5fd3cd3f20
commit
a13bb1db4a
18 changed files with 8 additions and 8 deletions
107
src/test/ChangeDocumentTest.js
Normal file
107
src/test/ChangeDocumentTest.js
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
var ChangeDocumentTest = new TestCase("ChangeDocumentTest", {
|
||||
|
||||
setUp : function() {
|
||||
this.doc1 = new ace.Document(["abc", "def"].join("\n"));
|
||||
this.doc2 = new ace.Document(["ghi", "jkl"].join("\n"));
|
||||
this.editor = new ace.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 ace.mode.Text());
|
||||
assertFalse(called);
|
||||
|
||||
this.doc2.setMode(new ace.mode.JavaScript());
|
||||
assertTrue(called);
|
||||
}
|
||||
});
|
||||
88
src/test/DocumentTest.js
Normal file
88
src/test/DocumentTest.js
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
var TextDocumentTest = new TestCase("TextDocumentTest", {
|
||||
|
||||
"test: find matching opening bracket" : function() {
|
||||
var doc = new ace.Document(["(()(", "())))"].join("\n"));
|
||||
|
||||
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 ace.Document(["(()(", "())))"].join("\n"));
|
||||
|
||||
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 ace.Document(["({[", ")]}"].join("\n"));
|
||||
|
||||
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 ace.Document(["1", "2", "3", "4"].join("\n"));
|
||||
|
||||
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 ace.Document(["1", "2", "3", "4"].join("\n"));
|
||||
|
||||
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 ace.Document(["1", "2", "3", "4"].join("\n"));
|
||||
|
||||
doc.duplicateLines(1, 2);
|
||||
assertEquals(["1", "2", "3", "2", "3", "4"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: duplicate last line" : function() {
|
||||
var doc = new ace.Document(["1", "2", "3"].join("\n"));
|
||||
|
||||
doc.duplicateLines(2, 2);
|
||||
assertEquals(["1", "2", "3", "3"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: duplicate first line" : function() {
|
||||
var doc = new ace.Document(["1", "2", "3"].join("\n"));
|
||||
|
||||
doc.duplicateLines(0, 0);
|
||||
assertEquals(["1", "1", "2", "3"].join("\n"), doc.toString());
|
||||
}
|
||||
});
|
||||
20
src/test/EventEmitterTest.js
Normal file
20
src/test/EventEmitterTest.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
var EventEmitter = function() {
|
||||
this.$initEvents();
|
||||
};
|
||||
ace.implement(EventEmitter.prototype, ace.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);
|
||||
}
|
||||
});
|
||||
|
||||
72
src/test/MockRenderer.js
Normal file
72
src/test/MockRenderer.js
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
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() {
|
||||
};
|
||||
77
src/test/NavigationTest.js
Normal file
77
src/test/NavigationTest.js
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
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 ace.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 ace.Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.navigateFileEnd();
|
||||
var cursor = editor.getSelection().getCursor();
|
||||
|
||||
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 ace.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 ace.Editor(new MockRenderer(), this.createTextDocument(200, 5));
|
||||
|
||||
editor.navigateTo(0, 0);
|
||||
editor.gotoLine(101);
|
||||
assertPosition(100, 0, editor.getSelection().getCursor());
|
||||
assertEquals(90, editor.getFirstVisibleRow());
|
||||
|
||||
editor.navigateTo(100, 0);
|
||||
editor.gotoLine(11);
|
||||
assertPosition(10, 0, editor.getSelection().getCursor());
|
||||
assertEquals(0, editor.getFirstVisibleRow());
|
||||
|
||||
editor.navigateTo(100, 0);
|
||||
editor.gotoLine(6);
|
||||
assertPosition(5, 0, editor.getSelection().getCursor());
|
||||
assertEquals(0, editor.getFirstVisibleRow());
|
||||
|
||||
editor.navigateTo(100, 0);
|
||||
editor.gotoLine(1);
|
||||
assertPosition(0, 0, editor.getSelection().getCursor());
|
||||
assertEquals(0, editor.getFirstVisibleRow());
|
||||
|
||||
editor.navigateTo(0, 0);
|
||||
editor.gotoLine(191);
|
||||
assertPosition(190, 0, editor.getSelection().getCursor());
|
||||
assertEquals(180, editor.getFirstVisibleRow());
|
||||
|
||||
editor.navigateTo(0, 0);
|
||||
editor.gotoLine(196);
|
||||
assertPosition(195, 0, editor.getSelection().getCursor());
|
||||
assertEquals(180, editor.getFirstVisibleRow());
|
||||
},
|
||||
|
||||
"test: goto visible line should only move the cursor and not scroll": function() {
|
||||
var editor = new ace.Editor(new MockRenderer(), this.createTextDocument(200, 5));
|
||||
|
||||
editor.navigateTo(0, 0);
|
||||
editor.gotoLine(12);
|
||||
assertPosition(11, 0, editor.getSelection().getCursor());
|
||||
assertEquals(0, editor.getFirstVisibleRow());
|
||||
|
||||
editor.navigateTo(30, 0);
|
||||
editor.gotoLine(33);
|
||||
assertPosition(32, 0, editor.getSelection().getCursor());
|
||||
assertEquals(30, editor.getFirstVisibleRow());
|
||||
}
|
||||
});
|
||||
250
src/test/SelectionTest.js
Normal file
250
src/test/SelectionTest.js
Normal file
|
|
@ -0,0 +1,250 @@
|
|||
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 ace.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 ace.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 ace.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 ace.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 ace.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 ace.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 ace.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 ace.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 ace.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 ace.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 ace.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 ace.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);
|
||||
}
|
||||
});
|
||||
274
src/test/TextEditTest.js
Normal file
274
src/test/TextEditTest.js
Normal file
|
|
@ -0,0 +1,274 @@
|
|||
var TextEditTest = TestCase("TextEditTest",
|
||||
{
|
||||
"test: delete line from the middle" : function() {
|
||||
var doc = new ace.Document(["a", "b", "c", "d"].join("\n"));
|
||||
var editor = new ace.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 ace.Document(["a", "b", "c", "d"].join("\n"));
|
||||
var editor = new ace.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 ace.Document(["a", "b", "c"].join("\n"));
|
||||
var editor = new ace.Editor(new MockRenderer(), doc);
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
assertEquals("b\nc", doc.toString());
|
||||
assertPosition(0, 0, editor.getCursorPosition());
|
||||
},
|
||||
|
||||
"test: delete last" : function() {
|
||||
var doc = new ace.Document(["a", "b", "c"].join("\n"));
|
||||
var editor = new ace.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 ace.Document(["a12345", "b12345", "c12345"].join("\n"));
|
||||
var editor = new ace.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 ace.Document([" a12345", " b12345", " c12345"].join("\n"));
|
||||
var editor = new ace.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 ace.Document(" 12");
|
||||
var editor = new ace.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 ace.Document([" abc", "cde"].join("\n"), new ace.mode.JavaScript());
|
||||
var editor = new ace.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 ace.Document(["// abc", "//cde"].join("\n"), new ace.mode.JavaScript());
|
||||
var editor = new ace.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());
|
||||
|
||||
var selection = editor.getSelectionRange();
|
||||
assertPosition(0, 0, selection.start);
|
||||
assertPosition(1, 1, selection.end);
|
||||
},
|
||||
|
||||
"test: move lines down should select moved lines" : function() {
|
||||
var doc = new ace.Document(["11", "22", "33", "44"].join("\n"));
|
||||
var editor = new ace.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 ace.Document(["11", "22", "33", "44"].join("\n"));
|
||||
var editor = new ace.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 ace.Document(["11", "22", "33", "44"].join("\n"));
|
||||
var editor = new ace.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 ace.Document(["11", "22", "33", "44"].join("\n"));
|
||||
var editor = new ace.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 ace.Document(["11", "22", "33", "44"].join("\n"));
|
||||
var editor = new ace.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 ace.Document("");
|
||||
var editor = new ace.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 ace.Document("");
|
||||
var editor = new ace.Editor(new MockRenderer(), doc);
|
||||
|
||||
doc.setUseSoftTabs(false);
|
||||
|
||||
editor.onTextInput("\t");
|
||||
assertEquals("\t", doc.toString());
|
||||
}
|
||||
});
|
||||
47
src/test/VirtualRendererTest.js
Normal file
47
src/test/VirtualRendererTest.js
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
var VirtualRendererTest = new TestCase("VirtualRendererTest", {
|
||||
|
||||
"test: convert document to screen coordinates" : function() {
|
||||
var el = document.createElement("div");
|
||||
var renderer = new ace.VirtualRenderer(el);
|
||||
|
||||
var doc = new ace.Document("01234\t567890\t1234");
|
||||
doc.setTabSize(4);
|
||||
renderer.setDocument(doc);
|
||||
|
||||
assertEquals(0, renderer.$documentToScreenColumn(0, 0));
|
||||
assertEquals(4, renderer.$documentToScreenColumn(0, 4));
|
||||
assertEquals(5, renderer.$documentToScreenColumn(0, 5));
|
||||
assertEquals(9, renderer.$documentToScreenColumn(0, 6));
|
||||
assertEquals(15, renderer.$documentToScreenColumn(0, 12));
|
||||
assertEquals(19, renderer.$documentToScreenColumn(0, 13));
|
||||
|
||||
doc.setTabSize(2);
|
||||
|
||||
assertEquals(0, renderer.$documentToScreenColumn(0, 0));
|
||||
assertEquals(4, renderer.$documentToScreenColumn(0, 4));
|
||||
assertEquals(5, renderer.$documentToScreenColumn(0, 5));
|
||||
assertEquals(7, renderer.$documentToScreenColumn(0, 6));
|
||||
assertEquals(13, renderer.$documentToScreenColumn(0, 12));
|
||||
assertEquals(15, renderer.$documentToScreenColumn(0, 13));
|
||||
},
|
||||
|
||||
"test: convert screen to document coordinates" : function() {
|
||||
var el = document.createElement("div");
|
||||
var renderer = new ace.VirtualRenderer(el);
|
||||
|
||||
var doc = new ace.Document("01234\t567890\t1234");
|
||||
doc.setTabSize(4);
|
||||
renderer.setDocument(doc);
|
||||
|
||||
assertEquals(0, renderer.$screenToDocumentColumn(0, 0));
|
||||
assertEquals(4, renderer.$screenToDocumentColumn(0, 4));
|
||||
assertEquals(5, renderer.$screenToDocumentColumn(0, 5));
|
||||
assertEquals(5, renderer.$screenToDocumentColumn(0, 6));
|
||||
assertEquals(5, renderer.$screenToDocumentColumn(0, 7));
|
||||
assertEquals(5, renderer.$screenToDocumentColumn(0, 8));
|
||||
assertEquals(6, renderer.$screenToDocumentColumn(0, 9));
|
||||
assertEquals(12, renderer.$screenToDocumentColumn(0, 15));
|
||||
assertEquals(13, renderer.$screenToDocumentColumn(0, 19));
|
||||
}
|
||||
// change tab size after setDocument (for text layer)
|
||||
});
|
||||
4
src/test/assertions.js
Normal file
4
src/test/assertions.js
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
assertPosition = function(row, column, cursor) {
|
||||
assertEquals(row, cursor.row);
|
||||
assertEquals(column, cursor.column);
|
||||
};
|
||||
34
src/test/mode/CssTest.js
Normal file
34
src/test/mode/CssTest.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
var CssTest = new TestCase("mode.CssTest", {
|
||||
|
||||
setUp : function() {
|
||||
this.mode = new ace.mode.Css();
|
||||
},
|
||||
|
||||
"test: toggle comment lines should not do anything" : function() {
|
||||
var doc = new ace.Document([" abc", "cde", "fg"].join("\n"));
|
||||
|
||||
var range = {
|
||||
start: {row: 0, column: 3},
|
||||
end: {row: 1, column: 1}
|
||||
};
|
||||
|
||||
var comment = this.mode.toggleCommentLines(doc, range, "start");
|
||||
assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
|
||||
"test: lines should keep indentation" : function() {
|
||||
assertEquals(" ", this.mode.getNextLineIndent(" abc", "start", " "));
|
||||
assertEquals("\t", this.mode.getNextLineIndent("\tabc", "start", " "));
|
||||
},
|
||||
|
||||
"test: new line after { should increase indent" : function() {
|
||||
assertEquals(" ", this.mode.getNextLineIndent(" abc{", "start", " "));
|
||||
assertEquals("\t ", this.mode.getNextLineIndent("\tabc { ", "start", " "));
|
||||
},
|
||||
|
||||
"test: no indent increase after { in a comment" : function() {
|
||||
assertEquals(" ", this.mode.getNextLineIndent(" /*{", "start", " "));
|
||||
assertEquals(" ", this.mode.getNextLineIndent(" /*{ ", "start", " "));
|
||||
}
|
||||
});
|
||||
37
src/test/mode/CssTokenizerTest.js
Normal file
37
src/test/mode/CssTokenizerTest.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
var CssTest = new TestCase("mode.CssTest", {
|
||||
|
||||
setUp : function() {
|
||||
this.tokenizer = new ace.mode.Css().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);
|
||||
}
|
||||
});
|
||||
25
src/test/mode/HtmlTokenizerTest.js
Normal file
25
src/test/mode/HtmlTokenizerTest.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
var HtmlTest = new TestCase("mode.HtmlTest", {
|
||||
|
||||
setUp : function() {
|
||||
this.tokenizer = new ace.mode.Html().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);
|
||||
}
|
||||
});
|
||||
87
src/test/mode/JavaScriptTest.js
Normal file
87
src/test/mode/JavaScriptTest.js
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
var JavaScriptTest = new TestCase("mode.JavaScriptTest", {
|
||||
|
||||
setUp : function() {
|
||||
this.mode = new ace.mode.JavaScript();
|
||||
},
|
||||
|
||||
"test: getTokenizer() (smoke test)" : function() {
|
||||
var tokenizer = this.mode.getTokenizer();
|
||||
|
||||
assertTrue(tokenizer instanceof ace.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 ace.Document([" abc", "cde", "fg"].join("\n"));
|
||||
|
||||
var range = {
|
||||
start: {row: 0, column: 3},
|
||||
end: {row: 1, column: 1}
|
||||
};
|
||||
|
||||
var comment = this.mode.toggleCommentLines(doc, range, "start");
|
||||
assertEquals(["// abc", "//cde", "fg"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: toggle comment on commented lines should remove leading '//' chars" : function() {
|
||||
var doc = new ace.Document(["// abc", "//cde", "fg"].join("\n"));
|
||||
|
||||
var range = {
|
||||
start: {row: 0, column: 3},
|
||||
end: {row: 1, column: 1}
|
||||
};
|
||||
|
||||
var comment = this.mode.toggleCommentLines(doc, range, "start");
|
||||
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 ace.Document(["// abc", "//cde", "fg"].join("\n"));
|
||||
|
||||
var range = {
|
||||
start: {row: 0, column: 3},
|
||||
end: {row: 2, column: 1}
|
||||
};
|
||||
|
||||
var comment = this.mode.toggleCommentLines(doc, range, "start");
|
||||
assertEquals(["//// abc", "////cde", "//fg"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
"test: auto indent after opening brace" : function() {
|
||||
assertEquals(" ", this.mode.getNextLineIndent("if () {", "start", " "));
|
||||
},
|
||||
|
||||
"test: no auto indent after opening brace in multi line comment" : function() {
|
||||
assertEquals("", this.mode.getNextLineIndent("/*if () {", "start", " "));
|
||||
assertEquals(" ", this.mode.getNextLineIndent(" abcd", "comment", " "));
|
||||
},
|
||||
|
||||
"test: no auto indent after opening brace in single line comment" : function() {
|
||||
assertEquals("", this.mode.getNextLineIndent("//if () {", "start", " "));
|
||||
assertEquals(" ", this.mode.getNextLineIndent(" //if () {", "start", " "));
|
||||
},
|
||||
|
||||
"test: no auto indent should add to existing indent" : function() {
|
||||
assertEquals(" ", this.mode.getNextLineIndent(" if () {", "start", " "));
|
||||
assertEquals(" ", this.mode.getNextLineIndent(" cde", "start", " "));
|
||||
},
|
||||
|
||||
"test: special indent in doc comments" : function() {
|
||||
assertEquals(" * ", this.mode.getNextLineIndent("/**", "doc-comment", " "));
|
||||
assertEquals(" * ", this.mode.getNextLineIndent(" /**", "doc-comment", " "));
|
||||
assertEquals(" * ", this.mode.getNextLineIndent(" *", "doc-comment", " "));
|
||||
assertEquals(" * ", this.mode.getNextLineIndent(" *", "doc-comment", " "));
|
||||
assertEquals(" ", this.mode.getNextLineIndent(" abc", "doc-comment", " "));
|
||||
},
|
||||
|
||||
"test: no indent after doc comments" : function() {
|
||||
assertEquals("", this.mode.getNextLineIndent(" */", "doc-comment", " "));
|
||||
}
|
||||
|
||||
// "test: outdent if first non WS character in line is a closing brace" : function() {
|
||||
// assertEquals("", this.mode.getNextLineIndent(")", "start", " "));
|
||||
// assertEquals(" ", this.mode.getNextLineIndent(" )", "start", " "));
|
||||
// }
|
||||
});
|
||||
52
src/test/mode/JavaScriptTokenizerTest.js
Normal file
52
src/test/mode/JavaScriptTokenizerTest.js
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
var JavaScriptTokenizerTest = new TestCase("mode.JavaScriptTokenizerTest", {
|
||||
|
||||
setUp : function() {
|
||||
this.tokenizer = new ace.mode.JavaScript().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);
|
||||
}
|
||||
});
|
||||
23
src/test/mode/TextTest.js
Normal file
23
src/test/mode/TextTest.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
var TextTest = new TestCase("mode.TextTest", {
|
||||
|
||||
setUp : function() {
|
||||
this.mode = new ace.mode.Text();
|
||||
},
|
||||
|
||||
"test: toggle comment lines should not do anything" : function() {
|
||||
var doc = new ace.Document([" abc", "cde", "fg"].join("\n"));
|
||||
|
||||
var range = {
|
||||
start: {row: 0, column: 3},
|
||||
end: {row: 1, column: 1}
|
||||
};
|
||||
|
||||
var comment = this.mode.toggleCommentLines(doc, range, "start");
|
||||
assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString());
|
||||
},
|
||||
|
||||
|
||||
"text: lines should not be indented" : function() {
|
||||
assertEquals("", this.mode.getNextLineIndent(" abc", " "));
|
||||
}
|
||||
});
|
||||
27
src/test/mode/XmlTest.js
Normal file
27
src/test/mode/XmlTest.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
var XmlTest = new TestCase("mode.XmlTest", {
|
||||
|
||||
setUp : function() {
|
||||
this.mode = new ace.mode.Xml();
|
||||
},
|
||||
|
||||
"test: getTokenizer() (smoke test)" : function() {
|
||||
var tokenizer = this.mode.getTokenizer();
|
||||
|
||||
assertTrue(tokenizer instanceof ace.Tokenizer);
|
||||
|
||||
var tokens = tokenizer.getLineTokens("<juhu>", "start").tokens;
|
||||
assertEquals("keyword", tokens[1].type);
|
||||
},
|
||||
|
||||
"test: toggle comment lines should not do anything" : function() {
|
||||
var doc = new ace.Document([" abc", "cde", "fg"].join("\n"));
|
||||
|
||||
var range = {
|
||||
start: {row: 0, column: 3},
|
||||
end: {row: 1, column: 1}
|
||||
};
|
||||
|
||||
var comment = this.mode.toggleCommentLines(doc, range, "start");
|
||||
assertEquals([" abc", "cde", "fg"].join("\n"), doc.toString());
|
||||
}
|
||||
});
|
||||
19
src/test/mode/XmlTokenizerTest.js
Normal file
19
src/test/mode/XmlTokenizerTest.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
var XmlTest = new TestCase("mode.XmlTest", {
|
||||
|
||||
setUp : function() {
|
||||
this.tokenizer = new ace.mode.Xml().getTokenizer();
|
||||
},
|
||||
|
||||
"test: tokenize1" : function() {
|
||||
|
||||
var line = "<Juhu>//Juhu Kinners</Kinners>";
|
||||
var tokens = this.tokenizer.getLineTokens(line, "start").tokens;
|
||||
|
||||
assertEquals(5, 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);
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue