@@ -122,7 +122,7 @@ function createErrDiff(actual, expected, operator) {
122
122
let a = actualLines [ actualLines . length - 1 ] ;
123
123
let b = expectedLines [ expectedLines . length - 1 ] ;
124
124
while ( a === b ) {
125
- if ( i ++ < 2 ) {
125
+ if ( i ++ < 3 ) {
126
126
end = `\n ${ a } ${ end } ` ;
127
127
} else {
128
128
other = a ;
@@ -154,7 +154,9 @@ function createErrDiff(actual, expected, operator) {
154
154
return `${ kReadableOperator . notIdentical } \n\n${ actualLines . join ( '\n' ) } \n` ;
155
155
}
156
156
157
- if ( i > 3 ) {
157
+ // There were at least five identical lines at the end. Mark a couple of
158
+ // skipped.
159
+ if ( i >= 5 ) {
158
160
end = `\n${ blue } ...${ white } ${ end } ` ;
159
161
skipped = true ;
160
162
}
@@ -169,46 +171,46 @@ function createErrDiff(actual, expected, operator) {
169
171
`\n${ green } + actual${ white } ${ red } - expected${ white } ` ;
170
172
const skippedMsg = ` ${ blue } ...${ white } Lines skipped` ;
171
173
174
+ let lines = actualLines ;
175
+ let plusMinus = `${ green } +${ white } ` ;
176
+ let maxLength = expectedLines . length ;
177
+ if ( actualLines . length < maxLines ) {
178
+ lines = expectedLines ;
179
+ plusMinus = `${ red } -${ white } ` ;
180
+ maxLength = actualLines . length ;
181
+ }
182
+
172
183
for ( i = 0 ; i < maxLines ; i ++ ) {
173
- if ( actualLines . length < i + 1 ) {
174
- // If more than one former line is identical, print that . Collapse those
175
- // in case more than three lines before were identical.
176
- if ( identical > 1 ) {
184
+ if ( maxLength < i + 1 ) {
185
+ // If more than two former lines are identical, print them . Collapse them
186
+ // in case more than five lines were identical.
187
+ if ( identical > 2 ) {
177
188
if ( identical > 3 ) {
178
- res += `\n${ blue } ...${ white } ` ;
179
- skipped = true ;
180
- } else if ( identical > 2 ) {
181
- res += `\n ${ expectedLines [ i - 2 ] } ` ;
189
+ if ( identical > 4 ) {
190
+ if ( identical === 5 ) {
191
+ res += `\n ${ lines [ i - 3 ] } ` ;
192
+ printedLines ++ ;
193
+ } else {
194
+ res += `\n${ blue } ...${ white } ` ;
195
+ skipped = true ;
196
+ }
197
+ }
198
+ res += `\n ${ lines [ i - 2 ] } ` ;
182
199
printedLines ++ ;
183
200
}
184
- res += `\n ${ expectedLines [ i - 1 ] } ` ;
201
+ res += `\n ${ lines [ i - 1 ] } ` ;
185
202
printedLines ++ ;
186
203
}
187
204
// No identical lines before.
188
205
identical = 0 ;
189
206
// Add the expected line to the cache.
190
- other += `\n${ red } -${ white } ${ expectedLines [ i ] } ` ;
191
- printedLines ++ ;
192
- // Only extra actual lines exist
193
- } else if ( expectedLines . length < i + 1 ) {
194
- // If more than one former line is identical, print that. Collapse those
195
- // in case more than three lines before were identical.
196
- if ( identical > 1 ) {
197
- if ( identical > 3 ) {
198
- res += `\n${ blue } ...${ white } ` ;
199
- skipped = true ;
200
- } else if ( identical > 2 ) {
201
- res += `\n ${ actualLines [ i - 2 ] } ` ;
202
- printedLines ++ ;
203
- }
204
- res += `\n ${ actualLines [ i - 1 ] } ` ;
205
- printedLines ++ ;
207
+ if ( lines === actualLines ) {
208
+ res += `\n${ plusMinus } ${ lines [ i ] } ` ;
209
+ } else {
210
+ other += `\n${ plusMinus } ${ lines [ i ] } ` ;
206
211
}
207
- // No identical lines before.
208
- identical = 0 ;
209
- // Add the actual line to the result.
210
- res += `\n${ green } +${ white } ${ actualLines [ i ] } ` ;
211
212
printedLines ++ ;
213
+ // Only extra actual lines exist
212
214
// Lines diverge
213
215
} else {
214
216
const expectedLine = expectedLines [ i ] ;
@@ -235,13 +237,19 @@ function createErrDiff(actual, expected, operator) {
235
237
actualLine += ',' ;
236
238
}
237
239
if ( divergingLines ) {
238
- // If more than one former line is identical, print that . Collapse those
239
- // in case more than three lines before were identical.
240
- if ( identical > 1 ) {
240
+ // If more than two former lines are identical, print them . Collapse
241
+ // them in case more than five lines were identical.
242
+ if ( identical > 2 ) {
241
243
if ( identical > 3 ) {
242
- res += `\n${ blue } ...${ white } ` ;
243
- skipped = true ;
244
- } else if ( identical > 2 ) {
244
+ if ( identical > 4 ) {
245
+ if ( identical === 5 ) {
246
+ res += `\n ${ actualLines [ i - 3 ] } ` ;
247
+ printedLines ++ ;
248
+ } else {
249
+ res += `\n${ blue } ...${ white } ` ;
250
+ skipped = true ;
251
+ }
252
+ }
245
253
res += `\n ${ actualLines [ i - 2 ] } ` ;
246
254
printedLines ++ ;
247
255
}
@@ -264,7 +272,7 @@ function createErrDiff(actual, expected, operator) {
264
272
identical ++ ;
265
273
// The very first identical line since the last diverging line is be
266
274
// added to the result.
267
- if ( identical === 1 ) {
275
+ if ( identical <= 2 ) {
268
276
res += `\n ${ actualLine } ` ;
269
277
printedLines ++ ;
270
278
}
0 commit comments