@@ -730,13 +730,78 @@ namespace FourSlash {
730
730
}
731
731
}
732
732
733
- public verifyReferencesAtPositionListContains ( fileName : string , start : number , end : number , isWriteAccess ?: boolean , isDefinition ?: boolean ) {
733
+ public verifyReferencesCountIs ( count : number , localFilesOnly = true ) {
734
734
const references = this . getReferencesAtCaret ( ) ;
735
+ let referencesCount = 0 ;
736
+
737
+ if ( localFilesOnly ) {
738
+ const localFiles = this . testData . files . map < string > ( file => file . fileName ) ;
739
+ // Count only the references in local files. Filter the ones in lib and other files.
740
+ ts . forEach ( references , entry => {
741
+ if ( localFiles . some ( ( fileName ) => fileName === entry . fileName ) ) {
742
+ referencesCount ++ ;
743
+ }
744
+ } ) ;
745
+ }
746
+ else {
747
+ referencesCount = references && references . length || 0 ;
748
+ }
749
+
750
+ if ( referencesCount !== count ) {
751
+ const condition = localFilesOnly ? "excluding libs" : "including libs" ;
752
+ this . raiseError ( "Expected references count (" + condition + ") to be " + count + ", but is actually " + referencesCount ) ;
753
+ }
754
+ }
755
+
756
+ public verifyReferencesAre ( expectedReferences : Range [ ] ) {
757
+ const actualReferences = this . getReferencesAtCaret ( ) || [ ] ;
758
+
759
+ if ( actualReferences . length > expectedReferences . length ) {
760
+ // Find the unaccounted-for reference.
761
+ for ( const actual of actualReferences ) {
762
+ if ( ! ts . forEach ( expectedReferences , r => r . start === actual . textSpan . start ) ) {
763
+ this . raiseError ( `A reference ${ actual } is unaccounted for.` ) ;
764
+ }
765
+ }
766
+ // Probably will never reach here.
767
+ this . raiseError ( `There are ${ actualReferences . length } references but only ${ expectedReferences . length } were expected.` ) ;
768
+ }
769
+
770
+ for ( const reference of expectedReferences ) {
771
+ const { fileName, start, end} = reference ;
772
+ if ( reference . marker ) {
773
+ const { isWriteAccess, isDefinition} = reference . marker . data ;
774
+ this . verifyReferencesWorker ( actualReferences , fileName , start , end , isWriteAccess , isDefinition ) ;
775
+ }
776
+ else {
777
+ this . verifyReferencesWorker ( actualReferences , fileName , start , end ) ;
778
+ }
779
+ }
780
+ }
781
+
782
+ public verifyReferencesOf ( { fileName, start} : Range , references : Range [ ] ) {
783
+ this . openFile ( fileName ) ;
784
+ this . goToPosition ( start ) ;
785
+ this . verifyReferencesAre ( references ) ;
786
+ }
735
787
788
+ public verifyRangesReferenceEachOther ( ranges ?: Range [ ] ) {
789
+ ranges = ranges || this . getRanges ( ) ;
790
+ assert ( ranges . length ) ;
791
+ for ( const range of ranges ) {
792
+ this . verifyReferencesOf ( range , ranges ) ;
793
+ }
794
+ }
795
+
796
+ public verifyReferencesAtPositionListContains ( fileName : string , start : number , end : number , isWriteAccess ?: boolean , isDefinition ?: boolean ) {
797
+ const references = this . getReferencesAtCaret ( ) ;
736
798
if ( ! references || references . length === 0 ) {
737
799
this . raiseError ( "verifyReferencesAtPositionListContains failed - found 0 references, expected at least one." ) ;
738
800
}
801
+ this . verifyReferencesWorker ( references , fileName , start , end , isWriteAccess , isDefinition ) ;
802
+ }
739
803
804
+ private verifyReferencesWorker ( references : ts . ReferenceEntry [ ] , fileName : string , start : number , end : number , isWriteAccess ?: boolean , isDefinition ?: boolean ) {
740
805
for ( let i = 0 ; i < references . length ; i ++ ) {
741
806
const reference = references [ i ] ;
742
807
if ( reference && reference . fileName === fileName && reference . textSpan . start === start && ts . textSpanEnd ( reference . textSpan ) === end ) {
@@ -752,29 +817,7 @@ namespace FourSlash {
752
817
753
818
const missingItem = { fileName, start, end, isWriteAccess, isDefinition } ;
754
819
this . raiseError ( `verifyReferencesAtPositionListContains failed - could not find the item: ${ stringify ( missingItem ) } in the returned list: (${ stringify ( references ) } )` ) ;
755
- }
756
-
757
- public verifyReferencesCountIs ( count : number , localFilesOnly = true ) {
758
- const references = this . getReferencesAtCaret ( ) ;
759
- let referencesCount = 0 ;
760
-
761
- if ( localFilesOnly ) {
762
- const localFiles = this . testData . files . map < string > ( file => file . fileName ) ;
763
- // Count only the references in local files. Filter the ones in lib and other files.
764
- ts . forEach ( references , entry => {
765
- if ( localFiles . some ( ( fileName ) => fileName === entry . fileName ) ) {
766
- referencesCount ++ ;
767
- }
768
- } ) ;
769
- }
770
- else {
771
- referencesCount = references && references . length || 0 ;
772
- }
773
820
774
- if ( referencesCount !== count ) {
775
- const condition = localFilesOnly ? "excluding libs" : "including libs" ;
776
- this . raiseError ( "Expected references count (" + condition + ") to be " + count + ", but is actually " + referencesCount ) ;
777
- }
778
821
}
779
822
780
823
private getMemberListAtCaret ( ) {
@@ -2836,14 +2879,6 @@ namespace FourSlashInterface {
2836
2879
this . state . verifyMemberListIsEmpty ( this . negative ) ;
2837
2880
}
2838
2881
2839
- public referencesCountIs ( count : number ) {
2840
- this . state . verifyReferencesCountIs ( count , /*localFilesOnly*/ false ) ;
2841
- }
2842
-
2843
- public referencesAtPositionContains ( range : FourSlash . Range , isWriteAccess ?: boolean , isDefinition ?: boolean ) {
2844
- this . state . verifyReferencesAtPositionListContains ( range . fileName , range . start , range . end , isWriteAccess , isDefinition ) ;
2845
- }
2846
-
2847
2882
public signatureHelpPresent ( ) {
2848
2883
this . state . verifySignatureHelpPresent ( ! this . negative ) ;
2849
2884
}
@@ -2935,6 +2970,22 @@ namespace FourSlashInterface {
2935
2970
this . state . verifyGetEmitOutputContentsForCurrentFile ( expected ) ;
2936
2971
}
2937
2972
2973
+ public referencesCountIs ( count : number ) {
2974
+ this . state . verifyReferencesCountIs ( count , /*localFilesOnly*/ false ) ;
2975
+ }
2976
+
2977
+ public referencesAre ( ranges : FourSlash . Range [ ] ) {
2978
+ this . state . verifyReferencesAre ( ranges ) ;
2979
+ }
2980
+
2981
+ public referencesOf ( start : FourSlash . Range , references : FourSlash . Range [ ] ) {
2982
+ this . state . verifyReferencesOf ( start , references ) ;
2983
+ }
2984
+
2985
+ public rangesReferenceEachOther ( ranges ?: FourSlash . Range [ ] ) {
2986
+ this . state . verifyRangesReferenceEachOther ( ranges ) ;
2987
+ }
2988
+
2938
2989
public currentParameterHelpArgumentNameIs ( name : string ) {
2939
2990
this . state . verifyCurrentParameterHelpName ( name ) ;
2940
2991
}
0 commit comments