From fe2b9e9e17fd0e8488727627334c0b92c3f31a0d Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 21 Jun 2019 10:38:31 -0700 Subject: [PATCH] Assert ranges exist when looped over in fourslash (#32012) --- src/harness/fourslash.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 17f6c587f8..cbe4c3336d 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1177,7 +1177,9 @@ Actual: ${stringify(fullActual)}`); public verifyRenameLocations(startRanges: ArrayOrSingle, options: FourSlashInterface.RenameLocationsOptions) { const { findInStrings = false, findInComments = false, ranges = this.getRanges(), providePrefixAndSuffixTextForRename = true } = ts.isArray(options) ? { findInStrings: false, findInComments: false, ranges: options, providePrefixAndSuffixTextForRename: true } : options; - for (const startRange of toArray(startRanges)) { + const _startRanges = toArray(startRanges); + assert(_startRanges.length); + for (const startRange of _startRanges) { this.goToRangeStart(startRange); const renameInfo = this.languageService.getRenameInfo(this.activeFile.fileName, this.currentCaretPosition); @@ -2731,6 +2733,7 @@ Actual: ${stringify(fullActual)}`); public verifyRangesAreOccurrences(isWriteAccess?: boolean, ranges?: Range[]) { ranges = ranges || this.getRanges(); + assert(ranges.length); for (const r of ranges) { this.goToRangeStart(r); this.verifyOccurrencesAtPositionListCount(ranges.length); @@ -2761,6 +2764,7 @@ Actual: ${stringify(fullActual)}`); public verifyRangesAreDocumentHighlights(ranges: Range[] | undefined, options: FourSlashInterface.VerifyDocumentHighlightsOptions | undefined) { ranges = ranges || this.getRanges(); + assert(ranges.length); const fileNames = options && options.filesToSearch || unique(ranges, range => range.fileName); for (const range of ranges) { this.goToRangeStart(range); @@ -2930,7 +2934,9 @@ Actual: ${stringify(fullActual)}`); } public noMoveToNewFile() { - for (const range of this.getRanges()) { + const ranges = this.getRanges(); + assert(ranges.length); + for (const range of ranges) { for (const refactor of this.getApplicableRefactors(range, { allowTextChangesInNewFiles: true })) { if (refactor.name === "Move to a new file") { ts.Debug.fail("Did not expect to get 'move to a new file' refactor");