[prev in list] [next in list] [prev in thread] [next in thread]
List: kupu-checkins
Subject: [kupu-checkins] r5549 - kupu/branch/guido-playground/tests
From: guido () codespeak ! net
Date: 2004-07-13 22:32:58
Message-ID: 20040713223258.8A1F95AA51 () thoth ! codespeak ! net
[Download RAW message or body]
Author: guido
Date: Wed Jul 14 00:32:56 2004
New Revision: 5549
Added:
kupu/branch/guido-playground/tests/test_kte.js
Modified:
kupu/branch/guido-playground/tests/run_tests.html
kupu/branch/guido-playground/tests/test_kupuhelpers.js
Log:
Added some basic tests for LineColorizer.
Modified: kupu/branch/guido-playground/tests/run_tests.html
==============================================================================
--- kupu/branch/guido-playground/tests/run_tests.html (original)
+++ kupu/branch/guido-playground/tests/run_tests.html Wed Jul 14 00:32:56 2004
@@ -16,6 +16,9 @@
<script type="text/javascript" src="../common/kupuhelpers.js"> </script>
<script type="text/javascript" src="test_kupuhelpers.js"> </script>
+<script type="text/javascript" src="../kte/kupute.js"> </script>
+<script type="text/javascript" src="test_kte.js"> </script>
+
<script type="text/javascript">
//<![CDATA[
@@ -25,6 +28,7 @@
testsuite.registerTest(KupuHelpersTestCase);
testsuite.registerTest(KupuEditorTestCase);
testsuite.registerTest(KupuSelectionTestCase);
+ testsuite.registerTest(LineColorizerTestCase);
testsuite.runSuite();
};
Added: kupu/branch/guido-playground/tests/test_kte.js
==============================================================================
--- (empty file)
+++ kupu/branch/guido-playground/tests/test_kte.js Wed Jul 14 00:32:56 2004
@@ -0,0 +1,86 @@
+/*****************************************************************************
+ *
+ * Copyright (c) 2003-2004 Kupu Contributors. All rights reserved.
+ *
+ * This software is distributed under the terms of the Kupu
+ * License. See LICENSE.txt for license text. For a list of Kupu
+ * Contributors see CREDITS.txt.
+ *
+ *****************************************************************************/
+
+// $Id: test_kte.js 5530 2004-07-11 16:47:44Z guido $
+
+// mapping from type of token to color
+var TypeToColorMap = {'foo': 'red',
+ 'bar': 'green'}
+
+// simple Python color map
+var TestSyntaxMap = {'foo': new Array('foo', 'bar', 'baz'),
+ 'bar': new Array(/[0-9][0-9\.]*/)
+ };
+
+function LineColorizerTestCase() {
+ this.setUp = function() {
+ this.colormap = buildColorMap(TypeToColorMap, TestSyntaxMap);
+ this.colorizer = new LineColorizer(document, this.colormap);
+ };
+
+ this.test_getText = function() {
+ var text = 'foobarbaz';
+ var div = document.createElement('div');
+ for (var i=0; i < text.length; i++) {
+ var chr = document.createTextNode(text.charAt(i));
+ div.appendChild(chr);
+ };
+ this.assertEquals(this.colorizer.getText(div), text);
+
+ var chunks = new Array('foo', 'bar', 'baz');
+ var div = document.createElement('div');
+ var previous = div;
+ for (var i=0; i < chunks.length; i++) {
+ var current = document.createElement('div');
+ current.appendChild(document.createTextNode(chunks[i]));
+ previous.appendChild(current);
+ previous = current;
+ };
+ this.assertEquals(this.colorizer.getText(div),
+ chunks.join(''));
+ };
+
+ this.test_tokenize = function() {
+ var text = "foo bar baz";
+ this.assertEquals(this.colorizer.tokenize(text),
+ new Array('foo', ' ', 'bar', ' ', 'baz'));
+
+ var text = " \t\n\xa0 \tfoo \t\n\xa0\t";
+ this.assertEquals(this.colorizer.tokenize(text),
+ new Array(' \t\n\xa0 \t', 'foo', ' \t\n\xa0\t'));
+
+ var text = "%#@#^%;\'~\\foo%#@#^%;\'~\\";
+ this.assertEquals(this.colorizer.tokenize(text),
+ new Array('%#@#^%;\'~\\', 'foo', '%#@#^%;\'~\\'));
+
+ var text = " foo = do('foo');";
+ this.assertEquals(this.colorizer.tokenize(text),
+ new Array(' ', 'foo', ' ', '=', ' ',
+ 'do', '(\'', 'foo', '\');'));
+ };
+
+ this.test_colorize = function() {
+ var tokens = new Array('test', ' ', 'foo', ' ', '1234.5');
+ var colored = this.colorizer.colorize(tokens);
+ var strings = new Array();
+ for (var i=0; i < colored.length; i++) {
+ var color = colored[i].style.color;
+ if (i == 2) {
+ this.assertEquals(color, 'red');
+ } else if (i == 4) {
+ this.assertEquals(color, 'green');
+ } else {
+ this.assert(!color || color == 'black');
+ };
+ };
+ };
+};
+
+LineColorizerTestCase.prototype = new TestCase;
Modified: kupu/branch/guido-playground/tests/test_kupuhelpers.js
==============================================================================
--- kupu/branch/guido-playground/tests/test_kupuhelpers.js (original)
+++ kupu/branch/guido-playground/tests/test_kupuhelpers.js Wed Jul 14 00:32:56 2004
@@ -138,6 +138,7 @@
};
this.testReplaceWithNode = function() {
+ // XXX
return;
var node = this.document.createElement('p');
var nbsp = this.document.createTextNode('\xa0');
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic