highlight.test.mjsJavaScript31 lines1.3 KiBraw download
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { loadTs } from './_loadts.mjs';
const { escapeHtml, highlightCommand } = await loadTs('src/lib/highlight.ts');
test('escapeHtml neutralises markup and attribute delimiters', () => {
const out = escapeHtml('<b onclick="x">&</b>');
assert.ok(!out.includes('<'));
assert.ok(!out.includes('>'));
assert.ok(!out.includes('"'));
assert.equal(out, '<b onclick="x">&</b>');
assert.equal(escapeHtml(123), '123');
});
test('highlightCommand never emits raw input markup', () => {
const out = highlightCommand('echo <script>alert(1)</script> "a<b"');
assert.ok(!/<script/.test(out));
assert.ok(!out.includes('a<b'));
assert.ok(out.includes('<script>'));
});
test('highlightCommand token classes', () => {
const out = highlightCommand('sudo tar -cf /dev/null 10.10.10.10 | sh');
assert.match(out, /<span class="tk-cmd">sudo<\/span>/);
assert.match(out, /<span class="tk-flag">-cf<\/span>/);
assert.match(out, /<span class="tk-num">10\.10\.10\.10<\/span>/);
assert.match(out, /<span class="tk-op">\|<\/span>/);
assert.equal(highlightCommand('# a comment'), '<span class="tk-muted"># a comment</span>');
assert.equal(highlightCommand('a\nb').split('\n').length, 2);
});