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

notebookOutput.test.ts

60 lines2.6 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 ["界界界界\twaiting\u001b[17G\u001b[Kdone", "界界界界 done"],
11 ["12345678waiting\r\t\u001b[Kdone", "12345678done"],
12 ["done\t\u001b[K", "done"],
13 ["\t\t\t\u001b[1CX\u001b[K", " ".repeat(25) + "X"],
14 [("\t".repeat(8) + "X\r\u001b[2K").repeat(20) + "Done", "Done"],
15 ["\t".repeat(8) + "waiting" + "\u001b[1K".repeat(20) + "\r\u001b[2KDone", "Done"],
16 ["\t".repeat(8) + "waiting" + "\rZ\u001b[72G\u001b[1K".repeat(100) + "\r\u001b[2KDone", "Done"],
17 ["\t".repeat(8) + "waiting" + "\u001b[1K".repeat(20) + "\rZ\u001b[1Kdone\u001b[K", " done"],
18 ["\u009b31mStatus: waiting\r\u009b9G\u009bKdone", "Status: done"],
19 ["HELLO\u001b[s\u001b[1G\u001b[KX\u001b[u!", "X !"],
20 ["def\u001b[F\u001b[Kdone", "done"],
21 ["A\u001b[31ḿ\u001b[K", "Á"],
22 ["界界界\rABC\rX\u001b[KDone", "XDone"],
23 ["界界界\rABC\rX\u001b[1K!", " !C 界"],
24 ["keep\u001b]0;\u009b2K\u0007end", "keepend"],
25 ["keep\u001b]0;\u001b[2K\u0007end", " end"],
26 ["界".repeat(8_000) + "\rX".repeat(5_000) + "\r\u001b[2KDone", "Done"],
27 ["á".repeat(110_000) + "\u001b[K".repeat(110_000) + "\r\u001b[2KDone", "Done"],
28 [
29 "a".repeat(1_000_000) + "\u001b[1K".repeat(1_000_000) + "\r" + "a".repeat(1_000_000),
30 "a".repeat(1_000_000),
31 ],
32 ["a" + "\u001b[999999C\u001b[2Kb\u001b[1G".repeat(100_000), "a" + "b".repeat(100_000)],
33])(
34 "applies horizontal cursor movement and line erases in a notebook stream (%#)",
35 (input, expected) => {
36 expect(notebookStreamText(input)).toBe(expected);
37 },
38);
39​
40it.each([
41 ["a\tbc\rXYZW", "XYZW bc"],
42 ["abcdefghij\r\tX", "abcdefghXj"],
43 ["ab\u009b31mcdefg\th\rZ", "Zbcdefg h"],
44 ["ab\u001b]0;title\u0007cdefg\th\rZ", "Zbcdefg h"],
45 ["a\tb\rX\bY", "Y b"],
46])("uses tab stops in a carriage-return redraw (%#)", (input, expected) => {
47 expect(notebookStreamText(input)).toBe(expected);
48});
49​
50it("bounds cursor padding across many short notebook lines", () => {
51 const input = "\u001b[999999999C\u001b[Kb\n\u009b999999999G\u009bKc\n".repeat(200);
52 const output = notebookStreamText(input);
53 expect(output.length).toBeLessThanOrEqual(input.length + 400);
54 expect(
55 output
56 .trim()
57 .split("\n")
58 .map((line) => line.trimStart()),
59 ).toEqual(Array.from({ length: 200 }, () => ["b", "c"]).flat());
60});