@@ -704,13 +704,55 @@ module FourSlash {
704
704
}
705
705
}
706
706
707
- public verifyCompletionListDoesNotContain ( symbol : string ) {
707
+ /**
708
+ * Verfiy that the completion list does NOT contain the given symbol. If text, or documentation, or kind are provided,
709
+ * the list contains the symbol all given parameters must matched. When any parameter is omitted, the parameters is ignored during comparison.
710
+ */
711
+ public verifyCompletionListDoesNotContain ( symbol : string , expectedText ?: string , expectedDocumentation ?: string , expectedKind ?: string ) {
712
+ let that = this ;
713
+ function filterByTextOrDocumentation ( entry : ts . CompletionEntry ) {
714
+ let details = that . getCompletionEntryDetails ( entry . name ) ;
715
+ let documentation = ts . displayPartsToString ( details . documentation ) ;
716
+ let text = ts . displayPartsToString ( details . displayParts ) ;
717
+ if ( expectedText && expectedDocumentation ) {
718
+ return ( documentation === expectedDocumentation && text === expectedText ) ? true : false ;
719
+ }
720
+ else if ( expectedText && ! expectedDocumentation ) {
721
+ return text === expectedText ? true : false ;
722
+ }
723
+ else if ( expectedDocumentation && ! expectedText ) {
724
+ return documentation === expectedDocumentation ? true : false ;
725
+ }
726
+ // Because expectedText and expectedDocumentation are undefined, we assume that
727
+ // users don't care to compare them so we will treat that entry as if the entry has matching text and documentation
728
+ // and keep it in the list of filtered entry.
729
+ return true ;
730
+ }
708
731
this . scenarioActions . push ( '<ShowCompletionList />' ) ;
709
732
this . scenarioActions . push ( '<VerifyCompletionDoesNotContainItem ItemName="' + escapeXmlAttributeValue ( symbol ) + '" />' ) ;
710
733
711
734
var completions = this . getCompletionListAtCaret ( ) ;
712
- if ( completions && completions . entries . filter ( e => e . name === symbol ) . length !== 0 ) {
713
- this . raiseError ( 'Completion list did contain ' + symbol ) ;
735
+ if ( completions ) {
736
+ let filterCompletions = completions . entries . filter ( e => e . name === symbol ) ;
737
+ filterCompletions = expectedKind ? filterCompletions . filter ( e => e . kind === expectedKind ) : filterCompletions ;
738
+ filterCompletions = filterCompletions . filter ( filterByTextOrDocumentation ) ;
739
+ if ( filterCompletions . length !== 0 ) {
740
+ // After filtered using all present criterion, if there are still symbol left in the list
741
+ // then these symbols must meet the criterion for Not supposed to be in the list. So we
742
+ // raise an error
743
+ let error = "Completion list did contain \'" + symbol + "\'." ;
744
+ let details = this . getCompletionEntryDetails ( filterCompletions [ 0 ] . name ) ;
745
+ if ( expectedText ) {
746
+ error += "Expected text: " + expectedText + " to equal: " + ts . displayPartsToString ( details . displayParts ) + "." ;
747
+ }
748
+ if ( expectedDocumentation ) {
749
+ error += "Expected documentation: " + expectedDocumentation + " to equal: " + ts . displayPartsToString ( details . documentation ) + "." ;
750
+ }
751
+ if ( expectedKind ) {
752
+ error += "Expected kind: " + expectedKind + " to equal: " + filterCompletions [ 0 ] . kind + "."
753
+ }
754
+ this . raiseError ( error ) ;
755
+ }
714
756
}
715
757
}
716
758
0 commit comments