The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { keyedLines, wordsOf } from "./HighlightedTokens"; |
| 4 | |
| 5 | function tokensOf(...contents: string[]) { |
| 6 | let offset = 0; |
| 7 | return contents.map((content) => { |
| 8 | const token = { content, offset }; |
| 9 | offset += content.length; |
| 10 | return token; |
| 11 | }); |
| 12 | } |
| 13 | |
| 14 | describe("wordsOf", () => { |
| 15 | it("keeps each piece's own token so colors survive regrouping", () => { |
| 16 | const [word] = wordsOf(tokensOf('"', "$HOME", '"')); |
| 17 | expect( |
| 18 | typeof word === "string" ? null : word?.pieces.map((piece) => piece.token.content), |
| 19 | ).toEqual(['"', "$HOME", '"']); |
| 20 | }); |
| 21 | }); |
| 22 | |
| 23 | describe("keyedLines", () => { |
| 24 | it.each([ |
| 25 | "git status\ngit diff", |
| 26 | "Get-ChildItem\r\nWrite-Output done\r\n", |
| 27 | "mixed\r\nendings\n\nlone \r stays", |
| 28 | ])("renders the same text as the source: %j", (code) => { |
| 29 | const lines = code.split(/\r?\n/u).map((line) => tokensOf(line)); |
| 30 | const rendered = keyedLines(code, lines) |
| 31 | .map(({ tokens, ending }) => tokens.map((token) => token.content).join("") + ending) |
| 32 | .join(""); |
| 33 | expect(rendered).toBe(code); |
| 34 | }); |
| 35 | }); |