forked from phcode-dev/staging.phcode.dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathunittests.js
More file actions
1 lines (1 loc) · 30.9 KB
/
Copy pathunittests.js
File metadata and controls
1 lines (1 loc) · 30.9 KB
1
define(function(require,exports,module){var Commands=brackets.getModule("command/Commands"),CommandManager=brackets.getModule("command/CommandManager"),MainViewManager=brackets.getModule("view/MainViewManager"),DocumentManager=brackets.getModule("document/DocumentManager"),EditorManager=brackets.getModule("editor/EditorManager"),FileSystem=brackets.getModule("filesystem/FileSystem"),FileUtils=brackets.getModule("file/FileUtils"),PreferencesManager=brackets.getModule("preferences/PreferencesManager"),SpecRunnerUtils=brackets.getModule("spec/SpecRunnerUtils"),JSCodeHints=require("main"),Preferences=brackets.getModule("JSUtils/Preferences"),Session=brackets.getModule("JSUtils/Session"),ScopeManager=brackets.getModule("JSUtils/ScopeManager"),HintUtils=brackets.getModule("JSUtils/HintUtils"),HintUtils2=require("HintUtils2"),ParameterHintProvider,phProvider=new(0,require("ParameterHintsProvider").JSParameterHintsProvider),extensionPath=SpecRunnerUtils.getTestPath("/spec/JSCodeHints-ext-unittest-files/"),testFolder=extensionPath+"basic-test-files/",testPath=extensionPath+"basic-test-files/file1.js",testHtmlPath=extensionPath+"basic-test-files/index.html",testDoc=null,testEditor,preTestText;CommandManager.register("test-file-open",Commands.FILE_OPEN,function(fileInfo){return DocumentManager.getDocumentForPath(fileInfo.fullPath).done(function(doc){MainViewManager._edit(MainViewManager.ACTIVE_PANE,doc)})}),describe("individualrun:JavaScript Code Hinting",function(){function fixPos(pos){return"sticky"in pos||(pos.sticky=null),pos}function expectHints(provider,key){return void 0===key&&(key=null),expect(provider.hasHints(testEditor,key)).toBe(!0),provider.getHints(null)}function expectNoHints(provider,key){void 0===key&&(key=null),expect(provider.hasHints(testEditor,key)).toBe(!1)}function _indexOf(hintList,hint){for(var index=-1,counter=0;counter<hintList.length;counter++)if(hintList[counter].data("token").value===hint){index=counter;break}return index}async function _waitForHints(hintObj,callback){var complete=!1,hintList=null;hintObj.hasOwnProperty("hints")?(complete=!0,hintList=hintObj.hints):hintObj.done(function(obj){complete=!0,hintList=obj.hints}),await awaitsFor(function(){return complete},"Expected hints did not resolve",3e3),callback(hintList)}async function expectCloseHints(provider,hintObj,newPos,expectedValue){await _waitForHints(hintObj,function(hintList){testEditor.setCursorPos(newPos),expect(provider.shouldCloseHints(JSCodeHints.getSession())).toBe(expectedValue)})}async function hintsAbsent(hintObj,absentHints){await _waitForHints(hintObj,function(hintList){expect(hintList).toBeTruthy(),absentHints.forEach(function(absentHint){expect(_indexOf(hintList,absentHint)).toBe(-1)})})}async function hintsPresent(hintObj,expectedHints){await _waitForHints(hintObj,function(hintList){expect(hintList).toBeTruthy(),expectedHints.forEach(function(expectedHint){expect(_indexOf(hintList,expectedHint)).not.toBe(-1)})})}async function hintsPresentOrdered(hintObj,expectedHints){var prevIndex=-1,currIndex;await _waitForHints(hintObj,function(hintList){expect(hintList).toBeTruthy(),expectedHints.forEach(function(expectedHint){currIndex=_indexOf(hintList,expectedHint),expect(currIndex).toBeGreaterThan(prevIndex),prevIndex=currIndex})})}async function hintsPresentExact(hintObj,expectedHints){await _waitForHints(hintObj,function(hintList){expect(hintList).toBeTruthy(),expect(hintList.length).toBe(expectedHints.length),expectedHints.forEach(function(expectedHint,index){expect(hintList[index].data("token").value).toBe(expectedHint)})})}function findHint(hintList,hintSelection){var i,l;for(i=0,l=hintList.length;i<l;++i){var current;if(hintSelection===hintList[i].data("token").value)return i}return-1}async function selectHint(provider,hintObj,hintSelection){expectHints(provider),await _waitForHints(hintObj,function(hintList){expect(hintList).toBeTruthy();var index=findHint(hintList,hintSelection);expect(hintList[index].data("token")).toBeTruthy(),expect(provider.insertHint(hintList[index])).toBe(!1)})}async function _waitForJump(jumpPromise,callback){var cursor=null,complete=!1;jumpPromise.done(function(){complete=!0}),await awaitsFor(function(){var activeEditor=EditorManager.getActiveEditor();return cursor=activeEditor.getCursorPos(),complete},"Expected jump did not occur",3e3),callback(cursor)}async function editorJumped(expectedLocation){var jumpPromise=JSCodeHints.handleJumpToDefinition();await _waitForJump(jumpPromise,function(newCursor){if(expect(newCursor.line).toBe(expectedLocation.line),expect(newCursor.ch).toBe(expectedLocation.ch),expectedLocation.file){var activeEditor=EditorManager.getActiveEditor();expect(activeEditor.document.file.name).toBe(expectedLocation.file)}})}async function expectNoParameterHint(){var requestStatus=void 0,request=phProvider._getParameterHint();request.fail(function(status){requestStatus=status}),await awaitsForFail(request,"ParameterHints"),expect(requestStatus).toBe(null)}function expectParameterHintClosed(){expect(phProvider.isHintDisplayed()).toBe(!1)}async function expectParameterHint(expectedParams,expectedParameter){var requestHints=void 0,request=null;function expectHint(hint){var params=hint.parameters,n=params.length,i;for(expect(params.length).toBe(expectedParams.length),expect(hint.currentIndex).toBe(expectedParameter),i=0;i<n;i++)expect(params[i].name).toBe(expectedParams[i].name),expect(params[i].type).toBe(expectedParams[i].type),params[i].isOptional?expect(expectedParams[i].isOptional).toBeTruthy():expect(expectedParams[i].isOptional).toBeFalsy()}request=phProvider._getParameterHint(),null===expectedParams?(request.fail(function(result){requestHints=result}),await awaitsForFail(request,"ParameterHints")):(request.done(function(result){requestHints=result}),await awaitsForDone(request,"ParameterHints")),null===expectedParams?expect(requestHints).toBe(null):expectHint(requestHints)}async function setupTest(path,primePump){DocumentManager.getDocumentForPath(path).done(function(doc){testDoc=doc}),await awaitsFor(function(){return null!==testDoc},"Unable to open test document",1e4),testEditor=SpecRunnerUtils.createMockEditorForDocument(testDoc),ScopeManager.handleProjectOpen(testFolder),await awaits(100);let session=new Session(testEditor);ScopeManager.handleEditorChange(session,testEditor.document,null),preTestText=testDoc.getText(),await awaitsForDone(ScopeManager._readyPromise()),await awaitsForDone(ScopeManager._maybeReset(JSCodeHints.getSession(),testDoc,!0))}function tearDownTest(){testDoc.setText(preTestText),MainViewManager._closeAll(MainViewManager.ALL_PANES),SpecRunnerUtils.destroyMockEditor(testDoc),testEditor=null,testDoc=null}describe("JavaScript Code Hinting Basic",function(){beforeAll(function(){brackets._configureJSCodeHints({noReset:!0})}),afterAll(function(){brackets._configureJSCodeHints({noReset:!1})}),beforeEach(async function(){await setupTest(testPath,!1)}),afterEach(function(){tearDownTest()}),it("should not list hints in string literal",function(){testEditor.setCursorPos({line:20,ch:22}),expectNoHints(JSCodeHints.jsHintProvider)},1e6),it("should list declared variable and function names in outer scope",async function(){testEditor.setCursorPos({line:6,ch:0});var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresent(hintObj,["A2","A3","funB","A1"])}),it("should filter hints by query",async function(){testEditor.setCursorPos({line:5,ch:10});var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresent(hintObj,["A1","A2","A3"]),await hintsAbsent(hintObj,["funB"])}),it("should list keywords",async function(){testEditor.setCursorPos({line:6,ch:0});var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresent(hintObj,["break","case","catch"])}),it("should NOT list implicitly defined globals from missing JSLint annotations",async function(){testEditor.setCursorPos({line:6,ch:0});var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsAbsent(hintObj,["ActiveXObject","CScript","VBArray"])}),it("should NOT list explicitly defined globals from JSLint annotations in other files",async function(){testEditor.setCursorPos({line:6,ch:0});var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsAbsent(hintObj,["crazyGlobal","anotherCrazyGlobal"])}),it("should NOT list implicitly defined globals from JSLint annotations in other files",async function(){testEditor.setCursorPos({line:6,ch:0});var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsAbsent(hintObj,["spawn","version","toint32"])}),it("should list literal constants",async function(){testEditor.setCursorPos({line:6,ch:0});var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresent(hintObj,["null","undefined","true","false"])}),it("should NOT list variables, function names and parameter names out of scope",async function(){testEditor.setCursorPos({line:6,ch:0});var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsAbsent(hintObj,["paramB2","paramB1"])}),it("should NOT list variables, function names and parameter names in other files",async function(){testEditor.setCursorPos({line:6,ch:0});var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsAbsent(hintObj,["E1","E2"])}),it("should NOT list property names on value lookups",async function(){testEditor.setCursorPos({line:6,ch:0});var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsAbsent(hintObj,["propA","propB","propC"])}),it("should list declared variable, function and parameter names in inner scope",async function(){testEditor.setCursorPos({line:12,ch:0});var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresent(hintObj,["B1","B2","funC","paramB1","paramB2","funB","A1","A2","A3"])}),it("should NOT list string literals from other files",async function(){testEditor.setCursorPos({line:6,ch:0});var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsAbsent(hintObj,["a very nice string"])}),it("should list property names that have been declared in the file",async function(){testEditor.setCursorPos({line:17,ch:11});var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresent(hintObj,["propB"])}),it("should list identifier names that occur in other files",async function(){testEditor.setCursorPos({line:16,ch:0});var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresent(hintObj,["D1","D2"])}),it("should NOT list variable, parameter or function names on property lookups",async function(){testEditor.setCursorPos({line:17,ch:11});var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsAbsent(hintObj,["A1","A2","funB","paramB1","paramB2","B1","B2","funC","paramC1","paramC2"])}),it("should NOT list keywords on property lookups",async function(){testEditor.setCursorPos({line:17,ch:11});var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsAbsent(hintObj,["case","function","var"])}),it("should close hints when move over '.' ",async function(){testEditor.setCursorPos({line:17,ch:11});var hintObj=expectHints(JSCodeHints.jsHintProvider);await expectCloseHints(JSCodeHints.jsHintProvider,hintObj,{line:17,ch:10},!0)}),it("should close hints only when move off the end of a property ",async function(){testEditor.setCursorPos({line:17,ch:11});var hintObj=expectHints(JSCodeHints.jsHintProvider);await expectCloseHints(JSCodeHints.jsHintProvider,hintObj,{line:17,ch:12},!1),await expectCloseHints(JSCodeHints.jsHintProvider,hintObj,{line:17,ch:13},!1),await expectCloseHints(JSCodeHints.jsHintProvider,hintObj,{line:17,ch:14},!1),await expectCloseHints(JSCodeHints.jsHintProvider,hintObj,{line:17,ch:15},!1),await expectCloseHints(JSCodeHints.jsHintProvider,hintObj,{line:17,ch:16},!1),await expectCloseHints(JSCodeHints.jsHintProvider,hintObj,{line:17,ch:17},!0)}),it("should close hints only when move off the beginning of an identifier ",async function(){testEditor.setCursorPos({line:17,ch:10});var hintObj=expectHints(JSCodeHints.jsHintProvider);await expectCloseHints(JSCodeHints.jsHintProvider,hintObj,{line:17,ch:9},!1),await expectCloseHints(JSCodeHints.jsHintProvider,hintObj,{line:17,ch:8},!1),await expectCloseHints(JSCodeHints.jsHintProvider,hintObj,{line:17,ch:7},!0)}),it("should close hints only when move off the beginning of a keyword ",async function(){testEditor.setCursorPos({line:24,ch:7});var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresent(hintObj,["var"]),await expectCloseHints(JSCodeHints.jsHintProvider,hintObj,{line:24,ch:6},!1),await expectCloseHints(JSCodeHints.jsHintProvider,hintObj,{line:24,ch:5},!1),await expectCloseHints(JSCodeHints.jsHintProvider,hintObj,{line:24,ch:4},!1),await expectCloseHints(JSCodeHints.jsHintProvider,hintObj,{line:24,ch:3},!0)}),it("should NOT list implicit hints on left-brace",async function(){testEditor.setCursorPos({line:6,ch:0}),expectNoHints(JSCodeHints.jsHintProvider,"{")}),it("should list explicit hints for variable and function names",async function(){testEditor.setCursorPos({line:6,ch:0});var hintObj=expectHints(JSCodeHints.jsHintProvider,null);await hintsPresent(hintObj,["A2","A3","funB","A1"])}),it("should list implicit hints when typing property lookups",async function(){testEditor.setCursorPos({line:17,ch:10});var hintObj=expectHints(JSCodeHints.jsHintProvider,".");await hintsPresent(hintObj,["B1","paramB1"])}),it("should give priority to identifier names associated with the current context",async function(){testEditor.setCursorPos({line:16,ch:0});var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresentOrdered(hintObj,["C1","B1"]),await hintsPresentOrdered(hintObj,["C2","B2"])}),it("should give priority to property names associated with the current context from other files",async function(){testEditor.setCursorPos({line:16,ch:0});var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresentOrdered(hintObj,["C1","D1"]),await hintsPresentOrdered(hintObj,["B1","D1"]),await hintsPresentOrdered(hintObj,["A1","D1"]),await hintsPresentOrdered(hintObj,["funB","funE"])}),it("should insert value hints with no current query",async function(){var start={line:6,ch:0},end={line:6,ch:2};testEditor.setCursorPos(start);var hintObj=expectHints(JSCodeHints.jsHintProvider);await selectHint(JSCodeHints.jsHintProvider,hintObj,"A2"),expect(testDoc.getRange(start,end)).toEql("A2")}),it("should insert value hints replacing the current query",async function(){var start={line:5,ch:10},before={line:5,ch:9},end={line:5,ch:11};testEditor.setCursorPos(start);var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresent(hintObj,["A1","A2","A3"]),await selectHint(JSCodeHints.jsHintProvider,hintObj,"A1"),expect(testDoc.getRange(before,end)).toEql("A1")}),it("should insert property hints with no current query",async function(){var start={line:6,ch:0},middle={line:6,ch:3},end={line:6,ch:8};testDoc.replaceRange("A1.",start,start),testEditor.setCursorPos(middle);var hintObj=expectHints(JSCodeHints.jsHintProvider);await selectHint(JSCodeHints.jsHintProvider,hintObj,"propA"),expect(fixPos(testEditor.getCursorPos())).toEql(fixPos(end)),expect(testDoc.getRange(start,end)).toEql("A1.propA"),expect(testDoc.getLine(end.line).length).toEql(8)}),it("should insert, not replace, property hints with no current query",async function(){var start={line:6,ch:0},middle={line:6,ch:3},end={line:6,ch:8},endplus={line:6,ch:12};testDoc.replaceRange("A1.prop",start,start),testEditor.setCursorPos(middle);var hintObj=expectHints(JSCodeHints.jsHintProvider);await selectHint(JSCodeHints.jsHintProvider,hintObj,"propA"),expect(fixPos(testEditor.getCursorPos())).toEql(fixPos(end)),expect(testDoc.getRange(start,endplus)).toEql("A1.propAprop"),expect(testDoc.getLine(end.line).length).toEql(12)}),it("should insert, not replace, property hints with a partial current query",async function(){var start={line:6,ch:0},middle={line:6,ch:6},end={line:6,ch:8};testDoc.replaceRange("A1.pro",start,start),testEditor.setCursorPos(middle);var hintObj=expectHints(JSCodeHints.jsHintProvider);await selectHint(JSCodeHints.jsHintProvider,hintObj,"propA"),expect(fixPos(testEditor.getCursorPos())).toEql(fixPos(end)),expect(testDoc.getRange(start,end)).toEql("A1.propA"),expect(testDoc.getLine(end.line).length).toEql(8)}),it("should replace property hints replacing a partial current query",async function(){var start={line:6,ch:0},middle={line:6,ch:6},end={line:6,ch:8},endplus={line:6,ch:10};testDoc.replaceRange("A1.propB",start,start),testEditor.setCursorPos(middle);var hintObj=expectHints(JSCodeHints.jsHintProvider);await selectHint(JSCodeHints.jsHintProvider,hintObj,"propA"),expect(fixPos(testEditor.getCursorPos())).toEql(fixPos(end)),expect(testDoc.getRange(start,endplus)).toEql("A1.propApB"),expect(testDoc.getLine(end.line).length).toEql(10)}),it("should replace property hints but not following delimiters",async function(){var start={line:6,ch:0},middle={line:6,ch:4},end={line:6,ch:9},endplus={line:6,ch:14};testDoc.replaceRange("(A1.prop)",start,start),testEditor.setCursorPos(middle);var hintObj=expectHints(JSCodeHints.jsHintProvider);await selectHint(JSCodeHints.jsHintProvider,hintObj,"propA"),expect(fixPos(testEditor.getCursorPos())).toEql(fixPos(end)),expect(testDoc.getRange(start,endplus)).toEql("(A1.propAprop)"),expect(testDoc.getLine(endplus.line).length).toEql(14)}),it("should list hints for string, as string assigned to 's', 's' assigned to 'r' and 'r' assigned to 't'",async function(){var start={line:26,ch:0},middle={line:26,ch:6};testDoc.replaceRange(" t.",start),testEditor.setCursorPos(middle);var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresentOrdered(hintObj,["charAt","charCodeAt","concat","indexOf"])}),it("should list function type",async function(){var start={line:37,ch:0},middle={line:37,ch:5};testDoc.replaceRange("funD(",start,start),testEditor.setCursorPos(middle),await expectParameterHint([{name:"a",type:"String"},{name:"b",type:"Number"}],0)}),it("should list exports from a requirejs module",async function(){var start={line:40,ch:21};testEditor.setCursorPos(start);var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresentExact(hintObj,["a","b","c","j"])}),it("should list later defined property names",async function(){var start={line:17,ch:11};testEditor.setCursorPos(start);var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresentExact(hintObj,["foo","propB"])}),it("should list matching property names",async function(){var cursor1={line:12,ch:0},cursor2={line:12,ch:6};testDoc.replaceRange("paramB",cursor1,cursor1),testEditor.setCursorPos(cursor2);var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresentExact(hintObj,["paramB1","paramB2"])}),it("should take anotation parameter type:String",async function(){var start={line:37,ch:21};testDoc.replaceRange("var k= funD(10,11).x.",start,start),testEditor.setCursorPos(start);var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresentOrdered(hintObj,["charAt","charCodeAt","concat","indexOf"])}),it("should take anotation parameter type:Number",async function(){var start={line:37,ch:21};testDoc.replaceRange("var k= funD(10,11).y.",start,start),testEditor.setCursorPos(start);var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresentOrdered(hintObj,["toExponential","toFixed","toString"])}),it("should add new method on String .prototype",async function(){var start={line:37,ch:0},testPos={line:40,ch:12};testDoc.replaceRange("String.prototype.times = function (count) {\n\treturn count < 1 ? '' : new Array[count + 1].join(this);\n};\n\"hello\".tim",start,start),testEditor.setCursorPos(testPos);var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresentOrdered(hintObj,["times","trim"])}),it("should list function defined from .prototype",async function(){var start={line:59,ch:5};testEditor.setCursorPos(start);var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresentExact(hintObj,["calc"])}),it("should list function type defined from .prototype",async function(){var start={line:59,ch:10};testEditor.setCursorPos(start),await expectParameterHint([{name:"a4",type:"Number"},{name:"b4",type:"Number"}],0)}),it("should list function inherited from super class",async function(){var start={line:79,ch:11};testEditor.setCursorPos(start);var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresentExact(hintObj,["amountDue","getAmountDue","getName","name","setAmountDue"])}),it("should show argument from from .prototype.Method",async function(){var start={line:80,ch:0},testPos={line:80,ch:24};testDoc.replaceRange("myCustomer.setAmountDue(",start),testEditor.setCursorPos(testPos),await expectParameterHint([{name:"amountDue",type:"Object"}],0)}),it("should show inner function type",async function(){var testPos={line:96,ch:23};testEditor.setCursorPos(testPos),await expectParameterHint([{name:"arg",type:"String"}],0)}),it("should show type for inner function returned function",async function(){var testPos={line:96,ch:33};testEditor.setCursorPos(testPos),expectHints(JSCodeHints.jsHintProvider),await expectParameterHint([],0)}),it("should list parameter function type and best guess for function call/return types",async function(){var testPos={line:139,ch:12};testEditor.setCursorPos(testPos),await expectParameterHint([{name:"f",type:"function(String, Number):String"}],0)}),it("should list array containing functions",async function(){var testPos={line:142,ch:7};testEditor.setCursorPos(testPos);var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresent(hintObj,["index1","index2"])}),it("should list function reference",async function(){var start={line:144,ch:0},testPos={line:144,ch:14};testDoc.replaceRange("funArr.index1(",start),testEditor.setCursorPos(testPos),await expectParameterHint([],0)}),it("should insert hint as [\"my-key\"] since 'my-key' is not a valid property name",async function(){var start={line:49,ch:0},middle={line:49,ch:5},end={line:49,ch:13};testDoc.replaceRange("arr.m",start,start),testEditor.setCursorPos(middle);var hintObj=expectHints(JSCodeHints.jsHintProvider);await selectHint(JSCodeHints.jsHintProvider,hintObj,"my-key"),expect(fixPos(testEditor.getCursorPos())).toEql(fixPos(end)),expect(testDoc.getRange(start,end)).toEql('arr["my-key"]'),expect(testDoc.getLine(end.line).length).toEql(13)}),it("should insert hint as [\"my-key\"] make sure this works if nothing is typed after the '.'",async function(){var start={line:49,ch:0},middle={line:49,ch:4},end={line:49,ch:13};testDoc.replaceRange("arr.",start,start),testEditor.setCursorPos(middle);var hintObj=expectHints(JSCodeHints.jsHintProvider);await selectHint(JSCodeHints.jsHintProvider,hintObj,"my-key"),expect(fixPos(testEditor.getCursorPos())).toEql(fixPos(end)),expect(testDoc.getRange(start,end)).toEql('arr["my-key"]'),expect(testDoc.getLine(end.line).length).toEql(13)}),it("should insert hint as '.for' since keywords can be used as property names",async function(){var start={line:49,ch:0},middle={line:49,ch:5},end={line:49,ch:7};testDoc.replaceRange("arr.f",start,start),testEditor.setCursorPos(middle);var hintObj=expectHints(JSCodeHints.jsHintProvider);await selectHint(JSCodeHints.jsHintProvider,hintObj,"for"),expect(fixPos(testEditor.getCursorPos())).toEql(fixPos(end)),expect(testDoc.getRange(start,end)).toEql("arr.for"),expect(testDoc.getLine(end.line).length).toEql(7)}),it("should jump to function",async function(){var start={line:43,ch:0};testEditor.setCursorPos(start),await editorJumped({line:7,ch:13})}),it("should jump to var",async function(){var start={line:44,ch:10};testEditor.setCursorPos(start),await editorJumped({line:3,ch:6})}),it("should jump to closure, early defined var",async function(){var start={line:17,ch:9};testEditor.setCursorPos(start),await editorJumped({line:10,ch:10})}),it("should jump to the definition in new module file",async function(){var start={line:40,ch:22};testEditor.setCursorPos(start),await editorJumped({line:4,ch:13,file:"MyModule.js"})}),it("should jump to the method definition in .prototype",async function(){var start={line:59,ch:8};testEditor.setCursorPos(start),await editorJumped({line:53,ch:21})}),it("should jump to parameter passed in the method",async function(){var start={line:63,ch:20};testEditor.setCursorPos(start),await editorJumped({line:61,ch:27})}),it("should jump to parameter passed in anonymous method",async function(){var start={line:83,ch:25};testEditor.setCursorPos(start),await editorJumped({line:81,ch:53})}),it("should jump to inner method",async function(){var start={line:96,ch:32};testEditor.setCursorPos(start),await editorJumped({line:94,ch:17})}),it("should jump to the actual function definition, and not the exports line",async function(){var start={line:159,ch:22};testEditor.setCursorPos(start),await editorJumped({line:11,ch:14,file:"MyModule.js"})}),it("should not hint function, variable, or param decls",async function(){var func={line:7,ch:12},param={line:7,ch:18},variable={line:10,ch:10};testEditor.setCursorPos(func),await expectNoParameterHint(),testEditor.setCursorPos(param),expectNoHints(JSCodeHints.jsHintProvider),testEditor.setCursorPos(variable),expectNoHints(JSCodeHints.jsHintProvider)}),it("should sort underscore names to the bottom",async function(){testEditor.setCursorPos({line:146,ch:0});var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresentOrdered(hintObj,["A1","A2","A3","funB","_A1"])}),it("should list all properties for unknown type",async function(){var start={line:149,ch:0},end={line:149,ch:5};testDoc.replaceRange("help.",start,start),testEditor.setCursorPos(end);var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresentOrdered(hintObj,["apply","charCodeAt","concat"])}),it("should switch to guesses after typing a query that does not match any hints",async function(){var start={line:150,ch:0},end={line:150,ch:5};testDoc.replaceRange("s.shift",start,start),testEditor.setCursorPos(end);var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresentOrdered(hintObj,["shift","shiftKey"])}),it("should handle valid non-ascii characters in a property name",async function(){var start={line:153,ch:0},end={line:153,ch:13};testDoc.replaceRange("hope.frenchçP",start,start),testEditor.setCursorPos(end);var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresentOrdered(hintObj,["frenchçProp"])}),it("should show guessed argument type from current passing parameter",async function(){var start={line:80,ch:0},testPos={line:80,ch:24};testDoc.replaceRange("myCustomer.setAmountDue(10)",start),testEditor.setCursorPos(testPos),await expectParameterHint([{name:"amountDue",type:"Number"}],0)}),it("should list parameter hint for record type annotation",async function(){var testPos={line:178,ch:25};testEditor.setCursorPos(testPos),await expectParameterHint([{name:"t",type:"{index: Number, name: String}"}],-1)}),it("should list parameter hint for optional parameters",async function(){var testPos={line:214,ch:17};testEditor.setCursorPos(testPos),await expectParameterHint([{name:"a",type:"Number",isOptional:!0},{name:"b",type:"String",isOptional:!0}],0)}),it("should list parameter hint for a function parameter",async function(){var testPos={line:181,ch:12};testEditor.setCursorPos(testPos),await expectParameterHint([{name:"compare",type:"function(Object, Object):Number",isOptional:!0}],-1)}),it("should list parameter hint for an array parameter",async function(){var testPos={line:184,ch:12};testEditor.setCursorPos(testPos),await expectParameterHint([{name:"other",type:"Array.<Object>"}],-1)}),it("should list parameter hint for a source array annotation",async function(){var testPos={line:200,ch:20};testEditor.setCursorPos(testPos),await expectParameterHint([{name:"a",type:"Array.<String>"}],0)}),it("should close parameter hint when move off function",async function(){var testPos={line:184,ch:12},endPos={line:184,ch:19};testEditor.setCursorPos(testPos),await expectParameterHint([{name:"other",type:"Array.<Object>"}],-1),testEditor.setCursorPos(endPos),await expectParameterHintClosed()}),it("should close parameter hint when move off function to another function",async function(){var testPos={line:184,ch:12},newPos={line:181,ch:12};testEditor.setCursorPos(testPos),await expectParameterHint([{name:"other",type:"Array.<Object>"}],-1),testEditor.setCursorPos(newPos),await expectParameterHintClosed()}),it("should update current parameter as the cursor moves",async function(){var testPos={line:186,ch:19},newPos={line:186,ch:20};testEditor.setCursorPos(testPos),await expectParameterHint([{name:"char",type:"String"},{name:"from",type:"Number",isOptional:!0}],0),testEditor.setCursorPos(newPos),await expectParameterHint([{name:"char",type:"String"},{name:"from",type:"Number",isOptional:!0}],1)}),it("should consider dot a hintable key based on preference",function(){var noHintsOnDot=PreferencesManager.get("jscodehints.noHintsOnDot");testEditor.setCursorPos({line:44,ch:10}),expect(noHintsOnDot).toBeFalsy(),expectHints(JSCodeHints.jsHintProvider,"."),PreferencesManager.set("jscodehints.noHintsOnDot",!0),expectNoHints(JSCodeHints.jsHintProvider,"."),PreferencesManager.set("jscodehints.noHintsOnDot",!!noHintsOnDot)})}),describe("JavaScript Code Hinting in a HTML file",function(){beforeEach(async function(){await setupTest(testHtmlPath,!1)}),afterEach(function(){tearDownTest()}),it("basic codehints in html file",async function(){var start={line:37,ch:9},end={line:37,ch:13};testDoc.replaceRange("x100.",start),testEditor.setCursorPos(end);var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresentOrdered(hintObj,["charAt","charCodeAt","concat","indexOf"])}),it("function type hint in html file",async function(){var start={line:36,ch:12};testEditor.setCursorPos(start),await expectParameterHint([{name:"a",type:"Number"}],0)}),it("should show function type code hint for function in script file inside html file",async function(){var start={line:22,ch:17};testEditor.setCursorPos(start),await expectParameterHint([{name:"a",type:"String"},{name:"b",type:"Number"}],0)}),it("should show function type code hint for function in another script file inside html file",async function(){var start={line:23,ch:17};testEditor.setCursorPos(start),await expectParameterHint([{name:"paramE1",type:"D1"},{name:"paramE2",type:"Number"}],0)}),it("should show global variable in another script file inside html file",async function(){var start={line:27,ch:8},end={line:27,ch:13},testPosStart={line:27,ch:11},testPosEnd={line:27,ch:21};testDoc.replaceRange("arr.m",start),testEditor.setCursorPos(end);var hintObj=expectHints(JSCodeHints.jsHintProvider);await hintsPresent(hintObj,["my-key"]),await selectHint(JSCodeHints.jsHintProvider,hintObj,"my-key"),expect(testDoc.getRange(testPosStart,testPosEnd)).toEql('["my-key"]')}),it("should jump to definition inside html file",async function(){var start={line:36,ch:10};testEditor.setCursorPos(start),await editorJumped({line:19,ch:20})}),it("should jump to funtion definition to loaded file1",async function(){var start={line:22,ch:15};testEditor.setCursorPos(start),await editorJumped({line:33,ch:13})}),it("should jump to funtion definition to loaded file2",async function(){var start={line:23,ch:15};testEditor.setCursorPos(start),await editorJumped({line:6,ch:13})}),it("should jump to property definition to loaded file1",async function(){var start={line:23,ch:28};testEditor.setCursorPos(start),await editorJumped({line:4,ch:16})}),it("should jump to property definition to loaded file2",async function(){var start={line:23,ch:18};testEditor.setCursorPos(start),await editorJumped({line:3,ch:6})})})})});