diff --git a/packages/runtime/src/paint/ansi-tokenizer.test.ts b/packages/runtime/src/paint/ansi-tokenizer.test.ts index b345977..3f5c021 100644 --- a/packages/runtime/src/paint/ansi-tokenizer.test.ts +++ b/packages/runtime/src/paint/ansi-tokenizer.test.ts @@ -44,9 +44,11 @@ describe("ansi-tokenizer", () => { expect(tokens[0]!.type).toBe("csi"); }); - test("returns empty for empty string", () => { + test("empty string returns a single empty text token (Ink parity)", () => { + // Ink's tokenizeAnsi('') falls through to the no-control-chars branch and + // returns [{type:'text', value:''}] — it has no empty-string early return. const tokens = tokenizeAnsi(""); - expect(tokens).toHaveLength(0); + expect(tokens).toEqual([{ type: "text", value: "" }]); }); // --- Ink parity tests --- diff --git a/packages/runtime/src/paint/ansi-tokenizer.ts b/packages/runtime/src/paint/ansi-tokenizer.ts index f9567ed..fafddd8 100644 --- a/packages/runtime/src/paint/ansi-tokenizer.ts +++ b/packages/runtime/src/paint/ansi-tokenizer.ts @@ -322,10 +322,8 @@ const malformedFromIndex = ( }; export const tokenizeAnsi = (text: string): AnsiToken[] => { - if (text.length === 0) { - return []; - } - + // No empty-string early return: Ink falls through to the no-control-chars + // branch so tokenizeAnsi('') === [{type:'text', value:''}] (ansi-tokenizer.ts). if (!hasAnsiControlCharacters(text)) { return [{ type: "text", value: text }]; }