/bundles/org.eclipse.orion.client.core/web/js-tests/esprima/esprimaJsContentAssistTests.js
JavaScript | 3061 lines | 2921 code | 70 blank | 70 comment | 37 complexity | 27560d996be7644d913843b1560fa467 MD5 | raw file
Possible License(s): BSD-3-Clause, BSD-2-Clause, Apache-2.0
Large files files are truncated, but you can click here to view the full file
- /*******************************************************************************
- * @license
- * Copyright (c) 2012 VMware, Inc. All Rights Reserved.
- * 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
- ******************************************************************************/
- /*global define esprima console setTimeout doctrine*/
- define(["plugins/esprima/esprimaJsContentAssist", "orion/assert", "esprima/esprima", "doctrine/doctrine"], function(mEsprimaPlugin, assert) {
-
- //////////////////////////////////////////////////////////
- // helpers
- //////////////////////////////////////////////////////////
- function computeContentAssist(buffer, prefix, offset, jsLintOptions) {
- if (!prefix) {
- prefix = "";
- }
- if (!offset) {
- offset = buffer.indexOf("/**/");
- if (offset < 0) {
- offset = buffer.length;
- }
- }
- var esprimaContentAssistant = new mEsprimaPlugin.EsprimaJavaScriptContentAssistProvider(null, jsLintOptions);
- return esprimaContentAssistant.computeProposals(buffer, offset, {prefix : prefix, inferredOnly : true });
- }
-
- function testProposal(proposal, text, description, prefix) {
- assert.equal(prefix + proposal.proposal, text, "Invalid proposal text");
- if (description) {
- assert.equal(proposal.description, description, "Invalid proposal description");
- }
- }
-
- function stringifyExpected(expectedProposals) {
- var text = "";
- for (var i = 0; i < expectedProposals.length; i++) {
- text += expectedProposals[i][0] + " : " + expectedProposals[i][1] + "\n";
- }
- return text;
- }
-
- function stringifyActual(actualProposals, prefix) {
- var text = "";
- for (var i = 0; i < actualProposals.length; i++) {
- text += prefix + actualProposals[i].proposal + " : " + actualProposals[i].description + "\n";
- }
- return text;
- }
-
- function testProposals(prefix, actualProposals, expectedProposals) {
- assert.equal(actualProposals.length, expectedProposals.length,
- "Wrong number of proposals. Expected:\n" + stringifyExpected(expectedProposals) +"\nActual:\n" + stringifyActual(actualProposals, prefix));
-
- for (var i = 0; i < actualProposals.length; i++) {
- testProposal(actualProposals[i], expectedProposals[i][0], expectedProposals[i][1], prefix);
- }
- }
- function parse(contents) {
- return esprima.parse(contents,{
- range: false,
- loc: false,
- tolerant: true
- });
- }
- function assertNoErrors(ast) {
- assert.ok(ast.errors===null || ast.errors.length===0,
- 'errors: '+ast.errors.length+'\n'+ast.errors);
- }
- function assertErrors(ast,expectedErrors) {
- var expectedErrorList = (expectedErrors instanceof Array ? expectedErrors: [expectedErrors]);
- var correctNumberOfErrors = ast.errors!==null && ast.errors.length===expectedErrorList.length;
- assert.ok(correctNumberOfErrors,'errors: '+ast.errors.length+'\n'+ast.errors);
- if (correctNumberOfErrors) {
- for (var e=0;e<expectedErrors.length;e++) {
- var expectedError = expectedErrorList[e];
- var actualError = ast.errors[e];
- assert.equal(actualError.lineNumber,expectedError.lineNumber,"checking line for message #"+(e+1)+": "+actualError);
- var actualMessage = actualError.message.replace(/Line [0-9]*: /,'');
- assert.equal(actualMessage,expectedError.message,"checking text for message #"+(e+1)+": "+actualError);
- }
- }
- }
- function stringify(parsedProgram) {
- var body = parsedProgram.body;
- if (body.length===1) {
- body=body[0];
- }
- var replacer = function(key,value) {
- if (key==='computed') {
- return;
- }
- return value;
- };
- return JSON.stringify(body,replacer).replace(/"/g,'');
- }
- function message(line, text) {
- return {
- lineNumber:line,
- message:text
- };
- }
- //////////////////////////////////////////////////////////
- // tests
- //////////////////////////////////////////////////////////
- var tests = {};
- tests.testEmpty = function() {};
- tests["test recovery basic parse"] = function() {
- var parsedProgram = parse("foo.bar");
- assertNoErrors(parsedProgram);
- assert.equal(stringify(parsedProgram),"{type:ExpressionStatement,expression:{type:MemberExpression,object:{type:Identifier,name:foo},property:{type:Identifier,name:bar}}}");
- };
- tests["test recovery - dot followed by EOF"] = function() {
- var parsedProgram = parse("foo.");
- assertErrors(parsedProgram,message(1,'Unexpected end of input'));
- assert.equal(stringify(parsedProgram),"{type:ExpressionStatement,expression:{type:MemberExpression,object:{type:Identifier,name:foo},property:null}}");
- };
- tests["test Empty Content Assist"] = function() {
- var results = computeContentAssist("x", "x");
- assert.equal(results.length, 0);
- };
-
- // non-inferencing content assist
- tests["test Empty File Content Assist"] = function() {
- var results = computeContentAssist("");
- testProposals("", results, [
- ["Array([val])", "Array([val]) : Array"],
- ["Boolean([val])", "Boolean([val]) : Boolean"],
- ["Date([val])", "Date([val]) : Date"],
- ["Error([err])", "Error([err]) : Error"],
- ["Function()", "Function() : Function"],
- ["Number([val])", "Number([val]) : Number"],
- ["Object([val])", "Object([val]) : Object"],
- ["RegExp([val])", "RegExp([val]) : RegExp"],
- ["decodeURI(uri)", "decodeURI(uri) : String"],
- ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
- ["encodeURI(uri)", "encodeURI(uri) : String"],
- ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
- ["eval(toEval)", "eval(toEval) : Object"],
- ["isFinite(num)", "isFinite(num) : Boolean"],
- ["isNaN(num)", "isNaN(num) : Boolean"],
- ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
- ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
- ["Infinity", "Infinity : Number"],
- ["JSON", "JSON : JSON"],
- ["Math", "Math : Math"],
- ["NaN", "NaN : Number"],
- ["this", "this : Global"],
- ["undefined", "undefined : undefined"],
- ["", "---------------------------------"],
- ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
- ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
- ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
- ["toLocaleString()", "toLocaleString() : String"],
- ["toString()", "toString() : String"],
- ["valueOf()", "valueOf() : Object"],
- ["prototype", "prototype : Object"]
- ]);
- };
- tests["test Single Var Content Assist"] = function() {
- var results = computeContentAssist("var zzz = 9;\n");
- testProposals("", results, [
- ["Array([val])", "Array([val]) : Array"],
- ["Boolean([val])", "Boolean([val]) : Boolean"],
- ["Date([val])", "Date([val]) : Date"],
- ["Error([err])", "Error([err]) : Error"],
- ["Function()", "Function() : Function"],
- ["Number([val])", "Number([val]) : Number"],
- ["Object([val])", "Object([val]) : Object"],
- ["RegExp([val])", "RegExp([val]) : RegExp"],
- ["decodeURI(uri)", "decodeURI(uri) : String"],
- ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
- ["encodeURI(uri)", "encodeURI(uri) : String"],
- ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
- ["eval(toEval)", "eval(toEval) : Object"],
- ["isFinite(num)", "isFinite(num) : Boolean"],
- ["isNaN(num)", "isNaN(num) : Boolean"],
- ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
- ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
- ["Infinity", "Infinity : Number"],
- ["JSON", "JSON : JSON"],
- ["Math", "Math : Math"],
- ["NaN", "NaN : Number"],
- ["this", "this : Global"],
- ["undefined", "undefined : undefined"],
- ["zzz", "zzz : Number"],
- ["", "---------------------------------"],
- ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
- ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
- ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
- ["toLocaleString()", "toLocaleString() : String"],
- ["toString()", "toString() : String"],
- ["valueOf()", "valueOf() : Object"],
- ["prototype", "prototype : Object"]
- ]);
- };
- tests["test Single Var Content Assist 2"] = function() {
- var results = computeContentAssist("var zzz;\n");
- testProposals("", results, [
- ["Array([val])", "Array([val]) : Array"],
- ["Boolean([val])", "Boolean([val]) : Boolean"],
- ["Date([val])", "Date([val]) : Date"],
- ["Error([err])", "Error([err]) : Error"],
- ["Function()", "Function() : Function"],
- ["Number([val])", "Number([val]) : Number"],
- ["Object([val])", "Object([val]) : Object"],
- ["RegExp([val])", "RegExp([val]) : RegExp"],
- ["decodeURI(uri)", "decodeURI(uri) : String"],
- ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
- ["encodeURI(uri)", "encodeURI(uri) : String"],
- ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
- ["eval(toEval)", "eval(toEval) : Object"],
- ["isFinite(num)", "isFinite(num) : Boolean"],
- ["isNaN(num)", "isNaN(num) : Boolean"],
- ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
- ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
- ["Infinity", "Infinity : Number"],
- ["JSON", "JSON : JSON"],
- ["Math", "Math : Math"],
- ["NaN", "NaN : Number"],
- ["this", "this : Global"],
- ["undefined", "undefined : undefined"],
- ["zzz", "zzz : Object"],
- ["", "---------------------------------"],
- ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
- ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
- ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
- ["toLocaleString()", "toLocaleString() : String"],
- ["toString()", "toString() : String"],
- ["valueOf()", "valueOf() : Object"],
- ["prototype", "prototype : Object"]
- ]);
- };
- tests["test multi var content assist 1"] = function() {
- var results = computeContentAssist("var zzz;\nvar xxx, yyy;\n");
- testProposals("", results, [
- ["Array([val])", "Array([val]) : Array"],
- ["Boolean([val])", "Boolean([val]) : Boolean"],
- ["Date([val])", "Date([val]) : Date"],
- ["Error([err])", "Error([err]) : Error"],
- ["Function()", "Function() : Function"],
- ["Number([val])", "Number([val]) : Number"],
- ["Object([val])", "Object([val]) : Object"],
- ["RegExp([val])", "RegExp([val]) : RegExp"],
- ["decodeURI(uri)", "decodeURI(uri) : String"],
- ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
- ["encodeURI(uri)", "encodeURI(uri) : String"],
- ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
- ["eval(toEval)", "eval(toEval) : Object"],
- ["isFinite(num)", "isFinite(num) : Boolean"],
- ["isNaN(num)", "isNaN(num) : Boolean"],
- ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
- ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
- ["Infinity", "Infinity : Number"],
- ["JSON", "JSON : JSON"],
- ["Math", "Math : Math"],
- ["NaN", "NaN : Number"],
- ["this", "this : Global"],
- ["undefined", "undefined : undefined"],
- ["xxx", "xxx : Object"],
- ["yyy", "yyy : Object"],
- ["zzz", "zzz : Object"],
- ["", "---------------------------------"],
- ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
- ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
- ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
- ["toLocaleString()", "toLocaleString() : String"],
- ["toString()", "toString() : String"],
- ["valueOf()", "valueOf() : Object"],
- ["prototype", "prototype : Object"]
- ]);
- };
- tests["test multi var content assist 2"] = function() {
- var results = computeContentAssist("var zzz;\nvar zxxx, xxx, yyy;\nz","z");
- testProposals("z", results, [
- ["zxxx", "zxxx : Object"],
- ["zzz", "zzz : Object"]
- ]);
- };
- tests["test single function content assist"] = function() {
- var results = computeContentAssist("function fun(a, b, c) {}\n");
- testProposals("", results, [
- ["Array([val])", "Array([val]) : Array"],
- ["Boolean([val])", "Boolean([val]) : Boolean"],
- ["Date([val])", "Date([val]) : Date"],
- ["Error([err])", "Error([err]) : Error"],
- ["Function()", "Function() : Function"],
- ["Number([val])", "Number([val]) : Number"],
- ["Object([val])", "Object([val]) : Object"],
- ["RegExp([val])", "RegExp([val]) : RegExp"],
- ["decodeURI(uri)", "decodeURI(uri) : String"],
- ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
- ["encodeURI(uri)", "encodeURI(uri) : String"],
- ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
- ["eval(toEval)", "eval(toEval) : Object"],
- ["fun(a, b, c)", "fun(a, b, c) : undefined"],
- ["isFinite(num)", "isFinite(num) : Boolean"],
- ["isNaN(num)", "isNaN(num) : Boolean"],
- ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
- ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
- ["Infinity", "Infinity : Number"],
- ["JSON", "JSON : JSON"],
- ["Math", "Math : Math"],
- ["NaN", "NaN : Number"],
- ["this", "this : Global"],
- ["undefined", "undefined : undefined"],
- ["", "---------------------------------"],
- ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
- ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
- ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
- ["toLocaleString()", "toLocaleString() : String"],
- ["toString()", "toString() : String"],
- ["valueOf()", "valueOf() : Object"],
- ["prototype", "prototype : Object"]
- ]);
- };
- tests["test multi function content assist 1"] = function() {
- var results = computeContentAssist("function fun(a, b, c) {}\nfunction other(a, b, c) {}\n");
- testProposals("", results, [
- ["Array([val])", "Array([val]) : Array"],
- ["Boolean([val])", "Boolean([val]) : Boolean"],
- ["Date([val])", "Date([val]) : Date"],
- ["Error([err])", "Error([err]) : Error"],
- ["Function()", "Function() : Function"],
- ["Number([val])", "Number([val]) : Number"],
- ["Object([val])", "Object([val]) : Object"],
- ["RegExp([val])", "RegExp([val]) : RegExp"],
- ["decodeURI(uri)", "decodeURI(uri) : String"],
- ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
- ["encodeURI(uri)", "encodeURI(uri) : String"],
- ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
- ["eval(toEval)", "eval(toEval) : Object"],
- ["fun(a, b, c)", "fun(a, b, c) : undefined"],
- ["isFinite(num)", "isFinite(num) : Boolean"],
- ["isNaN(num)", "isNaN(num) : Boolean"],
- ["other(a, b, c)", "other(a, b, c) : undefined"],
- ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
- ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
- ["Infinity", "Infinity : Number"],
- ["JSON", "JSON : JSON"],
- ["Math", "Math : Math"],
- ["NaN", "NaN : Number"],
- ["this", "this : Global"],
- ["undefined", "undefined : undefined"],
- ["", "---------------------------------"],
- ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
- ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
- ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
- ["toLocaleString()", "toLocaleString() : String"],
- ["toString()", "toString() : String"],
- ["valueOf()", "valueOf() : Object"],
- ["prototype", "prototype : Object"]
- ]);
- };
-
- tests["test no dupe 1"] = function() {
- var results = computeContentAssist(
- "var foo = 9; var other = function(foo) { f/**/ }", "f");
- testProposals("f", results, [
- ["foo", "foo : { }"]
- ]);
- };
-
- tests["test no dupe 2"] = function() {
- var results = computeContentAssist(
- "var foo = { }; var other = function(foo) { foo = 9;\nf/**/ }", "f");
- testProposals("f", results, [
- ["foo", "foo : Number"]
- ]);
- };
-
- tests["test no dupe 3"] = function() {
- var results = computeContentAssist(
- "var foo = function () { var foo = 9; \n f/**/};", "f");
- testProposals("f", results, [
- ["foo", "foo : Number"]
- ]);
- };
-
- tests["test no dupe 4"] = function() {
- var results = computeContentAssist(
- "var foo = 9; var other = function () { var foo = function() { return 9; }; \n f/**/};", "f");
- testProposals("f", results, [
- ["foo()", "foo() : Number"]
- ]);
- };
-
- tests["test scopes 1"] = function() {
- // only the outer foo is available
- var results = computeContentAssist(
- "var foo;\nfunction other(a, b, c) {\nfunction inner() { var foo2; }\nf/**/}", "f");
- testProposals("f", results, [
- ["foo", "foo : Object"]
- ]);
- };
- tests["test scopes 2"] = function() {
- // the inner assignment should not affect the value of foo
- var results = computeContentAssist("var foo;\n" +
- "var foo = 1;\nfunction other(a, b, c) {\nfunction inner() { foo2 = \"\"; }\nfoo.toF/**/}", "toF");
- testProposals("toF", results, [
- ["toFixed(digits)", "toFixed(digits) : Number"]
- ]);
- };
- tests["test multi function content assist 2"] = function() {
- var results = computeContentAssist("function fun(a, b, c) {}\nfunction other(a, b, c) {}\nf", "f");
- testProposals("f", results, [
- ["fun(a, b, c)", "fun(a, b, c) : undefined"]
- ]);
- };
- tests["test in function 1"] = function() {
- var results = computeContentAssist("function fun(a, b, c) {}\nfunction other(a, b, c) {/**/}", "");
- testProposals("", results, [
- ["a", "a : { }"],
- ["arguments", "arguments : Arguments"],
- ["b", "b : { }"],
- ["c", "c : { }"],
- ["", "---------------------------------"],
- ["Array([val])", "Array([val]) : Array"],
- ["Boolean([val])", "Boolean([val]) : Boolean"],
- ["Date([val])", "Date([val]) : Date"],
- ["Error([err])", "Error([err]) : Error"],
- ["Function()", "Function() : Function"],
- ["Number([val])", "Number([val]) : Number"],
- ["Object([val])", "Object([val]) : Object"],
- ["RegExp([val])", "RegExp([val]) : RegExp"],
- ["decodeURI(uri)", "decodeURI(uri) : String"],
- ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
- ["encodeURI(uri)", "encodeURI(uri) : String"],
- ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
- ["eval(toEval)", "eval(toEval) : Object"],
- ["fun(a, b, c)", "fun(a, b, c) : undefined"],
- ["isFinite(num)", "isFinite(num) : Boolean"],
- ["isNaN(num)", "isNaN(num) : Boolean"],
- ["other(a, b, c)", "other(a, b, c) : undefined"],
- ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
- ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
- ["Infinity", "Infinity : Number"],
- ["JSON", "JSON : JSON"],
- ["Math", "Math : Math"],
- ["NaN", "NaN : Number"],
- ["this", "this : Global"],
- ["undefined", "undefined : undefined"],
- ["", "---------------------------------"],
- ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
- ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
- ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
- ["toLocaleString()", "toLocaleString() : String"],
- ["toString()", "toString() : String"],
- ["valueOf()", "valueOf() : Object"],
- ["prototype", "prototype : Object"]
- ]);
- };
- tests["test in function 2"] = function() {
- var results = computeContentAssist("function fun(a, b, c) {}\nfunction other(a, b, c) {\n/**/nuthin}", "");
- testProposals("", results, [
- ["a", "a : { }"],
- ["arguments", "arguments : Arguments"],
- ["b", "b : { }"],
- ["c", "c : { }"],
- ["", "---------------------------------"],
- ["Array([val])", "Array([val]) : Array"],
- ["Boolean([val])", "Boolean([val]) : Boolean"],
- ["Date([val])", "Date([val]) : Date"],
- ["Error([err])", "Error([err]) : Error"],
- ["Function()", "Function() : Function"],
- ["Number([val])", "Number([val]) : Number"],
- ["Object([val])", "Object([val]) : Object"],
- ["RegExp([val])", "RegExp([val]) : RegExp"],
- ["decodeURI(uri)", "decodeURI(uri) : String"],
- ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
- ["encodeURI(uri)", "encodeURI(uri) : String"],
- ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
- ["eval(toEval)", "eval(toEval) : Object"],
- ["fun(a, b, c)", "fun(a, b, c) : undefined"],
- ["isFinite(num)", "isFinite(num) : Boolean"],
- ["isNaN(num)", "isNaN(num) : Boolean"],
- ["other(a, b, c)", "other(a, b, c) : undefined"],
- ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
- ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
- ["Infinity", "Infinity : Number"],
- ["JSON", "JSON : JSON"],
- ["Math", "Math : Math"],
- ["NaN", "NaN : Number"],
- ["this", "this : Global"],
- ["undefined", "undefined : undefined"],
- ["", "---------------------------------"],
- ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
- ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
- ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
- ["toLocaleString()", "toLocaleString() : String"],
- ["toString()", "toString() : String"],
- ["valueOf()", "valueOf() : Object"],
- ["prototype", "prototype : Object"]
- ]);
- };
- tests["test in function 3"] = function() {
- var results = computeContentAssist("function fun(a, b, c) {}\nfunction other(a, b, c) {f/**/}", "f");
- testProposals("f", results, [
- ["fun(a, b, c)", "fun(a, b, c) : undefined"]
- ]);
- };
- tests["test in function 4"] = function() {
- var results = computeContentAssist("function fun(a, b, c) {}\nfunction other(aa, ab, c) {a/**/}", "a");
- testProposals("a", results, [
- ["aa", "aa : { }"],
- ["ab", "ab : { }"],
- ["arguments", "arguments : Arguments"]
- ]);
- };
- tests["test in function 5"] = function() {
- // should not see 'aaa' since that is declared later
- var results = computeContentAssist("function fun(a, b, c) {}\nfunction other(aa, ab, c) {var abb;\na/**/\nvar aaa}", "a");
- testProposals("a", results, [
- ["abb", "abb : Object"],
- ["a", "---------------------------------"],
- ["aa", "aa : { }"],
- ["ab", "ab : { }"],
- ["arguments", "arguments : Arguments"]
- ]);
- };
- tests["test in function 6"] = function() {
- // should not see 'aaa' since that is declared later
- var results = computeContentAssist(
- "function fun(a, b, c) {\n" +
- "function other(aa, ab, c) {\n"+
- "var abb;\na/**/\nvar aaa\n}\n}", "a");
- testProposals("a", results, [
- ["abb", "abb : Object"],
- ["a", "---------------------------------"],
- ["aa", "aa : { }"],
- ["ab", "ab : { }"],
- ["arguments", "arguments : Arguments"],
- ["a", "---------------------------------"],
- ["a", "a : { }"]
- ]);
- };
- tests["test in function 7"] = function() {
- // should not see 'aaa' since that is declared later
- var results = computeContentAssist(
- "function fun(a, b, c) {/**/\n" +
- "function other(aa, ab, ac) {\n"+
- "var abb;\na\nvar aaa\n}\n}");
- testProposals("", results, [
- ["other(aa, ab, ac)", "other(aa, ab, ac) : undefined"],
- ["", "---------------------------------"],
- ["a", "a : { }"],
- ["arguments", "arguments : Arguments"],
- ["b", "b : { }"],
- ["c", "c : { }"],
- ["", "---------------------------------"],
- ["Array([val])", "Array([val]) : Array"],
- ["Boolean([val])", "Boolean([val]) : Boolean"],
- ["Date([val])", "Date([val]) : Date"],
- ["Error([err])", "Error([err]) : Error"],
- ["Function()", "Function() : Function"],
- ["Number([val])", "Number([val]) : Number"],
- ["Object([val])", "Object([val]) : Object"],
- ["RegExp([val])", "RegExp([val]) : RegExp"],
- ["decodeURI(uri)", "decodeURI(uri) : String"],
- ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
- ["encodeURI(uri)", "encodeURI(uri) : String"],
- ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
- ["eval(toEval)", "eval(toEval) : Object"],
- ["fun(a, b, c)", "fun(a, b, c) : undefined"],
- ["isFinite(num)", "isFinite(num) : Boolean"],
- ["isNaN(num)", "isNaN(num) : Boolean"],
- ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
- ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
- ["Infinity", "Infinity : Number"],
- ["JSON", "JSON : JSON"],
- ["Math", "Math : Math"],
- ["NaN", "NaN : Number"],
- ["this", "this : Global"],
- ["undefined", "undefined : undefined"],
- ["", "---------------------------------"],
- ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
- ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
- ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
- ["toLocaleString()", "toLocaleString() : String"],
- ["toString()", "toString() : String"],
- ["valueOf()", "valueOf() : Object"],
- ["prototype", "prototype : Object"]
- ]);
- };
- tests["test in function 8"] = function() {
- // should not see 'aaa' since that is declared later
- var results = computeContentAssist(
- "function fun(a, b, c) {\n" +
- "function other(aa, ab, ac) {\n"+
- "var abb;\na\nvar aaa\n} /**/\n}");
- testProposals("", results, [
- ["other(aa, ab, ac)", "other(aa, ab, ac) : undefined"],
- ["", "---------------------------------"],
- ["a", "a : { }"],
- ["arguments", "arguments : Arguments"],
- ["b", "b : { }"],
- ["c", "c : { }"],
- ["", "---------------------------------"],
- ["Array([val])", "Array([val]) : Array"],
- ["Boolean([val])", "Boolean([val]) : Boolean"],
- ["Date([val])", "Date([val]) : Date"],
- ["Error([err])", "Error([err]) : Error"],
- ["Function()", "Function() : Function"],
- ["Number([val])", "Number([val]) : Number"],
- ["Object([val])", "Object([val]) : Object"],
- ["RegExp([val])", "RegExp([val]) : RegExp"],
- ["decodeURI(uri)", "decodeURI(uri) : String"],
- ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
- ["encodeURI(uri)", "encodeURI(uri) : String"],
- ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
- ["eval(toEval)", "eval(toEval) : Object"],
- ["fun(a, b, c)", "fun(a, b, c) : undefined"],
- ["isFinite(num)", "isFinite(num) : Boolean"],
- ["isNaN(num)", "isNaN(num) : Boolean"],
- ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
- ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
- ["Infinity", "Infinity : Number"],
- ["JSON", "JSON : JSON"],
- ["Math", "Math : Math"],
- ["NaN", "NaN : Number"],
- ["this", "this : Global"],
- ["undefined", "undefined : undefined"],
- ["", "---------------------------------"],
- ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
- ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
- ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
- ["toLocaleString()", "toLocaleString() : String"],
- ["toString()", "toString() : String"],
- ["valueOf()", "valueOf() : Object"],
- ["prototype", "prototype : Object"]
- ]);
- };
-
-
- // all inferencing based content assist tests here
- tests["test Object inferencing with Variable"] = function() {
- var results = computeContentAssist("var t = {}\nt.h", "h");
- testProposals("h", results, [
- ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"]
- ]);
- };
- tests["test Object Literal inferencing"] = function() {
- var results = computeContentAssist("var t = { hhh : 1, hh2 : 8}\nt.h", "h");
- testProposals("h", results, [
- ["hh2", "hh2 : Number"],
- ["hhh", "hhh : Number"],
- ["h", "---------------------------------"],
- ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"]
- ]);
- };
- tests["test Simple String inferencing"] = function() {
- var results = computeContentAssist("''.char", "char");
- testProposals("char", results, [
- ["charAt(index)", "charAt(index) : String"],
- ["charCodeAt(index)", "charCodeAt(index) : Number"]
- ]);
- };
- tests["test Simple Date inferencing"] = function() {
- var results = computeContentAssist("new Date().setD", "setD");
- testProposals("setD", results, [
- ["setDate(date)", "setDate(date) : Number"],
- ["setDay(dayOfWeek)", "setDay(dayOfWeek) : Number"]
- ]);
- };
- tests["test Number inferencing with Variable"] = function() {
- var results = computeContentAssist("var t = 1\nt.to", "to");
- testProposals("to", results, [
- ["toExponential(digits)", "toExponential(digits) : Number"],
- ["toFixed(digits)", "toFixed(digits) : Number"],
- ["toPrecision(digits)", "toPrecision(digits) : Number"],
- ["to", "---------------------------------"],
- ["toLocaleString()", "toLocaleString() : String"],
- ["toString()", "toString() : String"]
- ]);
- };
-
- tests["test Data flow Object Literal inferencing"] = function() {
- var results = computeContentAssist("var s = { hhh : 1, hh2 : 8}\nvar t = s;\nt.h", "h");
- testProposals("h", results, [
- ["hh2", "hh2 : Number"],
- ["hhh", "hhh : Number"],
- ["h", "---------------------------------"],
- ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"]
- ]);
- };
- tests["test Data flow inferencing 1"] = function() {
- var results = computeContentAssist("var ttt = 9\nttt.toF", "toF");
- testProposals("toF", results, [
- ["toFixed(digits)", "toFixed(digits) : Number"]
- ]);
- };
- tests["test Data flow inferencing 2"] = function() {
- var results = computeContentAssist("ttt = 9\nttt.toF", "toF");
- testProposals("toF", results, [
- ["toFixed(digits)", "toFixed(digits) : Number"]
- ]);
- };
- tests["test Data flow inferencing 3"] = function() {
- var results = computeContentAssist("var ttt = \"\"\nttt = 9\nttt.toF", "toF");
- testProposals("toF", results, [
- ["toFixed(digits)", "toFixed(digits) : Number"]
- ]);
- };
- tests["test Data flow inferencing 4"] = function() {
- var results = computeContentAssist("var name = toString(property.key.value);\nname.co", "co");
- testProposals("co", results, [
- ["concat(array)", "concat(array) : String"]
- ]);
- };
-
- tests["test Simple this"] = function() {
- var results = computeContentAssist("var ssss = 4;\nthis.ss", "ss");
- testProposals("ss", results, [
- ["ssss", "ssss : Number"]
- ]);
- };
-
- tests["test Object Literal inside"] = function() {
- var results = computeContentAssist("var x = { the : 1, far : this.th/**/ };", "th");
- testProposals("th", results, [
- // type is 'Object' here, not number, since inside the object literal, we don't
- // know the types of literal fields
- ["the", "the : Object"]
- ]);
- };
- tests["test Object Literal outside"] = function() {
- var results = computeContentAssist("var x = { the : 1, far : 2 };\nx.th", "th");
- testProposals("th", results, [
- ["the", "the : Number"]
- ]);
- };
- tests["test Object Literal none"] = function() {
- var results = computeContentAssist("var x = { the : 1, far : 2 };\nthis.th", "th");
- testProposals("th", results, [
- ]);
- };
- tests["test Object Literal outside 2"] = function() {
- var results = computeContentAssist("var x = { the : 1, far : 2 };\nvar who = x.th", "th");
- testProposals("th", results, [
- ["the", "the : Number"]
- ]);
- };
- tests["test Object Literal outside 3"] = function() {
- var results = computeContentAssist("var x = { the : 1, far : 2 };\nwho(x.th/**/)", "th");
- testProposals("th", results, [
- ["the", "the : Number"]
- ]);
- };
- tests["test Object Literal outside 4"] = function() {
- var results = computeContentAssist("var x = { the : 1, far : 2 };\nwho(yyy, x.th/**/)", "th");
- testProposals("th", results, [
- ["the", "the : Number"]
- ]);
- };
- tests["test this reference 1"] = function() {
- var results = computeContentAssist("var xxxx;\nthis.x", "x");
- testProposals("x", results, [
- ["xxxx", "xxxx : Object"]
- ]);
- };
- tests["test binary expression 1"] = function() {
- var results = computeContentAssist("(1+3).toF", "toF");
- testProposals("toF", results, [
- ["toFixed(digits)", "toFixed(digits) : Number"]
- ]);
- };
-
- // not working since for loop is not storing slocs of var ii
- tests["test for loop 1"] = function() {
- var results = computeContentAssist("for (var ii=0;i/**/<8;ii++) { ii }", "i");
- testProposals("i", results, [
- ["isFinite(num)", "isFinite(num) : Boolean"],
- ["isNaN(num)", "isNaN(num) : Boolean"],
- ["ii", "ii : Number"],
- ["i", "---------------------------------"],
- ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"]
- ]);
- };
- tests["test for loop 2"] = function() {
- var results = computeContentAssist("for (var ii=0;ii<8;i/**/++) { ii }", "i");
- testProposals("i", results, [
- ["isFinite(num)", "isFinite(num) : Boolean"],
- ["isNaN(num)", "isNaN(num) : Boolean"],
- ["ii", "ii : Number"],
- ["i", "---------------------------------"],
- ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"]
- ]);
- };
- tests["test for loop 3"] = function() {
- var results = computeContentAssist("for (var ii=0;ii<8;ii++) { i/**/ }", "i");
- testProposals("i", results, [
- ["isFinite(num)", "isFinite(num) : Boolean"],
- ["isNaN(num)", "isNaN(num) : Boolean"],
- ["ii", "ii : Number"],
- ["i", "---------------------------------"],
- ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"]
- ]);
- };
- tests["test while loop 1"] = function() {
- var results = computeContentAssist("var iii;\nwhile(ii/**/ === null) {\n}", "ii");
- testProposals("ii", results, [
- ["iii", "iii : Object"]
- ]);
- };
- tests["test while loop 2"] = function() {
- var results = computeContentAssist("var iii;\nwhile(this.ii/**/ === null) {\n}", "ii");
- testProposals("ii", results, [
- ["iii", "iii : Object"]
- ]);
- };
- tests["test while loop 3"] = function() {
- var results = computeContentAssist("var iii;\nwhile(iii === null) {this.ii/**/\n}", "ii");
- testProposals("ii", results, [
- ["iii", "iii : Object"]
- ]);
- };
- tests["test catch clause 1"] = function() {
- var results = computeContentAssist("try { } catch (eee) {e/**/ }", "e");
- testProposals("e", results, [
- ["eee", "eee : Error"],
- ["e", "---------------------------------"],
- ["encodeURI(uri)", "encodeURI(uri) : String"],
- ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
- ["eval(toEval)", "eval(toEval) : Object"]
- ]);
- };
- tests["test catch clause 2"] = function() {
- // the type of the catch variable is Error
- var results = computeContentAssist("try { } catch (eee) {\neee.me/**/ }", "me");
- testProposals("me", results, [
- ["message", "message : String"]
- ]);
- };
-
-
- tests["test get global var"] = function() {
- // should infer that we are referring to the globally defined xxx, not the param
- var results = computeContentAssist("var xxx = 9;\nfunction fff(xxx) { this.xxx.toF/**/}", "toF");
- testProposals("toF", results, [
- ["toFixed(digits)", "toFixed(digits) : Number"]
- ]);
- };
-
- tests["test get local var"] = function() {
- // should infer that we are referring to the locally defined xxx, not the global
- var results = computeContentAssist("var xxx = 9;\nfunction fff(xxx) { xxx.toF/**/}", "toF");
- testProposals("toF", results, [
- ]);
- };
- tests["test Math 1"] = function() {
- var results = computeContentAssist("Mat", "Mat");
- testProposals("Mat", results, [
- ["Math", "Math : Math"]
- ]);
- };
- tests["test Math 2"] = function() {
- var results = computeContentAssist("this.Mat", "Mat");
- testProposals("Mat", results, [
- ["Math", "Math : Math"]
- ]);
- };
- tests["test Math 3"] = function() {
- // Math not available when this isn't the global this
- var results = computeContentAssist("var ff = { f: this.Mat/**/ }", "Mat");
- testProposals("Mat", results, [
- ]);
- };
- tests["test Math 4"] = function() {
- var results = computeContentAssist("this.Math.E", "E");
- testProposals("E", results, [
- ["E", "E : Number"]
- ]);
- };
- tests["test JSON 4"] = function() {
- var results = computeContentAssist("this.JSON.st", "st");
- testProposals("st", results, [
- ["stringify(obj)", "stringify(obj) : String"]
- ]);
- };
- tests["test multi-dot inferencing 1"] = function() {
- var results = computeContentAssist("var a = \"\";\na.charAt().charAt().charAt().ch", "ch");
- testProposals("ch", results, [
- ["charAt(index)", "charAt(index) : String"],
- ["charCodeAt(index)", "charCodeAt(index) : Number"]
- ]);
- };
- tests["test multi-dot inferencing 2"] = function() {
- var results = computeContentAssist(
- "var zz = {};\nzz.zz = zz;\nzz.zz.zz.z", "z");
- testProposals("z", results, [
- ["zz", "zz : { zz : { zz : {...} } }"]
- ]);
- };
- tests["test multi-dot inferencing 3"] = function() {
- var results = computeContentAssist(
- "var x = { yy : { } };\nx.yy.zz = 1;\nx.yy.z", "z");
- testProposals("z", results, [
- ["zz", "zz : Number"]
- ]);
- };
- tests["test multi-dot inferencing 4"] = function() {
- var results = computeContentAssist(
- "var x = { yy : { } };\nx.yy.zz = 1;\nx.yy.zz.toF", "toF");
- testProposals("toF", results, [
- ["toFixed(digits)", "toFixed(digits) : Number"]
- ]);
- };
- tests["test constructor 1"] = function() {
- var results = computeContentAssist(
- "function Fun() {\n this.xxx = 9;\n this.uuu = this.x/**/;}", "x");
- testProposals("x", results, [
- ["xxx", "xxx : Number"]
- ]);
- };
- tests["test constructor 2"] = function() {
- var results = computeContentAssist(
- "function Fun() { this.xxx = 9; this.uuu = this.xxx; }\n" +
- "var y = new Fun();\n" +
- "y.x", "x");
- testProposals("x", results, [
- ["xxx", "xxx : Number"]
- ]);
- };
- tests["test constructor 3"] = function() {
- var results = computeContentAssist(
- "function Fun() { this.xxx = 9; this.uuu = this.xxx; }\n" +
- "var y = new Fun();\n" +
- "y.xxx.toF", "toF");
- testProposals("toF", results, [
- ["toFixed(digits)", "toFixed(digits) : Number"]
- ]);
- };
- tests["test constructor 3"] = function() {
- var results = computeContentAssist(
- "function Fun() { this.xxx = 9; this.uuu = this.xxx; }\n" +
- "var y = new Fun();\n" +
- "y.uuu.toF", "toF");
- testProposals("toF", results, [
- ["toFixed(digits)", "toFixed(digits) : Number"]
- ]);
- };
-
- tests["test constructor 4"] = function() {
- var results = computeContentAssist(
- "var Fun = function () { this.xxx = 9; this.uuu = this.xxx; }\n" +
- "var y = new Fun();\n" +
- "y.uuu.toF", "toF");
- testProposals("toF", results, [
- ["toFixed(digits)", "toFixed(digits) : Number"]
- ]);
- };
-
- tests["test constructor 5"] = function() {
- var results = computeContentAssist(
- "var x = { Fun : function () { this.xxx = 9; this.uuu = this.xxx; } }\n" +
- "var y = new x.Fun();\n" +
- "y.uuu.toF", "toF");
- testProposals("toF", results, [
- ["toFixed(digits)", "toFixed(digits) : Number"]
- ]);
- };
-
- tests["test constructor 6"] = function() {
- var results = computeContentAssist(
- "var x = { Fun : function () { this.xxx = 9; this.uuu = this.xxx; } }\n" +
- "var y = new x.Fun().uuu.toF", "toF");
- testProposals("toF", results, [
- ["toFixed(digits)", "toFixed(digits) : Number"]
- ]);
- };
-
- tests["test constructor 7"] = function() {
- var results = computeContentAssist(
- "var Fun = function () { this.xxx = 9; this.uuu = this.xxx; }\n" +
- "var x = { Fun : Fun };\n" +
- "var y = new x.Fun();\n" +
- "y.uuu.toF", "toF");
- testProposals("toF", results, [
- ["toFixed(digits)", "toFixed(digits) : Number"]
- ]);
- };
-
- tests["test constructor 8"] = function() {
- var results = computeContentAssist(
- "var FunOrig = function () { this.xxx = 9; this.uuu = this.xxx; }\n" +
- "var x = { Fun : FunOrig };\n" +
- "var y = new x.Fun();\n" +
- "y.uuu.toF", "toF");
- testProposals("toF", results, [
- ["toFixed(digits)", "toFixed(digits) : Number"]
- ]);
- };
-
- // functions should not be available outside the scope that declares them
- tests["test constructor 9"] = function() {
- var results = computeContentAssist(
- "function outer() { function Inner() { }}\n" +
- "Inn", "Inn");
- testProposals("Inn", results, [
- // TODO FIXADE adding all constructors to global scope. not correct
- ["Inner()", "Inner() : Inner"]
- ]);
- };
-
- // should be able to reference functions using qualified name
- tests["test constructor 10"] = function() {
- var results = computeContentAssist(
- "var outer = { Inner : function() { }}\n" +
- "outer.Inn", "Inn");
- testProposals("Inn", results, [
- ["Inner()", "Inner() : outer.Inner"]
- ]);
- };
-
- tests["test Function args 1"] = function() {
- var results = computeContentAssist(
- "var ttt, uuu;\nttt(/**/)");
- testProposals("", results, [
- ["Array([val])", "Array([val]) : Array"],
- ["Boolean([val])", "Boolean([val]) : Boolean"],
- ["Date([val])", "Date([val]) : Date"],
- ["Error([err])", "Error([err]) : Error"],
- ["Function()", "Function() : Function"],
- ["Number([val])", "Number([val]) : Number"],
- ["Object([val])", "Object([val]) : Object"],
- ["RegExp([val])", "RegExp([val]) : RegExp"],
- ["decodeURI(uri)", "decodeURI(uri) : String"],
- ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
- ["encodeURI(uri)", "encodeURI(uri) : String"],
- ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
- ["eval(toEval)", "eval(toEval) : Object"],
- ["isFinite(num)", "isFinite(num) : Boolean"],
- ["isNaN(num)", "isNaN(num) : Boolean"],
- ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
- ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
- ["Infinity", "Infinity : Number"],
- ["JSON", "JSON : JSON"],
- ["Math", "Math : Math"],
- ["NaN", "NaN : Number"],
- ["this", "this : Global"],
- ["ttt", "ttt : Object"],
- ["undefined", "undefined : undefined"],
- ["uuu", "uuu : Object"],
- ["", "---------------------------------"],
- ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
- ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
- ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
- ["toLocaleString()", "toLocaleString() : String"],
- ["toString()", "toString() : String"],
- ["valueOf()", "valueOf() : Object"],
- ["prototype", "prototype : Object"]
- ]);
- };
- tests["test Function args 2"] = function() {
- var results = computeContentAssist(
- "var ttt, uuu;\nttt(ttt, /**/)");
- testProposals("", results, [
- ["Array([val])", "Array([val]) : Array"],
- ["Boolean([val])", "Boolean([val]) : Boolean"],
- ["Date([val])", "Date([val]) : Date"],
- ["Error([err])", "Error([err]) : Error"],
- ["Function()", "Function() : Function"],
- ["Number([val])", "Number([val]) : Number"],
- ["Object([val])", "Object([val]) : Object"],
- ["RegExp([val])", "RegExp([val]) : RegExp"],
- ["decodeURI(uri)", "decodeURI(uri) : String"],
- ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
- ["encodeURI(uri)", "encodeURI(uri) : String"],
- ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
- ["eval(toEval)", "eval(toEval) : Object"],
- ["isFinite(num)", "isFinite(num) : Boolean"],
- ["isNaN(num)", "isNaN(num) : Boolean"],
- ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
- ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
- ["Infinity", "Infinity : Number"],
- ["JSON", "JSON : JSON"],
- ["Math", "Math : Math"],
- ["NaN", "NaN : Number"],
- ["this", "this : Global"],
- ["ttt", "ttt : Object"],
- ["undefined", "undefined : undefined"],
- ["uuu", "uuu : Object"],
- ["", "---------------------------------"],
- ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
- ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
- ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
- ["toLocaleString()", "toLocaleString() : String"],
- ["toString()", "toString() : String"],
- ["valueOf()", "valueOf() : Object"],
- ["prototype", "prototype : Object"]
- ]);
- };
- tests["test Function args 3"] = function() {
- var results = computeContentAssist(
- "var ttt, uuu;\nttt(ttt, /**/, uuu)");
- testProposals("", results, [
- ["Array([val])", "Array([val]) : Array"],
- ["Boolean([val])", "Boolean([val]) : Boolean"],
- ["Date([val])", "Date([val]) : Date"],
- ["Error([err])", "Error([err]) : Error"],
- ["Function()", "Function() : Function"],
- ["Number([val])", "Number([val]) : Number"],
- ["Object([val])", "Object([val]) : Object"],
- ["RegExp([val])", "RegExp([val]) : RegExp"],
- ["decodeURI(uri)", "decodeURI(uri) : String"],
- ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
- ["encodeURI(uri)", "encodeURI(uri) : String"],
- ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
- ["eval(toEval)", "eval(toEval) : Object"],
- ["isFinite(num)", "isFinite(num) : Boolean"],
- ["isNaN(num)", "isNaN(num) : Boolean"],
- ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
- ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
- ["Infinity", "Infinity : Number"],
- ["JSON", "JSON : JSON"],
- ["Math", "Math : Math"],
- ["NaN", "NaN : Number"],
- ["this", "this : Global"],
- ["ttt", "ttt : Object"],
- ["undefined", "undefined : undefined"],
- ["uuu", "uuu : Object"],
- ["", "---------------------------------"],
- ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
- ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
- ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
- ["toLocaleString()", "toLocaleString() : String"],
- ["toString()", "toString() : String"],
- ["valueOf()", "valueOf() : Object"],
- ["prototype", "prototype : Object"]
- ]);
- };
-
- // check that function args don't get assigned the same type
- tests["test function args 4"] = function() {
- var results = computeContentAssist(
- "function tt(aaa, bbb) { aaa.foo = 9;bbb.foo = ''\naaa.f/**/}", "f");
- testProposals("f", results, [
- ["foo", "foo : Number"]
- ]);
- };
-
- // check that function args don't get assigned the same type
- tests["test function args 5"] = function() {
- var results = computeContentAssist(
- "function tt(aaa, bbb) { aaa.foo = 9;bbb.foo = ''\nbbb.f/**/}", "f");
- testProposals("f", results, [
- ["foo", "foo : String"]
- ]);
- };
-
- // FIXADE failing since we do not handle constructors that are not identifiers
- // tests["test constructor 5"] = function() {
- // var results = computeContentAssist(
- // "var obj = { Fun : function() { this.xxx = 9; this.uuu = this.xxx; } }\n" +
- // "var y = new obj.Fun();\n" +
- // "y.uuu.toF", "toF");
- // testProposals(results, [
- // ["toFixed(digits)", "toFixed(digits) : Number"]
- // ]);
- // };
- tests["test constructor 6"] = function() {
- var results = computeContentAssist(
- "function Fun2() {\n" +
- "function Fun() { this.xxx = 9; this.uuu = this.xxx; }\n" +
- "var y = new Fun();\n" +
- "y.uuu.toF/**/}", "toF");
- testProposals("toF", results, [
- ["toFixed(digits)", "toFixed(digits) : Number"]
- ]);
- };
-
-
- tests["test nested object expressions 1"] = function() {
- var results = computeContentAssist(
- "var ttt = { xxx : { yyy : { zzz : 1} } };\n" +
- "ttt.xxx.y", "y");
- testProposals("y", results, [
- ["yyy", "yyy : { zzz : Number }"]
- ]);
- };
- tests["test nested object expressions 2"] = function() {
- var results = computeContentAssist(
- "var ttt = { xxx : { yyy : { zzz : 1} } };\n" +
- "ttt.xxx.yyy.z", "z");
- testProposals("z", results, [
- ["zzz", "zzz : Number"]
- ]);
- };
- tests["test nested object expressions 3"] = function() {
- var results = computeContentAssist(
- "var ttt = { xxx : { yyy : { zzz : 1} } };\n" +
- "ttt.xxx.yyy.zzz.toF", "toF");
- testProposals("toF", results, [
- ["toFixed(digits)", "toFixed(digits) : Number"]
- ]);
- };
-
- tests["test function expression 1"] = function() {
- var results = computeContentAssist(
- "var ttt = function(a, b, c) { };\ntt", "tt");
- testProposals("tt", results, [
- ["ttt(a, b, c)", "ttt(a, b, c) : undefined"]
- ]);
- };
- tests["test function expression 2"] = function() {
- var results = computeContentAssist(
- "ttt = function(a, b, c) { };\ntt", "tt");
- testProposals("tt", results, [
- ["ttt(a, b, c)", "ttt(a, b, c) : undefined"]
- ]);
- };
- tests["test function expression 3"] = function() {
- var results = computeContentAssist(
- "ttt = { rrr : function(a, b, c) { } };\nttt.rr", "rr");
- testProposals("rr", results, [
- ["rrr(a, b, c)", "rrr(a, b, c) : undefined"]
- ]);
- };
- tests["test function expression 4"] = function() {
- var results = computeContentAssist(
- "var ttt = function(a, b) { };\nvar hhh = ttt;\nhhh", "hhh");
- testProposals("hhh", results, [
- ["hhh(a, b)", "hhh(a, b) : undefined"]
- ]);
- };
- tests["test function expression 4a"] = function() {
- var results = computeContentAssist(
- "function ttt(a, b) { };\nvar hhh = ttt;\nhhh", "hhh");
- testProposals("hhh", results, [
- ["hhh(a, b)", "hhh(a, b) : undefined"]
- ]);
- };
- tests["test function expression 5"] = function() {
- var results = computeContentAssist(
- "var uuu = { flart : function (a,b) { } };\nhhh = uuu.flart;\nhhh", "hhh");
- testProposals("hhh", results, [
- ["hhh(a, b)", "hhh(a, b) : undefined"]
- ]);
- };
- tests["test function expression 6"] = function() {
- var results = computeContentAssist(
- "var uuu = { flart : function (a,b) { } };\nhhh = uuu.flart;\nhhh.app", "app");
- testProposals("app", results, [
- ["apply(func, [argArray])", "apply(func, [argArray]) : Object"]
- ]);
- };
-
- tests["test globals 1"] = function() {
- var results = computeContentAssist("/*global faaa */\nfa", "fa");
- testProposals("fa", results, [
- ["faaa", "faaa : { }"]
- ]);
- };
- tests["te…
Large files files are truncated, but you can click here to view the full file