Skip to content

Commit fe2b9e9

Browse files
authored
Assert ranges exist when looped over in fourslash (#32012)
1 parent 903527e commit fe2b9e9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/harness/fourslash.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,9 @@ Actual: ${stringify(fullActual)}`);
11771177
public verifyRenameLocations(startRanges: ArrayOrSingle<Range>, options: FourSlashInterface.RenameLocationsOptions) {
11781178
const { findInStrings = false, findInComments = false, ranges = this.getRanges(), providePrefixAndSuffixTextForRename = true } = ts.isArray(options) ? { findInStrings: false, findInComments: false, ranges: options, providePrefixAndSuffixTextForRename: true } : options;
11791179

1180-
for (const startRange of toArray(startRanges)) {
1180+
const _startRanges = toArray(startRanges);
1181+
assert(_startRanges.length);
1182+
for (const startRange of _startRanges) {
11811183
this.goToRangeStart(startRange);
11821184

11831185
const renameInfo = this.languageService.getRenameInfo(this.activeFile.fileName, this.currentCaretPosition);
@@ -2731,6 +2733,7 @@ Actual: ${stringify(fullActual)}`);
27312733

27322734
public verifyRangesAreOccurrences(isWriteAccess?: boolean, ranges?: Range[]) {
27332735
ranges = ranges || this.getRanges();
2736+
assert(ranges.length);
27342737
for (const r of ranges) {
27352738
this.goToRangeStart(r);
27362739
this.verifyOccurrencesAtPositionListCount(ranges.length);
@@ -2761,6 +2764,7 @@ Actual: ${stringify(fullActual)}`);
27612764

27622765
public verifyRangesAreDocumentHighlights(ranges: Range[] | undefined, options: FourSlashInterface.VerifyDocumentHighlightsOptions | undefined) {
27632766
ranges = ranges || this.getRanges();
2767+
assert(ranges.length);
27642768
const fileNames = options && options.filesToSearch || unique(ranges, range => range.fileName);
27652769
for (const range of ranges) {
27662770
this.goToRangeStart(range);
@@ -2930,7 +2934,9 @@ Actual: ${stringify(fullActual)}`);
29302934
}
29312935

29322936
public noMoveToNewFile() {
2933-
for (const range of this.getRanges()) {
2937+
const ranges = this.getRanges();
2938+
assert(ranges.length);
2939+
for (const range of ranges) {
29342940
for (const refactor of this.getApplicableRefactors(range, { allowTextChangesInNewFiles: true })) {
29352941
if (refactor.name === "Move to a new file") {
29362942
ts.Debug.fail("Did not expect to get 'move to a new file' refactor");

0 commit comments

Comments
 (0)