Skip to content

Commit 7bafbea

Browse files
Add fourslash function for validating syntactic classification (microsoft#50362)
1 parent df25b77 commit 7bafbea

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/harness/fourslashImpl.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2749,6 +2749,13 @@ namespace FourSlash {
27492749
// fs.writeFileSync(testfilePath, newfile);
27502750
}
27512751

2752+
public verifyEncodedSyntacticClassificationsLength(expected: number) {
2753+
const actual = this.languageService.getEncodedSyntacticClassifications(this.activeFile.fileName, ts.createTextSpan(0, this.activeFile.content.length));
2754+
if (actual.spans.length !== expected) {
2755+
this.raiseError(`encodedSyntacticClassificationsLength failed - expected total spans to be ${expected} got ${actual.spans.length}`);
2756+
}
2757+
}
2758+
27522759
public verifyEncodedSemanticClassificationsLength(format: ts.SemanticClassificationFormat, expected: number) {
27532760
const actual = this.languageService.getEncodedSemanticClassifications(this.activeFile.fileName, ts.createTextSpan(0, this.activeFile.content.length), format);
27542761
if (actual.spans.length !== expected) {

src/harness/fourslashInterfaceImpl.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,10 @@ namespace FourSlashInterface {
541541
this.state.verifySyntacticClassifications(classifications);
542542
}
543543

544+
public encodedSyntacticClassificationsLength(length: number) {
545+
this.state.verifyEncodedSyntacticClassificationsLength(length);
546+
}
547+
544548
public encodedSemanticClassificationsLength(format: ts.SemanticClassificationFormat, length: number) {
545549
this.state.verifyEncodedSemanticClassificationsLength(format, length);
546550
}

tests/cases/fourslash/fourslash.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,10 @@ declare namespace FourSlashInterface {
378378
rangesAreDocumentHighlights(ranges?: Range[], options?: VerifyDocumentHighlightsOptions): void;
379379
rangesWithSameTextAreDocumentHighlights(): void;
380380
documentHighlightsOf(startRange: Range, ranges: Range[], options?: VerifyDocumentHighlightsOptions): void;
381-
/** Prefer semanticClassificationsAre for more descriptive tests */
382-
encodedSemanticClassificationsLength(format: "original" | "2020", length: number)
381+
/** Prefer {@link syntacticClassificationsAre} for more descriptive tests */
382+
encodedSyntacticClassificationsLength(expected: number): void;
383+
/** Prefer {@link semanticClassificationsAre} for more descriptive tests */
384+
encodedSemanticClassificationsLength(format: "original" | "2020", length: number): void;
383385
/**
384386
* This method *requires* a contiguous, complete, and ordered stream of classifications for a file.
385387
*/

0 commit comments

Comments
 (0)