* The `program` reading, one line per item, indented — the rail as a reader * meets it. A step prints its label, a fork its condition and each arm's, a * bracketed run its words.
(p: Awaited<ReturnType<typeof buildSteps>>)
| 286 | * bracketed run its words. |
| 287 | */ |
| 288 | function inOrder(p: Awaited<ReturnType<typeof buildSteps>>): string[] { |
| 289 | const label = (id: string) => p.steps.find((s) => s.id === id)?.label ?? id; |
| 290 | const out: string[] = []; |
| 291 | const walk = (block: WireBlock, indent: string): void => { |
| 292 | for (const item of block) { |
| 293 | if (item.kind === 'step') { |
| 294 | out.push(`${indent}${label(item.step)}${item.again ? ' (again)' : ''}`); |
| 295 | if (item.body) walk(item.body, `${indent} `); |
| 296 | } else if (item.kind === 'fork') { |
| 297 | out.push(`${indent}${item.form} ${item.on}`); |
| 298 | for (const arm of item.arms) { |
| 299 | out.push(`${indent} ${arm.when}${arm.ends ? ` → ${arm.ends}` : ''}`); |
| 300 | walk(arm.body, `${indent} `); |
| 301 | } |
| 302 | } else if (item.kind === 'block') { |
| 303 | out.push(`${indent}${item.block} ${item.via?.name ?? item.by ?? ''}`.trimEnd()); |
| 304 | walk(item.body, `${indent} `); |
| 305 | } else out.push(`${indent}cut ${item.why}`); |
| 306 | } |
| 307 | }; |
| 308 | if (p.program) walk(p.program.root, ''); |
| 309 | return out; |
| 310 | } |
| 311 | |
| 312 | describe('in the code’s order', () => { |
| 313 | it('reads an Express handler as it is written, helper and all', async () => { |
no test coverage detected