Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

notebookOutput.test.ts

42 lines1.7 KB

1import { expect, it } from "vite-plus/test";
2​
3import { notebookStreamText } from "./notebookOutput.ts";
4​
5it.each([
6 ["Processing…\r\u001b[2KDone", "Done"],
7 ["Status: waiting\r\u001b[9G\u001b[Kdone", "Status: done"],
8 ["Status: waiting\u001b[7D\u001b[Kdone", "Status: done"],
9 ["Status: waiting\u001b[1;9f\u001b[Kdone", "Status: done"],
10 ["\u009b31mStatus: waiting\r\u009b9G\u009bKdone", "Status: done"],
11 ["HELLO\u001b[s\u001b[1G\u001b[KX\u001b[u!", "X !"],
12 ["def\u001b[F\u001b[Kdone", "done"],
13 ["A\u001b[31ḿ\u001b[K", "Á"],
14 ["界界界\rABC\rX\u001b[KDone", "XDone"],
15 ["界界界\rABC\rX\u001b[1K!", " !C 界"],
16 ["keep\u001b]0;\u009b2K\u0007end", "keepend"],
17 ["keep\u001b]0;\u001b[2K\u0007end", " end"],
18 ["界".repeat(8_000) + "\rX".repeat(5_000) + "\r\u001b[2KDone", "Done"],
19 ["á".repeat(110_000) + "\u001b[K".repeat(110_000) + "\r\u001b[2KDone", "Done"],
20 [
21 "a".repeat(1_000_000) + "\u001b[1K".repeat(1_000_000) + "\r" + "a".repeat(1_000_000),
22 "a".repeat(1_000_000),
23 ],
24 ["a" + "\u001b[999999C\u001b[2Kb\u001b[1G".repeat(100_000), "a" + "b".repeat(100_000)],
25])(
26 "applies horizontal cursor movement and line erases in a notebook stream (%#)",
27 (input, expected) => {
28 expect(notebookStreamText(input)).toBe(expected);
29 },
30);
31​
32it("bounds cursor padding across many short notebook lines", () => {
33 const input = "\u001b[999999999C\u001b[Kb\n\u009b999999999G\u009bKc\n".repeat(200);
34 const output = notebookStreamText(input);
35 expect(output.length).toBeLessThanOrEqual(input.length + 400);
36 expect(
37 output
38 .trim()
39 .split("\n")
40 .map((line) => line.trimStart()),
41 ).toEqual(Array.from({ length: 200 }, () => ["b", "c"]).flat());
42});