@@ -1,4 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resetCapabilitiesCache, setCapabilities } from "@earendil-works/pi-tui";
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import { highlightCode, initTheme } from "../src/modes/interactive/theme/theme.ts";
|
||||
import { highlight, renderHighlightedHtml, supportsLanguage } from "../src/utils/syntax-highlight.ts";
|
||||
|
||||
describe("syntax highlight renderer", () => {
|
||||
@@ -46,3 +48,29 @@ describe("syntax highlight renderer", () => {
|
||||
expect(rendered).toContain("[number:1]");
|
||||
});
|
||||
});
|
||||
|
||||
describe("theme syntax highlighting", () => {
|
||||
beforeEach(() => {
|
||||
setCapabilities({ images: null, trueColor: true, hyperlinks: false });
|
||||
initTheme("dark");
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
resetCapabilitiesCache();
|
||||
});
|
||||
|
||||
it("colors diff additions and deletions in fenced diff blocks", () => {
|
||||
const lines = highlightCode("-old\n+new\n", "diff");
|
||||
|
||||
expect(lines[0]).toBe("\x1b[38;2;204;102;102m-old\x1b[39m");
|
||||
expect(lines[1]).toBe("\x1b[38;2;181;189;104m+new\x1b[39m");
|
||||
});
|
||||
|
||||
it("keeps cli-highlight default styled scopes mapped to theme styles", () => {
|
||||
expect(highlightCode("const re = /foo+/gi;", "javascript")[0]).toContain(
|
||||
"\x1b[38;2;206;145;120m/foo+/gi\x1b[39m",
|
||||
);
|
||||
expect(highlightCode("@decorator", "python")[0]).toBe("\x1b[38;2;128;128;128m@decorator\x1b[39m");
|
||||
expect(highlightCode("<div></div>", "html")[0]).toContain("\x1b[38;2;86;156;214mdiv\x1b[39m");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user