Merge pull request #8622 from Microsoft/navigation_bar_test

Add test for #7301
This commit is contained in:
Andy
2016-05-17 10:44:11 -07:00
35 changed files with 126 additions and 95 deletions

View File

@@ -1968,12 +1968,12 @@ namespace FourSlash {
}
}
public verifyGetScriptLexicalStructureListCount(expected: number) {
public verifyNavigationBarCount(expected: number) {
const items = this.languageService.getNavigationBarItems(this.activeFile.fileName);
const actual = this.getNavigationBarItemsCount(items);
if (expected !== actual) {
this.raiseError(`verifyGetScriptLexicalStructureListCount failed - found: ${actual} navigation items, expected: ${expected}.`);
this.raiseError(`verifyNavigationBarCount failed - found: ${actual} navigation items, expected: ${expected}.`);
}
}
@@ -1989,19 +1989,19 @@ namespace FourSlash {
return result;
}
public verifyGetScriptLexicalStructureListContains(name: string, kind: string) {
public verifyNavigationBarContains(name: string, kind: string) {
const items = this.languageService.getNavigationBarItems(this.activeFile.fileName);
if (!items || items.length === 0) {
this.raiseError("verifyGetScriptLexicalStructureListContains failed - found 0 navigation items, expected at least one.");
this.raiseError("verifyNavigationBarContains failed - found 0 navigation items, expected at least one.");
}
if (this.navigationBarItemsContains(items, name, kind)) {
return;
}
const missingItem = { name: name, kind: kind };
this.raiseError(`verifyGetScriptLexicalStructureListContains failed - could not find the item: ${JSON.stringify(missingItem, undefined, 2)} in the returned list: (${JSON.stringify(items, undefined, 2)})`);
const missingItem = { name, kind };
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) {
@@ -2021,6 +2021,20 @@ namespace FourSlash {
return false;
}
public verifyNavigationBarChildItem(parent: string, name: string, kind: string) {
const items = this.languageService.getNavigationBarItems(this.activeFile.fileName);
for (let i = 0; i < items.length; i++) {
const item = items[i];
if (item.text === parent) {
if (this.navigationBarItemsContains(item.childItems, name, kind))
return;
const missingItem = { name, kind };
this.raiseError(`verifyNavigationBarChildItem failed - could not find the item: ${JSON.stringify(missingItem)} in the children list: (${JSON.stringify(item.childItems, undefined, 2)})`);
}
}
}
public printNavigationItems(searchValue: string) {
const items = this.languageService.getNavigateToItems(searchValue);
const length = items && items.length;
@@ -2033,11 +2047,11 @@ namespace FourSlash {
}
}
public printScriptLexicalStructureItems() {
public printNavigationBar() {
const items = this.languageService.getNavigationBarItems(this.activeFile.fileName);
const length = items && items.length;
Harness.IO.log(`NavigationItems list (${length} items)`);
Harness.IO.log(`Navigation bar (${length} items)`);
for (let i = 0; i < length; i++) {
const item = items[i];
@@ -3029,19 +3043,23 @@ namespace FourSlashInterface {
this.DocCommentTemplate(/*expectedText*/ undefined, /*expectedOffset*/ undefined, /*empty*/ true);
}
public getScriptLexicalStructureListCount(count: number) {
this.state.verifyGetScriptLexicalStructureListCount(count);
public navigationBarCount(count: number) {
this.state.verifyNavigationBarCount(count);
}
// TODO: figure out what to do with the unused arguments.
public getScriptLexicalStructureListContains(
public navigationBarContains(
name: string,
kind: string,
fileName?: string,
parentName?: string,
isAdditionalSpan?: boolean,
markerPosition?: number) {
this.state.verifyGetScriptLexicalStructureListContains(name, kind);
this.state.verifyNavigationBarContains(name, kind);
}
public navigationBarChildItem(parent: string, name: string, kind: string) {
this.state.verifyNavigationBarChildItem(parent, name, kind);
}
public navigationItemsListCount(count: number, searchValue: string, matchKind?: string) {
@@ -3234,8 +3252,8 @@ namespace FourSlashInterface {
this.state.printNavigationItems(searchValue);
}
public printScriptLexicalStructureItems() {
this.state.printScriptLexicalStructureItems();
public printNavigationBar() {
this.state.printNavigationBar();
}
public printReferences() {

View File

@@ -5,4 +5,4 @@
goTo.marker();
edit.deleteAtCaret('class Bar { }'.length);
verify.getScriptLexicalStructureListContains('Foo', 'enum', 'tests/cases/fourslash/deleteClassWithEnumPresent.ts', '');
verify.navigationBarContains('Foo', 'enum', 'tests/cases/fourslash/deleteClassWithEnumPresent.ts', '');

View File

@@ -175,8 +175,9 @@ declare namespace FourSlashInterface {
DocCommentTemplate(expectedText: string, expectedOffset: number, empty?: boolean): void;
noDocCommentTemplate(): void;
getScriptLexicalStructureListCount(count: number): void;
getScriptLexicalStructureListContains(name: string, kind: string, fileName?: string, parentName?: string, isAdditionalSpan?: boolean, markerPosition?: number): void;
navigationBarCount(count: number): void;
navigationBarContains(name: string, kind: string, fileName?: string, parentName?: string, isAdditionalSpan?: boolean, markerPosition?: number): 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;
@@ -236,6 +237,7 @@ declare namespace FourSlashInterface {
printBreakpointAtCurrentLocation(): void;
printNameOrDottedNameSpans(pos: number): void;
printErrorList(): void;
printNavigationBar(): void;
printNavigationItems(searchValue?: string): void;
printScriptLexicalStructureItems(): void;
printReferences(): void;

View File

@@ -0,0 +1,11 @@
/// <reference path="fourslash.ts" />
////class C {
//// foo;
//// ["bar"]: string;
////}
verify.navigationBarCount(3);
verify.navigationBarContains("C", "class");
verify.navigationBarChildItem("C", "[\"bar\"]", "property");
verify.navigationBarChildItem("C", "foo", "property");

View File

@@ -3,7 +3,7 @@
//// {| "itemName": "c", "kind": "const", "parentName": "" |}const c = 0;
test.markers().forEach(marker => {
verify.getScriptLexicalStructureListContains(
verify.navigationBarContains(
marker.data.itemName,
marker.data.kind,
marker.fileName,

View File

@@ -29,7 +29,7 @@
test.markers().forEach(marker => {
if (marker.data) {
verify.getScriptLexicalStructureListContains(
verify.navigationBarContains(
marker.data.itemName,
marker.data.kind,
marker.fileName,
@@ -38,4 +38,4 @@ test.markers().forEach(marker => {
marker.position);
}
});
verify.getScriptLexicalStructureListCount(12);
verify.navigationBarCount(12);

View File

@@ -14,7 +14,7 @@
test.markers().forEach(marker => {
goTo.file(marker.fileName);
verify.getScriptLexicalStructureListContains(
verify.navigationBarContains(
marker.data.itemName,
marker.data.kind,
marker.fileName,

View File

@@ -3,7 +3,7 @@
//// {| "itemName": "c", "kind": "let", "parentName": "" |}let c = 0;
test.markers().forEach(marker => {
verify.getScriptLexicalStructureListContains(
verify.navigationBarContains(
marker.data.itemName,
marker.data.kind,
marker.fileName,

View File

@@ -6,16 +6,16 @@
////const bar1, [c, d]
////var {e, x: [f, g]} = {a:1, x:[]};
verify.getScriptLexicalStructureListCount(12); // global (1) + variable declarations (4) + binding patterns (7)
verify.getScriptLexicalStructureListContains("foo", "var");
verify.getScriptLexicalStructureListContains("bar", "var");
verify.getScriptLexicalStructureListContains("foo1", "let")
verify.getScriptLexicalStructureListContains("a", "let");
verify.getScriptLexicalStructureListContains("b", "let");
verify.getScriptLexicalStructureListContains("bar1", "const");
verify.getScriptLexicalStructureListContains("c", "const");
verify.getScriptLexicalStructureListContains("d", "const");
verify.getScriptLexicalStructureListContains("e", "var");
verify.getScriptLexicalStructureListContains("f", "var");
verify.getScriptLexicalStructureListContains("g", "var");
verify.navigationBarCount(12); // global (1) + variable declarations (4) + binding patterns (7)
verify.navigationBarContains("foo", "var");
verify.navigationBarContains("bar", "var");
verify.navigationBarContains("foo1", "let")
verify.navigationBarContains("a", "let");
verify.navigationBarContains("b", "let");
verify.navigationBarContains("bar1", "const");
verify.navigationBarContains("c", "const");
verify.navigationBarContains("d", "const");
verify.navigationBarContains("e", "var");
verify.navigationBarContains("f", "var");
verify.navigationBarContains("g", "var");

View File

@@ -11,4 +11,4 @@
//// }
////}
verify.getScriptLexicalStructureListCount(6); // 2x(class + field + constructor)
verify.navigationBarCount(6); // 2x(class + field + constructor)

View File

@@ -5,8 +5,8 @@
//// }
////}
verify.getScriptLexicalStructureListContains("Test", "class");
verify.getScriptLexicalStructureListContains("constructor", "constructor");
verify.navigationBarContains("Test", "class");
verify.navigationBarContains("constructor", "constructor");
// no other items
verify.getScriptLexicalStructureListCount(2);
verify.navigationBarCount(2);

View File

@@ -11,8 +11,8 @@
test.markers().forEach((marker) => {
if (marker.data) {
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
}
});
verify.getScriptLexicalStructureListCount(4);
verify.navigationBarCount(4);

View File

@@ -17,7 +17,7 @@
////}
test.markers().forEach((marker) => {
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
});
verify.getScriptLexicalStructureListCount(8); // 4 functions + global. Note: there are 8 because of the functions show up at the top level and as child items.
verify.navigationBarCount(8); // 4 functions + global. Note: there are 8 because of the functions show up at the top level and as child items.

View File

@@ -6,7 +6,7 @@
////}
test.markers().forEach((marker) => {
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
});
verify.getScriptLexicalStructureListCount(3); // <global> and 'f'.
verify.navigationBarCount(3); // <global> and 'f'.

View File

@@ -7,7 +7,7 @@
////}
test.markers().forEach((marker) => {
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
});
verify.getScriptLexicalStructureListCount(3); // <global> and 'f'
verify.navigationBarCount(3); // <global> and 'f'

View File

@@ -18,8 +18,8 @@
test.markers().forEach((marker) => {
if (marker.data) {
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
}
});
verify.getScriptLexicalStructureListCount(9);
verify.navigationBarCount(9);

View File

@@ -35,8 +35,8 @@
////}
test.markers().forEach((marker) => {
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
});
// no other items
verify.getScriptLexicalStructureListCount(17);
verify.navigationBarCount(17);

View File

@@ -45,8 +45,8 @@
test.markers().forEach((marker) => {
if (marker.data) {
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
}
});
verify.getScriptLexicalStructureListCount(23);
verify.navigationBarCount(23);

View File

@@ -8,5 +8,5 @@ edit.insertLine("module A");
edit.insert("export class ");
// should not crash
verify.getScriptLexicalStructureListCount(2);
verify.navigationBarCount(2);

View File

@@ -30,15 +30,15 @@
////}
goTo.marker("file1");
verify.getScriptLexicalStructureListCount(0);
verify.navigationBarCount(0);
goTo.marker("file2");
verify.getScriptLexicalStructureListContains("<global>", "module");
verify.getScriptLexicalStructureListContains("x", "var");
verify.getScriptLexicalStructureListCount(2);
verify.navigationBarContains("<global>", "module");
verify.navigationBarContains("x", "var");
verify.navigationBarCount(2);
goTo.marker("file3");
verify.getScriptLexicalStructureListContains("<global>", "module");
verify.getScriptLexicalStructureListContains("foo", "function");
verify.getScriptLexicalStructureListContains("bar", "function");
verify.getScriptLexicalStructureListCount(5);
verify.navigationBarContains("<global>", "module");
verify.navigationBarContains("foo", "function");
verify.navigationBarContains("bar", "function");
verify.navigationBarCount(5);

View File

@@ -5,7 +5,7 @@
////}
test.markers().forEach((marker) => {
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
});
verify.getScriptLexicalStructureListCount(2); // external module node + class + property
verify.navigationBarCount(2); // external module node + class + property

View File

@@ -9,7 +9,7 @@
////export var x: number;
test.markers().forEach((marker) => {
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
});
verify.getScriptLexicalStructureListCount(4); // external module node + variable in module + class + property
verify.navigationBarCount(4); // external module node + variable in module + class + property

View File

@@ -9,7 +9,7 @@
////export var x: number;
test.markers().forEach((marker) => {
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
});
verify.getScriptLexicalStructureListCount(4); // external module node + variable in module + class + property
verify.navigationBarCount(4); // external module node + variable in module + class + property

View File

@@ -19,12 +19,12 @@
//// export var z = 0;
////}
goTo.marker("file1");
verify.getScriptLexicalStructureListContains("Module1", "module");
verify.getScriptLexicalStructureListContains("x", "var");
verify.navigationBarContains("Module1", "module");
verify.navigationBarContains("x", "var");
// nothing else should show up
verify.getScriptLexicalStructureListCount(2);
verify.navigationBarCount(2);
goTo.marker("file2");
verify.getScriptLexicalStructureListContains("Module1.SubModule", "module");
verify.getScriptLexicalStructureListContains("y", "var");
verify.getScriptLexicalStructureListCount(2);
verify.navigationBarContains("Module1.SubModule", "module");
verify.navigationBarContains("y", "var");
verify.navigationBarCount(2);

View File

@@ -9,8 +9,8 @@
test.markers().forEach((marker) => {
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
});
/// Only have two named elements.
verify.getScriptLexicalStructureListCount(2);
verify.navigationBarCount(2);

View File

@@ -8,4 +8,4 @@
// The class is unnamed, so its method is not included either.
verify.getScriptLexicalStructureListCount(2);
verify.navigationBarCount(2);

View File

@@ -39,10 +39,10 @@
test.markers().forEach((marker) => {
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
});
/// We have 8 module keywords, and 4 var keywords.
/// The declarations of A.B.C.x do not get merged, so the 4 vars are independent.
/// The two 'A' modules, however, do get merged, so in reality we have 7 modules.
verify.getScriptLexicalStructureListCount(11);
verify.navigationBarCount(11);

View File

@@ -35,7 +35,7 @@
test.markers().forEach((marker) => {
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
});
verify.getScriptLexicalStructureListCount(9); // interface w/ 2 properties, class w/ 2 properties, 3 modules
verify.navigationBarCount(9); // interface w/ 2 properties, class w/ 2 properties, 3 modules

View File

@@ -6,10 +6,10 @@
//// }
////}
verify.getScriptLexicalStructureListContains("List", "class");
verify.getScriptLexicalStructureListContains("constructor", "constructor");
verify.getScriptLexicalStructureListContains("a", "property");
verify.getScriptLexicalStructureListContains("b", "property");
verify.navigationBarContains("List", "class");
verify.navigationBarContains("constructor", "constructor");
verify.navigationBarContains("a", "property");
verify.navigationBarContains("b", "property");
// no other items
verify.getScriptLexicalStructureListCount(4);
verify.navigationBarCount(4);

View File

@@ -11,7 +11,7 @@
////}
test.markers().forEach(marker => {
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
});
verify.getScriptLexicalStructureListCount(test.markers().length);
verify.navigationBarCount(test.markers().length);

View File

@@ -9,7 +9,7 @@
////}
test.markers().forEach(marker => {
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
});
verify.getScriptLexicalStructureListCount(test.markers().length);
verify.navigationBarCount(test.markers().length);

View File

@@ -7,7 +7,7 @@
////}
test.markers().forEach(marker => {
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
});
verify.getScriptLexicalStructureListCount(test.markers().length);
verify.navigationBarCount(test.markers().length);

View File

@@ -45,8 +45,8 @@
test.markers().forEach((marker) => {
if (marker.data) {
verify.getScriptLexicalStructureListContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
verify.navigationBarContains(marker.data.itemName, marker.data.kind, marker.fileName, marker.data.parentName);
}
});
verify.getScriptLexicalStructureListCount(23);
verify.navigationBarCount(23);

View File

@@ -3,7 +3,7 @@
//// {| "itemName": "c", "kind": "const", "parentName": "" |}const c = 0;
test.markers().forEach(marker => {
verify.getScriptLexicalStructureListContains(
verify.navigationBarContains(
marker.data.itemName,
marker.data.kind,
marker.fileName,

View File

@@ -3,7 +3,7 @@
//// {| "itemName": "c", "kind": "const", "parentName": "" |}const c = 0;
test.markers().forEach(marker => {
verify.getScriptLexicalStructureListContains(
verify.navigationBarContains(
marker.data.itemName,
marker.data.kind,
marker.fileName,