Skip to content

Commit 1f7d1d2

Browse files
author
Andy
committed
Merge pull request microsoft#8762 from Microsoft/navbar_tests
Make fourslash tests actually test parentName for navbar items
2 parents dd092d8 + db65724 commit 1f7d1d2

File tree

8 files changed

+43
-43
lines changed

8 files changed

+43
-43
lines changed

src/harness/fourslash.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,36 +1989,36 @@ namespace FourSlash {
19891989
return result;
19901990
}
19911991

1992-
public verifyNavigationBarContains(name: string, kind: string) {
1993-
const items = this.languageService.getNavigationBarItems(this.activeFile.fileName);
1992+
public verifyNavigationBarContains(name: string, kind: string, fileName?: string, parentName?: string, isAdditionalSpan?: boolean, markerPosition?: number) {
1993+
fileName = fileName || this.activeFile.fileName;
1994+
const items = this.languageService.getNavigationBarItems(fileName);
19941995

19951996
if (!items || items.length === 0) {
19961997
this.raiseError("verifyNavigationBarContains failed - found 0 navigation items, expected at least one.");
19971998
}
19981999

1999-
if (this.navigationBarItemsContains(items, name, kind)) {
2000+
if (this.navigationBarItemsContains(items, name, kind, parentName)) {
20002001
return;
20012002
}
20022003

2003-
const missingItem = { name, kind };
2004+
const missingItem = { name, kind, parentName };
20042005
this.raiseError(`verifyNavigationBarContains failed - could not find the item: ${JSON.stringify(missingItem, undefined, 2)} in the returned list: (${JSON.stringify(items, undefined, 2)})`);
20052006
}
20062007

2007-
private navigationBarItemsContains(items: ts.NavigationBarItem[], name: string, kind: string) {
2008-
if (items) {
2008+
private navigationBarItemsContains(items: ts.NavigationBarItem[], name: string, kind: string, parentName?: string) {
2009+
function recur(items: ts.NavigationBarItem[], curParentName: string) {
20092010
for (let i = 0; i < items.length; i++) {
20102011
const item = items[i];
2011-
if (item && item.text === name && item.kind === kind) {
2012+
if (item && item.text === name && item.kind === kind && (!parentName || curParentName === parentName)) {
20122013
return true;
20132014
}
2014-
2015-
if (this.navigationBarItemsContains(item.childItems, name, kind)) {
2015+
if (recur(item.childItems, item.text)) {
20162016
return true;
20172017
}
20182018
}
2019+
return false;
20192020
}
2020-
2021-
return false;
2021+
return recur(items, "");
20222022
}
20232023

20242024
public verifyNavigationBarChildItem(parent: string, name: string, kind: string) {
@@ -3055,7 +3055,7 @@ namespace FourSlashInterface {
30553055
parentName?: string,
30563056
isAdditionalSpan?: boolean,
30573057
markerPosition?: number) {
3058-
this.state.verifyNavigationBarContains(name, kind);
3058+
this.state.verifyNavigationBarContains(name, kind, fileName, parentName, isAdditionalSpan, markerPosition);
30593059
}
30603060

30613061
public navigationBarChildItem(parent: string, name: string, kind: string) {

tests/cases/fourslash/navbar_const.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference path="fourslash.ts" />
22

3-
//// {| "itemName": "c", "kind": "const", "parentName": "" |}const c = 0;
3+
//// {| "itemName": "c", "kind": "const", "parentName": "<global>" |}const c = 0;
44

55
test.markers().forEach(marker => {
66
verify.navigationBarContains(

tests/cases/fourslash/navbar_contains-no-duplicates.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference path="fourslash.ts" />
22
//// {| "itemName": "Windows", "kind": "module", "parentName": "" |}declare module Windows {
3-
//// {| "itemName": "Foundation", "kind": "module", "parentName": "Windows" |}export module Foundation {
3+
//// {| "itemName": "Foundation", "kind": "module", "parentName": "" |}export module Foundation {
44
//// export var {| "itemName": "A", "kind": "var" |}A;
55
//// {| "itemName": "Test", "kind": "class" |}export class Test {
66
//// {| "itemName": "wow", "kind": "method" |}public wow();
@@ -9,7 +9,7 @@
99
//// }
1010
////
1111
//// {| "itemName": "Windows", "kind": "module", "parentName": "", "isAdditionalRange": true |}declare module Windows {
12-
//// {| "itemName": "Foundation", "kind": "module", "parentName": "Windows", "isAdditionalRange": true |}export module Foundation {
12+
//// {| "itemName": "Foundation", "kind": "module", "parentName": "", "isAdditionalRange": true |}export module Foundation {
1313
//// export var {| "itemName": "B", "kind": "var" |}B;
1414
//// {| "itemName": "Test", "kind": "module" |}export module Test {
1515
//// {| "itemName": "Boom", "kind": "function" |}export function Boom(): number;

tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
////class Class {
44
//// constructor() {
5-
//// {| "itemName": "LocalFunctionInConstructor", "kind": "function", "parentName": "Class"|}function LocalFunctionInConstructor() {
5+
//// {| "itemName": "LocalFunctionInConstructor", "kind": "function", "parentName": "constructor"|}function LocalFunctionInConstructor() {
66
////
77
//// }
88
////
9-
//// {| "itemName": "LocalInterfaceInConstrcutor", "kind": "interface", "parentName": "foo"|}interface LocalInterfaceInConstrcutor {
9+
//// {| "itemName": "LocalInterfaceInConstrcutor", "kind": "interface", "parentName": ""|}interface LocalInterfaceInConstrcutor {
1010
//// }
1111
////
1212
//// enum LocalEnumInConstructor {
@@ -15,17 +15,17 @@
1515
//// }
1616
////
1717
//// method() {
18-
//// {| "itemName": "LocalFunctionInMethod", "kind": "function", "parentName": "foo"|}function LocalFunctionInMethod() {
19-
//// {| "itemName": "LocalFunctionInLocalFunctionInMethod", "kind": "function", "parentName": "bar"|}function LocalFunctionInLocalFunctionInMethod() {
18+
//// {| "itemName": "LocalFunctionInMethod", "kind": "function", "parentName": "method"|}function LocalFunctionInMethod() {
19+
//// {| "itemName": "LocalFunctionInLocalFunctionInMethod", "kind": "function", "parentName": "LocalFunctionInMethod"|}function LocalFunctionInLocalFunctionInMethod() {
2020
////
2121
//// }
2222
//// }
2323
////
24-
//// {| "itemName": "LocalInterfaceInMethod", "kind": "interface", "parentName": "foo"|}interface LocalInterfaceInMethod {
24+
//// {| "itemName": "LocalInterfaceInMethod", "kind": "interface", "parentName": ""|}interface LocalInterfaceInMethod {
2525
//// }
2626
////
27-
//// enum LocalEnumInMethod {
28-
//// {| "itemName": "LocalEnumMemberInMethod", "kind": "property", "parentName": "foo"|}LocalEnumMemberInMethod,
27+
//// {| "itemName": "LocalEnumInMethod", "kind": "enum", "parentName": ""|}enum LocalEnumInMethod {
28+
//// {| "itemName": "LocalEnumMemberInMethod", "kind": "property", "parentName": "LocalEnumInMethod"|}LocalEnumMemberInMethod,
2929
//// }
3030
//// }
3131
////

tests/cases/fourslash/navigationBarItemsItems.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,28 @@
1313
////{| "itemName": "Shapes", "kind": "module", "parentName": "" |}module Shapes {
1414
////
1515
//// // Class
16-
//// {| "itemName": "Point", "kind": "class", "parentName": "Shapes" |}export class Point implements IPoint {
17-
//// {| "itemName": "constructor", "kind": "constructor", "parentName": "Shapes.Point" |}constructor (public x: number, public y: number) { }
16+
//// {| "itemName": "Point", "kind": "class", "parentName": "" |}export class Point implements IPoint {
17+
//// {| "itemName": "constructor", "kind": "constructor", "parentName": "Point" |}constructor (public x: number, public y: number) { }
1818
////
1919
//// // Instance member
20-
//// {| "itemName": "getDist", "kind": "method", "parentName": "Shapes.Point" |}getDist() { return Math.sqrt(this.x * this.x + this.y * this.y); }
20+
//// {| "itemName": "getDist", "kind": "method", "parentName": "Point" |}getDist() { return Math.sqrt(this.x * this.x + this.y * this.y); }
2121
////
2222
//// // Getter
23-
//// {| "itemName": "value", "kind": "getter", "parentName": "Shapes.Point" |}get value(): number { return 0; }
23+
//// {| "itemName": "value", "kind": "getter", "parentName": "Point" |}get value(): number { return 0; }
2424
////
2525
//// // Setter
26-
//// {| "itemName": "value", "kind": "setter", "parentName": "Shapes.Point" |}set value(newValue: number) { return; }
26+
//// {| "itemName": "value", "kind": "setter", "parentName": "Point" |}set value(newValue: number) { return; }
2727
////
2828
//// // Static member
29-
//// {| "itemName": "origin", "kind": "property", "parentName": "Shapes.Point" |}static origin = new Point(0, 0);
29+
//// {| "itemName": "origin", "kind": "property", "parentName": "Point" |}static origin = new Point(0, 0);
3030
////
3131
//// // Static method
32-
//// {| "itemName": "getOrigin", "kind": "method", "parentName": "Shapes.Point" |}private static getOrigin() { return Point.origin;}
32+
//// {| "itemName": "getOrigin", "kind": "method", "parentName": "Point" |}private static getOrigin() { return Point.origin;}
3333
//// }
3434
////
35-
//// {| "itemName": "Values", "kind": "enum", "parentName": "Shapes" |}enum Values {
35+
//// {| "itemName": "Values", "kind": "enum", "parentName": "" |}enum Values {
3636
//// value1,
37-
//// {| "itemName": "value2", "kind": "property", "parentName": "Shapes.Values" |}value2,
37+
//// {| "itemName": "value2", "kind": "property", "parentName": "Values" |}value2,
3838
//// value3,
3939
//// }
4040
////}

tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//// {| "itemName": "s", "kind": "property", "parentName": "Bar" |}public s: string;
66
////}
77
////{| "itemName": "\"my fil\\\"e\"", "kind": "module" |}
8-
////{| "itemName": "x", "kind": "var", "parentName": "\"file\"" |}
8+
////{| "itemName": "x", "kind": "var", "parentName": "\"my fil\\\"e\"" |}
99
////export var x: number;
1010

1111
test.markers().forEach((marker) => {

tests/cases/fourslash/navigationBarItemsModules.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
////
2828
////{| "itemName": "A", "kind": "module" |}
2929
////module A {
30-
//// {| "itemName": "B", "kind": "module", "parentName": "E" |}
30+
//// {| "itemName": "B", "kind": "module", "parentName": "" |}
3131
//// module B {
32-
//// {| "itemName": "C", "kind": "module", "parentName": "F" |}
32+
//// {| "itemName": "C", "kind": "module", "parentName": "" |}
3333
//// module C {
3434
//// {| "itemName": "x", "kind": "var", "parentName": "C" |}
3535
//// declare var x;

tests/cases/fourslash/server/navbar01.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,28 @@
1313
////{| "itemName": "Shapes", "kind": "module", "parentName": "" |}module Shapes {
1414
////
1515
//// // Class
16-
//// {| "itemName": "Point", "kind": "class", "parentName": "Shapes" |}export class Point implements IPoint {
17-
//// {| "itemName": "constructor", "kind": "constructor", "parentName": "Shapes.Point" |}constructor (public x: number, public y: number) { }
16+
//// {| "itemName": "Point", "kind": "class", "parentName": "" |}export class Point implements IPoint {
17+
//// {| "itemName": "constructor", "kind": "constructor", "parentName": "Point" |}constructor (public x: number, public y: number) { }
1818
////
1919
//// // Instance member
20-
//// {| "itemName": "getDist", "kind": "method", "parentName": "Shapes.Point" |}getDist() { return Math.sqrt(this.x * this.x + this.y * this.y); }
20+
//// {| "itemName": "getDist", "kind": "method", "parentName": "Point" |}getDist() { return Math.sqrt(this.x * this.x + this.y * this.y); }
2121
////
2222
//// // Getter
23-
//// {| "itemName": "value", "kind": "getter", "parentName": "Shapes.Point" |}get value(): number { return 0; }
23+
//// {| "itemName": "value", "kind": "getter", "parentName": "Point" |}get value(): number { return 0; }
2424
////
2525
//// // Setter
26-
//// {| "itemName": "value", "kind": "setter", "parentName": "Shapes.Point" |}set value(newValue: number) { return; }
26+
//// {| "itemName": "value", "kind": "setter", "parentName": "Point" |}set value(newValue: number) { return; }
2727
////
2828
//// // Static member
29-
//// {| "itemName": "origin", "kind": "property", "parentName": "Shapes.Point" |}static origin = new Point(0, 0);
29+
//// {| "itemName": "origin", "kind": "property", "parentName": "Point" |}static origin = new Point(0, 0);
3030
////
3131
//// // Static method
32-
//// {| "itemName": "getOrigin", "kind": "method", "parentName": "Shapes.Point" |}private static getOrigin() { return Point.origin;}
32+
//// {| "itemName": "getOrigin", "kind": "method", "parentName": "Point" |}private static getOrigin() { return Point.origin;}
3333
//// }
3434
////
35-
//// {| "itemName": "Values", "kind": "enum", "parentName": "Shapes" |}enum Values {
35+
//// {| "itemName": "Values", "kind": "enum", "parentName": "" |}enum Values {
3636
//// value1,
37-
//// {| "itemName": "value2", "kind": "property", "parentName": "Shapes.Values" |}value2,
37+
//// {| "itemName": "value2", "kind": "property", "parentName": "Values" |}value2,
3838
//// value3,
3939
//// }
4040
////}

0 commit comments

Comments
 (0)