( screen: ScenarioScreenSnapshot, args: ScenarioScreenRegionAssertion, path: string, )
| 80 | } |
| 81 | |
| 82 | export function assertScreenRegion( |
| 83 | screen: ScenarioScreenSnapshot, |
| 84 | args: ScenarioScreenRegionAssertion, |
| 85 | path: string, |
| 86 | ): ScenarioMismatch | null { |
| 87 | const expectedSource = typeof args.text === "string" ? args.text.split("\n") : [...args.text]; |
| 88 | const expectedLines = expectedSource.map((line: string) => |
| 89 | line.padEnd(args.width, " ").slice(0, args.width), |
| 90 | ); |
| 91 | const actualLines: string[] = []; |
| 92 | for (let row = 0; row < args.height; row++) { |
| 93 | const line = screen.lines[args.y + row] ?? "".padEnd(screen.cols, " "); |
| 94 | actualLines.push(line.slice(args.x, args.x + args.width).padEnd(args.width, " ")); |
| 95 | } |
| 96 | const matchMode = args.match ?? "exact"; |
| 97 | const passed = |
| 98 | matchMode === "includes" |
| 99 | ? expectedLines.every((line: string, index: number) => |
| 100 | (actualLines[index] ?? "").includes(line.trimEnd()), |
| 101 | ) |
| 102 | : expectedLines.length === actualLines.length && |
| 103 | expectedLines.every((line: string, index: number) => line === (actualLines[index] ?? "")); |
| 104 | if (passed) return null; |
| 105 | return { |
| 106 | code: "ZR_SCENARIO_SCREEN_MISMATCH", |
| 107 | path, |
| 108 | detail: `Screen region assertion failed (${matchMode})`, |
| 109 | expected: expectedLines, |
| 110 | actual: actualLines, |
| 111 | }; |
| 112 | } |
| 113 | |
| 114 | export function assertCursor( |
| 115 | actual: ScenarioCursorSnapshot | null, |
no test coverage detected