@@ -1007,7 +1007,7 @@ namespace FourSlash {
1007
1007
1008
1008
// If any of the expected values are undefined, assume that users don't
1009
1009
// care about them.
1010
- if ( replacementSpan && ! TestState . textSpansEqual ( replacementSpan , entry . replacementSpan ) ) {
1010
+ if ( replacementSpan && ! ts . textSpansEqual ( replacementSpan , entry . replacementSpan ) ) {
1011
1011
return false ;
1012
1012
}
1013
1013
else if ( expectedText && text !== expectedText ) {
@@ -1644,7 +1644,7 @@ Actual: ${stringify(fullActual)}`);
1644
1644
} ) ;
1645
1645
}
1646
1646
1647
- public baselineGetEmitOutput ( insertResultsIntoVfs ?: boolean ) {
1647
+ private getEmitFiles ( ) : ReadonlyArray < FourSlashFile > {
1648
1648
// Find file to be emitted
1649
1649
const emitFiles : FourSlashFile [ ] = [ ] ; // List of FourSlashFile that has emitThisFile flag on
1650
1650
@@ -1661,12 +1661,29 @@ Actual: ${stringify(fullActual)}`);
1661
1661
this . raiseError ( "No emitThisFile is specified in the test file" ) ;
1662
1662
}
1663
1663
1664
+ return emitFiles ;
1665
+ }
1666
+
1667
+ public verifyGetEmitOutput ( expectedOutputFiles : ReadonlyArray < string > ) : void {
1668
+ const outputFiles = ts . flatMap ( this . getEmitFiles ( ) , e => this . languageService . getEmitOutput ( e . fileName ) . outputFiles ) ;
1669
+
1670
+ assert . deepEqual ( outputFiles . map ( f => f . name ) , expectedOutputFiles ) ;
1671
+
1672
+ for ( const { name, text } of outputFiles ) {
1673
+ const fromTestFile = this . getFileContent ( name ) ;
1674
+ if ( fromTestFile !== text ) {
1675
+ this . raiseError ( "Emit output is not as expected: " + showTextDiff ( fromTestFile , text ) ) ;
1676
+ }
1677
+ }
1678
+ }
1679
+
1680
+ public baselineGetEmitOutput ( ) : void {
1664
1681
Harness . Baseline . runBaseline (
1665
- this . testData . globalOptions [ MetadataOptionNames . baselineFile ] ,
1682
+ ts . Debug . assertDefined ( this . testData . globalOptions [ MetadataOptionNames . baselineFile ] ) ,
1666
1683
( ) => {
1667
1684
let resultString = "" ;
1668
1685
// Loop through all the emittedFiles and emit them one by one
1669
- emitFiles . forEach ( emitFile => {
1686
+ for ( const emitFile of this . getEmitFiles ( ) ) {
1670
1687
const emitOutput = this . languageService . getEmitOutput ( emitFile . fileName ) ;
1671
1688
// Print emitOutputStatus in readable format
1672
1689
resultString += "EmitSkipped: " + emitOutput . emitSkipped + Harness . IO . newLine ( ) ;
@@ -1692,13 +1709,10 @@ Actual: ${stringify(fullActual)}`);
1692
1709
1693
1710
for ( const outputFile of emitOutput . outputFiles ) {
1694
1711
const fileName = "FileName : " + outputFile . name + Harness . IO . newLine ( ) ;
1695
- resultString = resultString + fileName + outputFile . text ;
1696
- if ( insertResultsIntoVfs ) {
1697
- this . languageServiceAdapterHost . addScript ( ts . getNormalizedAbsolutePath ( outputFile . name , "/" ) , outputFile . text , /*isRootFile*/ true ) ;
1698
- }
1712
+ resultString = resultString + Harness . IO . newLine ( ) + fileName + outputFile . text ;
1699
1713
}
1700
1714
resultString += Harness . IO . newLine ( ) ;
1701
- } ) ;
1715
+ }
1702
1716
1703
1717
return resultString ;
1704
1718
} ) ;
@@ -2137,11 +2151,10 @@ Actual: ${stringify(fullActual)}`);
2137
2151
this . raiseError ( "verifyRangesInImplementationList failed - expected to find at least one implementation location but got 0" ) ;
2138
2152
}
2139
2153
2140
- const duplicate = findDuplicatedElement ( implementations , implementationsAreEqual ) ;
2154
+ const duplicate = findDuplicatedElement ( implementations , ts . documentSpansEqual ) ;
2141
2155
if ( duplicate ) {
2142
2156
const { textSpan, fileName } = duplicate ;
2143
- const end = textSpan . start + textSpan . length ;
2144
- this . raiseError ( `Duplicate implementations returned for range (${ textSpan . start } , ${ end } ) in ${ fileName } ` ) ;
2157
+ this . raiseError ( `Duplicate implementations returned for range (${ textSpan . start } , ${ ts . textSpanEnd ( textSpan ) } ) in ${ fileName } ` ) ;
2145
2158
}
2146
2159
2147
2160
const ranges = this . getRanges ( ) ;
@@ -2208,10 +2221,6 @@ Actual: ${stringify(fullActual)}`);
2208
2221
this . raiseError ( error ) ;
2209
2222
}
2210
2223
2211
- function implementationsAreEqual ( a : ImplementationLocationInformation , b : ImplementationLocationInformation ) {
2212
- return a . fileName === b . fileName && TestState . textSpansEqual ( a . textSpan , b . textSpan ) ;
2213
- }
2214
-
2215
2224
function displayPartIsEqualTo ( a : ts . SymbolDisplayPart , b : ts . SymbolDisplayPart ) : boolean {
2216
2225
return a . kind === b . kind && a . text === b . text ;
2217
2226
}
@@ -3260,7 +3269,7 @@ Actual: ${stringify(fullActual)}`);
3260
3269
3261
3270
if ( spanIndex !== undefined ) {
3262
3271
const span = this . getTextSpanForRangeAtIndex ( spanIndex ) ;
3263
- assert . isTrue ( TestState . textSpansEqual ( span , item . replacementSpan ) , this . assertionMessageAtLastKnownMarker ( stringify ( span ) + " does not equal " + stringify ( item . replacementSpan ) + " replacement span for " + stringify ( entryId ) ) ) ;
3272
+ assert . isTrue ( ts . textSpansEqual ( span , item . replacementSpan ) , this . assertionMessageAtLastKnownMarker ( stringify ( span ) + " does not equal " + stringify ( item . replacementSpan ) + " replacement span for " + stringify ( entryId ) ) ) ;
3264
3273
}
3265
3274
3266
3275
eq ( item . hasAction , hasAction , "hasAction" ) ;
@@ -3346,10 +3355,6 @@ Actual: ${stringify(fullActual)}`);
3346
3355
this . cancellationToken . resetCancelled ( ) ;
3347
3356
}
3348
3357
3349
- private static textSpansEqual ( a : ts . TextSpan | undefined , b : ts . TextSpan | undefined ) : boolean {
3350
- return ! ! a && ! ! b && a . start === b . start && a . length === b . length ;
3351
- }
3352
-
3353
3358
public getEditsForFileRename ( { oldPath, newPath, newFileContents } : FourSlashInterface . GetEditsForFileRenameOptions ) : void {
3354
3359
const test = ( fileContents : { readonly [ fileName : string ] : string } , description : string ) : void => {
3355
3360
const changes = this . languageService . getEditsForFileRename ( oldPath , newPath , this . formatCodeSettings , ts . emptyOptions ) ;
@@ -3551,8 +3556,13 @@ ${code}
3551
3556
3552
3557
function getNonFileNameOptionInObject ( optionObject : { [ s : string ] : string } ) : string | undefined {
3553
3558
for ( const option in optionObject ) {
3554
- if ( option !== MetadataOptionNames . fileName ) {
3555
- return option ;
3559
+ switch ( option ) {
3560
+ case MetadataOptionNames . fileName :
3561
+ case MetadataOptionNames . baselineFile :
3562
+ case MetadataOptionNames . emitThisFile :
3563
+ break ;
3564
+ default :
3565
+ return option ;
3556
3566
}
3557
3567
}
3558
3568
return undefined ;
@@ -4270,8 +4280,12 @@ namespace FourSlashInterface {
4270
4280
this . state . baselineCurrentFileNameOrDottedNameSpans ( ) ;
4271
4281
}
4272
4282
4273
- public baselineGetEmitOutput ( insertResultsIntoVfs ?: boolean ) {
4274
- this . state . baselineGetEmitOutput ( insertResultsIntoVfs ) ;
4283
+ public getEmitOutput ( expectedOutputFiles : ReadonlyArray < string > ) : void {
4284
+ this . state . verifyGetEmitOutput ( expectedOutputFiles ) ;
4285
+ }
4286
+
4287
+ public baselineGetEmitOutput ( ) {
4288
+ this . state . baselineGetEmitOutput ( ) ;
4275
4289
}
4276
4290
4277
4291
public baselineQuickInfo ( ) {
0 commit comments