| 289 | } |
| 290 | |
| 291 | function applyEllipses(actual: string, expected: string): string { |
| 292 | const changes = diffLines(expected, actual); |
| 293 | let result = ''; |
| 294 | for (let i = 0; i < changes.length; i++) { |
| 295 | const change = changes[i]; |
| 296 | if (change.removed) { |
| 297 | if (change.value.includes('…')) { |
| 298 | // Keep the ellipsis from expected |
| 299 | result += change.value; |
| 300 | // Skip any corresponding added block from actual |
| 301 | const nextChange = changes[i + 1]; |
| 302 | if (nextChange && nextChange.added) { |
| 303 | i++; |
| 304 | } |
| 305 | } else { |
| 306 | // Normal removal. If followed by an addition, it's a replacement. |
| 307 | const nextChange = changes[i + 1]; |
| 308 | if (nextChange && nextChange.added) { |
| 309 | result += nextChange.value; |
| 310 | i++; |
| 311 | } |
| 312 | } |
| 313 | } else if (change.added) { |
| 314 | // Pure addition |
| 315 | result += change.value; |
| 316 | } else { |
| 317 | // Unchanged |
| 318 | result += change.value; |
| 319 | } |
| 320 | } |
| 321 | return result; |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * Format virtual file content using Prettier |