@@ -525,6 +525,67 @@ 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 ( arg0 : any , endMarkerNames ?: string | string [ ] ) {
533
+ if ( endMarkerNames ) {
534
+ this . verifyGoToDefinitionPlain ( arg0 , endMarkerNames ) ;
535
+ }
536
+ else if ( arg0 instanceof Array ) {
537
+ const pairs : [ string | string [ ] , string | string [ ] ] [ ] = arg0 ;
538
+ for ( const [ start , end ] of pairs ) {
539
+ this . verifyGoToDefinitionPlain ( start , end ) ;
540
+ }
541
+ }
542
+ else {
543
+ const obj : { [ startMarkerName : string ] : string | string [ ] } = arg0 ;
544
+ for ( const startMarkerName in obj ) {
545
+ if ( ts . hasProperty ( obj , startMarkerName ) ) {
546
+ this . verifyGoToDefinitionPlain ( startMarkerName , obj [ startMarkerName ] ) ;
547
+ }
548
+ }
549
+ }
550
+ }
551
+
552
+ private verifyGoToDefinitionPlain ( startMarkerNames : string | string [ ] , endMarkerNames : string | string [ ] ) {
553
+ if ( startMarkerNames instanceof Array ) {
554
+ for ( const start of startMarkerNames ) {
555
+ this . verifyGoToDefinitionSingle ( start , endMarkerNames ) ;
556
+ }
557
+ }
558
+ else {
559
+ this . verifyGoToDefinitionSingle ( startMarkerNames , endMarkerNames ) ;
560
+ }
561
+ }
562
+
563
+ public verifyGoToDefinitionForMarkers ( markerNames : string [ ] ) {
564
+ for ( const markerName of markerNames ) {
565
+ this . verifyGoToDefinitionSingle ( `${ markerName } Reference` , `${ markerName } Definition` ) ;
566
+ }
567
+ }
568
+
569
+ private verifyGoToDefinitionSingle ( startMarkerName : string , endMarkerNames : string | string [ ] ) {
570
+ this . goToMarker ( startMarkerName ) ;
571
+ this . verifyGoToDefinitionWorker ( endMarkerNames instanceof Array ? endMarkerNames : [ endMarkerNames ] ) ;
572
+ }
573
+
574
+ private verifyGoToDefinitionWorker ( endMarkers : string [ ] ) {
575
+ const definitions = this . languageService . getDefinitionAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) || [ ] ;
576
+
577
+ if ( endMarkers . length !== definitions . length ) {
578
+ this . raiseError ( `goToDefinitions failed - expected to find ${ endMarkers . length } definitions but got ${ definitions . length } ` ) ;
579
+ }
580
+
581
+ for ( let i = 0 ; i < endMarkers . length ; i ++ ) {
582
+ const marker = this . getMarkerByName ( endMarkers [ i ] ) , definition = definitions [ i ] ;
583
+ if ( marker . fileName !== definition . fileName || marker . position !== definition . textSpan . start ) {
584
+ this . raiseError ( `goToDefinition failed for definition ${ i } : expected ${ marker . fileName } at ${ marker . position } , got ${ definition . fileName } at ${ definition . textSpan . start } ` ) ;
585
+ }
586
+ }
587
+ }
588
+
528
589
public verifyGetEmitOutputForCurrentFile ( expected : string ) : void {
529
590
const emit = this . languageService . getEmitOutput ( this . activeFile . fileName ) ;
530
591
if ( emit . outputFiles . length !== 1 ) {
@@ -1561,21 +1622,6 @@ namespace FourSlash {
1561
1622
this . goToPosition ( len ) ;
1562
1623
}
1563
1624
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
1625
public goToTypeDefinition ( definitionIndex : number ) {
1580
1626
const definitions = this . languageService . getTypeDefinitionAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ;
1581
1627
if ( ! definitions || ! definitions . length ) {
@@ -1591,28 +1637,6 @@ namespace FourSlash {
1591
1637
this . currentCaretPosition = definition . textSpan . start ;
1592
1638
}
1593
1639
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
1640
public verifyTypeDefinitionsCount ( negative : boolean , expectedCount : number ) {
1617
1641
const assertFn = negative ? assert . notEqual : assert . equal ;
1618
1642
@@ -1622,25 +1646,23 @@ namespace FourSlash {
1622
1646
assertFn ( actualCount , expectedCount , this . messageAtLastKnownMarker ( "Type definitions Count" ) ) ;
1623
1647
}
1624
1648
1625
- public verifyDefinitionsName ( negative : boolean , expectedName : string , expectedContainerName : string ) {
1649
+ public verifyGoToDefinitionName ( expectedName : string , expectedContainerName : string ) {
1626
1650
const definitions = this . languageService . getDefinitionAtPosition ( this . activeFile . fileName , this . currentCaretPosition ) ;
1627
1651
const actualDefinitionName = definitions && definitions . length ? definitions [ 0 ] . name : "" ;
1628
1652
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
- }
1653
+ assert . equal ( actualDefinitionName , expectedName , this . messageAtLastKnownMarker ( "Definition Info Name" ) ) ;
1654
+ assert . equal ( actualDefinitionContainerName , expectedContainerName , this . messageAtLastKnownMarker ( "Definition Info Container Name" ) ) ;
1637
1655
}
1638
1656
1639
1657
public getMarkers ( ) : Marker [ ] {
1640
1658
// Return a copy of the list
1641
1659
return this . testData . markers . slice ( 0 ) ;
1642
1660
}
1643
1661
1662
+ public getMarkerNames ( ) : string [ ] {
1663
+ return Object . keys ( this . testData . markerPositions ) ;
1664
+ }
1665
+
1644
1666
public getRanges ( ) : Range [ ] {
1645
1667
return this . testData . ranges ;
1646
1668
}
@@ -2742,6 +2764,10 @@ namespace FourSlashInterface {
2742
2764
return this . state . getMarkers ( ) ;
2743
2765
}
2744
2766
2767
+ public markerNames ( ) : string [ ] {
2768
+ return this . state . getMarkerNames ( ) ;
2769
+ }
2770
+
2745
2771
public marker ( name ?: string ) : FourSlash . Marker {
2746
2772
return this . state . getMarkerByName ( name ) ;
2747
2773
}
@@ -2777,10 +2803,6 @@ namespace FourSlashInterface {
2777
2803
this . state . goToEOF ( ) ;
2778
2804
}
2779
2805
2780
- public definition ( definitionIndex = 0 ) {
2781
- this . state . goToDefinition ( definitionIndex ) ;
2782
- }
2783
-
2784
2806
public type ( definitionIndex = 0 ) {
2785
2807
this . state . goToTypeDefinition ( definitionIndex ) ;
2786
2808
}
@@ -2885,22 +2907,10 @@ namespace FourSlashInterface {
2885
2907
this . state . verifyQuickInfoExists ( this . negative ) ;
2886
2908
}
2887
2909
2888
- public definitionCountIs ( expectedCount : number ) {
2889
- this . state . verifyDefinitionsCount ( this . negative , expectedCount ) ;
2890
- }
2891
-
2892
2910
public typeDefinitionCountIs ( expectedCount : number ) {
2893
2911
this . state . verifyTypeDefinitionsCount ( this . negative , expectedCount ) ;
2894
2912
}
2895
2913
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
2914
public isValidBraceCompletionAtPosition ( openingBrace : string ) {
2905
2915
this . state . verifyBraceCompletionAtPosition ( this . negative , openingBrace ) ;
2906
2916
}
@@ -2944,6 +2954,25 @@ namespace FourSlashInterface {
2944
2954
this . state . verifyCurrentFileContent ( text ) ;
2945
2955
}
2946
2956
2957
+ public goToDefinitionIs ( endMarkers : string | string [ ] ) {
2958
+ this . state . verifyGoToDefinitionIs ( endMarkers ) ;
2959
+ }
2960
+
2961
+ public goToDefinition ( startMarkerName : string | string [ ] , endMarkerName : string | string [ ] ) : void ;
2962
+ public goToDefinition ( startsAndEnds : [ string | string [ ] , string | string [ ] ] [ ] ) : void ;
2963
+ public goToDefinition ( startsAndEnds : { [ startMarkerName : string ] : string | string [ ] } ) : void ;
2964
+ public goToDefinition ( arg0 : any , endMarkerName ?: string | string [ ] ) {
2965
+ this . state . verifyGoToDefinition ( arg0 , endMarkerName ) ;
2966
+ }
2967
+
2968
+ public goToDefinitionForMarkers ( ...markerNames : string [ ] ) {
2969
+ this . state . verifyGoToDefinitionForMarkers ( markerNames ) ;
2970
+ }
2971
+
2972
+ public goToDefinitionName ( name : string , containerName : string ) {
2973
+ this . state . verifyGoToDefinitionName ( name , containerName ) ;
2974
+ }
2975
+
2947
2976
public verifyGetEmitOutputForCurrentFile ( expected : string ) : void {
2948
2977
this . state . verifyGetEmitOutputForCurrentFile ( expected ) ;
2949
2978
}
0 commit comments