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

pendingCodeHighlight.test.ts

28 lines943 Bytes

1import { expect, it } from "vite-plus/test";
2import { pendingCodeHighlight } from "./pendingCodeHighlight";
3​
4it("keeps completed colors and exact current text without retaining an edited tail", () => {
5 const colored = [
6 [{ content: "const n = 1;", color: "red", fontStyle: 0 }],
7 [{ content: "partial", color: "blue", fontStyle: 0 }],
8 ];
9 const result = pendingCodeHighlight(
10 "const n = 1;\npartial",
11 "const n = 1;\nchanged\nnext",
12 colored,
13 )!;
14 expect(result[0]).toBe(colored[0]);
15 expect(result.map((line) => line.map((token) => token.content).join("")).join("\n")).toBe(
16 "const n = 1;\nchanged\nnext",
17 );
18 expect(
19 result
20 .slice(1)
21 .flat()
22 .every((token) => token.color === null),
23 ).toBe(true);
24 expect(
25 pendingCodeHighlight("const n = 1;\npartial", "const n = 2;\npartial", colored),
26 ).toBeNull();
27 expect(pendingCodeHighlight("partial", "other", colored)).toBeNull();
28});