Files
zulip/frontend_tests/node_tests/fenced_code.js
Anders Kaseorg c1675913a2 web: Move web app to ‘web’ directory.
Ever since we started bundling the app with webpack, there’s been less
and less overlap between our ‘static’ directory (files belonging to
the frontend app) and Django’s interpretation of the ‘static’
directory (files served directly to the web).

Split the app out to its own ‘web’ directory outside of ‘static’, and
remove all the custom collectstatic --ignore rules.  This makes it
much clearer what’s actually being served to the web, and what’s being
bundled by webpack.  It also shrinks the release tarball by 3%.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-02-23 16:04:17 -08:00

44 lines
1.6 KiB
JavaScript

"use strict";
const {strict: assert} = require("assert");
const {zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const fenced_code = zrequire("../shared/src/fenced_code");
// Check the default behavior of fenced code blocks
// works properly before Markdown is initialized.
run_test("fenced_block_defaults", () => {
const input = "\n```\nfenced code\n```\n\nand then after\n";
const expected =
'\n\n<div class="codehilite"><pre><span></span><code>fenced code\n</code></pre></div>\n\n\nand then after\n\n';
const output = fenced_code.process_fenced_code(input);
assert.equal(output, expected);
});
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));
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),
);
let large_testcase = "";
// ```
// ````
// `````
// ... up to N chars
// We insert a N + 1 character fence.
for (let i = 3; i <= 20; i += 1) {
large_testcase += "`".repeat(i) + "\n";
}
assert.equal(fenced_code.get_unused_fence(large_testcase), "`".repeat(21));
});