From db6572433094ec1691ad30f9687b3a04eca3cd26 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 23 May 2016 09:44:28 -0700 Subject: [PATCH] Make fourslash tests actually test parentName for navbar items --- src/harness/fourslash.ts | 24 +++++++++---------- tests/cases/fourslash/navbar_const.ts | 2 +- .../navbar_contains-no-duplicates.ts | 4 ++-- ...ionBarItemsInsideMethodsAndConstructors.ts | 14 +++++------ .../fourslash/navigationBarItemsItems.ts | 18 +++++++------- ...navigationBarItemsItemsExternalModules3.ts | 2 +- .../fourslash/navigationBarItemsModules.ts | 4 ++-- tests/cases/fourslash/server/navbar01.ts | 18 +++++++------- 8 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index c237734e1d..7f2972e812 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1989,36 +1989,36 @@ namespace FourSlash { return result; } - public verifyNavigationBarContains(name: string, kind: string) { - const items = this.languageService.getNavigationBarItems(this.activeFile.fileName); + public verifyNavigationBarContains(name: string, kind: string, fileName?: string, parentName?: string, isAdditionalSpan?: boolean, markerPosition?: number) { + fileName = fileName || this.activeFile.fileName; + const items = this.languageService.getNavigationBarItems(fileName); if (!items || items.length === 0) { this.raiseError("verifyNavigationBarContains failed - found 0 navigation items, expected at least one."); } - if (this.navigationBarItemsContains(items, name, kind)) { + if (this.navigationBarItemsContains(items, name, kind, parentName)) { return; } - const missingItem = { name, kind }; + const missingItem = { name, kind, parentName }; this.raiseError(`verifyNavigationBarContains failed - could not find the item: ${JSON.stringify(missingItem, undefined, 2)} in the returned list: (${JSON.stringify(items, undefined, 2)})`); } - private navigationBarItemsContains(items: ts.NavigationBarItem[], name: string, kind: string) { - if (items) { + private navigationBarItemsContains(items: ts.NavigationBarItem[], name: string, kind: string, parentName?: string) { + function recur(items: ts.NavigationBarItem[], curParentName: string) { for (let i = 0; i < items.length; i++) { const item = items[i]; - if (item && item.text === name && item.kind === kind) { + if (item && item.text === name && item.kind === kind && (!parentName || curParentName === parentName)) { return true; } - - if (this.navigationBarItemsContains(item.childItems, name, kind)) { + if (recur(item.childItems, item.text)) { return true; } } + return false; } - - return false; + return recur(items, ""); } public verifyNavigationBarChildItem(parent: string, name: string, kind: string) { @@ -3055,7 +3055,7 @@ namespace FourSlashInterface { parentName?: string, isAdditionalSpan?: boolean, markerPosition?: number) { - this.state.verifyNavigationBarContains(name, kind); + this.state.verifyNavigationBarContains(name, kind, fileName, parentName, isAdditionalSpan, markerPosition); } public navigationBarChildItem(parent: string, name: string, kind: string) { diff --git a/tests/cases/fourslash/navbar_const.ts b/tests/cases/fourslash/navbar_const.ts index a2cdb80bae..5d8b42607c 100644 --- a/tests/cases/fourslash/navbar_const.ts +++ b/tests/cases/fourslash/navbar_const.ts @@ -1,6 +1,6 @@ /// -//// {| "itemName": "c", "kind": "const", "parentName": "" |}const c = 0; +//// {| "itemName": "c", "kind": "const", "parentName": "" |}const c = 0; test.markers().forEach(marker => { verify.navigationBarContains( diff --git a/tests/cases/fourslash/navbar_contains-no-duplicates.ts b/tests/cases/fourslash/navbar_contains-no-duplicates.ts index 4c612136b5..ec86e4b2f2 100644 --- a/tests/cases/fourslash/navbar_contains-no-duplicates.ts +++ b/tests/cases/fourslash/navbar_contains-no-duplicates.ts @@ -1,6 +1,6 @@ /// //// {| "itemName": "Windows", "kind": "module", "parentName": "" |}declare module Windows { -//// {| "itemName": "Foundation", "kind": "module", "parentName": "Windows" |}export module Foundation { +//// {| "itemName": "Foundation", "kind": "module", "parentName": "" |}export module Foundation { //// export var {| "itemName": "A", "kind": "var" |}A; //// {| "itemName": "Test", "kind": "class" |}export class Test { //// {| "itemName": "wow", "kind": "method" |}public wow(); @@ -9,7 +9,7 @@ //// } //// //// {| "itemName": "Windows", "kind": "module", "parentName": "", "isAdditionalRange": true |}declare module Windows { -//// {| "itemName": "Foundation", "kind": "module", "parentName": "Windows", "isAdditionalRange": true |}export module Foundation { +//// {| "itemName": "Foundation", "kind": "module", "parentName": "", "isAdditionalRange": true |}export module Foundation { //// export var {| "itemName": "B", "kind": "var" |}B; //// {| "itemName": "Test", "kind": "module" |}export module Test { //// {| "itemName": "Boom", "kind": "function" |}export function Boom(): number; diff --git a/tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts b/tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts index 7aaa3d7f5a..22ae359c73 100644 --- a/tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts +++ b/tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts @@ -2,11 +2,11 @@ ////class Class { //// constructor() { -//// {| "itemName": "LocalFunctionInConstructor", "kind": "function", "parentName": "Class"|}function LocalFunctionInConstructor() { +//// {| "itemName": "LocalFunctionInConstructor", "kind": "function", "parentName": "constructor"|}function LocalFunctionInConstructor() { //// //// } //// -//// {| "itemName": "LocalInterfaceInConstrcutor", "kind": "interface", "parentName": "foo"|}interface LocalInterfaceInConstrcutor { +//// {| "itemName": "LocalInterfaceInConstrcutor", "kind": "interface", "parentName": ""|}interface LocalInterfaceInConstrcutor { //// } //// //// enum LocalEnumInConstructor { @@ -15,17 +15,17 @@ //// } //// //// method() { -//// {| "itemName": "LocalFunctionInMethod", "kind": "function", "parentName": "foo"|}function LocalFunctionInMethod() { -//// {| "itemName": "LocalFunctionInLocalFunctionInMethod", "kind": "function", "parentName": "bar"|}function LocalFunctionInLocalFunctionInMethod() { +//// {| "itemName": "LocalFunctionInMethod", "kind": "function", "parentName": "method"|}function LocalFunctionInMethod() { +//// {| "itemName": "LocalFunctionInLocalFunctionInMethod", "kind": "function", "parentName": "LocalFunctionInMethod"|}function LocalFunctionInLocalFunctionInMethod() { //// //// } //// } //// -//// {| "itemName": "LocalInterfaceInMethod", "kind": "interface", "parentName": "foo"|}interface LocalInterfaceInMethod { +//// {| "itemName": "LocalInterfaceInMethod", "kind": "interface", "parentName": ""|}interface LocalInterfaceInMethod { //// } //// -//// enum LocalEnumInMethod { -//// {| "itemName": "LocalEnumMemberInMethod", "kind": "property", "parentName": "foo"|}LocalEnumMemberInMethod, +//// {| "itemName": "LocalEnumInMethod", "kind": "enum", "parentName": ""|}enum LocalEnumInMethod { +//// {| "itemName": "LocalEnumMemberInMethod", "kind": "property", "parentName": "LocalEnumInMethod"|}LocalEnumMemberInMethod, //// } //// } //// diff --git a/tests/cases/fourslash/navigationBarItemsItems.ts b/tests/cases/fourslash/navigationBarItemsItems.ts index 3804a0dab5..10dd8beb8f 100644 --- a/tests/cases/fourslash/navigationBarItemsItems.ts +++ b/tests/cases/fourslash/navigationBarItemsItems.ts @@ -13,28 +13,28 @@ ////{| "itemName": "Shapes", "kind": "module", "parentName": "" |}module Shapes { //// //// // Class -//// {| "itemName": "Point", "kind": "class", "parentName": "Shapes" |}export class Point implements IPoint { -//// {| "itemName": "constructor", "kind": "constructor", "parentName": "Shapes.Point" |}constructor (public x: number, public y: number) { } +//// {| "itemName": "Point", "kind": "class", "parentName": "" |}export class Point implements IPoint { +//// {| "itemName": "constructor", "kind": "constructor", "parentName": "Point" |}constructor (public x: number, public y: number) { } //// //// // Instance member -//// {| "itemName": "getDist", "kind": "method", "parentName": "Shapes.Point" |}getDist() { return Math.sqrt(this.x * this.x + this.y * this.y); } +//// {| "itemName": "getDist", "kind": "method", "parentName": "Point" |}getDist() { return Math.sqrt(this.x * this.x + this.y * this.y); } //// //// // Getter -//// {| "itemName": "value", "kind": "getter", "parentName": "Shapes.Point" |}get value(): number { return 0; } +//// {| "itemName": "value", "kind": "getter", "parentName": "Point" |}get value(): number { return 0; } //// //// // Setter -//// {| "itemName": "value", "kind": "setter", "parentName": "Shapes.Point" |}set value(newValue: number) { return; } +//// {| "itemName": "value", "kind": "setter", "parentName": "Point" |}set value(newValue: number) { return; } //// //// // Static member -//// {| "itemName": "origin", "kind": "property", "parentName": "Shapes.Point" |}static origin = new Point(0, 0); +//// {| "itemName": "origin", "kind": "property", "parentName": "Point" |}static origin = new Point(0, 0); //// //// // Static method -//// {| "itemName": "getOrigin", "kind": "method", "parentName": "Shapes.Point" |}private static getOrigin() { return Point.origin;} +//// {| "itemName": "getOrigin", "kind": "method", "parentName": "Point" |}private static getOrigin() { return Point.origin;} //// } //// -//// {| "itemName": "Values", "kind": "enum", "parentName": "Shapes" |}enum Values { +//// {| "itemName": "Values", "kind": "enum", "parentName": "" |}enum Values { //// value1, -//// {| "itemName": "value2", "kind": "property", "parentName": "Shapes.Values" |}value2, +//// {| "itemName": "value2", "kind": "property", "parentName": "Values" |}value2, //// value3, //// } ////} diff --git a/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts b/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts index 193da9ff47..6e6dc9871c 100644 --- a/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts +++ b/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts @@ -5,7 +5,7 @@ //// {| "itemName": "s", "kind": "property", "parentName": "Bar" |}public s: string; ////} ////{| "itemName": "\"my fil\\\"e\"", "kind": "module" |} -////{| "itemName": "x", "kind": "var", "parentName": "\"file\"" |} +////{| "itemName": "x", "kind": "var", "parentName": "\"my fil\\\"e\"" |} ////export var x: number; test.markers().forEach((marker) => { diff --git a/tests/cases/fourslash/navigationBarItemsModules.ts b/tests/cases/fourslash/navigationBarItemsModules.ts index 2f6e1d7f84..895a9e23a0 100644 --- a/tests/cases/fourslash/navigationBarItemsModules.ts +++ b/tests/cases/fourslash/navigationBarItemsModules.ts @@ -27,9 +27,9 @@ //// ////{| "itemName": "A", "kind": "module" |} ////module A { -//// {| "itemName": "B", "kind": "module", "parentName": "E" |} +//// {| "itemName": "B", "kind": "module", "parentName": "" |} //// module B { -//// {| "itemName": "C", "kind": "module", "parentName": "F" |} +//// {| "itemName": "C", "kind": "module", "parentName": "" |} //// module C { //// {| "itemName": "x", "kind": "var", "parentName": "C" |} //// declare var x; diff --git a/tests/cases/fourslash/server/navbar01.ts b/tests/cases/fourslash/server/navbar01.ts index 8e76e7c017..ef6ae650ef 100644 --- a/tests/cases/fourslash/server/navbar01.ts +++ b/tests/cases/fourslash/server/navbar01.ts @@ -13,28 +13,28 @@ ////{| "itemName": "Shapes", "kind": "module", "parentName": "" |}module Shapes { //// //// // Class -//// {| "itemName": "Point", "kind": "class", "parentName": "Shapes" |}export class Point implements IPoint { -//// {| "itemName": "constructor", "kind": "constructor", "parentName": "Shapes.Point" |}constructor (public x: number, public y: number) { } +//// {| "itemName": "Point", "kind": "class", "parentName": "" |}export class Point implements IPoint { +//// {| "itemName": "constructor", "kind": "constructor", "parentName": "Point" |}constructor (public x: number, public y: number) { } //// //// // Instance member -//// {| "itemName": "getDist", "kind": "method", "parentName": "Shapes.Point" |}getDist() { return Math.sqrt(this.x * this.x + this.y * this.y); } +//// {| "itemName": "getDist", "kind": "method", "parentName": "Point" |}getDist() { return Math.sqrt(this.x * this.x + this.y * this.y); } //// //// // Getter -//// {| "itemName": "value", "kind": "getter", "parentName": "Shapes.Point" |}get value(): number { return 0; } +//// {| "itemName": "value", "kind": "getter", "parentName": "Point" |}get value(): number { return 0; } //// //// // Setter -//// {| "itemName": "value", "kind": "setter", "parentName": "Shapes.Point" |}set value(newValue: number) { return; } +//// {| "itemName": "value", "kind": "setter", "parentName": "Point" |}set value(newValue: number) { return; } //// //// // Static member -//// {| "itemName": "origin", "kind": "property", "parentName": "Shapes.Point" |}static origin = new Point(0, 0); +//// {| "itemName": "origin", "kind": "property", "parentName": "Point" |}static origin = new Point(0, 0); //// //// // Static method -//// {| "itemName": "getOrigin", "kind": "method", "parentName": "Shapes.Point" |}private static getOrigin() { return Point.origin;} +//// {| "itemName": "getOrigin", "kind": "method", "parentName": "Point" |}private static getOrigin() { return Point.origin;} //// } //// -//// {| "itemName": "Values", "kind": "enum", "parentName": "Shapes" |}enum Values { +//// {| "itemName": "Values", "kind": "enum", "parentName": "" |}enum Values { //// value1, -//// {| "itemName": "value2", "kind": "property", "parentName": "Shapes.Values" |}value2, +//// {| "itemName": "value2", "kind": "property", "parentName": "Values" |}value2, //// value3, //// } ////}