Add test for #7301
This commit is contained in:
parent
3fb16f5930
commit
df8e7409c1
|
@ -1912,6 +1912,47 @@ namespace FourSlash {
|
|||
}
|
||||
}
|
||||
|
||||
public verifyNavigationBarCount(count: number) {
|
||||
const actual = this.navigationBarItems().length;
|
||||
if (actual !== count) {
|
||||
this.raiseError(`Expected ${count} items in navigation bar, got ${actual}`);
|
||||
}
|
||||
}
|
||||
|
||||
public verifyNavigationBarItem(text: string, kind: string) {
|
||||
this.verifyNavigationBarItemExists(this.navigationBarItems(), text, kind);
|
||||
}
|
||||
|
||||
public verifyNavigationBarChildItem(parent: string, text: string, kind: string) {
|
||||
const items = this.navigationBarItems();
|
||||
|
||||
// TODO: ts.find?
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
const item = items[i];
|
||||
if (item.text === parent) {
|
||||
this.verifyNavigationBarItemExists(item.childItems, text, kind);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.raiseError(`Could not find any parent named ${parent} in: ${JSON.stringify(items, undefined, 2)}`);
|
||||
}
|
||||
|
||||
private navigationBarItems() {
|
||||
return this.languageService.getNavigationBarItems(this.activeFile.fileName);
|
||||
}
|
||||
|
||||
private verifyNavigationBarItemExists(items: ts.NavigationBarItem[], text: string, kind: string) {
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
const item = items[i];
|
||||
if (item.text === text && item.kind === kind) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.raiseError(`Could not find ${JSON.stringify({text, kind}, undefined, 2)} in the navigation bar: ${JSON.stringify(items, undefined, 2)}`);
|
||||
}
|
||||
|
||||
/*
|
||||
Check number of navigationItems which match both searchValue and matchKind.
|
||||
Report an error if expected value and actual value do not match.
|
||||
|
@ -3044,6 +3085,18 @@ namespace FourSlashInterface {
|
|||
this.state.verifyGetScriptLexicalStructureListContains(name, kind);
|
||||
}
|
||||
|
||||
public navigationBarCount(count: number) {
|
||||
this.state.verifyNavigationBarCount(count);
|
||||
}
|
||||
|
||||
public navigationBarItem(text: string, kind: string) {
|
||||
this.state.verifyNavigationBarItem(text, kind);
|
||||
}
|
||||
|
||||
public navigationBarChildItem(parent: string, text: string, kind: string) {
|
||||
this.state.verifyNavigationBarChildItem(parent, text, kind);
|
||||
}
|
||||
|
||||
public navigationItemsListCount(count: number, searchValue: string, matchKind?: string) {
|
||||
this.state.verifyNavigationItemsCount(count, searchValue, matchKind);
|
||||
}
|
||||
|
|
|
@ -177,6 +177,9 @@ declare namespace FourSlashInterface {
|
|||
|
||||
getScriptLexicalStructureListCount(count: number): void;
|
||||
getScriptLexicalStructureListContains(name: string, kind: string, fileName?: string, parentName?: string, isAdditionalSpan?: boolean, markerPosition?: number): void;
|
||||
navigationBarCount(count: number);
|
||||
navigationBarItem(text: string, kind: string): void;
|
||||
navigationBarChildItem(parent: string, text: string, kind: string): void;
|
||||
navigationItemsListCount(count: number, searchValue: string, matchKind?: string): void;
|
||||
navigationItemsListContains(name: string, kind: string, searchValue: string, matchKind: string, fileName?: string, parentName?: string): void;
|
||||
occurrencesAtPositionContains(range: Range, isWriteAccess?: boolean): void;
|
||||
|
|
11
tests/cases/fourslash/getNavigationBarItems.ts
Normal file
11
tests/cases/fourslash/getNavigationBarItems.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////class C {
|
||||
//// foo;
|
||||
//// ["bar"]: string;
|
||||
////}
|
||||
|
||||
verify.navigationBarCount(1);
|
||||
verify.navigationBarItem("C", "class");
|
||||
verify.navigationBarChildItem("C", "[\"bar\"]", "property");
|
||||
verify.navigationBarChildItem("C", "foo", "property");
|
Loading…
Reference in a new issue