@@ -688,7 +688,7 @@ namespace FourSlash {
688688 this . verifyGoToXWorker ( toArray ( endMarker ) , ( ) => this . getGoToDefinition ( ) ) ;
689689 }
690690
691- public verifyGoToDefinition ( arg0 : any , endMarkerNames ?: ArrayOrSingle < string > ) {
691+ public verifyGoToDefinition ( arg0 : any , endMarkerNames ?: ArrayOrSingle < string > | { file : string } ) {
692692 this . verifyGoToX ( arg0 , endMarkerNames , ( ) => this . getGoToDefinitionAndBoundSpan ( ) ) ;
693693 }
694694
@@ -705,7 +705,7 @@ namespace FourSlash {
705705 this . languageService . getTypeDefinitionAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ) ;
706706 }
707707
708- private verifyGoToX ( arg0 : any , endMarkerNames : ArrayOrSingle < string > | undefined , getDefs : ( ) => readonly ts . DefinitionInfo [ ] | ts . DefinitionInfoAndBoundSpan | undefined ) {
708+ private verifyGoToX ( arg0 : any , endMarkerNames : ArrayOrSingle < string > | { file : string } | undefined , getDefs : ( ) => readonly ts . DefinitionInfo [ ] | ts . DefinitionInfoAndBoundSpan | undefined ) {
709709 if ( endMarkerNames ) {
710710 this . verifyGoToXPlain ( arg0 , endMarkerNames , getDefs ) ;
711711 }
@@ -725,7 +725,7 @@ namespace FourSlash {
725725 }
726726 }
727727
728- private verifyGoToXPlain ( startMarkerNames : ArrayOrSingle < string > , endMarkerNames : ArrayOrSingle < string > , getDefs : ( ) => readonly ts . DefinitionInfo [ ] | ts . DefinitionInfoAndBoundSpan | undefined ) {
728+ private verifyGoToXPlain ( startMarkerNames : ArrayOrSingle < string > , endMarkerNames : ArrayOrSingle < string > | { file : string } , getDefs : ( ) => readonly ts . DefinitionInfo [ ] | ts . DefinitionInfoAndBoundSpan | undefined ) {
729729 for ( const start of toArray ( startMarkerNames ) ) {
730730 this . verifyGoToXSingle ( start , endMarkerNames , getDefs ) ;
731731 }
@@ -737,12 +737,12 @@ namespace FourSlash {
737737 }
738738 }
739739
740- private verifyGoToXSingle ( startMarkerName : string , endMarkerNames : ArrayOrSingle < string > , getDefs : ( ) => readonly ts . DefinitionInfo [ ] | ts . DefinitionInfoAndBoundSpan | undefined ) {
740+ private verifyGoToXSingle ( startMarkerName : string , endMarkerNames : ArrayOrSingle < string > | { file : string } , getDefs : ( ) => readonly ts . DefinitionInfo [ ] | ts . DefinitionInfoAndBoundSpan | undefined ) {
741741 this . goToMarker ( startMarkerName ) ;
742742 this . verifyGoToXWorker ( toArray ( endMarkerNames ) , getDefs , startMarkerName ) ;
743743 }
744744
745- private verifyGoToXWorker ( endMarkers : readonly string [ ] , getDefs : ( ) => readonly ts . DefinitionInfo [ ] | ts . DefinitionInfoAndBoundSpan | undefined , startMarkerName ?: string ) {
745+ private verifyGoToXWorker ( endMarkers : readonly ( string | { file : string } ) [ ] , getDefs : ( ) => readonly ts . DefinitionInfo [ ] | ts . DefinitionInfoAndBoundSpan | undefined , startMarkerName ?: string ) {
746746 const defs = getDefs ( ) ;
747747 let definitions : readonly ts . DefinitionInfo [ ] ;
748748 let testName : string ;
@@ -762,21 +762,22 @@ namespace FourSlash {
762762 this . raiseError ( `${ testName } failed - expected to find ${ endMarkers . length } definitions but got ${ definitions . length } ` ) ;
763763 }
764764
765- ts . zipWith ( endMarkers , definitions , ( endMarker , definition , i ) => {
766- const marker = this . getMarkerByName ( endMarker ) ;
767- if ( ts . comparePaths ( marker . fileName , definition . fileName , /*ignoreCase*/ true ) !== ts . Comparison . EqualTo || marker . position !== definition . textSpan . start ) {
768- const filesToDisplay = ts . deduplicate ( [ marker . fileName , definition . fileName ] , ts . equateValues ) ;
769- const markers = [ { text : "EXPECTED" , fileName : marker . fileName , position : marker . position } , { text : "ACTUAL" , fileName : definition . fileName , position : definition . textSpan . start } ] ;
765+ ts . zipWith ( endMarkers , definitions , ( endMarkerOrFileResult , definition , i ) => {
766+ const expectedFileName = typeof endMarkerOrFileResult === "string" ? this . getMarkerByName ( endMarkerOrFileResult ) . fileName : endMarkerOrFileResult . file ;
767+ const expectedPosition = typeof endMarkerOrFileResult === "string" ? this . getMarkerByName ( endMarkerOrFileResult ) . position : 0 ;
768+ if ( ts . comparePaths ( expectedFileName , definition . fileName , /*ignoreCase*/ true ) !== ts . Comparison . EqualTo || expectedPosition !== definition . textSpan . start ) {
769+ const filesToDisplay = ts . deduplicate ( [ expectedFileName , definition . fileName ] , ts . equateValues ) ;
770+ const markers = [ { text : "EXPECTED" , fileName : expectedFileName , position : expectedPosition } , { text : "ACTUAL" , fileName : definition . fileName , position : definition . textSpan . start } ] ;
770771 const text = filesToDisplay . map ( fileName => {
771772 const markersToRender = markers . filter ( m => m . fileName === fileName ) . sort ( ( a , b ) => b . position - a . position ) ;
772- let fileContent = this . getFileContent ( fileName ) ;
773+ let fileContent = this . tryGetFileContent ( fileName ) || "" ;
773774 for ( const marker of markersToRender ) {
774775 fileContent = fileContent . slice ( 0 , marker . position ) + `\x1b[1;4m/*${ marker . text } */\x1b[0;31m` + fileContent . slice ( marker . position ) ;
775776 }
776777 return `// @Filename: ${ fileName } \n${ fileContent } ` ;
777778 } ) . join ( "\n\n" ) ;
778779
779- this . raiseError ( `${ testName } failed for definition ${ endMarker } (${ i } ): expected ${ marker . fileName } at ${ marker . position } , got ${ definition . fileName } at ${ definition . textSpan . start } \n\n${ text } \n` ) ;
780+ this . raiseError ( `${ testName } failed for definition ${ endMarkerOrFileResult } (${ i } ): expected ${ expectedFileName } at ${ expectedPosition } , got ${ definition . fileName } at ${ definition . textSpan . start } \n\n${ text } \n` ) ;
780781 }
781782 } ) ;
782783 }
0 commit comments