// @ts-check
"use strict";
const test = require("ava").default;
const helpers = require("../helpers");
test("clearHtmlCommentTextValid", (t) => {
t.plan(1);
const validComments = [
"",
"",
"",
"",
" ",
" ",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"texttext",
"texttext",
"texttext",
"",
"texttexttext",
"texttext",
"",
"",
"",
"",
" ",
" ",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"texttext",
"texttext",
"texttext",
"",
"texttexttext",
"texttext",
"",
"",
" -->",
"text-->",
"text-->",
"",
"-->",
"t-->",
"-->",
"t-->",
"t-->",
" "
];
const actual = helpers.clearHtmlCommentText(invalidComments.join("\n"));
const expected = invalidComments.join("\n");
t.is(actual, expected);
});
test("clearHtmlCommentTextNonGreedy", (t) => {
t.plan(1);
const nonGreedyComments = [
" -->",
" -->",
" -->",
" -->"
];
const nonGreedyResult = [
" -->",
" -->",
" -->",
" -->"
];
const actual = helpers.clearHtmlCommentText(nonGreedyComments.join("\n"));
const expected = nonGreedyResult.join("\n");
t.is(actual, expected);
});
test("clearHtmlCommentTextEmbedded", (t) => {
t.plan(1);
const embeddedComments = [
"texttext",
"",
"texttext",
"texttext",
"texttext"
];
const embeddedResult = [
"texttext",
"",
"texttext",
"texttext",
"texttext"
];
const actual = helpers.clearHtmlCommentText(embeddedComments.join("\n"));
const expected = embeddedResult.join("\n");
t.is(actual, expected);
});
test("unescapeMarkdown", (t) => {
t.plan(7);
// Test cases from https://spec.commonmark.org/0.29/#backslash-escapes
const testCases = [
[
"\\!\\\"\\#\\$\\%\\&\\'\\(\\)\\*\\+\\,\\-\\.\\/\\:\\;" +
"\\<\\=\\>\\?\\@\\[\\\\\\]\\^\\_\\`\\{\\|\\}\\~",
"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
],
[
"\\→\\A\\a\\ \\3\\φ\\«",
"\\→\\A\\a\\ \\3\\φ\\«"
],
[
`\\*not emphasized*
\\
not a tag
\\[not a link](/foo)
\\\`not code\`
1\\. not a list
\\* not a list
\\# not a heading
\\[foo]: /url "not a reference"
\\ö not a character entity`,
`*not emphasized*
not a tag
[not a link](/foo)
\`not code\`
1. not a list
* not a list
# not a heading
[foo]: /url "not a reference"
ö not a character entity`
],
[
"\\\\*emphasis*",
"\\*emphasis*"
],
[
`foo\\
bar`,
`foo\\
bar`
],
[
"Text \\<",
"Text _",
"_"
],
[
"Text \\\\<",
"Text _<",
"_"
]
];
testCases.forEach(function forTestCase(testCase) {
const [ markdown, expected, replacement ] = testCase;
const actual = helpers.unescapeMarkdown(markdown, replacement);
t.is(actual, expected);
});
});
test("isBlankLine", (t) => {
t.plan(33);
const blankLines = [
null,
"",
" ",
" ",
"\t\t\t",
"\r",
"\n",
"\t\r\n",
" ",
"",
"",
"\t",
">",
"> ",
"> > > \t",
"> ",
">>",
" ",
"-->",
"text --> --> text",
"text ",
"text text",
"text --> text --> text