diff --git a/.project b/.project new file mode 100644 index 00000000..78e8b1fb --- /dev/null +++ b/.project @@ -0,0 +1,11 @@ + + + editor + + + + + + + + diff --git a/jsTestDriver.conf b/jsTestDriver.conf new file mode 100644 index 00000000..5ce7df71 --- /dev/null +++ b/jsTestDriver.conf @@ -0,0 +1,6 @@ + +server: http://localhost:4224 + +load: + - src/*.js + - test/*.js \ No newline at end of file diff --git a/test/MockRenderer.js b/test/MockRenderer.js new file mode 100644 index 00000000..e06c0adb --- /dev/null +++ b/test/MockRenderer.js @@ -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() { +}; + diff --git a/test/NavigationTest.js b/test/NavigationTest.js new file mode 100644 index 00000000..14391d65 --- /dev/null +++ b/test/NavigationTest.js @@ -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()); + } +});