Merge with master

This commit is contained in:
Glenn Ruehle committed 2013-09-11 12:35:44 -07:00
commit ada68e2b1f
184 files changed
+19232 -3339

No files matched your search

@@ -27,18 +27,20 @@
define(function (require, exports, module) {
"use strict";
var Commands = brackets.getModule("command/Commands"),
CommandManager = brackets.getModule("command/CommandManager"),
DocumentManager = brackets.getModule("document/DocumentManager"),
Editor = brackets.getModule("editor/Editor").Editor,
EditorManager = brackets.getModule("editor/EditorManager"),
FileUtils = brackets.getModule("file/FileUtils"),
SpecRunnerUtils = brackets.getModule("spec/SpecRunnerUtils"),
UnitTestReporter = brackets.getModule("test/UnitTestReporter"),
JSCodeHints = require("main"),
Preferences = require("Preferences"),
ScopeManager = require("ScopeManager"),
HintUtils = require("HintUtils");
var Commands = brackets.getModule("command/Commands"),
CommandManager = brackets.getModule("command/CommandManager"),
DocumentManager = brackets.getModule("document/DocumentManager"),
Editor = brackets.getModule("editor/Editor").Editor,
EditorManager = brackets.getModule("editor/EditorManager"),
FileUtils = brackets.getModule("file/FileUtils"),
SpecRunnerUtils = brackets.getModule("spec/SpecRunnerUtils"),
UnitTestReporter = brackets.getModule("test/UnitTestReporter"),
JSCodeHints = require("main"),
Preferences = require("Preferences"),
ScopeManager = require("ScopeManager"),
HintUtils = require("HintUtils"),
HintUtils2 = require("HintUtils2"),
ParameterHintManager = require("ParameterHintManager");
var extensionPath = FileUtils.getNativeModuleDirectoryPath(module),
testPath = extensionPath + "/unittest-files/basic-test-files/file1.js",
@@ -152,6 +154,7 @@ define(function (require, exports, module) {
runs(function () { callback(hintList); });
}
/*
* Test if hints should be closed or not closed at a given position.
*
@@ -337,6 +340,90 @@ define(function (require, exports, module) {
}
/**
* Verify there is no parameter hint at the current cursor.
*/
function expectNoParameterHint() {
expect(ParameterHintManager.popUpHint()).toBe(null);
}
/**
* Verify the parameter hint is not visible.
*/
function expectParameterHintClosed() {
expect(ParameterHintManager.isHintDisplayed()).toBe(false);
}
/*
* Wait for a hint response object to resolve, then apply a callback
* to the result
*
* @param {Object + jQuery.Deferred} hintObj - a hint response object,
* possibly deferred
* @param {Function} callback - the callback to apply to the resolved
* hint response object
*/
function _waitForParameterHint(hintObj, callback) {
var complete = false,
hint = null;
hintObj.done(function () {
hint = JSCodeHints.getSession().getParameterHint();
complete = true;
});
waitsFor(function () {
return complete;
}, "Expected parameter hint did not resolve", 3000);
runs(function () { callback(hint); });
}
/**
* Show a function hint based on the code at the cursor. Verify the
* hint matches the passed in value.
*
* @param {Array<{name: string, type: string, isOptional: boolean}>}
* expectedParams - array of records, where each element of the array
* describes a function parameter. If null, then no hint is expected.
* @param {number} expectedParameter - the parameter at cursor.
*/
function expectParameterHint(expectedParams, expectedParameter) {
var request = ParameterHintManager.popUpHint();
if (expectedParams === null) {
expect(request).toBe(null);
return;
}
function expectHint(hint) {
var params = hint.parameters,
n = params.length,
i;
// compare params to expected params
expect(params.length).toBe(expectedParams.length);
expect(hint.currentIndex).toBe(expectedParameter);
for (i = 0; i < n; i++) {
expect(params[i].name).toBe(expectedParams[i].name);
expect(params[i].type).toBe(expectedParams[i].type);
if (params[i].isOptional) {
expect(expectedParams[i].isOptional).toBeTruthy();
} else {
expect(expectedParams[i].isOptional).toBeFalsy();
}
}
}
if (request) {
_waitForParameterHint(request, expectHint);
} else {
expectHint(JSCodeHints.getSession().getParameterHint());
}
}
function setupTest(path, primePump) {
DocumentManager.getDocumentForPath(path).done(function (doc) {
testDoc = doc;
@@ -731,14 +818,14 @@ define(function (require, exports, module) {
});
it("should list function type", function () {
var start = { line: 36, ch: 0 },
middle = { line: 36, ch: 5 };
var start = { line: 37, ch: 0 },
middle = { line: 37, ch: 5 };
testDoc.replaceRange("funD(", start, start);
testEditor.setCursorPos(middle);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
runs(function () {
hintsPresentExact(hintObj, ["funD(a: string, b: number) -> {x, y}"]);
expectParameterHint([{name: "a", type: "String"},
{name: "b", type: "Number"}], 0);
});
});
@@ -820,9 +907,8 @@ define(function (require, exports, module) {
it("should list function type defined from .prototype", function () {
var start = { line: 59, ch: 10 };
testEditor.setCursorPos(start);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
runs(function () {
hintsPresentExact(hintObj, ["calc(a4: number, b4: number) -> number"]);
expectParameterHint([{name: "a4", type: "Number"}, {name: "b4", type: "Number"}], 0);
});
});
@@ -841,9 +927,8 @@ define(function (require, exports, module) {
testDoc.replaceRange("myCustomer.setAmountDue(", start);
testEditor.setCursorPos(testPos);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
runs(function () {
hintsPresentOrdered(hintObj, ["setAmountDue(amountDue: ?)"]);
expectParameterHint([{name: "amountDue", type: "Object"}], 0);
});
});
@@ -851,9 +936,8 @@ define(function (require, exports, module) {
var testPos = { line: 96, ch: 23 };
testEditor.setCursorPos(testPos);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
runs(function () {
hintsPresentOrdered(hintObj, ["innerFunc(arg: string) -> {t}"]);
expectParameterHint([{name: "arg", type: "String"}], 0);
});
});
@@ -863,7 +947,7 @@ define(function (require, exports, module) {
testEditor.setCursorPos(testPos);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
runs(function () {
hintsPresentOrdered(hintObj, ["t() -> string"]);
expectParameterHint([], 0);
});
});
@@ -886,20 +970,18 @@ define(function (require, exports, module) {
var testPos = { line: 123, ch: 11 };
testEditor.setCursorPos(testPos);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
runs(function () {
hintsPresentExact(hintObj, ["funFuncArg(f: fn() -> number) -> number"]);
expectParameterHint([{name: "f", type: "function(): number"}], 0);
});
});
// parameter type anotation tests
// parameter type annotation tests
it("should list parameter function type and best guess for function call/return types", function () {
var testPos = { line: 139, ch: 12 };
testEditor.setCursorPos(testPos);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
runs(function () {
hintsPresentExact(hintObj, ["funFunc2Arg(f: fn(s: string, n: number) -> string)"]);
expectParameterHint([{name: "f", type: "function(String, Number):String"}], 0);
});
});
@@ -919,9 +1001,8 @@ define(function (require, exports, module) {
testDoc.replaceRange("funArr.index1(", start);
testEditor.setCursorPos(testPos);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
runs(function () {
hintsPresentExact(hintObj, ["index1() -> number"]);
expectParameterHint([], 0);
});
});
@@ -1060,7 +1141,7 @@ define(function (require, exports, module) {
runs(function () {
testEditor.setCursorPos(func);
expectNoHints(JSCodeHints.jsHintProvider);
expectNoParameterHint();
testEditor.setCursorPos(param);
expectNoHints(JSCodeHints.jsHintProvider);
testEditor.setCursorPos(variable);
@@ -1112,9 +1193,99 @@ define(function (require, exports, module) {
testPos = { line: 80, ch: 24 };
testDoc.replaceRange("myCustomer.setAmountDue(10)", start);
testEditor.setCursorPos(testPos);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
runs(function () {
hintsPresentOrdered(hintObj, ["setAmountDue(amountDue: number)"]);
expectParameterHint([{name: "amountDue", type: "Number"}], 0);
});
});
it("should list parameter hint for record type annotation", function () {
var testPos = { line: 178, ch: 25 };
testEditor.setCursorPos(testPos);
runs(function () {
expectParameterHint([{name: "t", type: "{index: Number, name: String}"}], -1);
});
});
// Tern issue #208. Fixed in the latest tern
xit("should list parameter hint for optional parameters", function () {
var testPos = { line: 214, ch: 17 };
testEditor.setCursorPos(testPos);
runs(function () {
expectParameterHint([{name: "a", type: "Number", isOptional: true}, {name: "b", type: "String", isOptional: true}], 0);
});
});
it("should list parameter hint for a function parameter", function () {
var testPos = { line: 181, ch: 12 };
testEditor.setCursorPos(testPos);
runs(function () {
expectParameterHint([{name: "compare",
type: "function(Object, Object):Number",
isOptional: true}], -1);
});
});
it("should list parameter hint for an array parameter", function () {
var testPos = { line: 184, ch: 12 };
testEditor.setCursorPos(testPos);
runs(function () {
expectParameterHint([{name: "other", type: "Array.<Object>"}], -1);
});
});
// Tern is not returning the correct function type info for the array annotation
xit("should list parameter hint for a source array annotation", function () {
var testPos = { line: 200, ch: 20 };
testEditor.setCursorPos(testPos);
runs(function () {
expectParameterHint([{name: "a", type: "Array.<String>"}], 0);
});
});
it("should close parameter hint when move off function", function () {
var testPos = { line: 184, ch: 12 },
endPos = { line: 184, ch: 19 };
testEditor.setCursorPos(testPos);
runs(function () {
expectParameterHint([{name: "other", type: "Array.<Object>"}], -1);
});
runs(function () {
testEditor.setCursorPos(endPos);
expectParameterHintClosed();
});
});
it("should close parameter hint when move off function to another function", function () {
var testPos = { line: 184, ch: 12 },
newPos = { line: 181, ch: 12 };
testEditor.setCursorPos(testPos);
runs(function () {
expectParameterHint([{name: "other", type: "Array.<Object>"}], -1);
});
runs(function () {
testEditor.setCursorPos(newPos);
expectParameterHintClosed();
});
});
it("should update current parameter as the cursor moves", function () {
var testPos = { line: 186, ch: 19 },
newPos = { line: 186, ch: 20 };
testEditor.setCursorPos(testPos);
runs(function () {
expectParameterHint([{name: "char", type: "String"},
{name: "from", type: "Number", isOptional: true}], 0);
});
runs(function () {
testEditor.setCursorPos(newPos);
expectParameterHint([{name: "char", type: "String"},
{name: "from", type: "Number", isOptional: true}], 1);
});
});
@@ -1146,9 +1317,8 @@ define(function (require, exports, module) {
var start = { line: 36, ch: 12 };
testEditor.setCursorPos(start);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
runs(function () {
hintsPresentExact(hintObj, ["foo(a: number) -> string"]);
expectParameterHint([{name: "a", type: "Number"}], 0);
});
});
@@ -1156,9 +1326,8 @@ define(function (require, exports, module) {
var start = { line: 22, ch: 17 };
testEditor.setCursorPos(start);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
runs(function () {
hintsPresentExact(hintObj, ["funD(a: string, b: number) -> {x, y}"]);
expectParameterHint([{name: "a", type: "String"}, {name: "b", type: "Number"}], 0);
});
});
@@ -1166,9 +1335,8 @@ define(function (require, exports, module) {
var start = { line: 23, ch: 17 };
testEditor.setCursorPos(start);
var hintObj = expectHints(JSCodeHints.jsHintProvider);
runs(function () {
hintsPresentExact(hintObj, ["funE(paramE1: D1, paramE2: number)"]);
expectParameterHint([{name: "paramE1", type: "D1"}, {name: "paramE2", type: "Number"}], 0);
});
});
@@ -1641,5 +1809,61 @@ define(function (require, exports, module) {
});
});
describe("JavaScript Code Hinting format parameters tests", function () {
it("should format parameters with no params", function () {
var params = [];
expect(HintUtils2.formatParameterHint(params)).toBe("");
});
it("should format parameters with one param", function () {
var params = [{name: "param1", type: "String"}];
expect(HintUtils2.formatParameterHint(params)).toBe("String param1");
});
it("should format parameters with one optional param", function () {
var params = [{name: "param1", type: "String", isOptional: true}];
expect(HintUtils2.formatParameterHint(params)).toBe("[String param1]");
});
it("should format parameters with one required, one optional param", function () {
var params = [{name: "param1", type: "String"},
{name: "param2", type: "String", isOptional: true}];
expect(HintUtils2.formatParameterHint(params)).toBe("String param1, [String param2]");
});
it("should format parameters with required param following an optional param", function () {
var params = [{name: "param1", type: "String"},
{name: "param2", type: "String", isOptional: true},
{name: "param3", type: "String"}];
expect(HintUtils2.formatParameterHint(params)).toBe("String param1, [String param2, String param3]");
});
it("should format parameters with optional param following an optional param", function () {
var params = [{name: "param1", type: "String"},
{name: "param2", type: "String", isOptional: true},
{name: "param3", type: "String", isOptional: true}];
expect(HintUtils2.formatParameterHint(params)).toBe("String param1, [String param2], [String param3]");
});
it("should format parameters with optional param following optional and required params", function () {
var params = [{name: "param1", type: "String"},
{name: "param2", type: "String", isOptional: true},
{name: "param3", type: "String"},
{name: "param4", type: "String", isOptional: true}];
expect(HintUtils2.formatParameterHint(params)).toBe("String param1, [String param2, String param3], [String param4]");
});
});
});
});