@@ -2018,7 +2018,31 @@ namespace FourSlash {
2018
2018
return this . languageService . getCodeFixesAtPosition ( fileName , diagnostic . start , diagnostic . length , [ diagnostic . code ] ) ;
2019
2019
}
2020
2020
2021
- public verifyCodeFixAtPosition ( expectedTextArray : string [ ] , errorCode ?: number ) {
2021
+ public verifyCodeFixAtPosition ( expectedText : string , errorCode ?: number ) {
2022
+ const ranges = this . getRanges ( ) ;
2023
+ if ( ranges . length == 0 ) {
2024
+ this . raiseError ( "At least one range should be specified in the testfile." ) ;
2025
+ }
2026
+
2027
+ const actual = this . getCodeFixes ( errorCode ) ;
2028
+
2029
+ if ( ! actual || actual . length == 0 ) {
2030
+ this . raiseError ( "No codefixes returned." ) ;
2031
+ }
2032
+
2033
+ if ( actual . length > 1 ) {
2034
+ this . raiseError ( "More than 1 codefix returned." ) ;
2035
+ }
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 } '` ) ;
2042
+ }
2043
+ }
2044
+
2045
+ public verifyImportFixAtPosition ( expectedTextArray : string [ ] , errorCode ?: number ) {
2022
2046
const ranges = this . getRanges ( ) ;
2023
2047
if ( ranges . length == 0 ) {
2024
2048
this . raiseError ( "At least one range should be specified in the testfile." ) ;
@@ -2042,7 +2066,7 @@ namespace FourSlash {
2042
2066
const sortedActualArray = actualTextArray . sort ( ) ;
2043
2067
if ( ! ts . arrayIsEqualTo ( sortedExpectedArray , sortedActualArray ) ) {
2044
2068
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' ) } '` ) ;
2069
+ `Actual text array doesn't match expected text array. \nActual: \n" ${ sortedActualArray . join ( " \n\n" ) } " \n---\nExpected: \n'${ sortedExpectedArray . join ( " \n\n" ) } '` ) ;
2046
2070
}
2047
2071
}
2048
2072
@@ -3299,8 +3323,12 @@ namespace FourSlashInterface {
3299
3323
this . DocCommentTemplate ( /*expectedText*/ undefined , /*expectedOffset*/ undefined , /*empty*/ true ) ;
3300
3324
}
3301
3325
3302
- public codeFixAtPosition ( expectedTextArray : string [ ] , errorCode ?: number ) : void {
3303
- this . state . verifyCodeFixAtPosition ( expectedTextArray , errorCode ) ;
3326
+ public codeFixAtPosition ( expectedText : string , errorCode ?: number ) : void {
3327
+ this . state . verifyCodeFixAtPosition ( expectedText , errorCode ) ;
3328
+ }
3329
+
3330
+ public importFixAtPosition ( expectedTextArray : string [ ] , errorCode ?: number ) : void {
3331
+ this . state . verifyImportFixAtPosition ( expectedTextArray , errorCode ) ;
3304
3332
}
3305
3333
3306
3334
public navigationBar ( json : any ) {
0 commit comments