Add fourslash function for validating syntactic classification (#50362)

This commit is contained in:
Daniel Rosenwasser 2022-08-18 11:28:08 -07:00 committed by GitHub
parent df25b77d0f
commit 7bafbeae90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View File

@ -2749,6 +2749,13 @@ namespace FourSlash {
// fs.writeFileSync(testfilePath, newfile);
}
public verifyEncodedSyntacticClassificationsLength(expected: number) {
const actual = this.languageService.getEncodedSyntacticClassifications(this.activeFile.fileName, ts.createTextSpan(0, this.activeFile.content.length));
if (actual.spans.length !== expected) {
this.raiseError(`encodedSyntacticClassificationsLength failed - expected total spans to be ${expected} got ${actual.spans.length}`);
}
}
public verifyEncodedSemanticClassificationsLength(format: ts.SemanticClassificationFormat, expected: number) {
const actual = this.languageService.getEncodedSemanticClassifications(this.activeFile.fileName, ts.createTextSpan(0, this.activeFile.content.length), format);
if (actual.spans.length !== expected) {

View File

@ -541,6 +541,10 @@ namespace FourSlashInterface {
this.state.verifySyntacticClassifications(classifications);
}
public encodedSyntacticClassificationsLength(length: number) {
this.state.verifyEncodedSyntacticClassificationsLength(length);
}
public encodedSemanticClassificationsLength(format: ts.SemanticClassificationFormat, length: number) {
this.state.verifyEncodedSemanticClassificationsLength(format, length);
}

View File

@ -378,8 +378,10 @@ declare namespace FourSlashInterface {
rangesAreDocumentHighlights(ranges?: Range[], options?: VerifyDocumentHighlightsOptions): void;
rangesWithSameTextAreDocumentHighlights(): void;
documentHighlightsOf(startRange: Range, ranges: Range[], options?: VerifyDocumentHighlightsOptions): void;
/** Prefer semanticClassificationsAre for more descriptive tests */
encodedSemanticClassificationsLength(format: "original" | "2020", length: number)
/** Prefer {@link syntacticClassificationsAre} for more descriptive tests */
encodedSyntacticClassificationsLength(expected: number): void;
/** Prefer {@link semanticClassificationsAre} for more descriptive tests */
encodedSemanticClassificationsLength(format: "original" | "2020", length: number): void;
/**
* This method *requires* a contiguous, complete, and ordered stream of classifications for a file.
*/