From bcabfcb2e2bcde513c6731c704fb8475725fcbc1 Mon Sep 17 00:00:00 2001 From: dgeorge Date: Fri, 28 Oct 2011 16:58:45 -0700 Subject: [PATCH] Added unit tests for TokenIterator --- lib/ace/test/all_browser.js | 1 + lib/ace/token_iterator_test.js | 198 +++++++++++++++++++++++++++++++++ 2 files changed, 199 insertions(+) create mode 100644 lib/ace/token_iterator_test.js diff --git a/lib/ace/test/all_browser.js b/lib/ace/test/all_browser.js index 42e32731..32ccfdd0 100644 --- a/lib/ace/test/all_browser.js +++ b/lib/ace/test/all_browser.js @@ -35,6 +35,7 @@ var tests = [ require("ace/search_test"), require("ace/selection_test"), require("ace/test/event_emitter_test"), + require("ace/token_iterator_test"), require("ace/virtual_renderer_test") ] diff --git a/lib/ace/token_iterator_test.js b/lib/ace/token_iterator_test.js new file mode 100644 index 00000000..aa29917b --- /dev/null +++ b/lib/ace/token_iterator_test.js @@ -0,0 +1,198 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Ajax.org Code Editor (ACE). + * + * The Initial Developer of the Original Code is + * Ajax.org B.V. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Fabian Jakobs + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +if (typeof process !== "undefined") { + require("../../support/paths"); +} + +define(function(require, exports, module) { + +var EditSession = require("ace/edit_session").EditSession; +var JavaScriptMode = require("ace/mode/javascript").Mode; +var TokenIterator = require("ace/token_iterator").TokenIterator; +var assert = require("ace/test/assertions"); + +module.exports = { + "test: token iterator initialization in JavaScript document" : function() { + var lines = [ + "function foo(items) {", + " for (var i=0; i= 0; i--) + assert.equal(iterator.stepBackward(), tokens[i]); + assert.equal(iterator.stepBackward(), null); + assert.equal(iterator.getCurrentToken(), null); + }, + + "test: token iterator reports correct row and column" : function() { + var lines = [ + "function foo(items) {", + " for (var i=0; i