@@ -948,7 +948,7 @@ namespace FourSlash {
948
948
949
949
const actual = checker . typeToString ( type ) ;
950
950
if ( actual !== expected ) {
951
- this . raiseError ( `Expected: ' ${ expected } ' , actual: ' ${ actual } '` ) ;
951
+ this . raiseError ( displayExpectedAndActualString ( expected , actual ) ) ;
952
952
}
953
953
}
954
954
@@ -1024,9 +1024,7 @@ namespace FourSlash {
1024
1024
private assertObjectsEqual < T > ( fullActual : T , fullExpected : T , msgPrefix = "" ) : void {
1025
1025
const recur = < U > ( actual : U , expected : U , path : string ) => {
1026
1026
const fail = ( msg : string ) => {
1027
- this . raiseError ( `${ msgPrefix } At ${ path } : ${ msg }
1028
- Expected: ${ stringify ( fullExpected ) }
1029
- Actual: ${ stringify ( fullActual ) } ` ) ;
1027
+ this . raiseError ( `${ msgPrefix } At ${ path } : ${ msg } ${ displayExpectedAndActualString ( stringify ( fullExpected ) , stringify ( fullActual ) ) } ` ) ;
1030
1028
} ;
1031
1029
1032
1030
if ( ( actual === undefined ) !== ( expected === undefined ) ) {
@@ -1058,9 +1056,7 @@ Actual: ${stringify(fullActual)}`);
1058
1056
if ( fullActual === fullExpected ) {
1059
1057
return ;
1060
1058
}
1061
- this . raiseError ( `${ msgPrefix }
1062
- Expected: ${ stringify ( fullExpected ) }
1063
- Actual: ${ stringify ( fullActual ) } ` ) ;
1059
+ this . raiseError ( `${ msgPrefix } ${ displayExpectedAndActualString ( stringify ( fullExpected ) , stringify ( fullActual ) ) } ` ) ;
1064
1060
}
1065
1061
recur ( fullActual , fullExpected , "" ) ;
1066
1062
@@ -2111,9 +2107,7 @@ Actual: ${stringify(fullActual)}`);
2111
2107
public verifyCurrentLineContent ( text : string ) {
2112
2108
const actual = this . getCurrentLineContent ( ) ;
2113
2109
if ( actual !== text ) {
2114
- throw new Error ( "verifyCurrentLineContent\n" +
2115
- "\tExpected: \"" + text + "\"\n" +
2116
- "\t Actual: \"" + actual + "\"" ) ;
2110
+ throw new Error ( "verifyCurrentLineContent\n" + displayExpectedAndActualString ( text , actual , /* quoted */ true ) ) ;
2117
2111
}
2118
2112
}
2119
2113
@@ -2139,25 +2133,19 @@ Actual: ${stringify(fullActual)}`);
2139
2133
public verifyTextAtCaretIs ( text : string ) {
2140
2134
const actual = this . getFileContent ( this . activeFile . fileName ) . substring ( this . currentCaretPosition , this . currentCaretPosition + text . length ) ;
2141
2135
if ( actual !== text ) {
2142
- throw new Error ( "verifyTextAtCaretIs\n" +
2143
- "\tExpected: \"" + text + "\"\n" +
2144
- "\t Actual: \"" + actual + "\"" ) ;
2136
+ throw new Error ( "verifyTextAtCaretIs\n" + displayExpectedAndActualString ( text , actual , /* quoted */ true ) ) ;
2145
2137
}
2146
2138
}
2147
2139
2148
2140
public verifyCurrentNameOrDottedNameSpanText ( text : string ) {
2149
2141
const span = this . languageService . getNameOrDottedNameSpan ( this . activeFile . fileName , this . currentCaretPosition , this . currentCaretPosition ) ;
2150
2142
if ( ! span ) {
2151
- return this . raiseError ( "verifyCurrentNameOrDottedNameSpanText\n" +
2152
- "\tExpected: \"" + text + "\"\n" +
2153
- "\t Actual: undefined" ) ;
2143
+ return this . raiseError ( "verifyCurrentNameOrDottedNameSpanText\n" + displayExpectedAndActualString ( "\"" + text + "\"" , "undefined" ) ) ;
2154
2144
}
2155
2145
2156
2146
const actual = this . getFileContent ( this . activeFile . fileName ) . substring ( span . start , ts . textSpanEnd ( span ) ) ;
2157
2147
if ( actual !== text ) {
2158
- this . raiseError ( "verifyCurrentNameOrDottedNameSpanText\n" +
2159
- "\tExpected: \"" + text + "\"\n" +
2160
- "\t Actual: \"" + actual + "\"" ) ;
2148
+ this . raiseError ( "verifyCurrentNameOrDottedNameSpanText\n" + displayExpectedAndActualString ( text , actual , /* quoted */ true ) ) ;
2161
2149
}
2162
2150
}
2163
2151
@@ -3690,7 +3678,7 @@ ${code}
3690
3678
expected = makeWhitespaceVisible ( expected ) ;
3691
3679
actual = makeWhitespaceVisible ( actual ) ;
3692
3680
}
3693
- return `Expected:\n ${ expected } \nActual:\n ${ actual } ` ;
3681
+ return displayExpectedAndActualString ( expected , actual ) ;
3694
3682
}
3695
3683
3696
3684
function differOnlyByWhitespace ( a : string , b : string ) {
@@ -3710,6 +3698,14 @@ ${code}
3710
3698
}
3711
3699
}
3712
3700
}
3701
+
3702
+ function displayExpectedAndActualString ( expected : string , actual : string , quoted = false ) {
3703
+ const expectMsg = "\x1b[1mExpected\x1b[0m\x1b[31m" ;
3704
+ const actualMsg = "\x1b[1mActual\x1b[0m\x1b[31m" ;
3705
+ const expectedString = quoted ? "\"" + expected + "\"" : expected ;
3706
+ const actualString = quoted ? "\"" + actual + "\"" : actual ;
3707
+ return `\n${ expectMsg } :\n${ expectedString } \n\n${ actualMsg } :\n${ actualString } ` ;
3708
+ }
3713
3709
}
3714
3710
3715
3711
namespace FourSlashInterface {
0 commit comments