@@ -525,6 +525,56 @@ namespace FourSlash {
525525 }
526526 }
527527
528+ public verifyGoToDefinitionIs ( endMarker : string | string [ ] ) {
529+ this . verifyGoToDefinitionWorker ( endMarker instanceof Array ? endMarker : [ endMarker ] ) ;
530+ }
531+
532+ public verifyGoToDefinition ( startsAndEnds : ( string | string [ ] ) [ ] ) {
533+ if ( startsAndEnds . length % 2 ) {
534+ throw new Error ( "verify.goToDefinition needs an even number of arguments." ) ;
535+ }
536+
537+ for ( let i = 0 ; i < startsAndEnds . length ; i += 2 ) {
538+ const start = startsAndEnds [ i ] ;
539+ const end = startsAndEnds [ i + 1 ] ;
540+
541+ if ( start instanceof Array ) {
542+ for ( const s of start ) {
543+ this . verifyGoToDefinitionSingle ( s , end ) ;
544+ }
545+ }
546+ else {
547+ this . verifyGoToDefinitionSingle ( start , end ) ;
548+ }
549+ }
550+ }
551+
552+ public verifyGoToDefinitionForMarkers ( markerNames : string [ ] ) {
553+ for ( const markerName of markerNames ) {
554+ this . verifyGoToDefinitionSingle ( `${ markerName } Reference` , `${ markerName } Definition` ) ;
555+ }
556+ }
557+
558+ private verifyGoToDefinitionSingle ( start : string , end : string | string [ ] ) {
559+ this . goToMarker ( start ) ;
560+ this . verifyGoToDefinitionWorker ( end instanceof Array ? end : [ end ] ) ;
561+ }
562+
563+ private verifyGoToDefinitionWorker ( endMarkers : string [ ] ) {
564+ const definitions = this . languageService . getDefinitionAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) || [ ] ;
565+
566+ if ( endMarkers . length !== definitions . length ) {
567+ this . raiseError ( `goToDefinitions failed - expected to find ${ endMarkers . length } definitions but got ${ definitions . length } ` ) ;
568+ }
569+
570+ for ( let i = 0 ; i < endMarkers . length ; i ++ ) {
571+ const marker = this . getMarkerByName ( endMarkers [ i ] ) , definition = definitions [ i ] ;
572+ if ( marker . fileName !== definition . fileName || marker . position !== definition . textSpan . start ) {
573+ this . raiseError ( `goToDefinition failed for definition ${ i } : expected ${ marker . fileName } at ${ marker . position } , got ${ definition . fileName } at ${ definition . textSpan . start } ` ) ;
574+ }
575+ }
576+ }
577+
528578 public verifyGetEmitOutputForCurrentFile ( expected : string ) : void {
529579 const emit = this . languageService . getEmitOutput ( this . activeFile . fileName ) ;
530580 if ( emit . outputFiles . length !== 1 ) {
@@ -1561,21 +1611,6 @@ namespace FourSlash {
15611611 this . goToPosition ( len ) ;
15621612 }
15631613
1564- public goToDefinition ( definitionIndex : number ) {
1565- const definitions = this . languageService . getDefinitionAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ;
1566- if ( ! definitions || ! definitions . length ) {
1567- this . raiseError ( "goToDefinition failed - expected to find at least one definition location but got 0" ) ;
1568- }
1569-
1570- if ( definitionIndex >= definitions . length ) {
1571- this . raiseError ( `goToDefinition failed - definitionIndex value (${ definitionIndex } ) exceeds definition list size (${ definitions . length } )` ) ;
1572- }
1573-
1574- const definition = definitions [ definitionIndex ] ;
1575- this . openFile ( definition . fileName ) ;
1576- this . currentCaretPosition = definition . textSpan . start ;
1577- }
1578-
15791614 public goToTypeDefinition ( definitionIndex : number ) {
15801615 const definitions = this . languageService . getTypeDefinitionAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ;
15811616 if ( ! definitions || ! definitions . length ) {
@@ -1591,28 +1626,6 @@ namespace FourSlash {
15911626 this . currentCaretPosition = definition . textSpan . start ;
15921627 }
15931628
1594- public verifyDefinitionLocationExists ( negative : boolean ) {
1595- const definitions = this . languageService . getDefinitionAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ;
1596-
1597- const foundDefinitions = definitions && definitions . length ;
1598-
1599- if ( foundDefinitions && negative ) {
1600- this . raiseError ( `goToDefinition - expected to 0 definition locations but got ${ definitions . length } ` ) ;
1601- }
1602- else if ( ! foundDefinitions && ! negative ) {
1603- this . raiseError ( "goToDefinition - expected to find at least one definition location but got 0" ) ;
1604- }
1605- }
1606-
1607- public verifyDefinitionsCount ( negative : boolean , expectedCount : number ) {
1608- const assertFn = negative ? assert . notEqual : assert . equal ;
1609-
1610- const definitions = this . languageService . getDefinitionAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ;
1611- const actualCount = definitions && definitions . length || 0 ;
1612-
1613- assertFn ( actualCount , expectedCount , this . messageAtLastKnownMarker ( "Definitions Count" ) ) ;
1614- }
1615-
16161629 public verifyTypeDefinitionsCount ( negative : boolean , expectedCount : number ) {
16171630 const assertFn = negative ? assert . notEqual : assert . equal ;
16181631
@@ -1622,25 +1635,23 @@ namespace FourSlash {
16221635 assertFn ( actualCount , expectedCount , this . messageAtLastKnownMarker ( "Type definitions Count" ) ) ;
16231636 }
16241637
1625- public verifyDefinitionsName ( negative : boolean , expectedName : string , expectedContainerName : string ) {
1638+ public verifyGoToDefinitionName ( expectedName : string , expectedContainerName : string ) {
16261639 const definitions = this . languageService . getDefinitionAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ;
16271640 const actualDefinitionName = definitions && definitions . length ? definitions [ 0 ] . name : "" ;
16281641 const actualDefinitionContainerName = definitions && definitions . length ? definitions [ 0 ] . containerName : "" ;
1629- if ( negative ) {
1630- assert . notEqual ( actualDefinitionName , expectedName , this . messageAtLastKnownMarker ( "Definition Info Name" ) ) ;
1631- assert . notEqual ( actualDefinitionContainerName , expectedContainerName , this . messageAtLastKnownMarker ( "Definition Info Container Name" ) ) ;
1632- }
1633- else {
1634- assert . equal ( actualDefinitionName , expectedName , this . messageAtLastKnownMarker ( "Definition Info Name" ) ) ;
1635- assert . equal ( actualDefinitionContainerName , expectedContainerName , this . messageAtLastKnownMarker ( "Definition Info Container Name" ) ) ;
1636- }
1642+ assert . equal ( actualDefinitionName , expectedName , this . messageAtLastKnownMarker ( "Definition Info Name" ) ) ;
1643+ assert . equal ( actualDefinitionContainerName , expectedContainerName , this . messageAtLastKnownMarker ( "Definition Info Container Name" ) ) ;
16371644 }
16381645
16391646 public getMarkers ( ) : Marker [ ] {
16401647 // Return a copy of the list
16411648 return this . testData . markers . slice ( 0 ) ;
16421649 }
16431650
1651+ public getMarkerNames ( ) : string [ ] {
1652+ return Object . keys ( this . testData . markerPositions ) ;
1653+ }
1654+
16441655 public getRanges ( ) : Range [ ] {
16451656 return this . testData . ranges ;
16461657 }
@@ -2742,6 +2753,10 @@ namespace FourSlashInterface {
27422753 return this . state . getMarkers ( ) ;
27432754 }
27442755
2756+ public markerNames ( ) : string [ ] {
2757+ return this . state . getMarkerNames ( ) ;
2758+ }
2759+
27452760 public marker ( name ?: string ) : FourSlash . Marker {
27462761 return this . state . getMarkerByName ( name ) ;
27472762 }
@@ -2777,10 +2792,6 @@ namespace FourSlashInterface {
27772792 this . state . goToEOF ( ) ;
27782793 }
27792794
2780- public definition ( definitionIndex = 0 ) {
2781- this . state . goToDefinition ( definitionIndex ) ;
2782- }
2783-
27842795 public type ( definitionIndex = 0 ) {
27852796 this . state . goToTypeDefinition ( definitionIndex ) ;
27862797 }
@@ -2885,22 +2896,10 @@ namespace FourSlashInterface {
28852896 this . state . verifyQuickInfoExists ( this . negative ) ;
28862897 }
28872898
2888- public definitionCountIs ( expectedCount : number ) {
2889- this . state . verifyDefinitionsCount ( this . negative , expectedCount ) ;
2890- }
2891-
28922899 public typeDefinitionCountIs ( expectedCount : number ) {
28932900 this . state . verifyTypeDefinitionsCount ( this . negative , expectedCount ) ;
28942901 }
28952902
2896- public definitionLocationExists ( ) {
2897- this . state . verifyDefinitionLocationExists ( this . negative ) ;
2898- }
2899-
2900- public verifyDefinitionsName ( name : string , containerName : string ) {
2901- this . state . verifyDefinitionsName ( this . negative , name , containerName ) ;
2902- }
2903-
29042903 public isValidBraceCompletionAtPosition ( openingBrace : string ) {
29052904 this . state . verifyBraceCompletionAtPosition ( this . negative , openingBrace ) ;
29062905 }
@@ -2944,6 +2943,22 @@ namespace FourSlashInterface {
29442943 this . state . verifyCurrentFileContent ( text ) ;
29452944 }
29462945
2946+ public goToDefinitionIs ( endMarkers : string | string [ ] ) {
2947+ this . state . verifyGoToDefinitionIs ( endMarkers ) ;
2948+ }
2949+
2950+ public goToDefinition ( ...startsAndEnds : ( string | string [ ] ) [ ] ) {
2951+ this . state . verifyGoToDefinition ( startsAndEnds ) ;
2952+ }
2953+
2954+ public goToDefinitionForMarkers ( ...markerNames : string [ ] ) {
2955+ this . state . verifyGoToDefinitionForMarkers ( markerNames ) ;
2956+ }
2957+
2958+ public goToDefinitionName ( name : string , containerName : string ) {
2959+ this . state . verifyGoToDefinitionName ( name , containerName ) ;
2960+ }
2961+
29472962 public verifyGetEmitOutputForCurrentFile ( expected : string ) : void {
29482963 this . state . verifyGetEmitOutputForCurrentFile ( expected ) ;
29492964 }
0 commit comments