const test = require("ava"); const HighlightPairedShortcode = require("../src/HighlightPairedShortcode"); test("Base", async t => { t.is(await HighlightPairedShortcode(`alert(); alert();`, "js", "", { alwaysWrapLineHighlights: true }), `
alert();
alert();
`);
});
test("Base with LF EOL, always wrap highlights", async t => {
t.is(await HighlightPairedShortcode('alert();\nalert();',
"js", "", { alwaysWrapLineHighlights: true }), `alert();
alert();
`);
});
test("Base with LF EOL, no wrap highlights", async t => {
t.is(await HighlightPairedShortcode('alert();\nalert();',
"js", "", { alwaysWrapLineHighlights: false }), `alert();
alert();
`);
});
test("Base with CRLF EOL, always wrap highlights", async t => {
t.is(await HighlightPairedShortcode('alert();\r\nalert();',
"js", "", { alwaysWrapLineHighlights: true }), `alert();
alert();
`);
});
test("Base with CRLF EOL, no wrap highlights", async t => {
t.is(await HighlightPairedShortcode('alert();\r\nalert();',
"js", "", { alwaysWrapLineHighlights: false }), `alert();
alert();
`);
});
test("Base with custom attributes", async t => {
t.is(await HighlightPairedShortcode(`alert();
alert();`, "js", "", { alwaysWrapLineHighlights: true, preAttributes: { tabindex: 0, 'data-testid': 'code' } }), `alert();
alert();
`);
});
test("Base change the line separator", async t => {
t.is(await HighlightPairedShortcode(`alert();
alert();`, "js", "", {
alwaysWrapLineHighlights: true,
lineSeparator: "\n",
}), `alert();
alert();
`);
});
test("Base No line highlights", async t => {
t.is(await HighlightPairedShortcode(`alert();
alert();`, "js", ""), `alert();
alert();
`);
});
test("Highlight Active", async t => {
t.is(await HighlightPairedShortcode(`alert();
alert();`, "js", "0", { alwaysWrapLineHighlights: true }), `alert();
alert();
`);
t.is(await HighlightPairedShortcode(`alert();
alert();`, "js", "0-1", { alwaysWrapLineHighlights: true }), `alert();
alert();
`);
});
test("Highlight Add/Remove", async t => {
t.is(await HighlightPairedShortcode(`alert();
alert();`, "js", "0 1", { alwaysWrapLineHighlights: true }), `alert();
alert();
`);
t.is(await HighlightPairedShortcode(`alert();
alert();`, "js", "1 0", { alwaysWrapLineHighlights: true }), `alert();
alert();
`);
});
test("Test loader typescript", async t => {
let script = `function greeter(person) {
return "Hello, " + person;
}
let user = "Jane User";
document.body.textContent = greeter(user);`;
t.is(await HighlightPairedShortcode(script, "typescript"), `function greeter(person) {
return "Hello, " + person;
}
let user = "Jane User";
document.body.textContent = greeter(user);
`);
});
test("Test loader ts", async t => {
let script = `function greeter(person) {
return "Hello, " + person;
}
let user = "Jane User";
document.body.textContent = greeter(user);`
t.is(await HighlightPairedShortcode(script, "ts"), `function greeter(person) {
return "Hello, " + person;
}
let user = "Jane User";
document.body.textContent = greeter(user);
`);
});
test("Test loader invalid language", async t => {
await t.throwsAsync(async () => {
await HighlightPairedShortcode("", "asldkjflksdaj");
});
});
test("Trim content option (defaults true)", async t => {
t.is(await HighlightPairedShortcode(` alert();
alert(); `, "js", "", {}), `alert();
alert();
`);
t.is(await HighlightPairedShortcode(` alert();
alert(); `, "js", "", { trim: true }), `alert();
alert();
`);
t.is(await HighlightPairedShortcode(` alert();
alert(); `, "js", "", { trim: false }), ` alert();
alert();
`);
});