Skip to content

Commit 44f2a99

Browse files
author
Andy Hanson
committed
Add test for #7301
1 parent cf74930 commit 44f2a99

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

src/harness/fourslash.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,6 +1912,47 @@ namespace FourSlash {
19121912
}
19131913
}
19141914

1915+
public verifyNavigationBarCount(count: number) {
1916+
const actual = this.navigationBarItems().length;
1917+
if (actual !== count) {
1918+
this.raiseError(`Expected ${count} items in navigation bar, got ${actual}`);
1919+
}
1920+
}
1921+
1922+
public verifyNavigationBarItem(text: string, kind: string) {
1923+
this.verifyNavigationBarItemExists(this.navigationBarItems(), text, kind);
1924+
}
1925+
1926+
public verifyNavigationBarChildItem(parent: string, text: string, kind: string) {
1927+
const items = this.navigationBarItems();
1928+
1929+
// TODO: ts.find?
1930+
for (let i = 0; i < items.length; i++) {
1931+
const item = items[i];
1932+
if (item.text === parent) {
1933+
this.verifyNavigationBarItemExists(item.childItems, text, kind);
1934+
return;
1935+
}
1936+
}
1937+
1938+
this.raiseError(`Could not find any parent named ${parent} in: ${JSON.stringify(items, undefined, 2)}`);
1939+
}
1940+
1941+
private navigationBarItems() {
1942+
return this.languageService.getNavigationBarItems(this.activeFile.fileName);
1943+
}
1944+
1945+
private verifyNavigationBarItemExists(items: ts.NavigationBarItem[], text: string, kind: string) {
1946+
for (let i = 0; i < items.length; i++) {
1947+
const item = items[i];
1948+
if (item.text === text && item.kind === kind) {
1949+
return;
1950+
}
1951+
}
1952+
1953+
this.raiseError(`Could not find ${JSON.stringify({text, kind}, undefined, 2)} in the navigation bar: ${JSON.stringify(items, undefined, 2)}`);
1954+
}
1955+
19151956
/*
19161957
Check number of navigationItems which match both searchValue and matchKind.
19171958
Report an error if expected value and actual value do not match.
@@ -3044,6 +3085,18 @@ namespace FourSlashInterface {
30443085
this.state.verifyGetScriptLexicalStructureListContains(name, kind);
30453086
}
30463087

3088+
public navigationBarCount(count: number) {
3089+
this.state.verifyNavigationBarCount(count);
3090+
}
3091+
3092+
public navigationBarItem(text: string, kind: string) {
3093+
this.state.verifyNavigationBarItem(text, kind);
3094+
}
3095+
3096+
public navigationBarChildItem(parent: string, text: string, kind: string) {
3097+
this.state.verifyNavigationBarChildItem(parent, text, kind);
3098+
}
3099+
30473100
public navigationItemsListCount(count: number, searchValue: string, matchKind?: string) {
30483101
this.state.verifyNavigationItemsCount(count, searchValue, matchKind);
30493102
}

tests/cases/fourslash/fourslash.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ declare namespace FourSlashInterface {
177177

178178
getScriptLexicalStructureListCount(count: number): void;
179179
getScriptLexicalStructureListContains(name: string, kind: string, fileName?: string, parentName?: string, isAdditionalSpan?: boolean, markerPosition?: number): void;
180+
navigationBarCount(count: number);
181+
navigationBarItem(text: string, kind: string): void;
182+
navigationBarChildItem(parent: string, text: string, kind: string): void;
180183
navigationItemsListCount(count: number, searchValue: string, matchKind?: string): void;
181184
navigationItemsListContains(name: string, kind: string, searchValue: string, matchKind: string, fileName?: string, parentName?: string): void;
182185
occurrencesAtPositionContains(range: Range, isWriteAccess?: boolean): void;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////class C {
4+
//// foo;
5+
//// ["bar"]: string;
6+
////}
7+
8+
verify.navigationBarCount(1);
9+
verify.navigationBarItem("C", "class");
10+
verify.navigationBarChildItem("C", "[\"bar\"]", "property");
11+
verify.navigationBarChildItem("C", "foo", "property");

0 commit comments

Comments
 (0)