(ops: readonly TestRecordedOp[], viewport: TestViewport)
| 336 | } |
| 337 | |
| 338 | function opsToText(ops: readonly TestRecordedOp[], viewport: TestViewport): string { |
| 339 | const grid: string[][] = []; |
| 340 | for (let y = 0; y < viewport.rows; y++) { |
| 341 | grid.push(new Array(viewport.cols).fill(" ")); |
| 342 | } |
| 343 | const clipStack: ClipRect[] = []; |
| 344 | |
| 345 | for (const op of ops) { |
| 346 | if (op.kind === "clear") { |
| 347 | fillGridRect(grid, viewport, clipStack, { x: 0, y: 0, w: viewport.cols, h: viewport.rows }); |
| 348 | continue; |
| 349 | } |
| 350 | |
| 351 | if (op.kind === "clearTo") { |
| 352 | fillGridRect(grid, viewport, clipStack, { x: 0, y: 0, w: op.cols, h: op.rows }); |
| 353 | continue; |
| 354 | } |
| 355 | |
| 356 | if (op.kind === "fillRect") { |
| 357 | fillGridRect(grid, viewport, clipStack, op); |
| 358 | continue; |
| 359 | } |
| 360 | |
| 361 | if (op.kind === "drawText") { |
| 362 | drawTextToGrid(grid, viewport, clipStack, op.x, op.y, op.text); |
| 363 | continue; |
| 364 | } |
| 365 | |
| 366 | if (op.kind === "pushClip") { |
| 367 | clipStack.push({ x: op.x, y: op.y, w: op.w, h: op.h }); |
| 368 | continue; |
| 369 | } |
| 370 | |
| 371 | if (op.kind === "popClip") { |
| 372 | clipStack.pop(); |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | const lines = grid.map((row) => row.join("").replace(/\s+$/u, "")); |
| 377 | while (lines.length > 1 && lines[lines.length - 1] === "") lines.pop(); |
| 378 | return lines.join("\n"); |
| 379 | } |
| 380 | |
| 381 | function findById(nodes: readonly TestRenderNode[], id: string): TestRenderNode | null { |
| 382 | for (const node of nodes) { |
no test coverage detected