forked from pjanik/orion.client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better content assist support for node.js.
We detect node.js files as those with the following jslint directive: /*jslint node:true */ For such files, content assist will now suggest appropriate globals. Furthermore, if a built-in node.js module is included via a require() call, content assist can make appropriate suggestions for the variable holding the return value of the call. The index file nodeIndex.js is still incomplete and a work in progress. Also includes related cleanup and improvement to various parts of the content assist code. Finally, add indexFileParsingTests.(html/js), with separate regression tests for our code for parsing index files. Signed-off-by: Manu Sridharan <msridhar@us.ibm.com>
- Loading branch information
Showing
10 changed files
with
2,300 additions
and
326 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
bundles/org.eclipse.orion.client.ui/web/js-tests/esprima/indexFileParsingTests.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | ||
"http://www.w3.org/TR/html4/loose.dtd"> | ||
<html> | ||
<head> | ||
<script src="../../orion/plugin.js"></script> | ||
<script src="../../requirejs/require.js"></script> | ||
<script> | ||
/*global window require */ | ||
require({ | ||
baseUrl: '../..', | ||
paths: { | ||
"scriptedLogger": "plugins/esprima/scriptedLogger", | ||
text: 'requirejs/text', | ||
i18n: 'requirejs/i18n', | ||
domReady: 'requirejs/domReady' | ||
} | ||
}); | ||
window.onload = function() { | ||
require(["orion/test","js-tests/esprima/indexFileParsingTests"], | ||
function(test, jsTests) { | ||
test.run(jsTests); | ||
}); | ||
}; | ||
</script> | ||
</head> | ||
<body> | ||
<h1>Unit tests for index file parsing</h1> | ||
</body> | ||
</html> |
159 changes: 159 additions & 0 deletions
159
bundles/org.eclipse.orion.client.ui/web/js-tests/esprima/indexFileParsingTests.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
/******************************************************************************* | ||
* @license | ||
* Copyright (c) 2012 VMware, Inc. All Rights Reserved. | ||
* Copyright (c) 2013 IBM Corporation. | ||
* | ||
* THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE | ||
* ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE | ||
* CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. | ||
* You can obtain a current copy of the Eclipse Public License from | ||
* http://www.opensource.org/licenses/eclipse-1.0.php | ||
* | ||
* Contributors: | ||
* Andrew Eisenberg (VMware) - initial API and implementation | ||
* Manu Sridharan (IBM) - Various improvements | ||
******************************************************************************/ | ||
|
||
/*global define esprima console setTimeout doctrine*/ | ||
define(["plugins/esprima/typesFromIndexFile", "plugins/esprima/typeEnvironment", "orion/assert"], function(mTypes, typeEnv, assert) { | ||
|
||
////////////////////////////////////////////////////////// | ||
// helpers | ||
////////////////////////////////////////////////////////// | ||
|
||
function testSig(ternSig, closureSig, constructorName) { | ||
assert.equal(mTypes.ternSig2ClosureSig(ternSig, constructorName), closureSig, "Bad conversion"); | ||
} | ||
|
||
function testType(type, name, expectedTypeInfo) { | ||
var result = mTypes.parseType(type, name); | ||
assert.equal(JSON.stringify(result.typeInfo), JSON.stringify(expectedTypeInfo), "Bad parse"); | ||
} | ||
|
||
function makeEnvironmentOptionsFromIndex(indexDataArr) { | ||
var options = {}; | ||
options.buffer = ""; | ||
options.uid = "0"; | ||
options.indexData = indexDataArr; | ||
return options; | ||
} | ||
|
||
function checkEnvironment(indexData, cb) { | ||
var options = makeEnvironmentOptionsFromIndex([indexData]); | ||
var envPromise = typeEnv.createEnvironment(options); | ||
var result = envPromise.then(cb); | ||
return result; | ||
} | ||
|
||
////////////////////////////////////////////////////////// | ||
// tests | ||
////////////////////////////////////////////////////////// | ||
|
||
var tests = {}; | ||
|
||
tests["test basic 1"] = function() { | ||
testSig("fn() -> String", "function():String"); | ||
}; | ||
|
||
tests["test basic 2"] = function() { | ||
testSig("fn(m: Number, n?: Number) -> Boolean", "function(m:Number,n:Number=):Boolean"); | ||
}; | ||
|
||
tests["test constructor 1"] = function() { | ||
// TODO is this really right? comma after Fizz? | ||
testSig("fn()", "function(new:Fizz):Fizz", "Fizz"); | ||
}; | ||
|
||
tests["test array of functions"] = function() { | ||
testSig("fn() -> [fn()]", "function():Array"); | ||
}; | ||
tests["test callback"] = function() { | ||
testSig("fn(cb: fn(x: Object) -> Object) -> Number", "function(cb:function(x:Object):Object):Number"); | ||
}; | ||
|
||
tests["test callback 2"] = function() { | ||
testSig("fn(cb: fn(x: Object) -> Object) -> fn(y: Object) -> Object", | ||
"function(cb:function(x:Object):Object):function(y:Object):Object"); | ||
}; | ||
|
||
tests["test callback 3"] = function() { | ||
testSig("fn(cb: fn(x: Object) -> fn(z: Object) -> Object, cb2: fn(p: Object) -> String) -> fn(y: Object) -> Object", | ||
"function(cb:function(x:Object):function(z:Object):Object,cb2:function(p:Object):String):function(y:Object):Object"); | ||
}; | ||
|
||
tests["test type 1"] = function() { | ||
var type = { | ||
fizz: "String", | ||
bazz: "Number" | ||
}; | ||
var expected = { | ||
"Foo": { | ||
"fizz": { | ||
"_typeObj": { | ||
"type": "NameExpression", | ||
"name": "String" | ||
} | ||
}, | ||
"bazz": { | ||
"_typeObj": { | ||
"type": "NameExpression", | ||
"name": "Number" | ||
} | ||
}, | ||
"$$isBuiltin": true | ||
} | ||
}; | ||
testType(type, "Foo", expected); | ||
}; | ||
|
||
tests["test type reference with dot"] = function() { | ||
var type = { | ||
foo: "+x.OtherType" | ||
}; | ||
var expected = { | ||
"Foo": { | ||
"foo": { | ||
"_typeObj": { | ||
"type": "NameExpression", | ||
"name": "x..OtherType..prototype" | ||
} | ||
}, | ||
"$$isBuiltin": true | ||
} | ||
}; | ||
testType(type, "Foo", expected); | ||
}; | ||
|
||
tests["test environment basic"] = function() { | ||
var index = { | ||
bizz: "String" | ||
}; | ||
return checkEnvironment(index, function (env) { | ||
assert.equal("String", env.lookupTypeObj("bizz").name, "bad environment"); | ||
}); | ||
}; | ||
|
||
tests["test environment prototype"] = function() { | ||
var index = { | ||
Fizz: { | ||
"!type": "fn(p:String)", | ||
prototype: { | ||
x: "String" | ||
} | ||
}, | ||
Buzz: { | ||
"!type": "fn(p:String)", | ||
prototype: { | ||
"!proto": "Fizz.prototype", | ||
y: "String" | ||
} | ||
} | ||
}; | ||
return checkEnvironment(index, function (env) { | ||
var t = env.lookupTypeObj("x", "Fizz..prototype"); | ||
// TODO figureout out what to check here!!! | ||
}); | ||
}; | ||
|
||
return tests; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.