PageRenderTime 64ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/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
  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["test globals 2"] = function() {
  1224. var results = computeContentAssist("/*global \t\n faaa \t\t\n faaa2 */\nfa", "fa");
  1225. testProposals("fa", results, [
  1226. ["faaa", "faaa : { }"],
  1227. ["faaa2", "faaa2 : { }"]
  1228. ]);
  1229. };
  1230. tests["test globals 3"] = function() {
  1231. var results = computeContentAssist("/*global \t\n faaa \t\t\n fass2 */\nvar t = 1;\nt.fa", "fa");
  1232. testProposals("fa", results, [
  1233. ]);
  1234. };
  1235. tests["test globals 4"] = function() {
  1236. var results = computeContentAssist("/*global \t\n faaa:true \t\t\n faaa2:false */\nfa", "fa");
  1237. testProposals("fa", results, [
  1238. ["faaa", "faaa : { }"],
  1239. ["faaa2", "faaa2 : { }"]
  1240. ]);
  1241. };
  1242. tests["test globals 5"] = function() {
  1243. var results = computeContentAssist("/*global \t\n faaa:true, \t\t\n faaa2:false, */\nfa", "fa");
  1244. testProposals("fa", results, [
  1245. ["faaa", "faaa : { }"],
  1246. ["faaa2", "faaa2 : { }"]
  1247. ]);
  1248. };
  1249. ////////////////////////////
  1250. // tests for complex names
  1251. ////////////////////////////
  1252. tests["test complex name 1"] = function() {
  1253. var results = computeContentAssist("function Ttt() { }\nvar ttt = new Ttt();\ntt", "tt");
  1254. testProposals("tt", results, [
  1255. ["ttt", "ttt : Ttt"]
  1256. ]);
  1257. };
  1258. tests["test complex name 2"] = function() {
  1259. var results = computeContentAssist("var Ttt = function() { };\nvar ttt = new Ttt();\ntt", "tt");
  1260. testProposals("tt", results, [
  1261. ["ttt", "ttt : Ttt"]
  1262. ]);
  1263. };
  1264. tests["test complex name 3"] = function() {
  1265. var results = computeContentAssist("var ttt = { };\ntt", "tt");
  1266. testProposals("tt", results, [
  1267. ["ttt", "ttt : { }"]
  1268. ]);
  1269. };
  1270. tests["test complex name 4"] = function() {
  1271. var results = computeContentAssist("var ttt = { aa: 1, bb: 2 };\ntt", "tt");
  1272. testProposals("tt", results, [
  1273. ["ttt", "ttt : { aa : Number, bb : Number }"]
  1274. ]);
  1275. };
  1276. tests["test complex name 5"] = function() {
  1277. var results = computeContentAssist("var ttt = { aa: 1, bb: 2 };\nttt.cc = 9;\ntt", "tt");
  1278. testProposals("tt", results, [
  1279. ["ttt", "ttt : { aa : Number, bb : Number, cc : Number }"]
  1280. ]);
  1281. };
  1282. ////////////////////////////
  1283. // tests for broken syntax
  1284. ////////////////////////////
  1285. tests["test broken after dot 1"] = function() {
  1286. var results = computeContentAssist("var ttt = { ooo:8};\nttt.", "");
  1287. testProposals("", results, [
  1288. ["ooo", "ooo : Number"],
  1289. ["", "---------------------------------"],
  1290. ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
  1291. ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
  1292. ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
  1293. ["toLocaleString()", "toLocaleString() : String"],
  1294. ["toString()", "toString() : String"],
  1295. ["valueOf()", "valueOf() : Object"],
  1296. ["prototype", "prototype : Object"]
  1297. ]);
  1298. };
  1299. tests["test broken after dot 2"] = function() {
  1300. var results = computeContentAssist("var ttt = { ooo:8};\nif (ttt.) { ttt }", "", "var ttt = { ooo:8};\nif (ttt.".length);
  1301. testProposals("", results, [
  1302. ["ooo", "ooo : Number"],
  1303. ["", "---------------------------------"],
  1304. ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
  1305. ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
  1306. ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
  1307. ["toLocaleString()", "toLocaleString() : String"],
  1308. ["toString()", "toString() : String"],
  1309. ["valueOf()", "valueOf() : Object"],
  1310. ["prototype", "prototype : Object"]
  1311. ]);
  1312. };
  1313. tests["test broken after dot 3"] = function() {
  1314. var results = computeContentAssist("var ttt = { ooo:this.};", "", "var ttt = { ooo:this.".length);
  1315. testProposals("", results, [
  1316. // inferred type of ooo is object since we don't put real types on object literal properties until after the post-op
  1317. ["ooo", "ooo : Object"],
  1318. ["", "---------------------------------"],
  1319. ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
  1320. ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
  1321. ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
  1322. ["toLocaleString()", "toLocaleString() : String"],
  1323. ["toString()", "toString() : String"],
  1324. ["valueOf()", "valueOf() : Object"],
  1325. ["prototype", "prototype : Object"]
  1326. ]);
  1327. };
  1328. // same as above, except use /**/
  1329. tests["test broken after dot 3a"] = function() {
  1330. var results = computeContentAssist("var ttt = { ooo:this./**/};", "");
  1331. testProposals("", results, [
  1332. // inferred type of ooo is object since we don't put real types on object literal properties until after the post-op
  1333. ["ooo", "ooo : Object"],
  1334. ["", "---------------------------------"],
  1335. ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
  1336. ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
  1337. ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
  1338. ["toLocaleString()", "toLocaleString() : String"],
  1339. ["toString()", "toString() : String"],
  1340. ["valueOf()", "valueOf() : Object"],
  1341. ["prototype", "prototype : Object"]
  1342. ]);
  1343. };
  1344. tests["test broken after dot 4"] = function() {
  1345. var results = computeContentAssist("var ttt = { ooo:8};\nfunction ff() { \nttt.}", "", "var ttt = { ooo:8};\nfunction ff() { \nttt.".length);
  1346. testProposals("", results, [
  1347. ["ooo", "ooo : Number"],
  1348. ["", "---------------------------------"],
  1349. ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
  1350. ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
  1351. ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
  1352. ["toLocaleString()", "toLocaleString() : String"],
  1353. ["toString()", "toString() : String"],
  1354. ["valueOf()", "valueOf() : Object"],
  1355. ["prototype", "prototype : Object"]
  1356. ]);
  1357. };
  1358. // same as above, except use /**/
  1359. tests["test broken after dot 4a"] = function() {
  1360. var results = computeContentAssist("var ttt = { ooo:8};\nfunction ff() { \nttt./**/}", "");
  1361. testProposals("", results, [
  1362. ["ooo", "ooo : Number"],
  1363. ["", "---------------------------------"],
  1364. ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
  1365. ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
  1366. ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
  1367. ["toLocaleString()", "toLocaleString() : String"],
  1368. ["toString()", "toString() : String"],
  1369. ["valueOf()", "valueOf() : Object"],
  1370. ["prototype", "prototype : Object"]
  1371. ]);
  1372. };
  1373. tests["test broken after dot 5"] = function() {
  1374. var results = computeContentAssist(
  1375. "var first = {ooo:9};\n" +
  1376. "first.\n" +
  1377. "var jjj;", "",
  1378. ("var first = {ooo:9};\n" +
  1379. "first.").length);
  1380. testProposals("", results, [
  1381. ["ooo", "ooo : Number"],
  1382. ["", "---------------------------------"],
  1383. ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
  1384. ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
  1385. ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
  1386. ["toLocaleString()", "toLocaleString() : String"],
  1387. ["toString()", "toString() : String"],
  1388. ["valueOf()", "valueOf() : Object"],
  1389. ["prototype", "prototype : Object"]
  1390. ]);
  1391. };
  1392. tests["test broken after dot 6"] = function() {
  1393. var results = computeContentAssist(
  1394. "var first = {ooo:9};\n" +
  1395. "first.\n" +
  1396. "if (x) { }", "",
  1397. ("var first = {ooo:9};\n" +
  1398. "first.").length);
  1399. testProposals("", results, [
  1400. ["ooo", "ooo : Number"],
  1401. ["", "---------------------------------"],
  1402. ["hasOwnProperty(property)", "hasOwnProperty(property) : boolean"],
  1403. ["isPrototypeOf(object)", "isPrototypeOf(object) : boolean"],
  1404. ["propertyIsEnumerable(property)", "propertyIsEnumerable(property) : boolean"],
  1405. ["toLocaleString()", "toLocaleString() : String"],
  1406. ["toString()", "toString() : String"],
  1407. ["valueOf()", "valueOf() : Object"],
  1408. ["prototype", "prototype : Object"]
  1409. ]);
  1410. };
  1411. // test return types of various simple functions
  1412. tests["test function return type 1"] = function() {
  1413. var results = computeContentAssist(
  1414. "var first = function() { return 9; };\nfirst().toF", "toF");
  1415. testProposals("toF", results, [
  1416. ["toFixed(digits)", "toFixed(digits) : Number"]
  1417. ]);
  1418. };
  1419. tests["test function return type 1a"] = function() {
  1420. // complete on a function, not a number
  1421. var results = computeContentAssist(
  1422. "var first = function() { return 9; };\nfirst.arg", "arg");
  1423. testProposals("arg", results, [
  1424. ["arguments", "arguments : Arguments"]
  1425. ]);
  1426. };
  1427. tests["test function return type 2"] = function() {
  1428. var results = computeContentAssist(
  1429. "function first() { return 9; };\nfirst().toF", "toF");
  1430. testProposals("toF", results, [
  1431. ["toFixed(digits)", "toFixed(digits) : Number"]
  1432. ]);
  1433. };
  1434. tests["test function return type 3"] = function() {
  1435. var results = computeContentAssist(
  1436. "var obj = { first : function () { return 9; } };\nobj.first().toF", "toF");
  1437. testProposals("toF", results, [
  1438. ["toFixed(digits)", "toFixed(digits) : Number"]
  1439. ]);
  1440. };
  1441. tests["test function return type 4"] = function() {
  1442. var results = computeContentAssist(
  1443. "function first() { return { ff : 9 }; };\nfirst().ff.toF", "toF");
  1444. testProposals("toF", results, [
  1445. ["toFixed(digits)", "toFixed(digits) : Number"]
  1446. ]);
  1447. };
  1448. tests["test function return type 5"] = function() {
  1449. var results = computeContentAssist(
  1450. "function first() { return function() { return 9; }; };\nvar ff = first();\nff().toF", "toF");
  1451. testProposals("toF", results, [
  1452. ["toFixed(digits)", "toFixed(digits) : Number"]
  1453. ]);
  1454. };
  1455. tests["test function return type 6"] = function() {
  1456. var results = computeContentAssist(
  1457. "function first() { return function() { return 9; }; };\nfirst()().toF", "toF");
  1458. testProposals("toF", results, [
  1459. ["toFixed(digits)", "toFixed(digits) : Number"]
  1460. ]);
  1461. };
  1462. // now test different ways that functions can be constructed
  1463. tests["test function return type if 1"] = function() {
  1464. var results = computeContentAssist(
  1465. "function first() { if(true) { return 8; } };\nfirst().toF", "toF");
  1466. testProposals("toF", results, [
  1467. ["toFixed(digits)", "toFixed(digits) : Number"]
  1468. ]);
  1469. };
  1470. tests["test function return type if 2"] = function() {
  1471. // always choose the last return statement
  1472. var results = computeContentAssist(
  1473. "function first() { if(true) { return ''; } else { return 8; } };\nfirst().toF", "toF");
  1474. testProposals("toF", results, [
  1475. ["toFixed(digits)", "toFixed(digits) : Number"]
  1476. ]);
  1477. };
  1478. tests["test function return type while"] = function() {
  1479. // always choose the last return statement
  1480. var results = computeContentAssist(
  1481. "function first() { while(true) { return 1; } };\nfirst().toF", "toF");
  1482. testProposals("toF", results, [
  1483. ["toFixed(digits)", "toFixed(digits) : Number"]
  1484. ]);
  1485. };
  1486. tests["test function return type do/while"] = function() {
  1487. // always choose the last return statement
  1488. var results = computeContentAssist(
  1489. "function first() { do { return 1; } while(true); };\nfirst().toF", "toF");
  1490. testProposals("toF", results, [
  1491. ["toFixed(digits)", "toFixed(digits) : Number"]
  1492. ]);
  1493. };
  1494. tests["test function return type for"] = function() {
  1495. // always choose the last return statement
  1496. var results = computeContentAssist(
  1497. "function first() { for (var i; i < 10; i++) { return 1; } };\nfirst().toF", "toF");
  1498. testProposals("toF", results, [
  1499. ["toFixed(digits)", "toFixed(digits) : Number"]
  1500. ]);
  1501. };
  1502. tests["test function return type for in"] = function() {
  1503. // always choose the last return statement
  1504. var results = computeContentAssist(
  1505. "function first() { for (var i in k) { return 1; } };\nfirst().toF", "toF");
  1506. testProposals("toF", results, [
  1507. ["toFixed(digits)", "toFixed(digits) : Number"]
  1508. ]);
  1509. };
  1510. tests["test function return type try 1"] = function() {
  1511. // always choose the last return statement
  1512. var results = computeContentAssist(
  1513. "function first() { try { return 1; } catch(e) { } };\nfirst().toF", "toF");
  1514. testProposals("toF", results, [
  1515. ["toFixed(digits)", "toFixed(digits) : Number"]
  1516. ]);
  1517. };
  1518. tests["test function return type try 2"] = function() {
  1519. // always choose the last return statement
  1520. var results = computeContentAssist(
  1521. "function first() { try { return 1; } catch(e) { } finally { } };\nfirst().toF", "toF");
  1522. testProposals("toF", results, [
  1523. ["toFixed(digits)", "toFixed(digits) : Number"]
  1524. ]);
  1525. };
  1526. tests["test function return type try 3"] = function() {
  1527. // always choose the last return statement
  1528. var results = computeContentAssist(
  1529. "function first() { try { return ''; } catch(e) { return 9; } finally { } };\nfirst().toF", "toF");
  1530. testProposals("toF", results, [
  1531. ["toFixed(digits)", "toFixed(digits) : Number"]
  1532. ]);
  1533. };
  1534. tests["test function return type try 4"] = function() {
  1535. // always choose the last return statement
  1536. var results = computeContentAssist(
  1537. "function first() { try { return ''; } catch(e) { return ''; } finally { return 9; } };\nfirst().toF", "toF");
  1538. testProposals("toF", results, [
  1539. ["toFixed(digits)", "toFixed(digits) : Number"]
  1540. ]);
  1541. };
  1542. tests["test function return type switch 1"] = function() {
  1543. // always choose the last return statement
  1544. var results = computeContentAssist(
  1545. "function first() { switch (v) { case a: return 9; } };\nfirst().toF", "toF");
  1546. testProposals("toF", results, [
  1547. ["toFixed(digits)", "toFixed(digits) : Number"]
  1548. ]);
  1549. };
  1550. tests["test function return type switch 2"] = function() {
  1551. // always choose the last return statement
  1552. var results = computeContentAssist(
  1553. "function first() { switch (v) { case b: return ''; case a: return 1; } };\nfirst().toF", "toF");
  1554. testProposals("toF", results, [
  1555. ["toFixed(digits)", "toFixed(digits) : Number"]
  1556. ]);
  1557. };
  1558. tests["test function return type switch 3"] = function() {
  1559. // always choose the last return statement
  1560. var results = computeContentAssist(
  1561. "function first() { switch (v) { case b: return ''; default: return 1; } };\nfirst().toF", "toF");
  1562. testProposals("toF", results, [
  1563. ["toFixed(digits)", "toFixed(digits) : Number"]
  1564. ]);
  1565. };
  1566. tests["test function return type nested block 1"] = function() {
  1567. // always choose the last return statement
  1568. var results = computeContentAssist(
  1569. "function first() { while(true) { a;\nb\n;return 9; } };\nfirst().toF", "toF");
  1570. testProposals("toF", results, [
  1571. ["toFixed(digits)", "toFixed(digits) : Number"]
  1572. ]);
  1573. };
  1574. tests["test function return type nest block 2"] = function() {
  1575. // always choose the last return statement
  1576. var results = computeContentAssist(
  1577. "function first() { while(true) { while(false) { \n;return 9; } } };\nfirst().toF", "toF");
  1578. testProposals("toF", results, [
  1579. ["toFixed(digits)", "toFixed(digits) : Number"]
  1580. ]);
  1581. };
  1582. tests["test function return type obj literal 1"] = function() {
  1583. var results = computeContentAssist(
  1584. "function first() { return { a : 9, b : '' }; };\nfir", "fir");
  1585. testProposals("fir", results, [
  1586. ["first()", "first() : { a : Number, b : String }"]
  1587. ]);
  1588. };
  1589. // not sure I like this. returning an object literal wrapped in a funtion looks no different from
  1590. // returning an object literal
  1591. tests["test function return type obj literal 2"] = function() {
  1592. var results = computeContentAssist(
  1593. "function first () {" +
  1594. " return function () {\n" +
  1595. " var a = { a : 9, b : '' };\n" +
  1596. " return a;\n" +
  1597. " }\n" +
  1598. "}\nfir", "fir");
  1599. testProposals("fir", results, [
  1600. ["first()", "first() : { a : Number, b : String }"]
  1601. ]);
  1602. };
  1603. tests["test function return type obj literal 3"] = function() {
  1604. var results = computeContentAssist(
  1605. "function first () {" +
  1606. " return function () {\n" +
  1607. " var a = { a : 9, b : '' };\n" +
  1608. " return a;\n" +
  1609. " }\n" +
  1610. "}\nfirst().ar", "ar");
  1611. testProposals("ar", results, [
  1612. ["arguments", "arguments : Arguments"]
  1613. ]);
  1614. };
  1615. tests["test function return type obj literal 4"] = function() {
  1616. var results = computeContentAssist(
  1617. "function first () {" +
  1618. " return function () {\n" +
  1619. " var a = { aa : 9, b : '' };\n" +
  1620. " return a;\n" +
  1621. " }\n" +
  1622. "}\nfirst()().a", "a");
  1623. testProposals("a", results, [
  1624. ["aa", "aa : Number"]
  1625. ]);
  1626. };
  1627. ///////////////////////////////////////////////
  1628. // Some tests for implicitly defined variables
  1629. ///////////////////////////////////////////////
  1630. // should see xxx as an object
  1631. tests["test implicit1"] = function() {
  1632. var results = computeContentAssist(
  1633. "xxx;\nxx", "xx");
  1634. testProposals("xx", results, [
  1635. ["xxx", "xxx : { }"]
  1636. ]);
  1637. };
  1638. tests["test implicit2"] = function() {
  1639. var results = computeContentAssist(
  1640. "xxx.yyy = 0;\nxxx.yy", "yy");
  1641. testProposals("yy", results, [
  1642. ["yyy", "yyy : Number"]
  1643. ]);
  1644. };
  1645. tests["test implicit3"] = function() {
  1646. var results = computeContentAssist(
  1647. "xxx;\n xxx.yyy = 0;\nxxx.yy", "yy");
  1648. testProposals("yy", results, [
  1649. ["yyy", "yyy : Number"]
  1650. ]);
  1651. };
  1652. tests["test implicit4"] = function() {
  1653. var results = computeContentAssist(
  1654. "xxx = 0;\nxx", "xx");
  1655. testProposals("xx", results, [
  1656. ["xxx", "xxx : Number"]
  1657. ]);
  1658. };
  1659. // implicits are available in the global scope
  1660. tests["test implicit5"] = function() {
  1661. var results = computeContentAssist(
  1662. "function inner() { xxx = 0; }\nxx", "xx");
  1663. testProposals("xx", results, [
  1664. ["xxx", "xxx : Number"]
  1665. ]);
  1666. };
  1667. // implicits are available in the global scope
  1668. tests["test implicit6"] = function() {
  1669. var results = computeContentAssist(
  1670. "var obj = { foo : function inner() { xxx = 0; } }\nxx", "xx");
  1671. testProposals("xx", results, [
  1672. ["xxx", "xxx : Number"]
  1673. ]);
  1674. };
  1675. // should not see an implicit if it comes after the invocation location
  1676. tests["test implicit7"] = function() {
  1677. var results = computeContentAssist(
  1678. "xx/**/\nxxx", "xx");
  1679. testProposals("xx", results, [
  1680. ]);
  1681. };
  1682. tests["test implicit8"] = function() {
  1683. var results = computeContentAssist(
  1684. "var xxx;\nvar obj = { foo : function inner() { xxx = 0; } }\nxx", "xx");
  1685. testProposals("xx", results, [
  1686. ["xxx", "xxx : Number"]
  1687. ]);
  1688. };
  1689. // not really an implicit variable, but
  1690. tests["test implicit9"] = function() {
  1691. var results = computeContentAssist(
  1692. "xxx", "xxx");
  1693. testProposals("xxx", results, [
  1694. ]);
  1695. };
  1696. ///////////////////////////////////////////////
  1697. // Binary and unary expressions
  1698. ///////////////////////////////////////////////
  1699. tests["test binary expr1"] = function() {
  1700. var results = computeContentAssist(
  1701. "(1 + 2).toF", "toF");
  1702. testProposals("toF", results, [
  1703. ["toFixed(digits)", "toFixed(digits) : Number"]
  1704. ]);
  1705. };
  1706. tests["test binary expr2"] = function() {
  1707. var results = computeContentAssist(
  1708. "(1 + '').char", "char");
  1709. testProposals("char", results, [
  1710. ["charAt(index)", "charAt(index) : String"],
  1711. ["charCodeAt(index)", "charCodeAt(index) : Number"]
  1712. ]);
  1713. };
  1714. tests["test binary expr3"] = function() {
  1715. var results = computeContentAssist(
  1716. "('' + 2).char", "char");
  1717. testProposals("char", results, [
  1718. ["charAt(index)", "charAt(index) : String"],
  1719. ["charCodeAt(index)", "charCodeAt(index) : Number"]
  1720. ]);
  1721. };
  1722. tests["test binary expr4"] = function() {
  1723. var results = computeContentAssist(
  1724. "('' + hucairz).char", "char");
  1725. testProposals("char", results, [
  1726. ["charAt(index)", "charAt(index) : String"],
  1727. ["charCodeAt(index)", "charCodeAt(index) : Number"]
  1728. ]);
  1729. };
  1730. tests["test binary expr5"] = function() {
  1731. var results = computeContentAssist(
  1732. "(hucairz + hucairz).toF", "toF");
  1733. testProposals("toF", results, [
  1734. ["toFixed(digits)", "toFixed(digits) : Number"]
  1735. ]);
  1736. };
  1737. tests["test binary expr6"] = function() {
  1738. var results = computeContentAssist(
  1739. "(hucairz - hucairz).toF", "toF");
  1740. testProposals("toF", results, [
  1741. ["toFixed(digits)", "toFixed(digits) : Number"]
  1742. ]);
  1743. };
  1744. tests["test binary expr7"] = function() {
  1745. var results = computeContentAssist(
  1746. "('' - '').toF", "toF");
  1747. testProposals("toF", results, [
  1748. ["toFixed(digits)", "toFixed(digits) : Number"]
  1749. ]);
  1750. };
  1751. tests["test binary expr8"] = function() {
  1752. var results = computeContentAssist(
  1753. "('' & '').toF", "toF");
  1754. testProposals("toF", results, [
  1755. ["toFixed(digits)", "toFixed(digits) : Number"]
  1756. ]);
  1757. };
  1758. tests["test binary expr9"] = function() {
  1759. var results = computeContentAssist(
  1760. "({ a : 9 } && '').a.toF", "toF");
  1761. testProposals("toF", results, [
  1762. ["toFixed(digits)", "toFixed(digits) : Number"]
  1763. ]);
  1764. };
  1765. tests["test binary expr10"] = function() {
  1766. var results = computeContentAssist(
  1767. "({ a : 9 } || '').a.toF", "toF");
  1768. testProposals("toF", results, [
  1769. ["toFixed(digits)", "toFixed(digits) : Number"]
  1770. ]);
  1771. };
  1772. tests["test binary expr11"] = function() {
  1773. var results = computeContentAssist(
  1774. "var aaa = function() { return hucairz || hucairz; }\naa", "aa");
  1775. testProposals("aa", results, [
  1776. ["aaa()", "aaa() : { }"]
  1777. ]);
  1778. };
  1779. tests["test binary expr12"] = function() {
  1780. var results = computeContentAssist(
  1781. "var aaa = function() { return hucairz | hucairz; }\naa", "aa");
  1782. testProposals("aa", results, [
  1783. ["aaa()", "aaa() : Number"]
  1784. ]);
  1785. };
  1786. tests["test binary expr12"] = function() {
  1787. var results = computeContentAssist(
  1788. "var aaa = function() { return hucairz == hucairz; }\naa", "aa");
  1789. testProposals("aa", results, [
  1790. ["aaa()", "aaa() : Boolean"]
  1791. ]);
  1792. };
  1793. tests["test unary expr1"] = function() {
  1794. var results = computeContentAssist(
  1795. "(x += y).toF", "toF");
  1796. testProposals("toF", results, [
  1797. ["toFixed(digits)", "toFixed(digits) : Number"]
  1798. ]);
  1799. };
  1800. tests["test unary expr2"] = function() {
  1801. var results = computeContentAssist(
  1802. "(x += 1).toF", "toF");
  1803. testProposals("toF", results, [
  1804. ["toFixed(digits)", "toFixed(digits) : Number"]
  1805. ]);
  1806. };
  1807. tests["test unary expr3"] = function() {
  1808. var results = computeContentAssist(
  1809. "var x = '';\n(x += 1).char", "char");
  1810. testProposals("char", results, [
  1811. ["charAt(index)", "charAt(index) : String"],
  1812. ["charCodeAt(index)", "charCodeAt(index) : Number"]
  1813. ]);
  1814. };
  1815. tests["test unary expr4"] = function() {
  1816. var results = computeContentAssist(
  1817. "var aaa = function() { return !hucairz; }\naa", "aa");
  1818. testProposals("aa", results, [
  1819. ["aaa()", "aaa() : Boolean"]
  1820. ]);
  1821. };
  1822. ///////////////////////////////////////////////
  1823. // Mucking around with a constructor function's prototype
  1824. ///////////////////////////////////////////////
  1825. tests["test constructor prototype1"] = function() {
  1826. var results = computeContentAssist(
  1827. "var AAA = function() { };\nAAA.prototype.foo = 9;\nnew AAA().f", "f");
  1828. testProposals("f", results, [
  1829. ["foo", "foo : Number"]
  1830. ]);
  1831. };
  1832. tests["test constructor prototype2"] = function() {
  1833. var results = computeContentAssist(
  1834. "var AAA = function() { };\nAAA.prototype = { foo : 9 };\nnew AAA().f", "f");
  1835. testProposals("f", results, [
  1836. ["foo", "foo : Number"]
  1837. ]);
  1838. };
  1839. tests["test constructor prototype3"] = function() {
  1840. var results = computeContentAssist(
  1841. "var AAA = function() { this.foo = 0; };\nAAA.prototype = { foo : '' };\nnew AAA().f", "f");
  1842. testProposals("f", results, [
  1843. ["foo", "foo : Number"]
  1844. ]);
  1845. };
  1846. tests["test constructor prototype4"] = function() {
  1847. var results = computeContentAssist(
  1848. "var AAA = function() { };\nAAA.prototype = { foo : 9 };\nvar x = new AAA();\n x.f", "f");
  1849. testProposals("f", results, [
  1850. ["foo", "foo : Number"]
  1851. ]);
  1852. };
  1853. tests["test constructor prototype5"] = function() {
  1854. var results = computeContentAssist(
  1855. "var AAA = function() { };\nAAA.prototype = { foo : '' };\nvar x = new AAA();\nx.foo = 9;\nx.f", "f");
  1856. testProposals("f", results, [
  1857. ["foo", "foo : Number"]
  1858. ]);
  1859. };
  1860. tests["test constructor prototype6"] = function() {
  1861. var results = computeContentAssist(
  1862. "var Fun = function() { };\n" +
  1863. "var obj = new Fun();\n" +
  1864. "Fun.prototype.num = 0;\n" +
  1865. "obj.n", "n");
  1866. testProposals("n", results, [
  1867. ["num", "num : Number"]
  1868. ]);
  1869. };
  1870. tests["test dotted constructor1"] = function() {
  1871. var results = computeContentAssist(
  1872. "var obj = { Fun : function() { }, fun : function() {}, fun2 : 9 }\nnew obj", "obj");
  1873. testProposals("obj", results, [
  1874. ["obj.Fun()", "obj.Fun() : obj.Fun"],
  1875. ["obj", "obj : { Fun : obj.Fun, fun : undefined, fun2 : Number }"]
  1876. ]);
  1877. };
  1878. tests["test dotted constructor2"] = function() {
  1879. var results = computeContentAssist(
  1880. "var obj = { Fun : function() { } }\nnew obj.F", "F");
  1881. testProposals("F", results, [
  1882. ["Fun()", "Fun() : obj.Fun"]
  1883. ]);
  1884. };
  1885. tests["test dotted constructor3"] = function() {
  1886. var results = computeContentAssist(
  1887. "var obj = { };\nobj.Fun = function() { };\nnew obj", "obj");
  1888. testProposals("obj", results, [
  1889. ["obj.Fun()", "obj.Fun() : obj.Fun"],
  1890. ["obj", "obj : { Fun : obj.Fun }"]
  1891. ]);
  1892. };
  1893. tests["test dotted constructor4"] = function() {
  1894. var results = computeContentAssist(
  1895. "var obj = { inner : { Fun : function() { } } }\nnew obj", "obj");
  1896. testProposals("obj", results, [
  1897. ["obj.inner.Fun()", "obj.inner.Fun() : obj.inner.Fun"],
  1898. ["obj", "obj : { inner : { Fun : {...} } }"]
  1899. ]);
  1900. };
  1901. tests["test dotted constructor5"] = function() {
  1902. var results = computeContentAssist(
  1903. "var obj = { inner : { } }\nobj.inner.Fun = function() { }\nnew obj", "obj");
  1904. testProposals("obj", results, [
  1905. ["obj.inner.Fun()", "obj.inner.Fun() : obj.inner.Fun"],
  1906. ["obj", "obj : { inner : { Fun : {...} } }"]
  1907. ]);
  1908. };
  1909. tests["test dotted constructor6"] = function() {
  1910. var results = computeContentAssist(
  1911. "var obj = { inner : { } }\nobj.inner.inner2 = { Fun : function() { } }\nnew obj", "obj");
  1912. testProposals("obj", results, [
  1913. ["obj.inner.inner2.Fun()", "obj.inner.inner2.Fun() : obj.inner.inner2.Fun"],
  1914. ["obj", "obj : { inner : { inner2 : {...} } }"]
  1915. ]);
  1916. };
  1917. // assign to another---should only have one proposal since we don't change the type name
  1918. tests["test dotted constructor7"] = function() {
  1919. var results = computeContentAssist(
  1920. "var obj = { inner : { Fun : function() { } } }\n" +
  1921. "var other = obj\n" +
  1922. "new other.inner", "inner");
  1923. testProposals("inner", results, [
  1924. ["inner", "inner : { Fun : obj.inner.Fun }"]
  1925. ]);
  1926. };
  1927. // assign sub-part to another---should only have one proposal since we don't change the type name
  1928. tests["test dotted constructor8"] = function() {
  1929. var results = computeContentAssist(
  1930. "var obj = { inner : { Fun : function() { } } }\n" +
  1931. "var other = obj.inner\n" +
  1932. "new other", "other");
  1933. testProposals("other", results, [
  1934. ["other", "other : { Fun : obj.inner.Fun }"]
  1935. ]);
  1936. };
  1937. // overloaded constructors
  1938. tests["test dotted constructor9"] = function() {
  1939. var results = computeContentAssist(
  1940. "var obj = { Fun : function() { this.yy1 = 9; } }\n" +
  1941. "var obj2 = { Fun : function() { this.yy2 = 9; } }\n" +
  1942. "var xxx = new obj.Fun();\n" +
  1943. "xxx.yy", "yy");
  1944. testProposals("yy", results, [
  1945. ["yy1", "yy1 : Number"]
  1946. ]);
  1947. };
  1948. tests["test dotted constructor10"] = function() {
  1949. var results = computeContentAssist(
  1950. "var obj = { Fun : function() { } }\nobj.Fun.prototype = { yy1 : 9};\n" +
  1951. "var obj2 = { Fun : function() { } }\nobj2.Fun.prototype = { yy2 : 9};\n" +
  1952. "var xxx = new obj.Fun();\n" +
  1953. "xxx.yy", "yy");
  1954. testProposals("yy", results, [
  1955. ["yy1", "yy1 : Number"]
  1956. ]);
  1957. };
  1958. // constructor declared inside a function should not be available externally
  1959. tests["test constructor in function"] = function() {
  1960. var results = computeContentAssist(
  1961. "var obj = function() { var Fn = function() { }; };\n" +
  1962. "new Fn", "Fn");
  1963. testProposals("Fn", results, [
  1964. ]);
  1965. };
  1966. // TODO FIXADE this is wrong, but we're still going to test it
  1967. // constructor declared as a member available in global scope
  1968. tests["test constructor in constructor BAD"] = function() {
  1969. var results = computeContentAssist(
  1970. "var obj = function() { this.Fn = function() { }; };\n" +
  1971. "new Fn", "Fn");
  1972. testProposals("Fn", results, [
  1973. ["Fn()", "Fn() : obj.Fn"]
  1974. ]);
  1975. };
  1976. // Not ideal, but a constructor being used from a constructed object is not dotted, but should be
  1977. tests["test constructor in constructor Not Ideal"] = function() {
  1978. var results = computeContentAssist(
  1979. "function Fun() { this.Inner = function() { }}\n" +
  1980. "var f = new Fun()\n" +
  1981. "new f.Inner", "Inner");
  1982. testProposals("Inner", results, [
  1983. // should be Fun.Inner, but is not
  1984. ["Inner()", "Inner() : Inner"]
  1985. ]);
  1986. };
  1987. // should not be able to redefine or add to global types
  1988. tests["test global redefine1"] = function() {
  1989. var results = computeContentAssist(
  1990. "this.JSON = {};\n" +
  1991. "JSON.st", "st");
  1992. testProposals("st", results, [
  1993. ["stringify(obj)", "stringify(obj) : String"]
  1994. ]);
  1995. };
  1996. // should not be able to redefine or add to global types
  1997. tests["test global redefine2"] = function() {
  1998. var results = computeContentAssist(
  1999. "this.JSON.stFOO;\n" +
  2000. "JSON.st", "st");
  2001. testProposals("st", results, [
  2002. ["stringify(obj)", "stringify(obj) : String"]
  2003. ]);
  2004. };
  2005. // browser awareness
  2006. tests["test browser1"] = function() {
  2007. var results = computeContentAssist(
  2008. "/*jslint browser:true*/\n" +
  2009. "thi", "thi"
  2010. );
  2011. testProposals("thi", results, [
  2012. ["this", "this : Window"]
  2013. ]);
  2014. };
  2015. tests["test browser2"] = function() {
  2016. var results = computeContentAssist(
  2017. "/*jslint browser:false*/\n" +
  2018. "thi", "thi"
  2019. );
  2020. testProposals("thi", results, [
  2021. ["this", "this : Global"]
  2022. ]);
  2023. };
  2024. // regular stuff should still work in the browser
  2025. tests["test browser3"] = function() {
  2026. var results = computeContentAssist(
  2027. "/*jslint browser:true*/\n" +
  2028. "JSON.st", "st");
  2029. testProposals("st", results, [
  2030. ["stringify(obj)", "stringify(obj) : String"]
  2031. ]);
  2032. };
  2033. tests["test browser4"] = function() {
  2034. var results = computeContentAssist(
  2035. "/*jslint browser:true*/\n" +
  2036. "locatio", "locatio"
  2037. );
  2038. testProposals("locatio", results, [
  2039. ["location", "location : Location"],
  2040. ["locationbar", "locationbar : BarInfo"]
  2041. ]);
  2042. };
  2043. tests["test browser5"] = function() {
  2044. var results = computeContentAssist(
  2045. "/*jslint browser:true*/\n" +
  2046. // should not be able to set a default property
  2047. "location = 5\n" +
  2048. "locatio", "locatio"
  2049. );
  2050. testProposals("locatio", results, [
  2051. ["location", "location : Location"],
  2052. ["locationbar", "locationbar : BarInfo"]
  2053. ]);
  2054. };
  2055. tests["test browser6"] = function() {
  2056. var results = computeContentAssist(
  2057. "/*global location*/\n" +
  2058. "/*jslint browser:true*/\n" +
  2059. "locatio", "locatio"
  2060. );
  2061. testProposals("locatio", results, [
  2062. ["location", "location : Location"],
  2063. ["locationbar", "locationbar : BarInfo"]
  2064. ]);
  2065. };
  2066. tests["test browser7"] = function() {
  2067. var results = computeContentAssist(
  2068. "/*jslint browser:true*/\n" +
  2069. "window.xx = 9;\nx", "x"
  2070. );
  2071. testProposals("x", results, [
  2072. ["xx", "xx : Number"]
  2073. ]);
  2074. };
  2075. tests["test browser8"] = function() {
  2076. var results = computeContentAssist(
  2077. "/*jslint browser:true*/\n" +
  2078. "var xx = 9;\nwindow.x", "x"
  2079. );
  2080. testProposals("x", results, [
  2081. ["xx", "xx : Number"]
  2082. ]);
  2083. };
  2084. tests["test browser9"] = function() {
  2085. var results = computeContentAssist(
  2086. "/*jslint browser:true*/\n" +
  2087. "var xx = 9;\nthis.x", "x"
  2088. );
  2089. testProposals("x", results, [
  2090. ["xx", "xx : Number"]
  2091. ]);
  2092. };
  2093. ////////////////////////////////////////
  2094. // jsdoc tests
  2095. ////////////////////////////////////////
  2096. if (!doctrine.isStub) {
  2097. // the basics
  2098. tests["test simple jsdoc1"] = function() {
  2099. var results = computeContentAssist(
  2100. "/** @type Number*/\n" +
  2101. "var xx;\nx", "x"
  2102. );
  2103. testProposals("x", results, [
  2104. ["xx", "xx : Number"]
  2105. ]);
  2106. };
  2107. tests["test simple jsdoc2"] = function() {
  2108. var results = computeContentAssist(
  2109. "/** @type String*/\n" +
  2110. "/** @type Number*/\n" +
  2111. "var xx;\nx", "x"
  2112. );
  2113. testProposals("x", results, [
  2114. ["xx", "xx : Number"]
  2115. ]);
  2116. };
  2117. tests["test simple jsdoc3"] = function() {
  2118. var results = computeContentAssist(
  2119. "/** @type Number*/\n" +
  2120. "/* @type String*/\n" +
  2121. "var xx;\nx", "x"
  2122. );
  2123. testProposals("x", results, [
  2124. ["xx", "xx : Number"]
  2125. ]);
  2126. };
  2127. tests["test simple jsdoc4"] = function() {
  2128. var results = computeContentAssist(
  2129. "/** @type Number*/\n" +
  2130. "// @type String\n" +
  2131. "var xx;\nx", "x"
  2132. );
  2133. testProposals("x", results, [
  2134. ["xx", "xx : Number"]
  2135. ]);
  2136. };
  2137. // This is actually a bug. We incorrectly recognize //* comments as jsdoc coments
  2138. tests["test simple jsdoc5"] = function() {
  2139. var results = computeContentAssist(
  2140. "/** @type Number*/\n" +
  2141. "//* @type String\n" +
  2142. "var xx;\nx", "x"
  2143. );
  2144. testProposals("x", results, [
  2145. ["xx", "xx : String"]
  2146. ]);
  2147. };
  2148. tests["test simple jsdoc6"] = function() {
  2149. var results = computeContentAssist(
  2150. "/** @type String*/\n" +
  2151. "var yy;\n" +
  2152. "/** @type Number*/\n" +
  2153. "var xx;\nx", "x"
  2154. );
  2155. testProposals("x", results, [
  2156. ["xx", "xx : Number"]
  2157. ]);
  2158. };
  2159. tests["test simple jsdoc7"] = function() {
  2160. var results = computeContentAssist(
  2161. "/** @type String*/" +
  2162. "var yy;" +
  2163. "/** @type Number*/" +
  2164. "var xx;x", "x"
  2165. );
  2166. testProposals("x", results, [
  2167. ["xx", "xx : Number"]
  2168. ]);
  2169. };
  2170. tests["test simple jsdoc8"] = function() {
  2171. var results = computeContentAssist(
  2172. "/** @returns String\n@type Number*/\n" +
  2173. "var xx;\nx", "x"
  2174. );
  2175. testProposals("x", results, [
  2176. ["xx", "xx : Number"]
  2177. ]);
  2178. };
  2179. tests["test simple jsdoc9"] = function() {
  2180. var results = computeContentAssist(
  2181. "/** @param String f\n@type Number*/\n" +
  2182. "var xx;\nx", "x"
  2183. );
  2184. testProposals("x", results, [
  2185. ["xx", "xx : Number"]
  2186. ]);
  2187. };
  2188. tests["test simple jsdoc10"] = function() {
  2189. var results = computeContentAssist(
  2190. "/** @return Number*/\n" +
  2191. "var xx = function() { };\nx", "x"
  2192. );
  2193. testProposals("x", results, [
  2194. ["xx()", "xx() : Number"]
  2195. ]);
  2196. };
  2197. tests["test simple jsdoc11"] = function() {
  2198. var results = computeContentAssist(
  2199. "/** @type String\n@return Number*/\n" +
  2200. "var xx = function() { };\nx", "x"
  2201. );
  2202. testProposals("x", results, [
  2203. ["xx()", "xx() : Number"]
  2204. ]);
  2205. };
  2206. tests["test simple jsdoc12"] = function() {
  2207. var results = computeContentAssist(
  2208. "var xx;\n" +
  2209. "/** @type String\n@return Number*/\n" +
  2210. "xx = function() { };\nx", "x"
  2211. );
  2212. testProposals("x", results, [
  2213. ["xx()", "xx() : Number"]
  2214. ]);
  2215. };
  2216. tests["test simple jsdoc13"] = function() {
  2217. var results = computeContentAssist(
  2218. "var xx;\n" +
  2219. "/** @type String\n@param Number ss*/\n" +
  2220. "xx = function(ss) { s/**/ };", "s"
  2221. );
  2222. testProposals("s", results, [
  2223. ["ss", "ss : Number"]
  2224. ]);
  2225. };
  2226. tests["test simple jsdoc14"] = function() {
  2227. var results = computeContentAssist(
  2228. "/** @type Number*/\n" +
  2229. "var xx;\n" +
  2230. "/** @type String*/\n" +
  2231. "xx;\nx", "x"
  2232. );
  2233. testProposals("x", results, [
  2234. ["xx", "xx : Number"]
  2235. ]);
  2236. };
  2237. // the complex types tag
  2238. tests["test type union jsdoc1"] = function() {
  2239. var results = computeContentAssist(
  2240. "/** @type {String|Number}*/\n" +
  2241. "var xx;\nx", "x"
  2242. );
  2243. // for union types, we arbitrarily choose the first type
  2244. testProposals("x", results, [
  2245. ["xx", "xx : String"]
  2246. ]);
  2247. };
  2248. tests["test type nullable jsdoc1"] = function() {
  2249. var results = computeContentAssist(
  2250. "/** @type {?String}*/\n" +
  2251. "var xx;\nx", "x"
  2252. );
  2253. testProposals("x", results, [
  2254. ["xx", "xx : String"]
  2255. ]);
  2256. };
  2257. tests["test type non-nullable jsdoc1"] = function() {
  2258. var results = computeContentAssist(
  2259. "/** @type {!String}*/\n" +
  2260. "var xx;\nx", "x"
  2261. );
  2262. testProposals("x", results, [
  2263. ["xx", "xx : String"]
  2264. ]);
  2265. };
  2266. tests["test type array jsdoc1"] = function() {
  2267. var results = computeContentAssist(
  2268. "/** @type {[]}*/\n" +
  2269. "var xx;\nx", "x"
  2270. );
  2271. testProposals("x", results, [
  2272. ["xx", "xx : Array"]
  2273. ]);
  2274. };
  2275. tests["test type parameterized jsdoc1"] = function() {
  2276. var results = computeContentAssist(
  2277. "/** @type {Array.<String>}*/\n" +
  2278. "var xx;\nx", "x"
  2279. );
  2280. // currently, we just ignore parameterization
  2281. testProposals("x", results, [
  2282. ["xx", "xx : Array"]
  2283. ]);
  2284. };
  2285. tests["test type record jsdoc1"] = function() {
  2286. var results = computeContentAssist(
  2287. "/** @type {{foo}}*/\n" +
  2288. "var xx;\nxx.fo", "fo"
  2289. );
  2290. testProposals("fo", results, [
  2291. ["foo", "foo : Object"]
  2292. ]);
  2293. };
  2294. tests["test type record jsdoc2"] = function() {
  2295. var results = computeContentAssist(
  2296. "/** @type {{foo:String}}*/\n" +
  2297. "var xx;\nxx.fo", "fo"
  2298. );
  2299. testProposals("fo", results, [
  2300. ["foo", "foo : String"]
  2301. ]);
  2302. };
  2303. tests["test type record jsdoc3"] = function() {
  2304. var results = computeContentAssist(
  2305. "/** @type {{foo:string,foo2:number}}*/\n" +
  2306. "var xx;\nxx.fo", "fo"
  2307. );
  2308. testProposals("fo", results, [
  2309. ["foo", "foo : String"],
  2310. ["foo2", "foo2 : Number"]
  2311. ]);
  2312. };
  2313. tests["test type record jsdoc4"] = function() {
  2314. var results = computeContentAssist(
  2315. "/** @type {{foo:{foo2:number}}}*/\n" +
  2316. "var xx;\nxx.foo.fo", "fo"
  2317. );
  2318. testProposals("fo", results, [
  2319. ["foo2", "foo2 : Number"]
  2320. ]);
  2321. };
  2322. tests["test type record jsdoc5"] = function() {
  2323. var results = computeContentAssist(
  2324. "function Flart() { this.xx = 9; }\n" +
  2325. "/** @type {{foo:{foo2:Flart}}}*/\n" +
  2326. "var xx;\nxx.foo.foo2.x", "x"
  2327. );
  2328. testProposals("x", results, [
  2329. ["xx", "xx : Number"]
  2330. ]);
  2331. };
  2332. tests["test type record jsdoc6"] = function() {
  2333. var results = computeContentAssist(
  2334. "/** @type {{foo:{foo:function()}}}*/\n" +
  2335. "var xx;\nxx.foo.foo", "foo"
  2336. );
  2337. testProposals("foo", results, [
  2338. ["foo()", "foo() : Object"]
  2339. ]);
  2340. };
  2341. tests["test type record jsdoc7"] = function() {
  2342. var results = computeContentAssist(
  2343. "/** @type {{foo:{foo:function(a:String,b:Number)}}}*/\n" +
  2344. "var xx;\nxx.foo.foo", "foo"
  2345. );
  2346. testProposals("foo", results, [
  2347. ["foo(a, b)", "foo(a, b) : Object"]
  2348. ]);
  2349. };
  2350. tests["test type record jsdoc8"] = function() {
  2351. var results = computeContentAssist(
  2352. "/** @type {{foo:{foo:function(a:String,b:Number):Number}}}*/\n" +
  2353. "var xx;\nxx.foo.foo", "foo"
  2354. );
  2355. testProposals("foo", results, [
  2356. ["foo(a, b)", "foo(a, b) : Number"]
  2357. ]);
  2358. };
  2359. tests["test type record jsdoc9"] = function() {
  2360. var results = computeContentAssist(
  2361. "/** @type {{foo:{foo:function(a:String,b:Number):{len:Number}}}}*/\n" +
  2362. "var xx;\nxx.foo.foo", "foo"
  2363. );
  2364. testProposals("foo", results, [
  2365. ["foo(a, b)", "foo(a, b) : { len : Number }"]
  2366. ]);
  2367. };
  2368. tests["test type record jsdoc10"] = function() {
  2369. var results = computeContentAssist(
  2370. "/** @type {{foo:function(a:String,b:Number):{len:function():Number}}}*/\n" +
  2371. "var xx;\nxx.foo().le", "le"
  2372. );
  2373. testProposals("le", results, [
  2374. ["len()", "len() : Number"]
  2375. ]);
  2376. };
  2377. tests["test type record jsdoc11"] = function() {
  2378. var results = computeContentAssist(
  2379. "/** @type {{foo:function():IDontExist}}*/\n" +
  2380. "var xx;\nxx.fo", "fo"
  2381. );
  2382. testProposals("fo", results, [
  2383. ["foo()", "foo() : Object"]
  2384. ]);
  2385. };
  2386. tests["test type record jsdoc12"] = function() {
  2387. var results = computeContentAssist(
  2388. "var Flart = function() {}" +
  2389. "/** @type {{foo:function(new:Flart):Number}}*/\n" +
  2390. "var xx;\nxx.fo", "fo"
  2391. );
  2392. testProposals("fo", results, [
  2393. ["foo()", "foo() : Flart"]
  2394. ]);
  2395. };
  2396. // the param tag
  2397. tests["test param jsdoc1"] = function() {
  2398. var results = computeContentAssist(
  2399. "/** @param {String} xx1\n@param {Number} xx2 */" +
  2400. "var flart = function(xx1,xx2) { xx/**/ }",
  2401. "xx");
  2402. testProposals("xx", results, [
  2403. ["xx1", "xx1 : String"],
  2404. ["xx2", "xx2 : Number"]
  2405. ]);
  2406. };
  2407. tests["test param jsdoc2"] = function() {
  2408. var results = computeContentAssist(
  2409. "/** @param {Number} xx2\n@param {String} xx1\n */" +
  2410. "var flart = function(xx1,xx2) { xx/**/ }",
  2411. "xx");
  2412. testProposals("xx", results, [
  2413. ["xx1", "xx1 : String"],
  2414. ["xx2", "xx2 : Number"]
  2415. ]);
  2416. };
  2417. tests["test param jsdoc3"] = function() {
  2418. var results = computeContentAssist(
  2419. "/** @param {function(String,Number):Number} xx2\n */" +
  2420. "var flart = function(xx1,xx2) { xx/**/ }",
  2421. "xx");
  2422. testProposals("xx", results, [
  2423. ["xx2(String, Number)", "xx2(String, Number) : Number"],
  2424. ["xx1", "xx1 : { }"]
  2425. ]);
  2426. };
  2427. tests["test param jsdoc4"] = function() {
  2428. var results = computeContentAssist(
  2429. "/** @param {function(a:String,Number):Number} xx2\n */" +
  2430. "var flart = function(xx1,xx2) { xx/**/ }",
  2431. "xx");
  2432. testProposals("xx", results, [
  2433. ["xx2(a, Number)", "xx2(a, Number) : Number"],
  2434. ["xx1", "xx1 : { }"]
  2435. ]);
  2436. };
  2437. tests["test param jsdoc5"] = function() {
  2438. var results = computeContentAssist(
  2439. "/** @param {function(a:String,?Number):Number} xx2\n */" +
  2440. "var flart = function(xx1,xx2) { xx/**/ }",
  2441. "xx");
  2442. testProposals("xx", results, [
  2443. ["xx2(a, Number)", "xx2(a, Number) : Number"],
  2444. ["xx1", "xx1 : { }"]
  2445. ]);
  2446. };
  2447. // the return tag
  2448. tests["test return jsdoc1"] = function() {
  2449. var results = computeContentAssist(
  2450. "/** @return {function(a:String,?Number):Number} xx2\n */" +
  2451. "var flart = function(xx1,xx2) { }\nflar",
  2452. "flar");
  2453. // hmmmm... functions returning functions not really showing up
  2454. testProposals("flar", results, [
  2455. ["flart(xx1, xx2)", "flart(xx1, xx2) : Number"]
  2456. ]);
  2457. };
  2458. tests["test return jsdoc2"] = function() {
  2459. var results = computeContentAssist(
  2460. "/** @return {function(String):Number} xx2\n */" +
  2461. "var flart = function(xx1,xx2) { }\n" +
  2462. "var other = flart();\noth", "oth");
  2463. testProposals("oth", results, [
  2464. ["other(String)", "other(String) : Number"]
  2465. ]);
  2466. };
  2467. // reassignment
  2468. tests["test reassignment jsdoc1"] = function() {
  2469. var results = computeContentAssist(
  2470. "/** @type {Number} xx2\n */" +
  2471. "var flar = '';\n" +
  2472. "fla", "fla");
  2473. testProposals("fla", results, [
  2474. ["flar", "flar : Number"]
  2475. ]);
  2476. };
  2477. // TODO this one is an open question. Should we allow reassignment of
  2478. // explicitly typed variables and parameters? Currently, we do.
  2479. tests["test reassignment jsdoc2"] = function() {
  2480. var results = computeContentAssist(
  2481. "/** @type {Number} xx2\n */" +
  2482. "var flar;\n" +
  2483. "flar = '';\n" +
  2484. "fla", "fla");
  2485. testProposals("fla", results, [
  2486. ["flar", "flar : String"]
  2487. ]);
  2488. };
  2489. // reassignment shouldn't happen here since uninteresting type is being assigned
  2490. tests["test reassignment jsdoc3"] = function() {
  2491. var results = computeContentAssist(
  2492. "/** @type {Number} xx2\n */" +
  2493. "var flar;\n" +
  2494. "flar = iDontKnow();\n" +
  2495. "fla", "fla");
  2496. testProposals("fla", results, [
  2497. ["flar", "flar : Number"]
  2498. ]);
  2499. };
  2500. // RIGEL-138 jsdoc support for functions parameters that are in object literals
  2501. tests["test object literal fn param jsdoc1"] = function() {
  2502. var results = computeContentAssist(
  2503. "var obj = {\n" +
  2504. " /** @param {String} foo */\n" +
  2505. " fun : function(foo) { foo/**/ }\n" +
  2506. "}", "foo");
  2507. testProposals("foo", results, [
  2508. ["foo", "foo : String"]
  2509. ]);
  2510. };
  2511. tests["test object literal type jsdoc1"] = function() {
  2512. var results = computeContentAssist(
  2513. "var obj = {\n" +
  2514. " /** @type {String} foo */\n" +
  2515. " foo : undefined\n" +
  2516. "};\n" +
  2517. "obj.foo", "foo");
  2518. testProposals("foo", results, [
  2519. ["foo", "foo : String"]
  2520. ]);
  2521. };
  2522. tests["test object literal fn return jsdoc1"] = function() {
  2523. var results = computeContentAssist(
  2524. "var foo = {\n" +
  2525. " /** @return {String} foo */\n" +
  2526. " fun : function(foo) { }\n" +
  2527. "}\n" +
  2528. "var res = foo.fun();\n" +
  2529. "res", "res");
  2530. testProposals("res", results, [
  2531. ["res", "res : String"]
  2532. ]);
  2533. };
  2534. tests["test dotted constructor jsdoc type 1"] = function() {
  2535. var results = computeContentAssist(
  2536. "var obj = { Fun : function() {} };\n" +
  2537. "/** @type obj.Fun */ var xxx;\nxx", "xx");
  2538. testProposals("xx", results, [
  2539. ["xxx", "xxx : obj.Fun"]
  2540. ]);
  2541. };
  2542. tests["test dotted constructor jsdoc type 2"] = function() {
  2543. var results = computeContentAssist(
  2544. "var obj = { Fun : function() { this.yyy = 9; } };\n" +
  2545. "/** @type obj.Fun */ var xxx;\nxxx.yy", "yy");
  2546. testProposals("yy", results, [
  2547. ["yyy", "yyy : Number"]
  2548. ]);
  2549. };
  2550. }
  2551. /////////////////////////////////////
  2552. // various tests for reassignment
  2553. // reassignments are only performed
  2554. // if the new type is not less general
  2555. // than the old type
  2556. /////////////////////////////////////
  2557. /*
  2558. undefined -> Object yes
  2559. undefined -> { } yes
  2560. undefined -> {a} yes
  2561. undefined -> any yes
  2562. Object -> undefined no
  2563. Object -> { } yes
  2564. Object -> {a} yes
  2565. Object -> any yes
  2566. { } -> undefined no
  2567. { } -> Object no
  2568. { } -> {a} yes
  2569. { } -> any yes
  2570. {a} -> undefined no
  2571. {a} -> Object no
  2572. {a} -> { } no
  2573. {a} -> any yes
  2574. any -> undefined no
  2575. any -> Object no
  2576. any -> { } no
  2577. any -> {a} yes
  2578. */
  2579. //undefined
  2580. tests["test reassignment undef->Obj"] = function() {
  2581. var results = computeContentAssist(
  2582. "var v = { a : undefined };\n" +
  2583. "v.a = new Object();\n" +
  2584. "v.a", "a");
  2585. testProposals("a", results, [
  2586. ["a", "a : Object"]
  2587. ]);
  2588. };
  2589. tests["test reassignment undef->{ }"] = function() {
  2590. var results = computeContentAssist(
  2591. "var v = { a : undefined };\n" +
  2592. "v.a = { };\n" +
  2593. "v.a", "a");
  2594. testProposals("a", results, [
  2595. ["a", "a : { }"]
  2596. ]);
  2597. };
  2598. tests["test reassignment undef->{a}"] = function() {
  2599. var results = computeContentAssist(
  2600. "var v = { a : undefined };\n" +
  2601. "v.a = { a: 9 };\n" +
  2602. "v.a", "a");
  2603. testProposals("a", results, [
  2604. ["a", "a : { a : Number }"]
  2605. ]);
  2606. };
  2607. tests["test reassignment undef->any"] = function() {
  2608. var results = computeContentAssist(
  2609. "var v = { a : undefined };\n" +
  2610. "v.a = 9;\n" +
  2611. "v.a", "a");
  2612. testProposals("a", results, [
  2613. ["a", "a : Number"]
  2614. ]);
  2615. };
  2616. // Obj
  2617. tests["test reassignment obj->undefined"] = function() {
  2618. var results = computeContentAssist(
  2619. "var v = { a : new Object() };\n" +
  2620. "v.a = undefined;\n" +
  2621. "v.a", "a");
  2622. testProposals("a", results, [
  2623. ["a", "a : Object"]
  2624. ]);
  2625. };
  2626. tests["test reassignment obj->{ }"] = function() {
  2627. var results = computeContentAssist(
  2628. "var v = { a : new Object() };\n" +
  2629. "v.a = { };\n" +
  2630. "v.a", "a");
  2631. testProposals("a", results, [
  2632. ["a", "a : { }"]
  2633. ]);
  2634. };
  2635. tests["test reassignment obj->{a}"] = function() {
  2636. var results = computeContentAssist(
  2637. "var v = { a : new Object() };\n" +
  2638. "v.a = { a: 9 };\n" +
  2639. "v.a", "a");
  2640. testProposals("a", results, [
  2641. ["a", "a : { a : Number }"]
  2642. ]);
  2643. };
  2644. tests["test reassignment obj->any"] = function() {
  2645. var results = computeContentAssist(
  2646. "var v = { a : new Object() };\n" +
  2647. "v.a = 9;\n" +
  2648. "v.a", "a");
  2649. testProposals("a", results, [
  2650. ["a", "a : Number"]
  2651. ]);
  2652. };
  2653. // { }
  2654. tests["test reassignment { }->undefined"] = function() {
  2655. var results = computeContentAssist(
  2656. "var v = { a : { } };\n" +
  2657. "v.a = undefined;\n" +
  2658. "v.a", "a");
  2659. testProposals("a", results, [
  2660. ["a", "a : { }"]
  2661. ]);
  2662. };
  2663. tests["test reassignment { }->obj"] = function() {
  2664. var results = computeContentAssist(
  2665. "var v = { a : { } };\n" +
  2666. "v.a = new Object();\n" +
  2667. "v.a", "a");
  2668. testProposals("a", results, [
  2669. ["a", "a : { }"]
  2670. ]);
  2671. };
  2672. tests["test reassignment { }->{a}"] = function() {
  2673. var results = computeContentAssist(
  2674. "var v = { a : { } };\n" +
  2675. "v.a = { a: 9 };\n" +
  2676. "v.a", "a");
  2677. testProposals("a", results, [
  2678. ["a", "a : { a : Number }"]
  2679. ]);
  2680. };
  2681. tests["test reassignment { }->any"] = function() {
  2682. var results = computeContentAssist(
  2683. "var v = { a : { } };\n" +
  2684. "v.a = 9;\n" +
  2685. "v.a", "a");
  2686. testProposals("a", results, [
  2687. ["a", "a : Number"]
  2688. ]);
  2689. };
  2690. // {a}
  2691. tests["test reassignment {a}->undefined"] = function() {
  2692. var results = computeContentAssist(
  2693. "var v = { a : { a:9 } };\n" +
  2694. "v.a = undefined;\n" +
  2695. "v.a", "a");
  2696. testProposals("a", results, [
  2697. ["a", "a : { a : Number }"]
  2698. ]);
  2699. };
  2700. tests["test reassignment {a}->obj"] = function() {
  2701. var results = computeContentAssist(
  2702. "var v = { a : {a:9 } };\n" +
  2703. "v.a = new Object();\n" +
  2704. "v.a", "a");
  2705. testProposals("a", results, [
  2706. ["a", "a : { a : Number }"]
  2707. ]);
  2708. };
  2709. tests["test reassignment {a}->{ }"] = function() {
  2710. var results = computeContentAssist(
  2711. "var v = { a : {a:9} };\n" +
  2712. "v.a = { };\n" +
  2713. "v.a", "a");
  2714. testProposals("a", results, [
  2715. ["a", "a : { a : Number }"]
  2716. ]);
  2717. };
  2718. tests["test reassignment {a}->{a}"] = function() {
  2719. var results = computeContentAssist(
  2720. "var v = { a : {a:9} };\n" +
  2721. "v.a = {b:9};\n" +
  2722. "v.a", "a");
  2723. testProposals("a", results, [
  2724. ["a", "a : { b : Number }"]
  2725. ]);
  2726. };
  2727. tests["test reassignment {a}->any"] = function() {
  2728. var results = computeContentAssist(
  2729. "var v = { a : {a:9} };\n" +
  2730. "v.a = 9;\n" +
  2731. "v.a", "a");
  2732. testProposals("a", results, [
  2733. ["a", "a : Number"]
  2734. ]);
  2735. };
  2736. // any
  2737. tests["test reassignment any->undefined"] = function() {
  2738. var results = computeContentAssist(
  2739. "var v = { a : 9 };\n" +
  2740. "v.a = undefined;\n" +
  2741. "v.a", "a");
  2742. testProposals("a", results, [
  2743. ["a", "a : Number"]
  2744. ]);
  2745. };
  2746. tests["test reassignment any->obj"] = function() {
  2747. var results = computeContentAssist(
  2748. "var v = { a : 9 };\n" +
  2749. "v.a = new Object();\n" +
  2750. "v.a", "a");
  2751. testProposals("a", results, [
  2752. ["a", "a : Number"]
  2753. ]);
  2754. };
  2755. tests["test reassignment any->{ }"] = function() {
  2756. var results = computeContentAssist(
  2757. "var v = { a : 9 };\n" +
  2758. "v.a = { };\n" +
  2759. "v.a", "a");
  2760. testProposals("a", results, [
  2761. ["a", "a : Number"]
  2762. ]);
  2763. };
  2764. tests["test reassignment any->{a}"] = function() {
  2765. var results = computeContentAssist(
  2766. "var v = { a : {a:9} };\n" +
  2767. "v.a = { a: 9};\n" +
  2768. "v.a", "a");
  2769. testProposals("a", results, [
  2770. ["a", "a : { a : Number }"]
  2771. ]);
  2772. };
  2773. tests["test reassignment any->any"] = function() {
  2774. var results = computeContentAssist(
  2775. "var v = { a : {a:9} };\n" +
  2776. "v.a = '';\n" +
  2777. "v.a", "a");
  2778. testProposals("a", results, [
  2779. ["a", "a : String"]
  2780. ]);
  2781. };
  2782. ///////////////////////////////////////////////////
  2783. // testing default jslint options
  2784. ///////////////////////////////////////////////////
  2785. var jsOptionsBrowser = {"options": { "browser": true }};
  2786. var jsOptionsNoBrowser = {"options": { "browser": false }};
  2787. var jsOptions1Global = {"global": [ "aaa" ]};
  2788. var jsOptions2Globals = {"global": [ "aaa", "aab"]};
  2789. var jsOptionsAndGlobals = {"global": [ "aaa", "aab"], "options": { "browser": true }};
  2790. tests["test browser:true in options"] = function() {
  2791. var results = computeContentAssist(
  2792. "wind", "wind", null, jsOptionsBrowser);
  2793. testProposals("wind", results, [
  2794. ["window", "window : Window"]
  2795. ]);
  2796. };
  2797. tests["test browser:false in options"] = function() {
  2798. var results = computeContentAssist(
  2799. "wind", "wind", null, jsOptionsNoBrowser);
  2800. testProposals("wind", results, [
  2801. ]);
  2802. };
  2803. tests["test browser:true in options overriden by browser:false in text"] = function() {
  2804. var results = computeContentAssist(
  2805. "/*jslint browser:false */\nwind", "wind", null, jsOptionsBrowser);
  2806. testProposals("wind", results, [
  2807. ]);
  2808. };
  2809. tests["test browser:false in options overriden by browser:true in text"] = function() {
  2810. var results = computeContentAssist(
  2811. "/*jslint browser:true */\nwind", "wind", null, jsOptionsNoBrowser);
  2812. testProposals("wind", results, [
  2813. ["window", "window : Window"]
  2814. ]);
  2815. };
  2816. tests["test 1 global in options"] = function() {
  2817. var results = computeContentAssist(
  2818. "aa", "aa", null, jsOptions1Global);
  2819. testProposals("aa", results, [
  2820. ["aaa", "aaa : { }"]
  2821. ]);
  2822. };
  2823. tests["test 2 globals in options"] = function() {
  2824. var results = computeContentAssist(
  2825. "aa", "aa", null, jsOptions2Globals);
  2826. testProposals("aa", results, [
  2827. ["aaa", "aaa : { }"],
  2828. ["aab", "aab : { }"]
  2829. ]);
  2830. };
  2831. tests["test 2 globals in options and in text"] = function() {
  2832. var results = computeContentAssist(
  2833. "/*global aac */\naa", "aa", null, jsOptions2Globals);
  2834. testProposals("aa", results, [
  2835. ["aaa", "aaa : { }"],
  2836. ["aab", "aab : { }"],
  2837. ["aac", "aac : { }"]
  2838. ]);
  2839. };
  2840. tests["test globals and browser1"] = function() {
  2841. var results = computeContentAssist(
  2842. "aa", "aa", null, jsOptionsAndGlobals);
  2843. testProposals("aa", results, [
  2844. ["aaa", "aaa : { }"],
  2845. ["aab", "aab : { }"]
  2846. ]);
  2847. };
  2848. tests["test globals and browser2"] = function() {
  2849. var results = computeContentAssist(
  2850. "wind", "wind", null, jsOptionsAndGlobals);
  2851. testProposals("wind", results, [
  2852. ["window", "window : Window"]
  2853. ]);
  2854. };
  2855. // RIGEL-100
  2856. tests["test obj literal with underscore"] = function() {
  2857. var results = computeContentAssist(
  2858. "var obj = { _myFun : function() { this._/**/ } }", "_");
  2859. testProposals("_", results, [
  2860. // inferred as object type since invocation request is happening inside of object literal.
  2861. ["_myFun", "_myFun : Object"]
  2862. ]);
  2863. };
  2864. return tests;
  2865. });