PageRenderTime 54ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/org.eclipse.orion.client.core/web/js-tests/esprima/esprimaJsContentAssistTests.js

https://github.com/eduardohl/orion.client
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

  1. /*******************************************************************************
  2. * @license
  3. * Copyright (c) 2012 VMware, Inc. All Rights Reserved.
  4. * THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
  5. * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
  6. * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
  7. * You can obtain a current copy of the Eclipse Public License from
  8. * http://www.opensource.org/licenses/eclipse-1.0.php
  9. *
  10. * Contributors:
  11. * Andrew Eisenberg (VMware) - initial API and implementation
  12. ******************************************************************************/
  13. /*global define esprima console setTimeout doctrine*/
  14. define(["plugins/esprima/esprimaJsContentAssist", "orion/assert", "esprima/esprima", "doctrine/doctrine"], function(mEsprimaPlugin, assert) {
  15. //////////////////////////////////////////////////////////
  16. // helpers
  17. //////////////////////////////////////////////////////////
  18. function computeContentAssist(buffer, prefix, offset, jsLintOptions) {
  19. if (!prefix) {
  20. prefix = "";
  21. }
  22. if (!offset) {
  23. offset = buffer.indexOf("/**/");
  24. if (offset < 0) {
  25. offset = buffer.length;
  26. }
  27. }
  28. var esprimaContentAssistant = new mEsprimaPlugin.EsprimaJavaScriptContentAssistProvider(null, jsLintOptions);
  29. return esprimaContentAssistant.computeProposals(buffer, offset, {prefix : prefix, inferredOnly : true });
  30. }
  31. function testProposal(proposal, text, description, prefix) {
  32. assert.equal(prefix + proposal.proposal, text, "Invalid proposal text");
  33. if (description) {
  34. assert.equal(proposal.description, description, "Invalid proposal description");
  35. }
  36. }
  37. function stringifyExpected(expectedProposals) {
  38. var text = "";
  39. for (var i = 0; i < expectedProposals.length; i++) {
  40. text += expectedProposals[i][0] + " : " + expectedProposals[i][1] + "\n";
  41. }
  42. return text;
  43. }
  44. function stringifyActual(actualProposals, prefix) {
  45. var text = "";
  46. for (var i = 0; i < actualProposals.length; i++) {
  47. text += prefix + actualProposals[i].proposal + " : " + actualProposals[i].description + "\n";
  48. }
  49. return text;
  50. }
  51. function testProposals(prefix, actualProposals, expectedProposals) {
  52. assert.equal(actualProposals.length, expectedProposals.length,
  53. "Wrong number of proposals. Expected:\n" + stringifyExpected(expectedProposals) +"\nActual:\n" + stringifyActual(actualProposals, prefix));
  54. for (var i = 0; i < actualProposals.length; i++) {
  55. testProposal(actualProposals[i], expectedProposals[i][0], expectedProposals[i][1], prefix);
  56. }
  57. }
  58. function parse(contents) {
  59. return esprima.parse(contents,{
  60. range: false,
  61. loc: false,
  62. tolerant: true
  63. });
  64. }
  65. function assertNoErrors(ast) {
  66. assert.ok(ast.errors===null || ast.errors.length===0,
  67. 'errors: '+ast.errors.length+'\n'+ast.errors);
  68. }
  69. function assertErrors(ast,expectedErrors) {
  70. var expectedErrorList = (expectedErrors instanceof Array ? expectedErrors: [expectedErrors]);
  71. var correctNumberOfErrors = ast.errors!==null && ast.errors.length===expectedErrorList.length;
  72. assert.ok(correctNumberOfErrors,'errors: '+ast.errors.length+'\n'+ast.errors);
  73. if (correctNumberOfErrors) {
  74. for (var e=0;e<expectedErrors.length;e++) {
  75. var expectedError = expectedErrorList[e];
  76. var actualError = ast.errors[e];
  77. assert.equal(actualError.lineNumber,expectedError.lineNumber,"checking line for message #"+(e+1)+": "+actualError);
  78. var actualMessage = actualError.message.replace(/Line [0-9]*: /,'');
  79. assert.equal(actualMessage,expectedError.message,"checking text for message #"+(e+1)+": "+actualError);
  80. }
  81. }
  82. }
  83. function stringify(parsedProgram) {
  84. var body = parsedProgram.body;
  85. if (body.length===1) {
  86. body=body[0];
  87. }
  88. var replacer = function(key,value) {
  89. if (key==='computed') {
  90. return;
  91. }
  92. return value;
  93. };
  94. return JSON.stringify(body,replacer).replace(/"/g,'');
  95. }
  96. function message(line, text) {
  97. return {
  98. lineNumber:line,
  99. message:text
  100. };
  101. }
  102. //////////////////////////////////////////////////////////
  103. // tests
  104. //////////////////////////////////////////////////////////
  105. var tests = {};
  106. tests.testEmpty = function() {};
  107. tests["test recovery basic parse"] = function() {
  108. var parsedProgram = parse("foo.bar");
  109. assertNoErrors(parsedProgram);
  110. assert.equal(stringify(parsedProgram),"{type:ExpressionStatement,expression:{type:MemberExpression,object:{type:Identifier,name:foo},property:{type:Identifier,name:bar}}}");
  111. };
  112. tests["test recovery - dot followed by EOF"] = function() {
  113. var parsedProgram = parse("foo.");
  114. assertErrors(parsedProgram,message(1,'Unexpected end of input'));
  115. assert.equal(stringify(parsedProgram),"{type:ExpressionStatement,expression:{type:MemberExpression,object:{type:Identifier,name:foo},property:null}}");
  116. };
  117. tests["test Empty Content Assist"] = function() {
  118. var results = computeContentAssist("x", "x");
  119. assert.equal(results.length, 0);
  120. };
  121. // non-inferencing content assist
  122. tests["test Empty File Content Assist"] = function() {
  123. var results = computeContentAssist("");
  124. testProposals("", results, [
  125. ["Array([val])", "Array([val]) : Array"],
  126. ["Boolean([val])", "Boolean([val]) : Boolean"],
  127. ["Date([val])", "Date([val]) : Date"],
  128. ["Error([err])", "Error([err]) : Error"],
  129. ["Function()", "Function() : Function"],
  130. ["Number([val])", "Number([val]) : Number"],
  131. ["Object([val])", "Object([val]) : Object"],
  132. ["RegExp([val])", "RegExp([val]) : RegExp"],
  133. ["decodeURI(uri)", "decodeURI(uri) : String"],
  134. ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
  135. ["encodeURI(uri)", "encodeURI(uri) : String"],
  136. ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
  137. ["eval(toEval)", "eval(toEval) : Object"],
  138. ["isFinite(num)", "isFinite(num) : Boolean"],
  139. ["isNaN(num)", "isNaN(num) : Boolean"],
  140. ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
  141. ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
  142. ["Infinity", "Infinity : Number"],
  143. ["JSON", "JSON : JSON"],
  144. ["Math", "Math : Math"],
  145. ["NaN", "NaN : Number"],
  146. ["this", "this : Global"],
  147. ["undefined", "undefined : undefined"],
  148. ["", "---------------------------------"],
  149. ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
  150. ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
  151. ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
  152. ["toLocaleString()", "toLocaleString() : String"],
  153. ["toString()", "toString() : String"],
  154. ["valueOf()", "valueOf() : Object"],
  155. ["prototype", "prototype : Object"]
  156. ]);
  157. };
  158. tests["test Single Var Content Assist"] = function() {
  159. var results = computeContentAssist("var zzz = 9;\n");
  160. testProposals("", results, [
  161. ["Array([val])", "Array([val]) : Array"],
  162. ["Boolean([val])", "Boolean([val]) : Boolean"],
  163. ["Date([val])", "Date([val]) : Date"],
  164. ["Error([err])", "Error([err]) : Error"],
  165. ["Function()", "Function() : Function"],
  166. ["Number([val])", "Number([val]) : Number"],
  167. ["Object([val])", "Object([val]) : Object"],
  168. ["RegExp([val])", "RegExp([val]) : RegExp"],
  169. ["decodeURI(uri)", "decodeURI(uri) : String"],
  170. ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
  171. ["encodeURI(uri)", "encodeURI(uri) : String"],
  172. ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
  173. ["eval(toEval)", "eval(toEval) : Object"],
  174. ["isFinite(num)", "isFinite(num) : Boolean"],
  175. ["isNaN(num)", "isNaN(num) : Boolean"],
  176. ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
  177. ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
  178. ["Infinity", "Infinity : Number"],
  179. ["JSON", "JSON : JSON"],
  180. ["Math", "Math : Math"],
  181. ["NaN", "NaN : Number"],
  182. ["this", "this : Global"],
  183. ["undefined", "undefined : undefined"],
  184. ["zzz", "zzz : Number"],
  185. ["", "---------------------------------"],
  186. ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
  187. ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
  188. ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
  189. ["toLocaleString()", "toLocaleString() : String"],
  190. ["toString()", "toString() : String"],
  191. ["valueOf()", "valueOf() : Object"],
  192. ["prototype", "prototype : Object"]
  193. ]);
  194. };
  195. tests["test Single Var Content Assist 2"] = function() {
  196. var results = computeContentAssist("var zzz;\n");
  197. testProposals("", results, [
  198. ["Array([val])", "Array([val]) : Array"],
  199. ["Boolean([val])", "Boolean([val]) : Boolean"],
  200. ["Date([val])", "Date([val]) : Date"],
  201. ["Error([err])", "Error([err]) : Error"],
  202. ["Function()", "Function() : Function"],
  203. ["Number([val])", "Number([val]) : Number"],
  204. ["Object([val])", "Object([val]) : Object"],
  205. ["RegExp([val])", "RegExp([val]) : RegExp"],
  206. ["decodeURI(uri)", "decodeURI(uri) : String"],
  207. ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
  208. ["encodeURI(uri)", "encodeURI(uri) : String"],
  209. ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
  210. ["eval(toEval)", "eval(toEval) : Object"],
  211. ["isFinite(num)", "isFinite(num) : Boolean"],
  212. ["isNaN(num)", "isNaN(num) : Boolean"],
  213. ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
  214. ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
  215. ["Infinity", "Infinity : Number"],
  216. ["JSON", "JSON : JSON"],
  217. ["Math", "Math : Math"],
  218. ["NaN", "NaN : Number"],
  219. ["this", "this : Global"],
  220. ["undefined", "undefined : undefined"],
  221. ["zzz", "zzz : Object"],
  222. ["", "---------------------------------"],
  223. ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
  224. ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
  225. ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
  226. ["toLocaleString()", "toLocaleString() : String"],
  227. ["toString()", "toString() : String"],
  228. ["valueOf()", "valueOf() : Object"],
  229. ["prototype", "prototype : Object"]
  230. ]);
  231. };
  232. tests["test multi var content assist 1"] = function() {
  233. var results = computeContentAssist("var zzz;\nvar xxx, yyy;\n");
  234. testProposals("", results, [
  235. ["Array([val])", "Array([val]) : Array"],
  236. ["Boolean([val])", "Boolean([val]) : Boolean"],
  237. ["Date([val])", "Date([val]) : Date"],
  238. ["Error([err])", "Error([err]) : Error"],
  239. ["Function()", "Function() : Function"],
  240. ["Number([val])", "Number([val]) : Number"],
  241. ["Object([val])", "Object([val]) : Object"],
  242. ["RegExp([val])", "RegExp([val]) : RegExp"],
  243. ["decodeURI(uri)", "decodeURI(uri) : String"],
  244. ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
  245. ["encodeURI(uri)", "encodeURI(uri) : String"],
  246. ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
  247. ["eval(toEval)", "eval(toEval) : Object"],
  248. ["isFinite(num)", "isFinite(num) : Boolean"],
  249. ["isNaN(num)", "isNaN(num) : Boolean"],
  250. ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
  251. ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
  252. ["Infinity", "Infinity : Number"],
  253. ["JSON", "JSON : JSON"],
  254. ["Math", "Math : Math"],
  255. ["NaN", "NaN : Number"],
  256. ["this", "this : Global"],
  257. ["undefined", "undefined : undefined"],
  258. ["xxx", "xxx : Object"],
  259. ["yyy", "yyy : Object"],
  260. ["zzz", "zzz : Object"],
  261. ["", "---------------------------------"],
  262. ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
  263. ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
  264. ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
  265. ["toLocaleString()", "toLocaleString() : String"],
  266. ["toString()", "toString() : String"],
  267. ["valueOf()", "valueOf() : Object"],
  268. ["prototype", "prototype : Object"]
  269. ]);
  270. };
  271. tests["test multi var content assist 2"] = function() {
  272. var results = computeContentAssist("var zzz;\nvar zxxx, xxx, yyy;\nz","z");
  273. testProposals("z", results, [
  274. ["zxxx", "zxxx : Object"],
  275. ["zzz", "zzz : Object"]
  276. ]);
  277. };
  278. tests["test single function content assist"] = function() {
  279. var results = computeContentAssist("function fun(a, b, c) {}\n");
  280. testProposals("", results, [
  281. ["Array([val])", "Array([val]) : Array"],
  282. ["Boolean([val])", "Boolean([val]) : Boolean"],
  283. ["Date([val])", "Date([val]) : Date"],
  284. ["Error([err])", "Error([err]) : Error"],
  285. ["Function()", "Function() : Function"],
  286. ["Number([val])", "Number([val]) : Number"],
  287. ["Object([val])", "Object([val]) : Object"],
  288. ["RegExp([val])", "RegExp([val]) : RegExp"],
  289. ["decodeURI(uri)", "decodeURI(uri) : String"],
  290. ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
  291. ["encodeURI(uri)", "encodeURI(uri) : String"],
  292. ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
  293. ["eval(toEval)", "eval(toEval) : Object"],
  294. ["fun(a, b, c)", "fun(a, b, c) : undefined"],
  295. ["isFinite(num)", "isFinite(num) : Boolean"],
  296. ["isNaN(num)", "isNaN(num) : Boolean"],
  297. ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
  298. ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
  299. ["Infinity", "Infinity : Number"],
  300. ["JSON", "JSON : JSON"],
  301. ["Math", "Math : Math"],
  302. ["NaN", "NaN : Number"],
  303. ["this", "this : Global"],
  304. ["undefined", "undefined : undefined"],
  305. ["", "---------------------------------"],
  306. ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
  307. ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
  308. ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
  309. ["toLocaleString()", "toLocaleString() : String"],
  310. ["toString()", "toString() : String"],
  311. ["valueOf()", "valueOf() : Object"],
  312. ["prototype", "prototype : Object"]
  313. ]);
  314. };
  315. tests["test multi function content assist 1"] = function() {
  316. var results = computeContentAssist("function fun(a, b, c) {}\nfunction other(a, b, c) {}\n");
  317. testProposals("", results, [
  318. ["Array([val])", "Array([val]) : Array"],
  319. ["Boolean([val])", "Boolean([val]) : Boolean"],
  320. ["Date([val])", "Date([val]) : Date"],
  321. ["Error([err])", "Error([err]) : Error"],
  322. ["Function()", "Function() : Function"],
  323. ["Number([val])", "Number([val]) : Number"],
  324. ["Object([val])", "Object([val]) : Object"],
  325. ["RegExp([val])", "RegExp([val]) : RegExp"],
  326. ["decodeURI(uri)", "decodeURI(uri) : String"],
  327. ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
  328. ["encodeURI(uri)", "encodeURI(uri) : String"],
  329. ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
  330. ["eval(toEval)", "eval(toEval) : Object"],
  331. ["fun(a, b, c)", "fun(a, b, c) : undefined"],
  332. ["isFinite(num)", "isFinite(num) : Boolean"],
  333. ["isNaN(num)", "isNaN(num) : Boolean"],
  334. ["other(a, b, c)", "other(a, b, c) : undefined"],
  335. ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
  336. ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
  337. ["Infinity", "Infinity : Number"],
  338. ["JSON", "JSON : JSON"],
  339. ["Math", "Math : Math"],
  340. ["NaN", "NaN : Number"],
  341. ["this", "this : Global"],
  342. ["undefined", "undefined : undefined"],
  343. ["", "---------------------------------"],
  344. ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
  345. ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
  346. ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
  347. ["toLocaleString()", "toLocaleString() : String"],
  348. ["toString()", "toString() : String"],
  349. ["valueOf()", "valueOf() : Object"],
  350. ["prototype", "prototype : Object"]
  351. ]);
  352. };
  353. tests["test no dupe 1"] = function() {
  354. var results = computeContentAssist(
  355. "var foo = 9; var other = function(foo) { f/**/ }", "f");
  356. testProposals("f", results, [
  357. ["foo", "foo : { }"]
  358. ]);
  359. };
  360. tests["test no dupe 2"] = function() {
  361. var results = computeContentAssist(
  362. "var foo = { }; var other = function(foo) { foo = 9;\nf/**/ }", "f");
  363. testProposals("f", results, [
  364. ["foo", "foo : Number"]
  365. ]);
  366. };
  367. tests["test no dupe 3"] = function() {
  368. var results = computeContentAssist(
  369. "var foo = function () { var foo = 9; \n f/**/};", "f");
  370. testProposals("f", results, [
  371. ["foo", "foo : Number"]
  372. ]);
  373. };
  374. tests["test no dupe 4"] = function() {
  375. var results = computeContentAssist(
  376. "var foo = 9; var other = function () { var foo = function() { return 9; }; \n f/**/};", "f");
  377. testProposals("f", results, [
  378. ["foo()", "foo() : Number"]
  379. ]);
  380. };
  381. tests["test scopes 1"] = function() {
  382. // only the outer foo is available
  383. var results = computeContentAssist(
  384. "var foo;\nfunction other(a, b, c) {\nfunction inner() { var foo2; }\nf/**/}", "f");
  385. testProposals("f", results, [
  386. ["foo", "foo : Object"]
  387. ]);
  388. };
  389. tests["test scopes 2"] = function() {
  390. // the inner assignment should not affect the value of foo
  391. var results = computeContentAssist("var foo;\n" +
  392. "var foo = 1;\nfunction other(a, b, c) {\nfunction inner() { foo2 = \"\"; }\nfoo.toF/**/}", "toF");
  393. testProposals("toF", results, [
  394. ["toFixed(digits)", "toFixed(digits) : Number"]
  395. ]);
  396. };
  397. tests["test multi function content assist 2"] = function() {
  398. var results = computeContentAssist("function fun(a, b, c) {}\nfunction other(a, b, c) {}\nf", "f");
  399. testProposals("f", results, [
  400. ["fun(a, b, c)", "fun(a, b, c) : undefined"]
  401. ]);
  402. };
  403. tests["test in function 1"] = function() {
  404. var results = computeContentAssist("function fun(a, b, c) {}\nfunction other(a, b, c) {/**/}", "");
  405. testProposals("", results, [
  406. ["a", "a : { }"],
  407. ["arguments", "arguments : Arguments"],
  408. ["b", "b : { }"],
  409. ["c", "c : { }"],
  410. ["", "---------------------------------"],
  411. ["Array([val])", "Array([val]) : Array"],
  412. ["Boolean([val])", "Boolean([val]) : Boolean"],
  413. ["Date([val])", "Date([val]) : Date"],
  414. ["Error([err])", "Error([err]) : Error"],
  415. ["Function()", "Function() : Function"],
  416. ["Number([val])", "Number([val]) : Number"],
  417. ["Object([val])", "Object([val]) : Object"],
  418. ["RegExp([val])", "RegExp([val]) : RegExp"],
  419. ["decodeURI(uri)", "decodeURI(uri) : String"],
  420. ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
  421. ["encodeURI(uri)", "encodeURI(uri) : String"],
  422. ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
  423. ["eval(toEval)", "eval(toEval) : Object"],
  424. ["fun(a, b, c)", "fun(a, b, c) : undefined"],
  425. ["isFinite(num)", "isFinite(num) : Boolean"],
  426. ["isNaN(num)", "isNaN(num) : Boolean"],
  427. ["other(a, b, c)", "other(a, b, c) : undefined"],
  428. ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
  429. ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
  430. ["Infinity", "Infinity : Number"],
  431. ["JSON", "JSON : JSON"],
  432. ["Math", "Math : Math"],
  433. ["NaN", "NaN : Number"],
  434. ["this", "this : Global"],
  435. ["undefined", "undefined : undefined"],
  436. ["", "---------------------------------"],
  437. ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
  438. ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
  439. ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
  440. ["toLocaleString()", "toLocaleString() : String"],
  441. ["toString()", "toString() : String"],
  442. ["valueOf()", "valueOf() : Object"],
  443. ["prototype", "prototype : Object"]
  444. ]);
  445. };
  446. tests["test in function 2"] = function() {
  447. var results = computeContentAssist("function fun(a, b, c) {}\nfunction other(a, b, c) {\n/**/nuthin}", "");
  448. testProposals("", results, [
  449. ["a", "a : { }"],
  450. ["arguments", "arguments : Arguments"],
  451. ["b", "b : { }"],
  452. ["c", "c : { }"],
  453. ["", "---------------------------------"],
  454. ["Array([val])", "Array([val]) : Array"],
  455. ["Boolean([val])", "Boolean([val]) : Boolean"],
  456. ["Date([val])", "Date([val]) : Date"],
  457. ["Error([err])", "Error([err]) : Error"],
  458. ["Function()", "Function() : Function"],
  459. ["Number([val])", "Number([val]) : Number"],
  460. ["Object([val])", "Object([val]) : Object"],
  461. ["RegExp([val])", "RegExp([val]) : RegExp"],
  462. ["decodeURI(uri)", "decodeURI(uri) : String"],
  463. ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
  464. ["encodeURI(uri)", "encodeURI(uri) : String"],
  465. ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
  466. ["eval(toEval)", "eval(toEval) : Object"],
  467. ["fun(a, b, c)", "fun(a, b, c) : undefined"],
  468. ["isFinite(num)", "isFinite(num) : Boolean"],
  469. ["isNaN(num)", "isNaN(num) : Boolean"],
  470. ["other(a, b, c)", "other(a, b, c) : undefined"],
  471. ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
  472. ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
  473. ["Infinity", "Infinity : Number"],
  474. ["JSON", "JSON : JSON"],
  475. ["Math", "Math : Math"],
  476. ["NaN", "NaN : Number"],
  477. ["this", "this : Global"],
  478. ["undefined", "undefined : undefined"],
  479. ["", "---------------------------------"],
  480. ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
  481. ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
  482. ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
  483. ["toLocaleString()", "toLocaleString() : String"],
  484. ["toString()", "toString() : String"],
  485. ["valueOf()", "valueOf() : Object"],
  486. ["prototype", "prototype : Object"]
  487. ]);
  488. };
  489. tests["test in function 3"] = function() {
  490. var results = computeContentAssist("function fun(a, b, c) {}\nfunction other(a, b, c) {f/**/}", "f");
  491. testProposals("f", results, [
  492. ["fun(a, b, c)", "fun(a, b, c) : undefined"]
  493. ]);
  494. };
  495. tests["test in function 4"] = function() {
  496. var results = computeContentAssist("function fun(a, b, c) {}\nfunction other(aa, ab, c) {a/**/}", "a");
  497. testProposals("a", results, [
  498. ["aa", "aa : { }"],
  499. ["ab", "ab : { }"],
  500. ["arguments", "arguments : Arguments"]
  501. ]);
  502. };
  503. tests["test in function 5"] = function() {
  504. // should not see 'aaa' since that is declared later
  505. var results = computeContentAssist("function fun(a, b, c) {}\nfunction other(aa, ab, c) {var abb;\na/**/\nvar aaa}", "a");
  506. testProposals("a", results, [
  507. ["abb", "abb : Object"],
  508. ["a", "---------------------------------"],
  509. ["aa", "aa : { }"],
  510. ["ab", "ab : { }"],
  511. ["arguments", "arguments : Arguments"]
  512. ]);
  513. };
  514. tests["test in function 6"] = function() {
  515. // should not see 'aaa' since that is declared later
  516. var results = computeContentAssist(
  517. "function fun(a, b, c) {\n" +
  518. "function other(aa, ab, c) {\n"+
  519. "var abb;\na/**/\nvar aaa\n}\n}", "a");
  520. testProposals("a", results, [
  521. ["abb", "abb : Object"],
  522. ["a", "---------------------------------"],
  523. ["aa", "aa : { }"],
  524. ["ab", "ab : { }"],
  525. ["arguments", "arguments : Arguments"],
  526. ["a", "---------------------------------"],
  527. ["a", "a : { }"]
  528. ]);
  529. };
  530. tests["test in function 7"] = function() {
  531. // should not see 'aaa' since that is declared later
  532. var results = computeContentAssist(
  533. "function fun(a, b, c) {/**/\n" +
  534. "function other(aa, ab, ac) {\n"+
  535. "var abb;\na\nvar aaa\n}\n}");
  536. testProposals("", results, [
  537. ["other(aa, ab, ac)", "other(aa, ab, ac) : undefined"],
  538. ["", "---------------------------------"],
  539. ["a", "a : { }"],
  540. ["arguments", "arguments : Arguments"],
  541. ["b", "b : { }"],
  542. ["c", "c : { }"],
  543. ["", "---------------------------------"],
  544. ["Array([val])", "Array([val]) : Array"],
  545. ["Boolean([val])", "Boolean([val]) : Boolean"],
  546. ["Date([val])", "Date([val]) : Date"],
  547. ["Error([err])", "Error([err]) : Error"],
  548. ["Function()", "Function() : Function"],
  549. ["Number([val])", "Number([val]) : Number"],
  550. ["Object([val])", "Object([val]) : Object"],
  551. ["RegExp([val])", "RegExp([val]) : RegExp"],
  552. ["decodeURI(uri)", "decodeURI(uri) : String"],
  553. ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
  554. ["encodeURI(uri)", "encodeURI(uri) : String"],
  555. ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
  556. ["eval(toEval)", "eval(toEval) : Object"],
  557. ["fun(a, b, c)", "fun(a, b, c) : undefined"],
  558. ["isFinite(num)", "isFinite(num) : Boolean"],
  559. ["isNaN(num)", "isNaN(num) : Boolean"],
  560. ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
  561. ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
  562. ["Infinity", "Infinity : Number"],
  563. ["JSON", "JSON : JSON"],
  564. ["Math", "Math : Math"],
  565. ["NaN", "NaN : Number"],
  566. ["this", "this : Global"],
  567. ["undefined", "undefined : undefined"],
  568. ["", "---------------------------------"],
  569. ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
  570. ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
  571. ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
  572. ["toLocaleString()", "toLocaleString() : String"],
  573. ["toString()", "toString() : String"],
  574. ["valueOf()", "valueOf() : Object"],
  575. ["prototype", "prototype : Object"]
  576. ]);
  577. };
  578. tests["test in function 8"] = function() {
  579. // should not see 'aaa' since that is declared later
  580. var results = computeContentAssist(
  581. "function fun(a, b, c) {\n" +
  582. "function other(aa, ab, ac) {\n"+
  583. "var abb;\na\nvar aaa\n} /**/\n}");
  584. testProposals("", results, [
  585. ["other(aa, ab, ac)", "other(aa, ab, ac) : undefined"],
  586. ["", "---------------------------------"],
  587. ["a", "a : { }"],
  588. ["arguments", "arguments : Arguments"],
  589. ["b", "b : { }"],
  590. ["c", "c : { }"],
  591. ["", "---------------------------------"],
  592. ["Array([val])", "Array([val]) : Array"],
  593. ["Boolean([val])", "Boolean([val]) : Boolean"],
  594. ["Date([val])", "Date([val]) : Date"],
  595. ["Error([err])", "Error([err]) : Error"],
  596. ["Function()", "Function() : Function"],
  597. ["Number([val])", "Number([val]) : Number"],
  598. ["Object([val])", "Object([val]) : Object"],
  599. ["RegExp([val])", "RegExp([val]) : RegExp"],
  600. ["decodeURI(uri)", "decodeURI(uri) : String"],
  601. ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
  602. ["encodeURI(uri)", "encodeURI(uri) : String"],
  603. ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
  604. ["eval(toEval)", "eval(toEval) : Object"],
  605. ["fun(a, b, c)", "fun(a, b, c) : undefined"],
  606. ["isFinite(num)", "isFinite(num) : Boolean"],
  607. ["isNaN(num)", "isNaN(num) : Boolean"],
  608. ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
  609. ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
  610. ["Infinity", "Infinity : Number"],
  611. ["JSON", "JSON : JSON"],
  612. ["Math", "Math : Math"],
  613. ["NaN", "NaN : Number"],
  614. ["this", "this : Global"],
  615. ["undefined", "undefined : undefined"],
  616. ["", "---------------------------------"],
  617. ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
  618. ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
  619. ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
  620. ["toLocaleString()", "toLocaleString() : String"],
  621. ["toString()", "toString() : String"],
  622. ["valueOf()", "valueOf() : Object"],
  623. ["prototype", "prototype : Object"]
  624. ]);
  625. };
  626. // all inferencing based content assist tests here
  627. tests["test Object inferencing with Variable"] = function() {
  628. var results = computeContentAssist("var t = {}\nt.h", "h");
  629. testProposals("h", results, [
  630. ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"]
  631. ]);
  632. };
  633. tests["test Object Literal inferencing"] = function() {
  634. var results = computeContentAssist("var t = { hhh : 1, hh2 : 8}\nt.h", "h");
  635. testProposals("h", results, [
  636. ["hh2", "hh2 : Number"],
  637. ["hhh", "hhh : Number"],
  638. ["h", "---------------------------------"],
  639. ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"]
  640. ]);
  641. };
  642. tests["test Simple String inferencing"] = function() {
  643. var results = computeContentAssist("''.char", "char");
  644. testProposals("char", results, [
  645. ["charAt(index)", "charAt(index) : String"],
  646. ["charCodeAt(index)", "charCodeAt(index) : Number"]
  647. ]);
  648. };
  649. tests["test Simple Date inferencing"] = function() {
  650. var results = computeContentAssist("new Date().setD", "setD");
  651. testProposals("setD", results, [
  652. ["setDate(date)", "setDate(date) : Number"],
  653. ["setDay(dayOfWeek)", "setDay(dayOfWeek) : Number"]
  654. ]);
  655. };
  656. tests["test Number inferencing with Variable"] = function() {
  657. var results = computeContentAssist("var t = 1\nt.to", "to");
  658. testProposals("to", results, [
  659. ["toExponential(digits)", "toExponential(digits) : Number"],
  660. ["toFixed(digits)", "toFixed(digits) : Number"],
  661. ["toPrecision(digits)", "toPrecision(digits) : Number"],
  662. ["to", "---------------------------------"],
  663. ["toLocaleString()", "toLocaleString() : String"],
  664. ["toString()", "toString() : String"]
  665. ]);
  666. };
  667. tests["test Data flow Object Literal inferencing"] = function() {
  668. var results = computeContentAssist("var s = { hhh : 1, hh2 : 8}\nvar t = s;\nt.h", "h");
  669. testProposals("h", results, [
  670. ["hh2", "hh2 : Number"],
  671. ["hhh", "hhh : Number"],
  672. ["h", "---------------------------------"],
  673. ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"]
  674. ]);
  675. };
  676. tests["test Data flow inferencing 1"] = function() {
  677. var results = computeContentAssist("var ttt = 9\nttt.toF", "toF");
  678. testProposals("toF", results, [
  679. ["toFixed(digits)", "toFixed(digits) : Number"]
  680. ]);
  681. };
  682. tests["test Data flow inferencing 2"] = function() {
  683. var results = computeContentAssist("ttt = 9\nttt.toF", "toF");
  684. testProposals("toF", results, [
  685. ["toFixed(digits)", "toFixed(digits) : Number"]
  686. ]);
  687. };
  688. tests["test Data flow inferencing 3"] = function() {
  689. var results = computeContentAssist("var ttt = \"\"\nttt = 9\nttt.toF", "toF");
  690. testProposals("toF", results, [
  691. ["toFixed(digits)", "toFixed(digits) : Number"]
  692. ]);
  693. };
  694. tests["test Data flow inferencing 4"] = function() {
  695. var results = computeContentAssist("var name = toString(property.key.value);\nname.co", "co");
  696. testProposals("co", results, [
  697. ["concat(array)", "concat(array) : String"]
  698. ]);
  699. };
  700. tests["test Simple this"] = function() {
  701. var results = computeContentAssist("var ssss = 4;\nthis.ss", "ss");
  702. testProposals("ss", results, [
  703. ["ssss", "ssss : Number"]
  704. ]);
  705. };
  706. tests["test Object Literal inside"] = function() {
  707. var results = computeContentAssist("var x = { the : 1, far : this.th/**/ };", "th");
  708. testProposals("th", results, [
  709. // type is 'Object' here, not number, since inside the object literal, we don't
  710. // know the types of literal fields
  711. ["the", "the : Object"]
  712. ]);
  713. };
  714. tests["test Object Literal outside"] = function() {
  715. var results = computeContentAssist("var x = { the : 1, far : 2 };\nx.th", "th");
  716. testProposals("th", results, [
  717. ["the", "the : Number"]
  718. ]);
  719. };
  720. tests["test Object Literal none"] = function() {
  721. var results = computeContentAssist("var x = { the : 1, far : 2 };\nthis.th", "th");
  722. testProposals("th", results, [
  723. ]);
  724. };
  725. tests["test Object Literal outside 2"] = function() {
  726. var results = computeContentAssist("var x = { the : 1, far : 2 };\nvar who = x.th", "th");
  727. testProposals("th", results, [
  728. ["the", "the : Number"]
  729. ]);
  730. };
  731. tests["test Object Literal outside 3"] = function() {
  732. var results = computeContentAssist("var x = { the : 1, far : 2 };\nwho(x.th/**/)", "th");
  733. testProposals("th", results, [
  734. ["the", "the : Number"]
  735. ]);
  736. };
  737. tests["test Object Literal outside 4"] = function() {
  738. var results = computeContentAssist("var x = { the : 1, far : 2 };\nwho(yyy, x.th/**/)", "th");
  739. testProposals("th", results, [
  740. ["the", "the : Number"]
  741. ]);
  742. };
  743. tests["test this reference 1"] = function() {
  744. var results = computeContentAssist("var xxxx;\nthis.x", "x");
  745. testProposals("x", results, [
  746. ["xxxx", "xxxx : Object"]
  747. ]);
  748. };
  749. tests["test binary expression 1"] = function() {
  750. var results = computeContentAssist("(1+3).toF", "toF");
  751. testProposals("toF", results, [
  752. ["toFixed(digits)", "toFixed(digits) : Number"]
  753. ]);
  754. };
  755. // not working since for loop is not storing slocs of var ii
  756. tests["test for loop 1"] = function() {
  757. var results = computeContentAssist("for (var ii=0;i/**/<8;ii++) { ii }", "i");
  758. testProposals("i", results, [
  759. ["isFinite(num)", "isFinite(num) : Boolean"],
  760. ["isNaN(num)", "isNaN(num) : Boolean"],
  761. ["ii", "ii : Number"],
  762. ["i", "---------------------------------"],
  763. ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"]
  764. ]);
  765. };
  766. tests["test for loop 2"] = function() {
  767. var results = computeContentAssist("for (var ii=0;ii<8;i/**/++) { ii }", "i");
  768. testProposals("i", results, [
  769. ["isFinite(num)", "isFinite(num) : Boolean"],
  770. ["isNaN(num)", "isNaN(num) : Boolean"],
  771. ["ii", "ii : Number"],
  772. ["i", "---------------------------------"],
  773. ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"]
  774. ]);
  775. };
  776. tests["test for loop 3"] = function() {
  777. var results = computeContentAssist("for (var ii=0;ii<8;ii++) { i/**/ }", "i");
  778. testProposals("i", results, [
  779. ["isFinite(num)", "isFinite(num) : Boolean"],
  780. ["isNaN(num)", "isNaN(num) : Boolean"],
  781. ["ii", "ii : Number"],
  782. ["i", "---------------------------------"],
  783. ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"]
  784. ]);
  785. };
  786. tests["test while loop 1"] = function() {
  787. var results = computeContentAssist("var iii;\nwhile(ii/**/ === null) {\n}", "ii");
  788. testProposals("ii", results, [
  789. ["iii", "iii : Object"]
  790. ]);
  791. };
  792. tests["test while loop 2"] = function() {
  793. var results = computeContentAssist("var iii;\nwhile(this.ii/**/ === null) {\n}", "ii");
  794. testProposals("ii", results, [
  795. ["iii", "iii : Object"]
  796. ]);
  797. };
  798. tests["test while loop 3"] = function() {
  799. var results = computeContentAssist("var iii;\nwhile(iii === null) {this.ii/**/\n}", "ii");
  800. testProposals("ii", results, [
  801. ["iii", "iii : Object"]
  802. ]);
  803. };
  804. tests["test catch clause 1"] = function() {
  805. var results = computeContentAssist("try { } catch (eee) {e/**/ }", "e");
  806. testProposals("e", results, [
  807. ["eee", "eee : Error"],
  808. ["e", "---------------------------------"],
  809. ["encodeURI(uri)", "encodeURI(uri) : String"],
  810. ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
  811. ["eval(toEval)", "eval(toEval) : Object"]
  812. ]);
  813. };
  814. tests["test catch clause 2"] = function() {
  815. // the type of the catch variable is Error
  816. var results = computeContentAssist("try { } catch (eee) {\neee.me/**/ }", "me");
  817. testProposals("me", results, [
  818. ["message", "message : String"]
  819. ]);
  820. };
  821. tests["test get global var"] = function() {
  822. // should infer that we are referring to the globally defined xxx, not the param
  823. var results = computeContentAssist("var xxx = 9;\nfunction fff(xxx) { this.xxx.toF/**/}", "toF");
  824. testProposals("toF", results, [
  825. ["toFixed(digits)", "toFixed(digits) : Number"]
  826. ]);
  827. };
  828. tests["test get local var"] = function() {
  829. // should infer that we are referring to the locally defined xxx, not the global
  830. var results = computeContentAssist("var xxx = 9;\nfunction fff(xxx) { xxx.toF/**/}", "toF");
  831. testProposals("toF", results, [
  832. ]);
  833. };
  834. tests["test Math 1"] = function() {
  835. var results = computeContentAssist("Mat", "Mat");
  836. testProposals("Mat", results, [
  837. ["Math", "Math : Math"]
  838. ]);
  839. };
  840. tests["test Math 2"] = function() {
  841. var results = computeContentAssist("this.Mat", "Mat");
  842. testProposals("Mat", results, [
  843. ["Math", "Math : Math"]
  844. ]);
  845. };
  846. tests["test Math 3"] = function() {
  847. // Math not available when this isn't the global this
  848. var results = computeContentAssist("var ff = { f: this.Mat/**/ }", "Mat");
  849. testProposals("Mat", results, [
  850. ]);
  851. };
  852. tests["test Math 4"] = function() {
  853. var results = computeContentAssist("this.Math.E", "E");
  854. testProposals("E", results, [
  855. ["E", "E : Number"]
  856. ]);
  857. };
  858. tests["test JSON 4"] = function() {
  859. var results = computeContentAssist("this.JSON.st", "st");
  860. testProposals("st", results, [
  861. ["stringify(obj)", "stringify(obj) : String"]
  862. ]);
  863. };
  864. tests["test multi-dot inferencing 1"] = function() {
  865. var results = computeContentAssist("var a = \"\";\na.charAt().charAt().charAt().ch", "ch");
  866. testProposals("ch", results, [
  867. ["charAt(index)", "charAt(index) : String"],
  868. ["charCodeAt(index)", "charCodeAt(index) : Number"]
  869. ]);
  870. };
  871. tests["test multi-dot inferencing 2"] = function() {
  872. var results = computeContentAssist(
  873. "var zz = {};\nzz.zz = zz;\nzz.zz.zz.z", "z");
  874. testProposals("z", results, [
  875. ["zz", "zz : { zz : { zz : {...} } }"]
  876. ]);
  877. };
  878. tests["test multi-dot inferencing 3"] = function() {
  879. var results = computeContentAssist(
  880. "var x = { yy : { } };\nx.yy.zz = 1;\nx.yy.z", "z");
  881. testProposals("z", results, [
  882. ["zz", "zz : Number"]
  883. ]);
  884. };
  885. tests["test multi-dot inferencing 4"] = function() {
  886. var results = computeContentAssist(
  887. "var x = { yy : { } };\nx.yy.zz = 1;\nx.yy.zz.toF", "toF");
  888. testProposals("toF", results, [
  889. ["toFixed(digits)", "toFixed(digits) : Number"]
  890. ]);
  891. };
  892. tests["test constructor 1"] = function() {
  893. var results = computeContentAssist(
  894. "function Fun() {\n this.xxx = 9;\n this.uuu = this.x/**/;}", "x");
  895. testProposals("x", results, [
  896. ["xxx", "xxx : Number"]
  897. ]);
  898. };
  899. tests["test constructor 2"] = function() {
  900. var results = computeContentAssist(
  901. "function Fun() { this.xxx = 9; this.uuu = this.xxx; }\n" +
  902. "var y = new Fun();\n" +
  903. "y.x", "x");
  904. testProposals("x", results, [
  905. ["xxx", "xxx : Number"]
  906. ]);
  907. };
  908. tests["test constructor 3"] = function() {
  909. var results = computeContentAssist(
  910. "function Fun() { this.xxx = 9; this.uuu = this.xxx; }\n" +
  911. "var y = new Fun();\n" +
  912. "y.xxx.toF", "toF");
  913. testProposals("toF", results, [
  914. ["toFixed(digits)", "toFixed(digits) : Number"]
  915. ]);
  916. };
  917. tests["test constructor 3"] = function() {
  918. var results = computeContentAssist(
  919. "function Fun() { this.xxx = 9; this.uuu = this.xxx; }\n" +
  920. "var y = new Fun();\n" +
  921. "y.uuu.toF", "toF");
  922. testProposals("toF", results, [
  923. ["toFixed(digits)", "toFixed(digits) : Number"]
  924. ]);
  925. };
  926. tests["test constructor 4"] = function() {
  927. var results = computeContentAssist(
  928. "var Fun = function () { this.xxx = 9; this.uuu = this.xxx; }\n" +
  929. "var y = new Fun();\n" +
  930. "y.uuu.toF", "toF");
  931. testProposals("toF", results, [
  932. ["toFixed(digits)", "toFixed(digits) : Number"]
  933. ]);
  934. };
  935. tests["test constructor 5"] = function() {
  936. var results = computeContentAssist(
  937. "var x = { Fun : function () { this.xxx = 9; this.uuu = this.xxx; } }\n" +
  938. "var y = new x.Fun();\n" +
  939. "y.uuu.toF", "toF");
  940. testProposals("toF", results, [
  941. ["toFixed(digits)", "toFixed(digits) : Number"]
  942. ]);
  943. };
  944. tests["test constructor 6"] = function() {
  945. var results = computeContentAssist(
  946. "var x = { Fun : function () { this.xxx = 9; this.uuu = this.xxx; } }\n" +
  947. "var y = new x.Fun().uuu.toF", "toF");
  948. testProposals("toF", results, [
  949. ["toFixed(digits)", "toFixed(digits) : Number"]
  950. ]);
  951. };
  952. tests["test constructor 7"] = function() {
  953. var results = computeContentAssist(
  954. "var Fun = function () { this.xxx = 9; this.uuu = this.xxx; }\n" +
  955. "var x = { Fun : Fun };\n" +
  956. "var y = new x.Fun();\n" +
  957. "y.uuu.toF", "toF");
  958. testProposals("toF", results, [
  959. ["toFixed(digits)", "toFixed(digits) : Number"]
  960. ]);
  961. };
  962. tests["test constructor 8"] = function() {
  963. var results = computeContentAssist(
  964. "var FunOrig = function () { this.xxx = 9; this.uuu = this.xxx; }\n" +
  965. "var x = { Fun : FunOrig };\n" +
  966. "var y = new x.Fun();\n" +
  967. "y.uuu.toF", "toF");
  968. testProposals("toF", results, [
  969. ["toFixed(digits)", "toFixed(digits) : Number"]
  970. ]);
  971. };
  972. // functions should not be available outside the scope that declares them
  973. tests["test constructor 9"] = function() {
  974. var results = computeContentAssist(
  975. "function outer() { function Inner() { }}\n" +
  976. "Inn", "Inn");
  977. testProposals("Inn", results, [
  978. // TODO FIXADE adding all constructors to global scope. not correct
  979. ["Inner()", "Inner() : Inner"]
  980. ]);
  981. };
  982. // should be able to reference functions using qualified name
  983. tests["test constructor 10"] = function() {
  984. var results = computeContentAssist(
  985. "var outer = { Inner : function() { }}\n" +
  986. "outer.Inn", "Inn");
  987. testProposals("Inn", results, [
  988. ["Inner()", "Inner() : outer.Inner"]
  989. ]);
  990. };
  991. tests["test Function args 1"] = function() {
  992. var results = computeContentAssist(
  993. "var ttt, uuu;\nttt(/**/)");
  994. testProposals("", results, [
  995. ["Array([val])", "Array([val]) : Array"],
  996. ["Boolean([val])", "Boolean([val]) : Boolean"],
  997. ["Date([val])", "Date([val]) : Date"],
  998. ["Error([err])", "Error([err]) : Error"],
  999. ["Function()", "Function() : Function"],
  1000. ["Number([val])", "Number([val]) : Number"],
  1001. ["Object([val])", "Object([val]) : Object"],
  1002. ["RegExp([val])", "RegExp([val]) : RegExp"],
  1003. ["decodeURI(uri)", "decodeURI(uri) : String"],
  1004. ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
  1005. ["encodeURI(uri)", "encodeURI(uri) : String"],
  1006. ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
  1007. ["eval(toEval)", "eval(toEval) : Object"],
  1008. ["isFinite(num)", "isFinite(num) : Boolean"],
  1009. ["isNaN(num)", "isNaN(num) : Boolean"],
  1010. ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
  1011. ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
  1012. ["Infinity", "Infinity : Number"],
  1013. ["JSON", "JSON : JSON"],
  1014. ["Math", "Math : Math"],
  1015. ["NaN", "NaN : Number"],
  1016. ["this", "this : Global"],
  1017. ["ttt", "ttt : Object"],
  1018. ["undefined", "undefined : undefined"],
  1019. ["uuu", "uuu : Object"],
  1020. ["", "---------------------------------"],
  1021. ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
  1022. ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
  1023. ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
  1024. ["toLocaleString()", "toLocaleString() : String"],
  1025. ["toString()", "toString() : String"],
  1026. ["valueOf()", "valueOf() : Object"],
  1027. ["prototype", "prototype : Object"]
  1028. ]);
  1029. };
  1030. tests["test Function args 2"] = function() {
  1031. var results = computeContentAssist(
  1032. "var ttt, uuu;\nttt(ttt, /**/)");
  1033. testProposals("", results, [
  1034. ["Array([val])", "Array([val]) : Array"],
  1035. ["Boolean([val])", "Boolean([val]) : Boolean"],
  1036. ["Date([val])", "Date([val]) : Date"],
  1037. ["Error([err])", "Error([err]) : Error"],
  1038. ["Function()", "Function() : Function"],
  1039. ["Number([val])", "Number([val]) : Number"],
  1040. ["Object([val])", "Object([val]) : Object"],
  1041. ["RegExp([val])", "RegExp([val]) : RegExp"],
  1042. ["decodeURI(uri)", "decodeURI(uri) : String"],
  1043. ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
  1044. ["encodeURI(uri)", "encodeURI(uri) : String"],
  1045. ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
  1046. ["eval(toEval)", "eval(toEval) : Object"],
  1047. ["isFinite(num)", "isFinite(num) : Boolean"],
  1048. ["isNaN(num)", "isNaN(num) : Boolean"],
  1049. ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
  1050. ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
  1051. ["Infinity", "Infinity : Number"],
  1052. ["JSON", "JSON : JSON"],
  1053. ["Math", "Math : Math"],
  1054. ["NaN", "NaN : Number"],
  1055. ["this", "this : Global"],
  1056. ["ttt", "ttt : Object"],
  1057. ["undefined", "undefined : undefined"],
  1058. ["uuu", "uuu : Object"],
  1059. ["", "---------------------------------"],
  1060. ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
  1061. ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
  1062. ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
  1063. ["toLocaleString()", "toLocaleString() : String"],
  1064. ["toString()", "toString() : String"],
  1065. ["valueOf()", "valueOf() : Object"],
  1066. ["prototype", "prototype : Object"]
  1067. ]);
  1068. };
  1069. tests["test Function args 3"] = function() {
  1070. var results = computeContentAssist(
  1071. "var ttt, uuu;\nttt(ttt, /**/, uuu)");
  1072. testProposals("", results, [
  1073. ["Array([val])", "Array([val]) : Array"],
  1074. ["Boolean([val])", "Boolean([val]) : Boolean"],
  1075. ["Date([val])", "Date([val]) : Date"],
  1076. ["Error([err])", "Error([err]) : Error"],
  1077. ["Function()", "Function() : Function"],
  1078. ["Number([val])", "Number([val]) : Number"],
  1079. ["Object([val])", "Object([val]) : Object"],
  1080. ["RegExp([val])", "RegExp([val]) : RegExp"],
  1081. ["decodeURI(uri)", "decodeURI(uri) : String"],
  1082. ["decodeURIComponent(encodedURIString)", "decodeURIComponent(encodedURIString) : String"],
  1083. ["encodeURI(uri)", "encodeURI(uri) : String"],
  1084. ["encodeURIComponent(decodedURIString)", "encodeURIComponent(decodedURIString) : String"],
  1085. ["eval(toEval)", "eval(toEval) : Object"],
  1086. ["isFinite(num)", "isFinite(num) : Boolean"],
  1087. ["isNaN(num)", "isNaN(num) : Boolean"],
  1088. ["parseFloat(str, [radix])", "parseFloat(str, [radix]) : Number"],
  1089. ["parseInt(str, [radix])", "parseInt(str, [radix]) : Number"],
  1090. ["Infinity", "Infinity : Number"],
  1091. ["JSON", "JSON : JSON"],
  1092. ["Math", "Math : Math"],
  1093. ["NaN", "NaN : Number"],
  1094. ["this", "this : Global"],
  1095. ["ttt", "ttt : Object"],
  1096. ["undefined", "undefined : undefined"],
  1097. ["uuu", "uuu : Object"],
  1098. ["", "---------------------------------"],
  1099. ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
  1100. ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
  1101. ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
  1102. ["toLocaleString()", "toLocaleString() : String"],
  1103. ["toString()", "toString() : String"],
  1104. ["valueOf()", "valueOf() : Object"],
  1105. ["prototype", "prototype : Object"]
  1106. ]);
  1107. };
  1108. // check that function args don't get assigned the same type
  1109. tests["test function args 4"] = function() {
  1110. var results = computeContentAssist(
  1111. "function tt(aaa, bbb) { aaa.foo = 9;bbb.foo = ''\naaa.f/**/}", "f");
  1112. testProposals("f", results, [
  1113. ["foo", "foo : Number"]
  1114. ]);
  1115. };
  1116. // check that function args don't get assigned the same type
  1117. tests["test function args 5"] = function() {
  1118. var results = computeContentAssist(
  1119. "function tt(aaa, bbb) { aaa.foo = 9;bbb.foo = ''\nbbb.f/**/}", "f");
  1120. testProposals("f", results, [
  1121. ["foo", "foo : String"]
  1122. ]);
  1123. };
  1124. // FIXADE failing since we do not handle constructors that are not identifiers
  1125. // tests["test constructor 5"] = function() {
  1126. // var results = computeContentAssist(
  1127. // "var obj = { Fun : function() { this.xxx = 9; this.uuu = this.xxx; } }\n" +
  1128. // "var y = new obj.Fun();\n" +
  1129. // "y.uuu.toF", "toF");
  1130. // testProposals(results, [
  1131. // ["toFixed(digits)", "toFixed(digits) : Number"]
  1132. // ]);
  1133. // };
  1134. tests["test constructor 6"] = function() {
  1135. var results = computeContentAssist(
  1136. "function Fun2() {\n" +
  1137. "function Fun() { this.xxx = 9; this.uuu = this.xxx; }\n" +
  1138. "var y = new Fun();\n" +
  1139. "y.uuu.toF/**/}", "toF");
  1140. testProposals("toF", results, [
  1141. ["toFixed(digits)", "toFixed(digits) : Number"]
  1142. ]);
  1143. };
  1144. tests["test nested object expressions 1"] = function() {
  1145. var results = computeContentAssist(
  1146. "var ttt = { xxx : { yyy : { zzz : 1} } };\n" +
  1147. "ttt.xxx.y", "y");
  1148. testProposals("y", results, [
  1149. ["yyy", "yyy : { zzz : Number }"]
  1150. ]);
  1151. };
  1152. tests["test nested object expressions 2"] = function() {
  1153. var results = computeContentAssist(
  1154. "var ttt = { xxx : { yyy : { zzz : 1} } };\n" +
  1155. "ttt.xxx.yyy.z", "z");
  1156. testProposals("z", results, [
  1157. ["zzz", "zzz : Number"]
  1158. ]);
  1159. };
  1160. tests["test nested object expressions 3"] = function() {
  1161. var results = computeContentAssist(
  1162. "var ttt = { xxx : { yyy : { zzz : 1} } };\n" +
  1163. "ttt.xxx.yyy.zzz.toF", "toF");
  1164. testProposals("toF", results, [
  1165. ["toFixed(digits)", "toFixed(digits) : Number"]
  1166. ]);
  1167. };
  1168. tests["test function expression 1"] = function() {
  1169. var results = computeContentAssist(
  1170. "var ttt = function(a, b, c) { };\ntt", "tt");
  1171. testProposals("tt", results, [
  1172. ["ttt(a, b, c)", "ttt(a, b, c) : undefined"]
  1173. ]);
  1174. };
  1175. tests["test function expression 2"] = function() {
  1176. var results = computeContentAssist(
  1177. "ttt = function(a, b, c) { };\ntt", "tt");
  1178. testProposals("tt", results, [
  1179. ["ttt(a, b, c)", "ttt(a, b, c) : undefined"]
  1180. ]);
  1181. };
  1182. tests["test function expression 3"] = function() {
  1183. var results = computeContentAssist(
  1184. "ttt = { rrr : function(a, b, c) { } };\nttt.rr", "rr");
  1185. testProposals("rr", results, [
  1186. ["rrr(a, b, c)", "rrr(a, b, c) : undefined"]
  1187. ]);
  1188. };
  1189. tests["test function expression 4"] = function() {
  1190. var results = computeContentAssist(
  1191. "var ttt = function(a, b) { };\nvar hhh = ttt;\nhhh", "hhh");
  1192. testProposals("hhh", results, [
  1193. ["hhh(a, b)", "hhh(a, b) : undefined"]
  1194. ]);
  1195. };
  1196. tests["test function expression 4a"] = function() {
  1197. var results = computeContentAssist(
  1198. "function ttt(a, b) { };\nvar hhh = ttt;\nhhh", "hhh");
  1199. testProposals("hhh", results, [
  1200. ["hhh(a, b)", "hhh(a, b) : undefined"]
  1201. ]);
  1202. };
  1203. tests["test function expression 5"] = function() {
  1204. var results = computeContentAssist(
  1205. "var uuu = { flart : function (a,b) { } };\nhhh = uuu.flart;\nhhh", "hhh");
  1206. testProposals("hhh", results, [
  1207. ["hhh(a, b)", "hhh(a, b) : undefined"]
  1208. ]);
  1209. };
  1210. tests["test function expression 6"] = function() {
  1211. var results = computeContentAssist(
  1212. "var uuu = { flart : function (a,b) { } };\nhhh = uuu.flart;\nhhh.app", "app");
  1213. testProposals("app", results, [
  1214. ["apply(func, [argArray])", "apply(func, [argArray]) : Object"]
  1215. ]);
  1216. };
  1217. tests["test globals 1"] = function() {
  1218. var results = computeContentAssist("/*global faaa */\nfa", "fa");
  1219. testProposals("fa", results, [
  1220. ["faaa", "faaa : { }"]
  1221. ]);
  1222. };
  1223. tests["te…

Large files files are truncated, but you can click here to view the full file