Skip to content

Commit afd1449

Browse files
committed
test(core): add newline wrap renderer regression coverage
1 parent be73751 commit afd1449

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

packages/core/src/renderer/__tests__/renderer.text.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,44 @@ function expectBlob(frame: ParsedFrame, blobIndex: number): TextRunBlob {
296296
return blob;
297297
}
298298

299+
function drawTextsByY(frame: ParsedFrame): readonly DrawTextCommand[] {
300+
return Object.freeze([...frame.drawTexts].sort((a, b) => a.y - b.y || a.x - b.x));
301+
}
302+
303+
describe("renderer text - wrap newline handling", () => {
304+
test("wrap=true renders explicit newline lines on separate rows", () => {
305+
const frame = parseFrame(
306+
renderBytes(textVNode("First line\nSecond line", { wrap: true }), { cols: 20, rows: 4 }),
307+
);
308+
const draws = drawTextsByY(frame).filter((cmd) => cmd.text.length > 0);
309+
310+
assert.equal(draws.length, 2);
311+
const first = draws[0];
312+
const second = draws[1];
313+
assert.ok(first !== undefined);
314+
assert.ok(second !== undefined);
315+
assert.equal(first.y, 0);
316+
assert.equal(first.text, "First line");
317+
assert.equal(second.y, 1);
318+
assert.equal(second.text, "Second line");
319+
});
320+
321+
test("wrap=true preserves blank lines from double newlines", () => {
322+
const frame = parseFrame(renderBytes(textVNode("Alpha\n\nOmega", { wrap: true }), { cols: 20, rows: 6 }));
323+
const draws = drawTextsByY(frame).filter((cmd) => cmd.text.length > 0);
324+
325+
assert.equal(draws.length, 2);
326+
const first = draws[0];
327+
const second = draws[1];
328+
assert.ok(first !== undefined);
329+
assert.ok(second !== undefined);
330+
assert.equal(first.y, 0);
331+
assert.equal(first.text, "Alpha");
332+
assert.equal(second.y, 2);
333+
assert.equal(second.text, "Omega");
334+
});
335+
});
336+
299337
describe("renderer text - transform ANSI styling", () => {
300338
const gradientTransform = (): string => "\u001b[31mA\u001b[32mB\u001b[0m";
301339

0 commit comments

Comments
 (0)