2020-07-23 22:41:45 +02:00
|
|
|
const fenced_code = zrequire("fenced_code", "shared/js/fenced_code");
|
2019-08-26 09:04:34 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("get_unused_fence", () => {
|
|
|
|
assert.equal(fenced_code.get_unused_fence("```js\nsomething\n```"), "`".repeat(4));
|
|
|
|
assert.equal(fenced_code.get_unused_fence("````\nsomething\n````"), "`".repeat(5));
|
|
|
|
assert.equal(fenced_code.get_unused_fence("```\n````\n``````"), "`".repeat(7));
|
|
|
|
assert.equal(fenced_code.get_unused_fence("~~~\nsomething\n~~~"), "`".repeat(3));
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
fenced_code.get_unused_fence("```code\nterminating fence is indented and longer\n ````"),
|
|
|
|
"`".repeat(5),
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
fenced_code.get_unused_fence("```code\nterminating fence is extra indented\n ````"),
|
|
|
|
"`".repeat(4),
|
|
|
|
);
|
2020-07-15 01:29:15 +02:00
|
|
|
let large_testcase = "";
|
2019-08-26 09:04:34 +02:00
|
|
|
// ```
|
|
|
|
// ````
|
|
|
|
// `````
|
2020-03-28 01:25:56 +01:00
|
|
|
// ... up to N chars
|
2019-08-26 09:04:34 +02:00
|
|
|
// We insert a N + 1 character fence.
|
|
|
|
for (let i = 3; i <= 20; i += 1) {
|
2020-07-15 01:29:15 +02:00
|
|
|
large_testcase += "`".repeat(i) + "\n";
|
2019-08-26 09:04:34 +02:00
|
|
|
}
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(fenced_code.get_unused_fence(large_testcase), "`".repeat(21));
|
2019-08-26 09:04:34 +02:00
|
|
|
});
|