1import * as NodeFS from "node:fs";
2import * as NodePath from "node:path";
3import { describe, expect, it } from "vite-plus/test";
4
5import { HIGHLIGHTS_LANGUAGE_IDS, HIGHLIGHTS_THEME_STYLES } from "../src/lib/highlights.generated";
6import { computeHighlightsData } from "./generate-highlights.mts";
7
8describe("generate highlights", () => {
9 // Token and language IDs are the native build's ABI. Bumping
10 // @pierre/highlights without regenerating would mislabel every token.
11 it("matches the installed @pierre/highlights", async () => {
12 const data = await computeHighlightsData();
13 const nativeSource = NodeFS.readFileSync(
14 NodePath.resolve(
15 import.meta.dirname,
16 "../modules/t3-highlights/Vendor/highlights/highlights.c",
17 ),
18 "utf8",
19 );
20
21 const stale = "Stale. Run WASM2C=<wabt 1.0.42>/bin/wasm2c vp run generate:highlights.";
22 expect(HIGHLIGHTS_LANGUAGE_IDS, stale).toEqual(data.languageIds);
23 expect(HIGHLIGHTS_THEME_STYLES, stale).toEqual(data.themeStyles);
24 expect(nativeSource.slice(0, nativeSource.indexOf("\n")), stale).toContain(
25 data.source.wasmSha256,
26 );
27 });
28});