mirror of
https://github.com/earendil-works/pi.git
synced 2026-06-18 15:54:04 +08:00
23 lines
824 B
TypeScript
23 lines
824 B
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { stripAnsi } from "../src/utils/ansi.js";
|
|
|
|
describe("stripAnsi", () => {
|
|
it("strips RIS without leaking the final byte", () => {
|
|
expect(stripAnsi("\x1bcdone")).toBe("done");
|
|
});
|
|
|
|
it("strips single-byte ESC sequences without leaking final bytes", () => {
|
|
for (let code = "g".charCodeAt(0); code <= "m".charCodeAt(0); code++) {
|
|
expect(stripAnsi(`\x1b${String.fromCharCode(code)}ok`)).toBe("ok");
|
|
}
|
|
for (let code = "r".charCodeAt(0); code <= "t".charCodeAt(0); code++) {
|
|
expect(stripAnsi(`\x1b${String.fromCharCode(code)}ok`)).toBe("ok");
|
|
}
|
|
});
|
|
|
|
it("strips common ANSI sequences used in tool output", () => {
|
|
const input = "a\x1b[31mred\x1b[0m\x1b]8;;https://example.com\x07link\x1b]8;;\x07z";
|
|
expect(stripAnsi(input)).toBe("aredlinkz");
|
|
});
|
|
});
|