From aa3c176aa6215d49ec8f9fb8525f45b5df2d2e4b Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 21 Nov 2014 12:24:58 -0800 Subject: [PATCH] Tests for local function --- .../quickInfoDisplayPartsLocalFunction.ts | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 tests/cases/fourslash/quickInfoDisplayPartsLocalFunction.ts diff --git a/tests/cases/fourslash/quickInfoDisplayPartsLocalFunction.ts b/tests/cases/fourslash/quickInfoDisplayPartsLocalFunction.ts new file mode 100644 index 00000000000..b9578c7f522 --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsLocalFunction.ts @@ -0,0 +1,92 @@ +/// + +////function /*1*/outerFoo() { +//// function /*2*/foo(param: string, optionalParam?: string, paramWithInitializer = "hello", ...restParam: string[]) { +//// } +//// function /*3*/foowithoverload(a: string): string; +//// function /*4*/foowithoverload(a: number): number; +//// function /*5*/foowithoverload(a: any): any { +//// return a; +//// } +//// function /*6*/foowith3overload(a: string): string; +//// function /*7*/foowith3overload(a: number): number; +//// function /*8*/foowith3overload(a: boolean): boolean; +//// function /*9*/foowith3overload(a: any): any { +//// return a; +//// } +//// /*10*/foo("hello"); +//// /*11*/foowithoverload("hello"); +//// /*12*/foowithoverload(10); +//// /*13*/foowith3overload("hello"); +//// /*14*/foowith3overload(10); +//// /*15*/foowith3overload(true); +////} +/////*16*/outerFoo(); + +var marker = 0; +function verifyOuterFunction() { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("function", "", { start: test.markerByName(marker.toString()).position, length: "outerFoo".length }, + [{ text: "(", kind: "punctuation" }, { text: "function", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "outerFoo", kind: "functionName" }, { text: "(", kind: "punctuation" }, + { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "void", kind: "keyword" }], + []); +} + +function verifyFunctionWithoutOverload() { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("local function", "", { start: test.markerByName(marker.toString()).position, length: "foo".length }, + [{ text: "(", kind: "punctuation" }, { text: "local function", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "foo", kind: "functionName" }, { text: "(", kind: "punctuation" }, + { text: "param", kind: "parameterName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, + { text: ",", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "optionalParam", kind: "parameterName" }, { text: "?", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, + { text: ",", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "paramWithInitializer", kind: "parameterName" }, { text: "?", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, + { text: ",", kind: "punctuation" }, { text: " ", kind: "space" }, + { text: "...", kind: "punctuation" }, { text: "restParam", kind: "parameterName" }, { text: ":", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: "string", kind: "keyword" }, { text: "[", kind: "punctuation" }, { text: "]", kind: "punctuation" }, + { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: "void", kind: "keyword" }], + []); +} + +function verifyFunctionWithOverload(functionName: string, type: string, overloadCount: number) { + marker++; + goTo.marker(marker.toString()); + verify.verifyQuickInfoDisplayParts("local function", "", { start: test.markerByName(marker.toString()).position, length: functionName.length }, + [{ text: "(", kind: "punctuation" }, { text: "local function", kind: "text" }, { text: ")", kind: "punctuation" }, + { text: " ", kind: "space" }, { text: functionName, kind: "functionName" }, { text: "(", kind: "punctuation" }, + { text: "a", kind: "parameterName" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: type, kind: "keyword" }, + { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, { text: type, kind: "keyword" }, + { text: " ", kind: "space" }, { text: "(", kind: "punctuation" }, { text: "+", kind: "operator" }, { text: overloadCount.toString(), kind: "numericLiteral" }, + { text: " ", kind: "space" }, { text: overloadCount === 1 ? "overload" : "overloads", kind: "text" }, { text: ")", kind: "punctuation" }], + []); +} + + +// Declarations +verifyOuterFunction(); + +verifyFunctionWithoutOverload(); + +verifyFunctionWithOverload("foowithoverload", "string", 1); +verifyFunctionWithOverload("foowithoverload", "number", 1); +verifyFunctionWithOverload("foowithoverload", "string", 1); + +verifyFunctionWithOverload("foowith3overload", "string", 2); +verifyFunctionWithOverload("foowith3overload", "number", 2); +verifyFunctionWithOverload("foowith3overload", "boolean", 2); +verifyFunctionWithOverload("foowith3overload", "string", 2); + +// Calls +verifyFunctionWithoutOverload(); + +verifyFunctionWithOverload("foowithoverload", "string", 1); +verifyFunctionWithOverload("foowithoverload", "number", 1); + +verifyFunctionWithOverload("foowith3overload", "string", 2); +verifyFunctionWithOverload("foowith3overload", "number", 2); +verifyFunctionWithOverload("foowith3overload", "boolean", 2); +verifyOuterFunction();