From 4769c47cd99adf4c9268803f4196a64c682ed8e8 Mon Sep 17 00:00:00 2001 From: ache Date: Mon, 27 Jan 2020 01:15:07 +0100 Subject: Add tests --- __tests__/index.js | 126 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 90 insertions(+), 36 deletions(-) diff --git a/__tests__/index.js b/__tests__/index.js index d6f1ed9..7ac7b0c 100644 --- a/__tests__/index.js +++ b/__tests__/index.js @@ -44,6 +44,8 @@ const parse = x => parse5.parse(x); const mainTestString = 'Inline *test*{style="em:4"} paragraph. Use **multiple**{ style="color:pink"} inline ~~block~~ tag. Line `tagCode`{ style="color:yellow"}.'; +/* Basic tests */ + test('basic-default', t => { const {contents} = renderDefault(mainTestString); t.deepEqual(parse(contents), parse('

Inline test paragraph. Use multiple inline block tag. Line tagCode.

')); @@ -61,11 +63,86 @@ test('basic-raw', t => {

Inline test paragraph. Use multiple inline block tag. Line tagCode.

`)); }); +/* Support tests + * + * They test the support of one element each. + */ + test('em', t => { const {contents} = render('textexamplenointerest **Important**{style=4em} still no interest'); t.deepEqual(parse(contents), parse('

textexamplenointerest Important still no interest

')); }); +test('fenced code', t => { + const fencedCodeString = `~~~lang info=string +This is an awesome code + +~~~ +`; + const {contents} = render(fencedCodeString); + t.deepEqual(parse(contents), parse(`
This is an awesome code
+
+
`)); +}); + +test('fenced code brackets', t => { + const fencedCodeString = `~~~lang {info=string} +This is an awesome code + +~~~ +`; + const {contents} = render(fencedCodeString); + t.deepEqual(parse(contents), parse(`
This is an awesome code
+
+
`)); +}); + +test('fenced code brackets and spaces', t => { + const fencedCodeString = `~~~lang {info=string} +This is an awesome code + +~~~ +`; + const {contents} = render(fencedCodeString); + t.deepEqual(parse(contents), parse(`
This is an awesome code
+
+
`)); +}); + +test('image', t => { + const imageMd = '![Test image](url.com){ alt="This is alt" longdesc="qsdf"}'; + const {contents} = render(imageMd); + t.deepEqual(parse(contents), parse('

This is alt

')); +}); + +test('link', t => { + const linkMd = 'This is a link :[Test link](ache.one){ ping="http://ache.one/big.brother"}'; + const {contents} = render(linkMd); + t.deepEqual(parse(contents), parse('

This is a link :Test link

')); +}); + +test('atx header', t => { + const imageMd = ` +Title of the article +==================== +{data-id="title"} + +`; + const {contents} = render(imageMd); + t.deepEqual(parse(contents), parse('

Title of the article

')); +}); + +test('emphasis and strong', t => { + const emphasis = 'Hey ! *That looks cool*{style="color: blue;"} ! No, that\'s **not**{.not} !'; + const {contents} = render(emphasis); + t.deepEqual(parse(contents), parse('

Hey ! That looks cool ! No, that\'s not !')); +}); + +/* Readme tests + * + * Should be act acording to the README.md + */ + test('readme-default', t => { const fileExample = file(join(__dirname, 'readMeTest.txt')); const {contents} = renderDefault(fileExample); @@ -92,6 +169,12 @@ test('readme', t => {

You can use the fprintf function to format the output to a file.

`)); }); +/* Extended tests + * + * They test the support of the feature that extended the pool of attribute + * that can be parsed. + */ + test('extended', t => { const renderExtended = generateExtendParser({extends: {image: ['quality']}}); const extentedString = `*Wait* ! @@ -140,48 +223,19 @@ test('invalid-extend', t => { t.deepEqual(parse(contents), parse('

Wait ! I love you!

')); }); +/* Special attributes tests + * + * aria attributes: Focused on accessibility. They have the form aria-* + * Global custom attributes: User ended attributes. They have the form data-* + * + */ + test('global-aria', t => { const invalidString = ' *Wait* ! I **love**{ style="color: pink;" aria-love="true" } you!'; const {contents} = renderDefault(invalidString); t.deepEqual(parse(contents), parse('

Wait ! I love you!

')); }); -test('fenced code', t => { - const fencedCodeString = `~~~lang info=string -This is an awesome code - -~~~ -`; - const {contents} = render(fencedCodeString); - t.deepEqual(parse(contents), parse(`
This is an awesome code
-
-
`)); -}); - -test('fenced code brackets', t => { - const fencedCodeString = `~~~lang {info=string} -This is an awesome code - -~~~ -`; - const {contents} = render(fencedCodeString); - t.deepEqual(parse(contents), parse(`
This is an awesome code
-
-
`)); -}); - -test('fenced code brackets and spaces', t => { - const fencedCodeString = `~~~lang {info=string} -This is an awesome code - -~~~ -`; - const {contents} = render(fencedCodeString); - t.deepEqual(parse(contents), parse(`
This is an awesome code
-
-
`)); -}); - test('global custom attribute', t => { const renderExtended = generateExtendParser({extends: {image: ['quality']}}); const extentedString = `*Wait* ! -- cgit v1.2.3