@@ -452,7 +452,8 @@ namespace FourSlash {
452
452
}
453
453
454
454
private messageAtLastKnownMarker ( message : string ) {
455
- return "Marker: " + this . lastKnownMarker + "\n" + message ;
455
+ const locationDescription = this . lastKnownMarker ? this . lastKnownMarker : this . getLineColStringAtPosition ( this . currentCaretPosition ) ;
456
+ return `At ${ locationDescription } : ${ message } ` ;
456
457
}
457
458
458
459
private assertionMessageAtLastKnownMarker ( msg : string ) {
@@ -562,7 +563,7 @@ namespace FourSlash {
562
563
}
563
564
564
565
public verifyGoToDefinitionIs ( endMarker : string | string [ ] ) {
565
- this . verifyGoToXWorker ( endMarker instanceof Array ? endMarker : [ endMarker ] , ( ) => this . getGoToDefinition ( ) ) ;
566
+ this . verifyGoToXWorker ( toArray ( endMarker ) , ( ) => this . getGoToDefinition ( ) ) ;
566
567
}
567
568
568
569
public verifyGoToDefinition ( arg0 : any , endMarkerNames ?: string | string [ ] ) {
@@ -582,7 +583,7 @@ namespace FourSlash {
582
583
if ( endMarkerNames ) {
583
584
this . verifyGoToXPlain ( arg0 , endMarkerNames , getDefs ) ;
584
585
}
585
- else if ( arg0 instanceof Array ) {
586
+ else if ( ts . isArray ( arg0 ) ) {
586
587
const pairs : [ string | string [ ] , string | string [ ] ] [ ] = arg0 ;
587
588
for ( const [ start , end ] of pairs ) {
588
589
this . verifyGoToXPlain ( start , end , getDefs ) ;
@@ -599,13 +600,8 @@ namespace FourSlash {
599
600
}
600
601
601
602
private verifyGoToXPlain ( startMarkerNames : string | string [ ] , endMarkerNames : string | string [ ] , getDefs : ( ) => ts . DefinitionInfo [ ] | undefined ) {
602
- if ( startMarkerNames instanceof Array ) {
603
- for ( const start of startMarkerNames ) {
604
- this . verifyGoToXSingle ( start , endMarkerNames , getDefs ) ;
605
- }
606
- }
607
- else {
608
- this . verifyGoToXSingle ( startMarkerNames , endMarkerNames , getDefs ) ;
603
+ for ( const start of toArray ( startMarkerNames ) ) {
604
+ this . verifyGoToXSingle ( start , endMarkerNames , getDefs ) ;
609
605
}
610
606
}
611
607
@@ -617,7 +613,7 @@ namespace FourSlash {
617
613
618
614
private verifyGoToXSingle ( startMarkerName : string , endMarkerNames : string | string [ ] , getDefs : ( ) => ts . DefinitionInfo [ ] | undefined ) {
619
615
this . goToMarker ( startMarkerName ) ;
620
- this . verifyGoToXWorker ( endMarkerNames instanceof Array ? endMarkerNames : [ endMarkerNames ] , getDefs ) ;
616
+ this . verifyGoToXWorker ( toArray ( endMarkerNames ) , getDefs ) ;
621
617
}
622
618
623
619
private verifyGoToXWorker ( endMarkers : string [ ] , getDefs : ( ) => ts . DefinitionInfo [ ] | undefined ) {
@@ -899,8 +895,74 @@ namespace FourSlash {
899
895
}
900
896
}
901
897
902
- public verifyRangesWithSameTextReferenceEachOther ( ) {
903
- this . rangesByText ( ) . forEach ( ranges => this . verifyRangesReferenceEachOther ( ranges ) ) ;
898
+ public verifyReferenceGroups ( startRanges : Range | Range [ ] , parts : Array < { definition : string , ranges : Range [ ] } > ) : void {
899
+ interface ReferenceJson { definition : string ; ranges : ts . ReferenceEntry [ ] ; }
900
+ type ReferencesJson = ReferenceJson [ ] ;
901
+ const fullExpected = parts . map < ReferenceJson > ( ( { definition, ranges } ) => ( { definition, ranges : ranges . map ( rangeToReferenceEntry ) } ) ) ;
902
+
903
+ for ( const startRange of toArray ( startRanges ) ) {
904
+ this . goToRangeStart ( startRange ) ;
905
+ const fullActual = this . findReferencesAtCaret ( ) . map < ReferenceJson > ( ( { definition, references } ) => ( {
906
+ definition : definition . displayParts . map ( d => d . text ) . join ( "" ) ,
907
+ ranges : references
908
+ } ) ) ;
909
+ this . assertObjectsEqual < ReferencesJson > ( fullActual , fullExpected ) ;
910
+ }
911
+
912
+ function rangeToReferenceEntry ( r : Range ) {
913
+ let { isWriteAccess, isDefinition } = ( r . marker && r . marker . data ) || { isWriteAccess : false , isDefinition : false } ;
914
+ isWriteAccess = ! ! isWriteAccess ; isDefinition = ! ! isDefinition ;
915
+ return { fileName : r . fileName , textSpan : { start : r . start , length : r . end - r . start } , isWriteAccess, isDefinition }
916
+ }
917
+ }
918
+
919
+ public verifyNoReferences ( markerNameOrRange ?: string | Range ) {
920
+ if ( markerNameOrRange ) {
921
+ if ( typeof markerNameOrRange === "string" ) {
922
+ this . goToMarker ( markerNameOrRange ) ;
923
+ }
924
+ else {
925
+ this . goToRangeStart ( markerNameOrRange ) ;
926
+ }
927
+ }
928
+
929
+ const refs = this . getReferencesAtCaret ( ) ;
930
+ if ( refs && refs . length ) {
931
+ console . log ( refs ) ;
932
+ this . raiseError ( "Expected getReferences to fail" ) ;
933
+ }
934
+ }
935
+
936
+ public verifySingleReferenceGroup ( definition : string , ranges ?: Range [ ] ) {
937
+ ranges = ranges || this . getRanges ( ) ;
938
+ this . verifyReferenceGroups ( ranges , [ { definition, ranges } ] ) ;
939
+ }
940
+
941
+ private assertObjectsEqual < T > ( fullActual : T , fullExpected : T , msgPrefix = "" ) : void {
942
+ const recur = < U > ( actual : U , expected : U , path : string ) => {
943
+ const fail = ( msg : string ) => {
944
+ console . log ( "Expected:" , stringify ( fullExpected ) ) ;
945
+ console . log ( "Actual: " , stringify ( fullActual ) ) ;
946
+ this . raiseError ( `${ msgPrefix } At ${ path } : ${ msg } ` ) ;
947
+ } ;
948
+
949
+ for ( const key in actual ) if ( ts . hasProperty ( actual as any , key ) ) {
950
+ const ak = actual [ key ] , ek = expected [ key ] ;
951
+ if ( typeof ak === "object" && typeof ek === "object" ) {
952
+ recur ( ak , ek , path ? path + "." + key : key ) ;
953
+ }
954
+ else if ( ak !== ek ) {
955
+ fail ( `Expected '${ key } ' to be '${ ek } ', got '${ ak } '` ) ;
956
+ }
957
+ }
958
+ for ( const key in expected ) if ( ts . hasProperty ( expected as any , key ) ) {
959
+ if ( ! ts . hasProperty ( actual as any , key ) ) {
960
+ fail ( `${ msgPrefix } Missing property '${ key } '` ) ;
961
+ }
962
+ }
963
+ } ;
964
+ recur ( fullActual , fullExpected , "" ) ;
965
+
904
966
}
905
967
906
968
public verifyDisplayPartsOfReferencedSymbol ( expected : ts . SymbolDisplayPart [ ] ) {
@@ -974,7 +1036,7 @@ namespace FourSlash {
974
1036
public verifyQuickInfos ( namesAndTexts : { [ name : string ] : string | [ string , string ] } ) {
975
1037
for ( const name in namesAndTexts ) if ( ts . hasProperty ( namesAndTexts , name ) ) {
976
1038
const text = namesAndTexts [ name ] ;
977
- if ( text instanceof Array ) {
1039
+ if ( ts . isArray ( text ) ) {
978
1040
assert ( text . length === 2 ) ;
979
1041
const [ expectedText , expectedDocumentation ] = text ;
980
1042
this . verifyQuickInfoAt ( name , expectedText , expectedDocumentation ) ;
@@ -1411,13 +1473,6 @@ namespace FourSlash {
1411
1473
Harness . IO . log ( membersString ) ;
1412
1474
}
1413
1475
1414
- public printReferences ( ) {
1415
- const references = this . getReferencesAtCaret ( ) ;
1416
- ts . forEach ( references , entry => {
1417
- Harness . IO . log ( stringify ( entry ) ) ;
1418
- } ) ;
1419
- }
1420
-
1421
1476
public printContext ( ) {
1422
1477
ts . forEach ( this . languageServiceAdapterHost . getFilenames ( ) , Harness . IO . log ) ;
1423
1478
}
@@ -3082,6 +3137,10 @@ ${code}
3082
3137
}
3083
3138
return ts . arrayFrom ( set . keys ( ) ) ;
3084
3139
}
3140
+
3141
+ function toArray < T > ( x : T | T [ ] ) : T [ ] {
3142
+ return ts . isArray ( x ) ? x : [ x ] ;
3143
+ }
3085
3144
}
3086
3145
3087
3146
namespace FourSlashInterface {
@@ -3346,6 +3405,18 @@ namespace FourSlashInterface {
3346
3405
this . state . verifyReferencesOf ( start , references ) ;
3347
3406
}
3348
3407
3408
+ public referenceGroups ( startRanges : FourSlash . Range [ ] , parts : Array < { definition : string , ranges : FourSlash . Range [ ] } > ) {
3409
+ this . state . verifyReferenceGroups ( startRanges , parts ) ;
3410
+ }
3411
+
3412
+ public noReferences ( markerNameOrRange ?: string | FourSlash . Range ) {
3413
+ this . state . verifyNoReferences ( markerNameOrRange ) ;
3414
+ }
3415
+
3416
+ public singleReferenceGroup ( definition : string , ranges ?: FourSlash . Range [ ] ) {
3417
+ this . state . verifySingleReferenceGroup ( definition , ranges ) ;
3418
+ }
3419
+
3349
3420
public rangesReferenceEachOther ( ranges ?: FourSlash . Range [ ] ) {
3350
3421
this . state . verifyRangesReferenceEachOther ( ranges ) ;
3351
3422
}
@@ -3354,10 +3425,6 @@ namespace FourSlashInterface {
3354
3425
this . state . verifyDisplayPartsOfReferencedSymbol ( expected ) ;
3355
3426
}
3356
3427
3357
- public rangesWithSameTextReferenceEachOther ( ) {
3358
- this . state . verifyRangesWithSameTextReferenceEachOther ( ) ;
3359
- }
3360
-
3361
3428
public currentParameterHelpArgumentNameIs ( name : string ) {
3362
3429
this . state . verifyCurrentParameterHelpName ( name ) ;
3363
3430
}
@@ -3660,10 +3727,6 @@ namespace FourSlashInterface {
3660
3727
this . state . printNavigationBar ( ) ;
3661
3728
}
3662
3729
3663
- public printReferences ( ) {
3664
- this . state . printReferences ( ) ;
3665
- }
3666
-
3667
3730
public printContext ( ) {
3668
3731
this . state . printContext ( ) ;
3669
3732
}
0 commit comments