@@ -525,6 +525,56 @@ namespace FourSlash {
525
525
}
526
526
}
527
527
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
+
528
578
public verifyGetEmitOutputForCurrentFile ( expected : string ) : void {
529
579
const emit = this . languageService . getEmitOutput ( this . activeFile . fileName ) ;
530
580
if ( emit . outputFiles . length !== 1 ) {
@@ -1561,21 +1611,6 @@ namespace FourSlash {
1561
1611
this . goToPosition ( len ) ;
1562
1612
}
1563
1613
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
-
1579
1614
public goToTypeDefinition ( definitionIndex : number ) {
1580
1615
const definitions = this . languageService . getTypeDefinitionAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ;
1581
1616
if ( ! definitions || ! definitions . length ) {
@@ -1591,28 +1626,6 @@ namespace FourSlash {
1591
1626
this . currentCaretPosition = definition . textSpan . start ;
1592
1627
}
1593
1628
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
-
1616
1629
public verifyTypeDefinitionsCount ( negative : boolean , expectedCount : number ) {
1617
1630
const assertFn = negative ? assert . notEqual : assert . equal ;
1618
1631
@@ -1622,25 +1635,23 @@ namespace FourSlash {
1622
1635
assertFn ( actualCount , expectedCount , this . messageAtLastKnownMarker ( "Type definitions Count" ) ) ;
1623
1636
}
1624
1637
1625
- public verifyDefinitionsName ( negative : boolean , expectedName : string , expectedContainerName : string ) {
1638
+ public verifyGoToDefinitionName ( expectedName : string , expectedContainerName : string ) {
1626
1639
const definitions = this . languageService . getDefinitionAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ;
1627
1640
const actualDefinitionName = definitions && definitions . length ? definitions [ 0 ] . name : "" ;
1628
1641
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" ) ) ;
1637
1644
}
1638
1645
1639
1646
public getMarkers ( ) : Marker [ ] {
1640
1647
// Return a copy of the list
1641
1648
return this . testData . markers . slice ( 0 ) ;
1642
1649
}
1643
1650
1651
+ public getMarkerNames ( ) : string [ ] {
1652
+ return Object . keys ( this . testData . markerPositions ) ;
1653
+ }
1654
+
1644
1655
public getRanges ( ) : Range [ ] {
1645
1656
return this . testData . ranges ;
1646
1657
}
@@ -2742,6 +2753,10 @@ namespace FourSlashInterface {
2742
2753
return this . state . getMarkers ( ) ;
2743
2754
}
2744
2755
2756
+ public markerNames ( ) : string [ ] {
2757
+ return this . state . getMarkerNames ( ) ;
2758
+ }
2759
+
2745
2760
public marker ( name ?: string ) : FourSlash . Marker {
2746
2761
return this . state . getMarkerByName ( name ) ;
2747
2762
}
@@ -2777,10 +2792,6 @@ namespace FourSlashInterface {
2777
2792
this . state . goToEOF ( ) ;
2778
2793
}
2779
2794
2780
- public definition ( definitionIndex = 0 ) {
2781
- this . state . goToDefinition ( definitionIndex ) ;
2782
- }
2783
-
2784
2795
public type ( definitionIndex = 0 ) {
2785
2796
this . state . goToTypeDefinition ( definitionIndex ) ;
2786
2797
}
@@ -2885,22 +2896,10 @@ namespace FourSlashInterface {
2885
2896
this . state . verifyQuickInfoExists ( this . negative ) ;
2886
2897
}
2887
2898
2888
- public definitionCountIs ( expectedCount : number ) {
2889
- this . state . verifyDefinitionsCount ( this . negative , expectedCount ) ;
2890
- }
2891
-
2892
2899
public typeDefinitionCountIs ( expectedCount : number ) {
2893
2900
this . state . verifyTypeDefinitionsCount ( this . negative , expectedCount ) ;
2894
2901
}
2895
2902
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
-
2904
2903
public isValidBraceCompletionAtPosition ( openingBrace : string ) {
2905
2904
this . state . verifyBraceCompletionAtPosition ( this . negative , openingBrace ) ;
2906
2905
}
@@ -2944,6 +2943,22 @@ namespace FourSlashInterface {
2944
2943
this . state . verifyCurrentFileContent ( text ) ;
2945
2944
}
2946
2945
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
+
2947
2962
public verifyGetEmitOutputForCurrentFile ( expected : string ) : void {
2948
2963
this . state . verifyGetEmitOutputForCurrentFile ( expected ) ;
2949
2964
}
0 commit comments