@@ -2018,27 +2018,31 @@ namespace FourSlash {
2018
2018
return this . languageService . getCodeFixesAtPosition ( fileName , diagnostic . start , diagnostic . length , [ diagnostic . code ] ) ;
2019
2019
}
2020
2020
2021
- public verifyCodeFixAtPosition ( expectedText : string , errorCode ?: number ) {
2021
+ public verifyCodeFixAtPosition ( expectedTextArray : string [ ] , errorCode ?: number ) {
2022
2022
const ranges = this . getRanges ( ) ;
2023
2023
if ( ranges . length == 0 ) {
2024
2024
this . raiseError ( "At least one range should be specified in the testfile." ) ;
2025
2025
}
2026
2026
2027
- const actual = this . getCodeFixes ( errorCode ) ;
2027
+ const codeFixes = this . getCodeFixes ( errorCode ) ;
2028
2028
2029
- if ( ! actual || actual . length == 0 ) {
2029
+ if ( ! codeFixes || codeFixes . length == 0 ) {
2030
2030
this . raiseError ( "No codefixes returned." ) ;
2031
2031
}
2032
2032
2033
- if ( actual . length > 1 ) {
2034
- this . raiseError ( "More than 1 codefix returned." ) ;
2033
+ const actualTextArray : string [ ] = [ ] ;
2034
+ const scriptInfo = this . languageServiceAdapterHost . getScriptInfo ( codeFixes [ 0 ] . changes [ 0 ] . fileName ) ;
2035
+ const originalContent = scriptInfo . content ;
2036
+ for ( const codeFix of codeFixes ) {
2037
+ this . applyEdits ( codeFix . changes [ 0 ] . fileName , codeFix . changes [ 0 ] . textChanges , /*isFormattingEdit*/ false ) ;
2038
+ actualTextArray . push ( this . normalizeNewlines ( this . rangeText ( ranges [ 0 ] ) ) ) ;
2039
+ scriptInfo . updateContent ( originalContent ) ;
2035
2040
}
2036
-
2037
- this . applyEdits ( actual [ 0 ] . changes [ 0 ] . fileName , actual [ 0 ] . changes [ 0 ] . textChanges , /*isFormattingEdit*/ false ) ;
2038
- const actualText = this . rangeText ( ranges [ 0 ] ) ;
2039
-
2040
- if ( this . removeWhitespace ( actualText ) !== this . removeWhitespace ( expectedText ) ) {
2041
- this . raiseError ( `Actual text doesn't match expected text. Actual: '${ actualText } ' Expected: '${ expectedText } '` ) ;
2041
+ const sortedExpectedArray = ts . map ( expectedTextArray , str => this . normalizeNewlines ( str ) ) . sort ( ) ;
2042
+ const sortedActualArray = actualTextArray . sort ( ) ;
2043
+ if ( ! ts . arrayIsEqualTo ( sortedExpectedArray , sortedActualArray ) ) {
2044
+ this . raiseError (
2045
+ `Actual text array doesn't match expected text array. \nActual: \n'${ sortedActualArray . join ( '\n\n' ) } '\n---\nExpected: \n'${ sortedExpectedArray . join ( '\n\n' ) } '` ) ;
2042
2046
}
2043
2047
}
2044
2048
@@ -2075,6 +2079,10 @@ namespace FourSlash {
2075
2079
} ) ;
2076
2080
}
2077
2081
2082
+ private normalizeNewlines ( str : string ) {
2083
+ return str . replace ( / \r ? \n / g, "\n" ) ;
2084
+ }
2085
+
2078
2086
public verifyBraceCompletionAtPosition ( negative : boolean , openingBrace : string ) {
2079
2087
2080
2088
const openBraceMap = ts . createMap < ts . CharacterCodes > ( {
@@ -3291,8 +3299,8 @@ namespace FourSlashInterface {
3291
3299
this . DocCommentTemplate ( /*expectedText*/ undefined , /*expectedOffset*/ undefined , /*empty*/ true ) ;
3292
3300
}
3293
3301
3294
- public codeFixAtPosition ( expectedText : string , errorCode ?: number ) : void {
3295
- this . state . verifyCodeFixAtPosition ( expectedText , errorCode ) ;
3302
+ public codeFixAtPosition ( expectedTextArray : string [ ] , errorCode ?: number ) : void {
3303
+ this . state . verifyCodeFixAtPosition ( expectedTextArray , errorCode ) ;
3296
3304
}
3297
3305
3298
3306
public navigationBar ( json : any ) {
0 commit comments