summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorMike Rennie2013-12-09 13:57:04 (EST)
committer Gerrit Code Review @ Eclipse.org2013-12-09 14:59:32 (EST)
commit7c11e862dcc065b99be42103da364f5fa2d9f259 (patch)
treee266935db7a0aaf8abb53a0332352a93d8f47da1
parentfdc80d9dc49419854e880bcb57b613b69129c393 (diff)
downloadorg.eclipse.orion.client-7c11e862dcc065b99be42103da364f5fa2d9f259.zip
org.eclipse.orion.client-7c11e862dcc065b99be42103da364f5fa2d9f259.tar.gz
org.eclipse.orion.client-7c11e862dcc065b99be42103da364f5fa2d9f259.tar.bz2
Bug 422493 - Add unit test for the outlinerv20131209-1959refs/changes/25/19525/2
Change-Id: I2cb0f496b1b6d3afa107a78788dca9ce5d476cd4 Signed-off-by: Mike Rennie <Michael_Rennie@ca.ibm.com>
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/js-tests/outlinerTests.html10
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/js-tests/outlinerTests.js122
2 files changed, 112 insertions, 20 deletions
diff --git a/bundles/org.eclipse.orion.client.javascript/web/js-tests/outlinerTests.html b/bundles/org.eclipse.orion.client.javascript/web/js-tests/outlinerTests.html
index 585edc8..043f94c 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/js-tests/outlinerTests.html
+++ b/bundles/org.eclipse.orion.client.javascript/web/js-tests/outlinerTests.html
@@ -10,7 +10,8 @@
text: 'requirejs/text',
i18n: 'requirejs/i18n',
domReady: 'requirejs/domReady',
- estraverse: 'estraverse/estraverse'
+ estraverse: 'estraverse/estraverse',
+ esprima: 'esprima/esprima'
},
isTest: true
});
@@ -25,12 +26,7 @@
<body>
<h2>JavaScript Source Outline Tests</h2>
<p>
-This test suite provides the following tests:
-<ul>
-<li><strong></strong> - </li>
-<li><strong></strong> - </li>
-<li><strong></strong> - </li>
-</ul>
+This suite tests the <code>javascript.JSOutliner</code>
</p>
</body>
</html> \ No newline at end of file
diff --git a/bundles/org.eclipse.orion.client.javascript/web/js-tests/outlinerTests.js b/bundles/org.eclipse.orion.client.javascript/web/js-tests/outlinerTests.js
index 8da32de..8f8b28e 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/js-tests/outlinerTests.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/js-tests/outlinerTests.js
@@ -10,24 +10,120 @@
******************************************************************************/
/*global console:true define*/
define([
- "orion/assert"
-], function(assert) {
+ 'orion/assert',
+ 'javascript/astManager',
+ 'orion/Deferred',
+ 'javascript/outliner'
+], function(Assert, ASTManager, Deferred, Outliner) {
- var Tests = {
-
- test_funcDeclaration1: function() {
-
- },
-
- test_funcExpression1: function() {
-
- },
+ var astManager = new ASTManager();
+ var outliner = new Outliner.JSOutliner(astManager);
+ var context = {
+ text: "",
+ getText: function() {
+ return new Deferred().resolve(this.text);
+ }
+ };
- test_objExpression1: function() {
-
+ /**
+ * @name tearDown
+ * @description Resets the test state between runs, must explicitly be called per-test
+ * @function
+ * @public
+ */
+ function tearDown() {
+ context.text = "";
+ astManager.updated();
+ };
+
+ /**
+ * @name assertElement
+ * @description Checks the given element against the expected name, start and end to make sure it is outlined correctly
+ * @function
+ * @public
+ * @param {Object} element The computed outline element to check
+ * @param {String} label The expected outline label
+ * @param {Number} start The expected start offset of the element
+ * @param {Number} end The expected end offset of the element
+ */
+ function assertElement(element, label, start, end) {
+ if(!element) {
+ Assert.fail("The tested element cannot be null");
+ }
+ if(!element.label) {
+ Assert.fail("The outlined element must have a label");
+ }
+ if(!element.start) {
+ Assert.fail("The outlined element must have a start range");
}
+ if(!element.end) {
+ Assert.fail("The outlied element must have an end range");
+ }
+ Assert.equal(element.label, label, "The label is not the same");
+ Assert.equal(element.start, start, "The start range is not the same");
+ Assert.equal(element.end, end, "The end range is not the same");
+ };
+
+ var Tests = {};
+ /**
+ * Tests a function declaration
+ */
+ Tests.test_funcDeclaration1 = function() {
+ context.text = "function F1(p1, p2) {};";
+ return outliner.computeOutline(context).then(function(outline) {
+ try {
+ if(!outline || outline.length < 1) {
+ Assert.fail("There should be one outline element");
+ }
+ assertElement(outline[0], "F1(p1, p2)", 9, 11);
+ }
+ finally {
+ tearDown();
+ }
+ });
};
+ /**
+ * Tests a function expression
+ */
+ Tests.test_funcExpression1 = function() {
+ context.text = "var obj = {\n"+
+ "\titem: function(p1, p2) {}\n"+
+ "};";
+ return outliner.computeOutline(context).then(function(outline) {
+ try {
+ if(!outline || outline.length < 1) {
+ Assert.fail("There should be one outline element");
+ }
+ if(!outline[0].children || outline[0].children.length < 1) {
+ Assert.fail("There should be one child outline element");
+ }
+ assertElement(outline[0].children[0], "item(p1, p2)", 13, 17);
+ }
+ finally {
+ tearDown();
+ }
+ });
+ };
+
+ /**
+ * Tests an object expression
+ */
+ Tests.test_objExpression1 = function() {
+ context.text = "var object = {};";
+ return outliner.computeOutline(context).then(function(outline) {
+ try {
+ if(!outline || outline.length < 1) {
+ Assert.fail("There should be one outline element");
+ }
+ assertElement(outline[0], "var object = {...}", 4, 10);
+ }
+ finally {
+ tearDown();
+ }
+ });
+ };
+
return Tests;
}); \ No newline at end of file