import { test } from "node:test";
import assert from "node:assert/strict";
import { highlight } from "../src/highlight.js";
const kinds = (tokens) => tokens.map((token) => `${token.kind}:${token.text}`);
test("go strings, comments, numbers and keywords are separated", () => {
const tokens = highlight('func main() {\n // note\n x := 42\n s := "hi"\n}', "go");
assert.ok(kinds(tokens).includes("keyword:func"));
assert.ok(kinds(tokens).includes("comment:// note"));
assert.ok(kinds(tokens).includes("number:42"));
assert.ok(kinds(tokens).includes('string:"hi"'));
assert.ok(kinds(tokens).some((entry) => entry.startsWith("plain: ")));
});
test("shell uses hash comments and javascript-style sharing is avoided", () => {
const tokens = highlight("echo hi # note\ncd /tmp", "sh");
assert.ok(kinds(tokens).includes("keyword:echo"));
assert.ok(kinds(tokens).includes("comment:# note"));
});
test("unknown languages still colour strings and numbers safely", () => {
const tokens = highlight('x = "a" + 2', "nonsense");
assert.ok(kinds(tokens).includes('string:"a"'));
assert.ok(kinds(tokens).includes("number:2"));
});
test("the output is token text only, never markup", () => {
const tokens = highlight('
', "html");
assert.equal(tokens.map((token) => token.text).join(""), '
');
assert.ok(tokens.every((token) => !("html" in token)));
});