Change reference tests to verify actual ranges referenced and not just their count

This commit is contained in:
Andy Hanson
2016-06-22 06:31:50 -07:00
parent 14774d6438
commit 1aafc553dd
83 changed files with 582 additions and 994 deletions

View File

@@ -730,29 +730,6 @@ namespace FourSlash {
}
}
public verifyReferencesCountIs(count: number, localFilesOnly = true) {
const references = this.getReferencesAtCaret();
let referencesCount = 0;
if (localFilesOnly) {
const localFiles = this.testData.files.map<string>(file => file.fileName);
// Count only the references in local files. Filter the ones in lib and other files.
ts.forEach(references, entry => {
if (localFiles.some((fileName) => fileName === entry.fileName)) {
referencesCount++;
}
});
}
else {
referencesCount = references && references.length || 0;
}
if (referencesCount !== count) {
const condition = localFilesOnly ? "excluding libs" : "including libs";
this.raiseError("Expected references count (" + condition + ") to be " + count + ", but is actually " + referencesCount);
}
}
public verifyReferencesAre(expectedReferences: Range[]) {
const actualReferences = this.getReferencesAtCaret() || [];
@@ -760,7 +737,7 @@ namespace FourSlash {
// Find the unaccounted-for reference.
for (const actual of actualReferences) {
if (!ts.forEach(expectedReferences, r => r.start === actual.textSpan.start)) {
this.raiseError(`A reference ${actual} is unaccounted for.`);
this.raiseError(`A reference ${stringify(actual)} is unaccounted for.`);
}
}
// Probably will never reach here.
@@ -769,7 +746,7 @@ namespace FourSlash {
for (const reference of expectedReferences) {
const {fileName, start, end} = reference;
if (reference.marker) {
if (reference.marker && reference.marker.data) {
const {isWriteAccess, isDefinition} = reference.marker.data;
this.verifyReferencesWorker(actualReferences, fileName, start, end, isWriteAccess, isDefinition);
}
@@ -793,12 +770,8 @@ namespace FourSlash {
}
}
public verifyReferencesAtPositionListContains(fileName: string, start: number, end: number, isWriteAccess?: boolean, isDefinition?: boolean) {
const references = this.getReferencesAtCaret();
if (!references || references.length === 0) {
this.raiseError("verifyReferencesAtPositionListContains failed - found 0 references, expected at least one.");
}
this.verifyReferencesWorker(references, fileName, start, end, isWriteAccess, isDefinition);
public verifyRangesWithSameTextReferenceEachOther(ranges?: Range[]) {
ts.forEachValue(this.rangesByText(), ranges => this.verifyRangesReferenceEachOther(ranges));
}
private verifyReferencesWorker(references: ts.ReferenceEntry[], fileName: string, start: number, end: number, isWriteAccess?: boolean, isDefinition?: boolean) {
@@ -817,7 +790,6 @@ namespace FourSlash {
const missingItem = { fileName, start, end, isWriteAccess, isDefinition };
this.raiseError(`verifyReferencesAtPositionListContains failed - could not find the item: ${stringify(missingItem)} in the returned list: (${stringify(references)})`);
}
private getMemberListAtCaret() {
@@ -1541,19 +1513,32 @@ namespace FourSlash {
}
private updateMarkersForEdit(fileName: string, minChar: number, limChar: number, text: string) {
for (let i = 0; i < this.testData.markers.length; i++) {
const marker = this.testData.markers[i];
for (const marker of this.testData.markers) {
if (marker.fileName === fileName) {
if (marker.position > minChar) {
if (marker.position < limChar) {
// Marker is inside the edit - mark it as invalidated (?)
marker.position = -1;
}
else {
// Move marker back/forward by the appropriate amount
marker.position += (minChar - limChar) + text.length;
}
marker.position = updatePosition(marker.position);
}
}
for (const range of this.testData.ranges) {
if (range.fileName === fileName) {
range.start = updatePosition(range.start);
range.end = updatePosition(range.end);
}
}
function updatePosition(position: number) {
if (position > minChar) {
if (position < limChar) {
// Inside the edit - mark it as invalidated (?)
return -1;
}
else {
// Move marker back/forward by the appropriate amount
return position + (minChar - limChar) + text.length;
}
}
else {
return position;
}
}
}
@@ -1648,8 +1633,20 @@ namespace FourSlash {
}
public getRanges(): Range[] {
// Return a copy of the list
return this.testData.ranges.slice(0);
return this.testData.ranges;
}
public rangesByText(): ts.Map<Range[]> {
const result: ts.Map<Range[]> = {};
for (const range of this.getRanges()) {
const text = this.rangeText(range);
(ts.getProperty(result, text) || (result[text] = [])).push(range);
}
return result;
}
private rangeText({fileName, start, end}: Range, more = false): string {
return this.getFileContent(fileName).slice(start, end);
}
public verifyCaretAtMarker(markerName = "") {
@@ -2772,6 +2769,10 @@ namespace FourSlashInterface {
return this.state.getRanges();
}
public rangesByText(): ts.Map<FourSlash.Range[]> {
return this.state.rangesByText();
}
public markerByName(s: string): FourSlash.Marker {
return this.state.getMarkerByName(s);
}
@@ -2970,10 +2971,6 @@ namespace FourSlashInterface {
this.state.verifyGetEmitOutputContentsForCurrentFile(expected);
}
public referencesCountIs(count: number) {
this.state.verifyReferencesCountIs(count, /*localFilesOnly*/ false);
}
public referencesAre(ranges: FourSlash.Range[]) {
this.state.verifyReferencesAre(ranges);
}
@@ -2986,6 +2983,10 @@ namespace FourSlashInterface {
this.state.verifyRangesReferenceEachOther(ranges);
}
public rangesWithSameTextReferenceEachOther(ranges?: FourSlash.Range[]) {
this.state.verifyRangesWithSameTextReferenceEachOther(ranges);
}
public currentParameterHelpArgumentNameIs(name: string) {
this.state.verifyCurrentParameterHelpName(name);
}