add "js Test Driver" unit tests

This commit is contained in:
Fabian Jakobs 2010-04-12 12:43:28 +02:00
commit 4572d9f335
4 changed files with 126 additions and 0 deletions

11
.project Normal file
View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>editor</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>

6
jsTestDriver.conf Normal file
View file

@ -0,0 +1,6 @@
server: http://localhost:4224
load:
- src/*.js
- test/*.js

58
test/MockRenderer.js Normal file
View file

@ -0,0 +1,58 @@
MockRenderer = function() {
this.container = document.createElement("div");
this.cursor = {
row: 0,
column: 0
}
this.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.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.draw = function() {
};

51
test/NavigationTest.js Normal file
View file

@ -0,0 +1,51 @@
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.TextDocument(text);
},
"test: navigate to end of file should place the cursor on last row and column" : function() {
var editor = new ace.Editor(this.createTextDocument(200, 10),
new MockRenderer());
editor.navigateFileEnd();
var cursor = editor.getCursorPosition();
assertEquals(199, cursor.row);
assertEquals(10, cursor.column);
},
"test: navigate to end of file should scroll the last line into view" : function() {
var editor = new ace.Editor(this.createTextDocument(200, 10),
new MockRenderer());
editor.navigateFileEnd();
var cursor = editor.getCursorPosition();
assertTrue(editor.getFirstVisibleRow() <= cursor.row);
assertTrue(editor.getLastVisibleRow() >= cursor.row);
},
"test: navigate to start of file should place the cursor on the first row and column" : function() {
var editor = new ace.Editor(this.createTextDocument(200, 10),
new MockRenderer());
editor.navigateFileStart();
var cursor = editor.getCursorPosition();
assertEquals(0, cursor.row);
assertEquals(0, cursor.column);
},
"test: navigate to start of file should scroll the first row into view" : function() {
var editor = new ace.Editor(this.createTextDocument(200, 10),
new MockRenderer());
editor.scrollToRow(editor.getLastVisibleRow() + 20);
editor.navigateFileStart();
assertEquals(0, editor.getFirstVisibleRow());
}
});