diff --git a/lib/shared/markdown.test.js b/lib/shared/markdown.test.js new file mode 100644 --- /dev/null +++ b/lib/shared/markdown.test.js @@ -0,0 +1,54 @@ +// @flow + +import { spoilerRegex } from './markdown.js'; + +// Each of the below tests is subject to the following RegEx pattern: +// Spoiler RegEx: /^\|\|([^\n]+?)\|\|/g + +describe('spoilerRegex', () => { + it('We expect a spoiler with a single space character to match.', () => { + expect('|| ||').toMatch(spoilerRegex); + }); + + it('We expect a spoiler with regular text + spaces to match (1).', () => { + expect('|| hello ||').toMatch(spoilerRegex); + }); + + it('We expect a spoiler with regular text + spaces to match (2).', () => { + expect('||SPOILER||').toMatch(spoilerRegex); + }); + + it('We expect a spoiler containing any number of || within it to match (1).', () => { + expect('|| || ||').toMatch(spoilerRegex); + }); + + it('We expect a spoiler containing any number of || within it to match (2).', () => { + expect('||||||').toMatch(spoilerRegex); + }); + + it('We expect a spoiler containing any number of || within it, as well as regular text + spaces, to match.', () => { + expect('||SPOILER||SPOILER||').toMatch(spoilerRegex); + }); + + it('We do not expect a spoiler containing a new line character to match (1).', () => { + expect('||\n||').not.toMatch(spoilerRegex); + }); + + it('We do not expect a spoiler containing a new line character to match (2).', () => { + expect('||\r\n||').not.toMatch(spoilerRegex); + }); + + it('We do not expect an empty spoiler to match.', () => { + expect('||||').not.toMatch(spoilerRegex); + }); + + it('We expect a spoiler containing a single space to match, even when split across multiple lines.', () => { + expect('|| \ + ||').toMatch(spoilerRegex); + }); + + it('We do not expect a spoiler containing a new line character to match (3).', () => { + expect('|| \n\ + ||').not.toMatch(spoilerRegex); + }); +});