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, with errorOnInvalidLanguage option", async t => { await t.throwsAsync(async () => { await HighlightPairedShortcode("", "asldkjflksdaj", null, { errorOnInvalidLanguage: true }); }, { message: `"asldkjflksdaj" is not a valid Prism.js language for eleventy-plugin-syntaxhighlight` }); }); test("Test loader invalid language (should pass)", async t => { t.is(await HighlightPairedShortcode("test test test", "asldkjflksdaj"), `
test test test
`) }); test("Test loader invalid language with ignore", async t => { let src = `hello hello` t.is(await HighlightPairedShortcode(src, "asldkjflksdaj"), `
hello
hello
`); }); 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();
`); });