123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- /* ***** BEGIN LICENSE BLOCK *****
- * Distributed under the BSD license:
- *
- * Copyright (c) 2010, Ajax.org B.V.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of Ajax.org B.V. nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * ***** END LICENSE BLOCK ***** */
- if (typeof process !== "undefined") {
- ace_require("amd-loader");
- }
- define(function(ace_require, exports, module) {
- "use strict";
- var Range = ace_require("./range").Range;
- var EditSession = ace_require("./edit_session").EditSession;
- var assert = ace_require("./test/assertions");
- module.exports = {
-
- name: "ACE range.js",
-
- "test: create range": function() {
- var range = new 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 = 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 Range(0, 20, 100, 30).clipRows(10, 30), 10, 0, 31, 0);
- assert.range(new Range(0, 20, 30, 10).clipRows(10, 30), 10, 0, 30, 10);
- var range = new 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 Range(1, 2, 1, 2);
- assert.ok(range.isEmpty());
- var range = new Range(1, 2, 1, 6);
- assert.notOk(range.isEmpty());
- },
- "test: is multi line": function() {
- var range = new Range(1, 2, 1, 6);
- assert.notOk(range.isMultiLine());
- var range = new Range(1, 2, 2, 6);
- assert.ok(range.isMultiLine());
- },
- "test: clone": function() {
- var range = new 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 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 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 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 Range(0, 2, 1, 2);
- assert.range(range.collapseRows(), 0, 0, 1, 0);
- var range = new Range(2, 2, 3, 1);
- assert.range(range.collapseRows(), 2, 0, 3, 0);
- var range = new Range(2, 2, 3, 0);
- assert.range(range.collapseRows(), 2, 0, 2, 0);
- var range = new Range(2, 0, 2, 0);
- assert.range(range.collapseRows(), 2, 0, 2, 0);
- },
-
- "test: to screen range" : function() {
- var session = new EditSession([
- "juhu",
- "12\t\t34",
- "ぁぁa",
- "\t\t34"
- ]);
-
- var range = new Range(0, 0, 0, 3);
- assert.range(range.toScreenRange(session), 0, 0, 0, 3);
-
- var range = new Range(1, 1, 1, 3);
- assert.range(range.toScreenRange(session), 1, 1, 1, 4);
-
- var range = new Range(2, 1, 2, 2);
- assert.range(range.toScreenRange(session), 2, 2, 2, 4);
- var range = new Range(3, 0, 3, 4);
- assert.range(range.toScreenRange(session), 3, 0, 3, 10);
- }
- };
- });
- if (typeof module !== "undefined" && module === ace_require.main) {
- ace_require("asyncjs").test.testcase(module.exports).exec();
- }
|