fix(runtime): tokenizeAnsi('') returns a single empty text token, matching Ink (#95)
Ink's tokenizeAnsi has no empty-string early return — '' falls through to the
no-control-chars branch and yields [{type:'text', value:''}]. vue had an extra
`if (text.length === 0) return []` guard that diverged from Ink at the tokenizer
boundary. Removed it (the production caller sanitizeAnsi short-circuits '' before
tokenizing, so no behavior changes downstream) and flipped the test.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -44,9 +44,11 @@ describe("ansi-tokenizer", () => {
|
|||||||
expect(tokens[0]!.type).toBe("csi");
|
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("");
|
const tokens = tokenizeAnsi("");
|
||||||
expect(tokens).toHaveLength(0);
|
expect(tokens).toEqual([{ type: "text", value: "" }]);
|
||||||
});
|
});
|
||||||
|
|
||||||
// --- Ink parity tests ---
|
// --- Ink parity tests ---
|
||||||
|
|||||||
@@ -322,10 +322,8 @@ const malformedFromIndex = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const tokenizeAnsi = (text: string): AnsiToken[] => {
|
export const tokenizeAnsi = (text: string): AnsiToken[] => {
|
||||||
if (text.length === 0) {
|
// No empty-string early return: Ink falls through to the no-control-chars
|
||||||
return [];
|
// branch so tokenizeAnsi('') === [{type:'text', value:''}] (ansi-tokenizer.ts).
|
||||||
}
|
|
||||||
|
|
||||||
if (!hasAnsiControlCharacters(text)) {
|
if (!hasAnsiControlCharacters(text)) {
|
||||||
return [{ type: "text", value: text }];
|
return [{ type: "text", value: text }];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user