feat(Util): backport escapeMarkdown PRs to v13 (#8703)

This commit is contained in:
RedGuy12
2022-10-10 12:14:36 -05:00
committed by GitHub
parent ea117bfb7e
commit 8a6588a132
3 changed files with 136 additions and 12 deletions

View File

@@ -5,6 +5,8 @@
const Util = require('../src/util/Util');
const testString = "`_Behold!_`\n||___~~***```js\n`use strict`;\nrequire('discord.js');```***~~___||";
const testStringForums =
'# Title\n## Subtitle\n### Subsubtitle\n- Bullet list\n - # Title with bullet\n * Subbullet\n1. Number list\n 1. Sub number list';
describe('escapeCodeblock', () => {
test('shared', () => {
@@ -94,6 +96,48 @@ describe('escapeSpoiler', () => {
});
});
describe('escapeHeading', () => {
test('shared', () => {
expect(Util.escapeHeading(testStringForums)).toBe(
'\\# Title\n\\## Subtitle\n\\### Subsubtitle\n- Bullet list\n - \\# Title with bullet\n * Subbullet\n1. Number list\n 1. Sub number list',
);
});
test('basic', () => {
expect(Util.escapeHeading('# test')).toBe('\\# test');
});
});
describe('escapeBulletedList', () => {
test('shared', () => {
expect(Util.escapeBulletedList(testStringForums)).toBe(
'# Title\n## Subtitle\n### Subsubtitle\n\\- Bullet list\n \\- # Title with bullet\n \\* Subbullet\n1. Number list\n 1. Sub number list',
);
});
test('basic', () => {
expect(Util.escapeBulletedList('- test')).toBe('\\- test');
});
});
describe('escapeNumberedList', () => {
test('shared', () => {
expect(Util.escapeNumberedList(testStringForums)).toBe(
'# Title\n## Subtitle\n### Subsubtitle\n- Bullet list\n - # Title with bullet\n * Subbullet\n1\\. Number list\n 1\\. Sub number list',
);
});
test('basic', () => {
expect(Util.escapeNumberedList('1. test')).toBe('1\\. test');
});
});
describe('escapeMaskedLink', () => {
test('basic', () => {
expect(Util.escapeMaskedLink('[test](https://discord.js.org)')).toBe('\\[test](https://discord.js.org)');
});
});
describe('escapeMarkdown', () => {
test('shared', () => {
expect(Util.escapeMarkdown(testString)).toBe(
@@ -176,7 +220,7 @@ describe('escapeMarkdown', () => {
);
});
test('edge-case odd number of fenses with no code block content', () => {
test('edge-case odd number of fences with no code block content', () => {
expect(
Util.escapeMarkdown('**foo** ```**bar**``` **fizz** ``` **buzz**', {
codeBlock: false,