Permalink
Browse files

Ace definitions updated. I added more tests.

  • Loading branch information...
Diullei committed Feb 19, 2013
1 parent 996158f commit 9b008b0b542c94040e24ecf9fc696b6b0b5b2088
View
@@ -240,7 +240,7 @@ module AceAjax {
* Gives list of tokens of the row. (tokens are cached)
* @param row The row to get tokens at
**/
- getTokens(row: number): any;
+ getTokens(row: number): TokenInfo[];
/**
* [Returns the state of tokenization at the end of a row.]{: #BackgroundTokenizer.getState}
@@ -531,7 +531,7 @@ module AceAjax {
* Starts tokenizing at the row indicated. Returns a list of objects of the tokenized rows.
* @param row The row to start at
**/
- getTokens(row: number): any[];
+ getTokens(row: number): TokenInfo[];
/**
* Returns an object indicating the token at the current row. The object has two properties: `index` and `start`.
@@ -1817,6 +1817,8 @@ module AceAjax {
end: Position;
+ isEmpty(): bool;
+
/**
* Returns `true` if and only if the starting row and column, and ending row and column, are equivalent to those given by `range`.
* @param range A range to check against
@@ -1994,6 +1996,7 @@ module AceAjax {
* @param endColumn The ending column
**/
declare var Range: {
+ fromPoints(pos1: Position, pos2: Position): Range;
new(startRow: number, startColumn: number, endRow: number, endColumn: number): Range;
}
@@ -2125,6 +2128,12 @@ module AceAjax {
**/
export interface Selection {
+ addEventListener(ev: string, callback: Function);
+
+ moveCursorWordLeft();
+
+ moveCursorWordRight();
+
fromOrientedRange(range: Range);
setSelectionRange(match);
@@ -2476,7 +2485,7 @@ module AceAjax {
/**
* Returns the current tokenized string.
**/
- getCurrentToken(): string;
+ getCurrentToken(): TokenInfo;
/**
* Returns the current row.
@@ -2583,10 +2592,18 @@ module AceAjax {
**/
export interface VirtualRenderer {
+ scroller: any;
+
+ characterWidth: number;
+
+ lineHeight: number;
+
+ screenToTextCoordinates(left: number, top: number);
+
/**
* Associates the renderer with an [[EditSession `EditSession`]].
**/
- setSession();
+ setSession(session: IEditSession);
/**
* Triggers a partial update of the text, from the range given by the two parameters.
@@ -2913,7 +2930,7 @@ module AceAjax {
* @param container The root element of the editor
* @param theme The starting theme
**/
- new(container: HTMLElement, theme: string): VirtualRenderer;
+ new(container: HTMLElement, theme?: string): VirtualRenderer;
}
}
View
@@ -16,6 +16,11 @@ var JavaScriptMode = null;
/// <reference path="tests/ace-multi_select-tests.ts" />
/// <reference path="tests/ace-placeholder-tests.ts" />
/// <reference path="tests/ace-range_list-tests.ts" />
+/// <reference path="tests/ace-range-tests.ts" />
+/// <reference path="tests/ace-search-tests.ts" />
+/// <reference path="tests/ace-selection-tests.ts" />
+/// <reference path="tests/ace-token_iterator-tests.ts" />
+/// <reference path="tests/ace-virtual_renderer-tests.ts" />
@@ -0,0 +1,146 @@
+/// <reference path="../ace.d.ts" />
+
+exports = {
+
+ name: "ACE range.js",
+
+ "test: create range": function () {
+ var range = new AceAjax.Range(1, 2, 3, 4);
+
+ assert.equal(range.start.row, 1);
+ assert.equal(range.start.column, 2);
+ assert.equal(range.end.row, 3);
+ assert.equal(range.end.column, 4);
+ },
+
+ "test: create from points": function () {
+ var range = AceAjax.Range.fromPoints({ row: 1, column: 2 }, { row: 3, column: 4 });
+
+ assert.equal(range.start.row, 1);
+ assert.equal(range.start.column, 2);
+ assert.equal(range.end.row, 3);
+ assert.equal(range.end.column, 4);
+ },
+
+ "test: clip to rows": function () {
+ assert.range(new AceAjax.Range(0, 20, 100, 30).clipRows(10, 30), 10, 0, 31, 0);
+ assert.range(new AceAjax.Range(0, 20, 30, 10).clipRows(10, 30), 10, 0, 30, 10);
+
+ var range = new AceAjax.Range(0, 20, 3, 10);
+ var range = range.clipRows(10, 30);
+
+ assert.ok(range.isEmpty());
+ assert.range(range, 10, 0, 10, 0);
+ },
+
+ "test: isEmpty": function () {
+ var range = new AceAjax.Range(1, 2, 1, 2);
+ assert.ok(range.isEmpty());
+
+ var range = new AceAjax.Range(1, 2, 1, 6);
+ assert.notOk(range.isEmpty());
+ },
+
+ "test: is multi line": function () {
+ var range = new AceAjax.Range(1, 2, 1, 6);
+ assert.notOk(range.isMultiLine());
+
+ var range = new AceAjax.Range(1, 2, 2, 6);
+ assert.ok(range.isMultiLine());
+ },
+
+ "test: clone": function () {
+ var range = new AceAjax.Range(1, 2, 3, 4);
+ var clone = range.clone();
+
+ assert.position(clone.start, 1, 2);
+ assert.position(clone.end, 3, 4);
+
+ clone.start.column = 20;
+ assert.position(range.start, 1, 2);
+
+ clone.end.column = 20;
+ assert.position(range.end, 3, 4);
+ },
+
+ "test: contains for multi line ranges": function () {
+ var range = new AceAjax.Range(1, 10, 5, 20);
+
+ assert.ok(range.contains(1, 10));
+ assert.ok(range.contains(2, 0));
+ assert.ok(range.contains(3, 100));
+ assert.ok(range.contains(5, 19));
+ assert.ok(range.contains(5, 20));
+
+ assert.notOk(range.contains(1, 9));
+ assert.notOk(range.contains(0, 0));
+ assert.notOk(range.contains(5, 21));
+ },
+
+ "test: contains for single line ranges": function () {
+ var range = new AceAjax.Range(1, 10, 1, 20);
+
+ assert.ok(range.contains(1, 10));
+ assert.ok(range.contains(1, 15));
+ assert.ok(range.contains(1, 20));
+
+ assert.notOk(range.contains(0, 9));
+ assert.notOk(range.contains(2, 9));
+ assert.notOk(range.contains(1, 9));
+ assert.notOk(range.contains(1, 21));
+ },
+
+ "test: extend range": function () {
+ var range = new AceAjax.Range(2, 10, 2, 30);
+
+ var range = range.extend(2, 5);
+ assert.range(range, 2, 5, 2, 30);
+
+ var range = range.extend(2, 35);
+ assert.range(range, 2, 5, 2, 35);
+
+ var range = range.extend(2, 15);
+ assert.range(range, 2, 5, 2, 35);
+
+ var range = range.extend(1, 4);
+ assert.range(range, 1, 4, 2, 35);
+
+ var range = range.extend(6, 10);
+ assert.range(range, 1, 4, 6, 10);
+ },
+
+ "test: collapse rows": function () {
+ var range = new AceAjax.Range(0, 2, 1, 2);
+ assert.range(range.collapseRows(), 0, 0, 1, 0);
+
+ var range = new AceAjax.Range(2, 2, 3, 1);
+ assert.range(range.collapseRows(), 2, 0, 3, 0);
+
+ var range = new AceAjax.Range(2, 2, 3, 0);
+ assert.range(range.collapseRows(), 2, 0, 2, 0);
+
+ var range = new AceAjax.Range(2, 0, 2, 0);
+ assert.range(range.collapseRows(), 2, 0, 2, 0);
+ },
+
+ "test: to screen range": function () {
+ var session = new AceAjax.EditSession([
+ "juhu",
+ "12\t\t34",
+ "ぁぁa",
+ "\t\t34",
+ ]);
+
+ var range = new AceAjax.Range(0, 0, 0, 3);
+ assert.range(range.toScreenRange(session), 0, 0, 0, 3);
+
+ var range = new AceAjax.Range(1, 1, 1, 3);
+ assert.range(range.toScreenRange(session), 1, 1, 1, 4);
+
+ var range = new AceAjax.Range(2, 1, 2, 2);
+ assert.range(range.toScreenRange(session), 2, 2, 2, 4);
+
+ var range = new AceAjax.Range(3, 0, 3, 4);
+ assert.range(range.toScreenRange(session), 3, 0, 3, 10);
+ }
+};
Oops, something went wrong.

0 comments on commit 9b008b0

Please sign in to comment.