Skip to content

Commit

Permalink
fix filtering unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
c0dzilla committed Mar 1, 2020
1 parent 9b82798 commit 7ccec1f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 30 deletions.
2 changes: 1 addition & 1 deletion app/markdown/lib/parser/filtered/filtered.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const filterMarkdownTags = function(message) {
message = message.replace(new RegExp(`(?:<|&lt;)(?:${ schemes }):\\/\\/[^\\|]+\\|(.+?)(?=>|&gt;)(?:>|&gt;)`, 'gm'), (match, title) => title);

// Filter headings
message = message.replace(/^#{1,4} (([\S\w\d-_\/\*\.,\\][ \u00a0\u1680\u180e\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]?)+)/gm, '$1');
message = message.replace(/(^#{1,4}) (([\S\w\d-_\/\*\.,\\][ \u00a0\u1680\u180e\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]?)+)/gm, '$2');

// Filter bold
message = message.replace(/(^|>|[ >_~`])\*{1,2}([^\*\r\n]+)\*{1,2}([<_~`]|\B|\b|$)/gm, '$1$2$3');
Expand Down
51 changes: 22 additions & 29 deletions app/markdown/tests/client.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ const nested = {
const boldFiltered = {
'*Hello*': 'Hello',
'**Hello**': 'Hello',
'**Hello': 'Hello',
'*Hello**': 'Hello',
'He*llo': 'He*llo',
'*Hello': '*Hello',
Expand All @@ -255,10 +254,10 @@ const boldFiltered = {
const italicFiltered = {
_Hello_: 'Hello',
__Hello__: 'Hello',
__Hello: 'Hello',
_Hello__: 'Hello',
He_llo: 'He_llo',
_Hello: '_Hello',
__Hello: '__Hello',
Hello_: 'Hello_',
___Hello___: '___Hello___',
___Hello__: '___Hello__',
Expand All @@ -273,7 +272,7 @@ const italicFiltered = {
const strikeFiltered = {
'~Hello~': 'Hello',
'~~Hello~~': 'Hello',
'~~Hello': 'Hello',
'~~Hello': '~~Hello',
'~Hello~~': 'Hello',
'He~llo': 'He~llo',
'~Hello': '~Hello',
Expand All @@ -299,18 +298,16 @@ const headingFiltered = {
'####Hello': '####Hello',
'He#llo': 'He#llo',
'# Hello there': 'Hello there',
'Hi, # Hello': 'Hi, Hello',
'Hi, # Hello there': 'Hi, Hello there',
'Hi, # Hello': 'Hi, # Hello',
'Hi, # Hello there': 'Hi, # Hello there',
};

const quoteFiltered = {
'&gt;Hello': 'Hello',
'&gt; Hello': ' Hello',
'&lt;Hello': '&lt;Hello',
' &gt;Hello': ' &gt;Hello',
'Hello &gt; there': 'Hello &gt; there',
'>Hello': 'Hello',
'> Hello': ' Hello',
'>>>\nHello\n<<<': 'Hello',
'>>>\nHello there!\n<<<': 'Hello there!',
'>>>\n Hello there! \n<<<': ' Hello there! ',
};

const linkFiltered = {
Expand Down Expand Up @@ -345,41 +342,41 @@ const defaultObjectTest = (result, object, objectKey) => assert.equal(result.htm
const testObject = (object, parser = original, test = defaultObjectTest) => {
Object.keys(object).forEach((objectKey) => {
describe(objectKey, () => {
const message = parser === original ? { html: s.escapeHTML(objectKey) } : object[objectKey];
const result = parser === original ? Markdown.mountTokensBack(parser(message)) : parser(message);

const message = parser === original ? { html: s.escapeHTML(objectKey) } : objectKey;
const result = parser === original ? Markdown.mountTokensBack(parser(message)) : { html: parser(message) };
it(`should be equal to ${ object[objectKey] }`, () => {
test(result, object, objectKey);
});
});
});
};


describe('Original', function() {
describe('Bold', () => testObject(bold, original));
describe('Bold', () => testObject(bold));

describe('Italic', () => testObject(italic, original));
describe('Italic', () => testObject(italic));

describe('Strike', () => testObject(strike, original));
describe('Strike', () => testObject(strike));

describe('Headers', () => {
describe('Level 1', () => testObject(headersLevel1, original));
describe('Level 1', () => testObject(headersLevel1));

describe('Level 2', () => testObject(headersLevel2, original));
describe('Level 2', () => testObject(headersLevel2));

describe('Level 3', () => testObject(headersLevel3, original));
describe('Level 3', () => testObject(headersLevel3));

describe('Level 4', () => testObject(headersLevel4, original));
describe('Level 4', () => testObject(headersLevel4));
});

describe('Quote', () => testObject(quote, original));
describe('Quote', () => testObject(quote));

describe('Link', () => testObject(link, original));
describe('Link', () => testObject(link));

describe('Inline Code', () => testObject(inlinecode, original));
describe('Inline Code', () => testObject(inlinecode));

describe('Code', () => testObject(code, original));
describe('Code', () => testObject(code));

describe('Nested', () => testObject(nested));
});

describe('Filtered', function() {
Expand All @@ -397,10 +394,6 @@ describe('Filtered', function() {

describe('inlinecodeFilter', () => testObject(inlinecodeFiltered, filtered));

describe('Code', () => testObject(code));

describe('Nested', () => testObject(nested));

describe('blockcodeFilter', () => testObject(blockcodeFiltered, filtered));
});

Expand Down

0 comments on commit 7ccec1f

Please sign in to comment.