From df8e7409c1f3ff67aea00df6d6b56391af5ff4fd Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 16 May 2016 08:18:33 -0700 Subject: [PATCH] Add test for #7301 --- src/harness/fourslash.ts | 53 +++++++++++++++++++ tests/cases/fourslash/fourslash.ts | 3 ++ .../cases/fourslash/getNavigationBarItems.ts | 11 ++++ 3 files changed, 67 insertions(+) create mode 100644 tests/cases/fourslash/getNavigationBarItems.ts diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index d6035aaa02..cdef2554f9 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -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); } diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 48d69f0a85..86061b53e7 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -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; diff --git a/tests/cases/fourslash/getNavigationBarItems.ts b/tests/cases/fourslash/getNavigationBarItems.ts new file mode 100644 index 0000000000..665767916b --- /dev/null +++ b/tests/cases/fourslash/getNavigationBarItems.ts @@ -0,0 +1,11 @@ +/// + +////class C { +//// foo; +//// ["bar"]: string; +////} + +verify.navigationBarCount(1); +verify.navigationBarItem("C", "class"); +verify.navigationBarChildItem("C", "[\"bar\"]", "property"); +verify.navigationBarChildItem("C", "foo", "property");