Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 67 additions & 5 deletions src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ namespace FourSlash {
}

// Entry points from fourslash.ts
public goToMarker(name = "") {
const marker = this.getMarkerByName(name);
public goToMarker(name: string | Marker = "") {
const marker = typeof name === "string" ? this.getMarkerByName(name) : name;
if (this.activeFile.fileName !== marker.fileName) {
this.openFile(marker.fileName);
}
Expand All @@ -382,10 +382,37 @@ namespace FourSlash {
if (marker.position === -1 || marker.position > content.length) {
throw new Error(`Marker "${name}" has been invalidated by unrecoverable edits to the file.`);
}
this.lastKnownMarker = name;
const mName = typeof name === "string" ? name : this.markerName(marker);
this.lastKnownMarker = mName;
this.goToPosition(marker.position);
}

public goToEachMarker(action: () => void) {
const markers = this.getMarkers();
assert(markers.length);
for (const marker of markers) {
this.goToMarker(marker);
action();
}
}

public goToEachRange(action: () => void) {
const ranges = this.getRanges();
assert(ranges.length);
for (const range of ranges) {
this.goToRangeStart(range);
action();
}
}

private markerName(m: Marker): string {
return ts.forEachEntry(this.testData.markerPositions, (marker, name) => {
if (marker === m) {
return name;
}
})!;
}

public goToPosition(pos: number) {
this.currentCaretPosition = pos;
}
Expand Down Expand Up @@ -1668,7 +1695,7 @@ namespace FourSlash {
this.goToPosition(len);
}

private goToRangeStart({fileName, start}: Range) {
public goToRangeStart({fileName, start}: Range) {
this.openFile(fileName);
this.goToPosition(start);
}
Expand Down Expand Up @@ -2365,6 +2392,21 @@ namespace FourSlash {
return this.languageService.getDocumentHighlights(this.activeFile.fileName, this.currentCaretPosition, filesToSearch);
}

public verifyRangesAreOccurrences(isWriteAccess?: boolean) {
const ranges = this.getRanges();
for (const r of ranges) {
this.goToRangeStart(r);
this.verifyOccurrencesAtPositionListCount(ranges.length);
for (const range of ranges) {
this.verifyOccurrencesAtPositionListContains(range.fileName, range.start, range.end, isWriteAccess);
}
}
}

public verifyRangesAreRenameLocations(findInStrings: boolean, findInComments: boolean) {
this.goToEachRange(() => this.verifyRenameLocations(findInStrings, findInComments));
}

public verifyRangesWithSameTextAreDocumentHighlights() {
this.rangesByText().forEach(ranges => this.verifyRangesAreDocumentHighlights(ranges));
}
Expand Down Expand Up @@ -3078,10 +3120,22 @@ namespace FourSlashInterface {
// Moves the caret to the specified marker,
// or the anonymous marker ('/**/') if no name
// is given
public marker(name?: string) {
public marker(name?: string | FourSlash.Marker) {
this.state.goToMarker(name);
}

public eachMarker(action: () => void) {
this.state.goToEachMarker(action);
}

public rangeStart(range: FourSlash.Range) {
this.state.goToRangeStart(range);
}

public eachRange(action: () => void) {
this.state.goToEachRange(action);
}

public bof() {
this.state.goToBOF();
}
Expand Down Expand Up @@ -3432,6 +3486,14 @@ namespace FourSlashInterface {
this.state.verifyOccurrencesAtPositionListCount(expectedCount);
}

public rangesAreOccurrences(isWriteAccess?: boolean) {
this.state.verifyRangesAreOccurrences(isWriteAccess);
}

public rangesAreRenameLocations(findInStrings = false, findInComments = false) {
this.state.verifyRangesAreRenameLocations(findInStrings, findInComments);
}

public rangesAreDocumentHighlights(ranges?: FourSlash.Range[]) {
this.state.verifyRangesAreDocumentHighlights(ranges);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,4 @@

////function A</*genericName5*/


test.markers().forEach((m) => {
goTo.position(m.position, m.fileName);
verify.completionListIsEmpty();
});
goTo.eachMarker(() => verify.completionListIsEmpty());
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,4 @@

//// try {} catch(a/*catchVariable2*/


test.markers().forEach((m) => {
goTo.position(m.position, m.fileName);
verify.completionListIsEmpty();
});
goTo.eachMarker(() => verify.completionListIsEmpty());
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@

////class a/*className2*/

test.markers().forEach((m) => {
goTo.position(m.position, m.fileName);
verify.completionListIsEmpty();
});
goTo.eachMarker(() => verify.completionListIsEmpty());
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,4 @@

//// function func2({ a, b/*parameter2*/

test.markers().forEach(m => {
goTo.position(m.position, m.fileName);
verify.completionListIsEmpty();
});
goTo.eachMarker(() => verify.completionListIsEmpty());
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@

////enum a { /*enumValueName1*/


test.markers().forEach((m) => {
goTo.position(m.position, m.fileName);
verify.completionListIsEmpty();
});
goTo.eachMarker(() => verify.completionListIsEmpty());
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@
////var aa = 1;
////enum a { foo, /*enumValueName3*/

test.markers().forEach((m) => {
goTo.position(m.position, m.fileName);
verify.completionListIsEmpty();
});
goTo.eachMarker(() => verify.completionListIsEmpty());
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,4 @@

////var x = 0; enum /*enumName4*/

test.markers().forEach((m) => {
goTo.position(m.position, m.fileName);
verify.completionListIsEmpty();
});
goTo.eachMarker(() => verify.completionListIsEmpty());
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,4 @@

////function a/*functionName2*/


test.markers().forEach((m) => {
goTo.position(m.position, m.fileName);
verify.completionListIsEmpty();
});
goTo.eachMarker(() => verify.completionListIsEmpty());
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@

////interface a { /*interfaceValue1*/

test.markers().forEach((m) => {
goTo.position(m.position, m.fileName);
verify.completionListIsEmpty();
});
goTo.eachMarker(() => verify.completionListIsEmpty());
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@

////interface a { f/*interfaceValue2*/

test.markers().forEach((m) => {
goTo.position(m.position, m.fileName);
verify.completionListIsEmpty();
});
goTo.eachMarker(() => verify.completionListIsEmpty());
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@

////interface a { f; /*interfaceValue3*/

test.markers().forEach((m) => {
goTo.position(m.position, m.fileName);
verify.completionListIsEmpty();
});
goTo.eachMarker(() => verify.completionListIsEmpty());
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,4 @@

////interface a/*interfaceName2*/


test.markers().forEach((m) => {
goTo.position(m.position, m.fileName);
verify.completionListIsEmpty();
});
goTo.eachMarker(() => verify.completionListIsEmpty());
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,4 @@

////class bar10{ constructor(...a/*constructorParamter6*/


test.markers().forEach((m) => {
goTo.position(m.position, m.fileName);
verify.completionListIsEmpty();
});
goTo.eachMarker(() => verify.completionListIsEmpty());
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
//// private a/*property7*/
////}

test.markers().forEach((m) => {
goTo.position(m.position, m.fileName);
goTo.eachMarker(() => {
verify.not.completionListIsEmpty();
verify.completionListAllowsNewIdentifier();
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,4 @@

////var a2, a/*varName4*/

test.markers().forEach((m) => {
goTo.position(m.position, m.fileName);
verify.completionListIsEmpty();
});
goTo.eachMarker(() => verify.completionListIsEmpty());
5 changes: 1 addition & 4 deletions tests/cases/fourslash/completionListAtInvalidLocations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,4 @@
////foo;
////var v10 = /reg/*inRegExp1*/ex/;

test.markers().forEach((m) => {
goTo.position(m.position, m.fileName);
verify.completionListIsEmpty();
});
goTo.eachMarker(() => verify.completionListIsEmpty());
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//// var y : any = "", x = (a/*var5*/

////class C{}
////var y = new C(
////var y = new C(

//// class C{}
//// var y = new C(0, /*var7*/
Expand All @@ -26,9 +26,4 @@

////var y = 10; y=/*var12*/

test.markers().forEach((m) => {
goTo.position(m.position, m.fileName);
verify.completionListAllowsNewIdentifier();
});


goTo.eachMarker(() => verify.completionListAllowsNewIdentifier());
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

////class bar7{ constructor(private a, /*constructorParamter6*/


test.markers().forEach((m) => {
goTo.position(m.position, m.fileName);
goTo.eachMarker(() => {
verify.not.completionListIsEmpty();
verify.completionListAllowsNewIdentifier();
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,4 @@
//// public static a/*property2*/
////}

test.markers().forEach((m) => {
goTo.position(m.position, m.fileName);
verify.completionListIsEmpty();
});
goTo.eachMarker(() => verify.completionListIsEmpty());
5 changes: 1 addition & 4 deletions tests/cases/fourslash/completionListInIndexSignature01.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,4 @@
//// [x/*5*/yz: number]: boolean;
//// [/*6*/

for (let marker of test.markers()) {
goTo.position(marker.position);
verify.completionListAllowsNewIdentifier();
}
goTo.eachMarker(() => verify.completionListAllowsNewIdentifier());
5 changes: 1 addition & 4 deletions tests/cases/fourslash/completionListInIndexSignature02.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,4 @@
////type T = {
//// [xyz: /*5*/

for (let marker of test.markers()) {
goTo.position(marker.position);
verify.not.completionListAllowsNewIdentifier();
}
goTo.eachMarker(() => verify.not.completionListAllowsNewIdentifier());
6 changes: 2 additions & 4 deletions tests/cases/fourslash/completionListInObjectLiteral4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
////funcE({ /*E*/ });
////funcF({ /*F*/ });


for (const marker of test.markers()) {
goTo.position(marker.position);
goTo.eachMarker(() => {
verify.completionListContains("hello");
verify.completionListContains("world");
}
});
6 changes: 1 addition & 5 deletions tests/cases/fourslash/completionListInStringLiterals1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@
////"/*1*/ /*2*/\/*3*/
//// /*4*/ \\/*5*/

test.markers().forEach(marker => {
goTo.position(marker.position);

verify.completionListIsEmpty()
});
goTo.eachMarker(() => verify.completionListIsEmpty());
6 changes: 1 addition & 5 deletions tests/cases/fourslash/completionListInStringLiterals2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@
//// /*4*/ \\\/*5*/
//// /*6*/

test.markers().forEach(marker => {
goTo.position(marker.position);

verify.completionListIsEmpty()
});
goTo.eachMarker(() => verify.completionListIsEmpty());
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@
////
/////*6*/`asdasd${/*7*/ 2 + 1.1 /*8*/} 12312 {

test.markers().forEach(marker => {
goTo.position(marker.position);

verify.completionListItemsCountIsGreaterThan(0)
});
goTo.eachMarker(() => verify.completionListItemsCountIsGreaterThan(0));
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@
////
////`asdasd$/*7*/{ 2 + 1.1 }/*8*/ 12312 /*9*/{/*10*/

test.markers().forEach(marker => {
goTo.position(marker.position);

verify.completionListIsEmpty()
});
goTo.eachMarker(() => verify.completionListIsEmpty());
Loading