From 4d45d80c792ead4d4d9206304b2515f07cc07a7d Mon Sep 17 00:00:00 2001 From: ache Date: Sun, 27 May 2018 21:36:18 +0200 Subject: Add more tests with parse5 --- __tests__/index.js | 59 ++++++++++++++++++----------------------------- __tests__/input-simple.md | 4 ++-- 2 files changed, 24 insertions(+), 39 deletions(-) diff --git a/__tests__/index.js b/__tests__/index.js index 7deab30..03176a2 100644 --- a/__tests__/index.js +++ b/__tests__/index.js @@ -1,5 +1,3 @@ -import {readFileSync as file} from 'fs'; -import {join} from 'path'; import unified from 'unified'; import test from 'ava'; @@ -28,128 +26,115 @@ const renderRaw = text => unified() .use(stringify) .processSync(text); -test('line-input', t => { - const {contents} = render(file(join(__dirname, 'input-simple.md'))); - t.snapshot(contents); -}); +const parse = cont => parse5.parse(cont); test('line-input-simple', t => { const {contents} = render('[__here__]'); - t.is(contents, '

'); + t.deepEqual(parse(contents), parse('

')); }); test('line-input-empty', t => { const {contents} = render('[____]'); - t.is(contents, '

'); + t.deepEqual(parse(contents), parse('

')); }); test('line-input-simple-raw', t => { const {contents} = renderRaw('[__here__]'); - t.is(contents, '

'); + t.deepEqual(parse(contents), parse('

')); }); test('line-input-empty-raw', t => { const {contents} = renderRaw('[____]'); - t.is(contents, '

'); + t.deepEqual(parse(contents), parse('

')); }); test('line-input-id', t => { const {contents} = render('[__Some text__]{#unicorn}'); - t.is(contents, '

'); + t.deepEqual(parse(contents), parse('

')); }); test('line-input-class', t => { const {contents} = render('[_______panda__]{.unicorn}'); - t.is(contents, '

'); + t.deepEqual(parse(contents), parse('

')); }); test('line-input-classes', t => { const {contents} = render('[__strong unicorn__]{.unicorn .fox}'); - t.is(contents, '

'); + t.deepEqual(parse(contents), parse('

')); }); test('line-input-key-value', t => { const {contents} = render('[__math exercice__]{unicorn="horse + horn"}'); - t.is(contents, '

'); + t.deepEqual(parse(contents), parse('

')); }); test('line-input-overwrite-type', t => { const {contents} = render('[__Good answer__]{type=buttom}'); - t.is(contents, '

'); + t.deepEqual(parse(contents), parse('

')); }); test('line-input-overwrite-placeholder', t => { const {contents} = render('[__Please not a bad answer__]{placeholder=\'not here\'}'); - t.is(contents, '

'); + t.deepEqual(parse(contents), parse('

')); }); test('line-input-overwrite-class', t => { const {contents} = render('[__A result__]{class=\'unicorn\' .fox}'); - t.is(contents, '

'); + t.deepEqual(parse(contents), parse('

')); }); test('line-input-overwrite-id', t => { const {contents} = render('[__email__]{id=unicorn #fox}'); - t.is(contents, '

'); + t.deepEqual(parse(contents), parse('

')); }); test('line-input-multi-id', t => { const {contents} = render('[__Login__]{#unicorn #fox}'); - t.is(contents, '

'); -}); - -test('line-input-raw', t => { - const {contents} = renderRaw(file(join(__dirname, 'input-raw.md'))); - t.snapshot(contents); + t.deepEqual(parse(contents), parse('

')); }); test('line-input-password', t => { const {contents} = render('[__Password__]{#passwd type=password}'); - t.is(contents, '

'); + t.deepEqual(parse(contents), parse('

')); }); test('not a line-input', t => { const {contents} = renderRaw(` [_ text line_______]`); - t.is(null, dom5.query(parse5.parse(contents), - dom5.predicates.hasTagName('input'))); + t.is(null, dom5.query(parse5.parse(contents), dom5.predicates.hasTagName('input'))); }); test('not a line-input 2', t => { const {contents} = renderRaw(` [___]`); - t.is(null, dom5.query(parse5.parse(contents), - dom5.predicates.hasTagName('input'))); + t.is(null, dom5.query(parse5.parse(contents), dom5.predicates.hasTagName('input'))); }); test('not a line-input 3', t => { const {contents} = renderRaw(` [______ Not a line input _______] some text`); - t.is(null, dom5.query(parse5.parse(contents), - dom5.predicates.hasTagName('input'))); + t.is(null, dom5.query(parse5.parse(contents), dom5.predicates.hasTagName('input'))); }); test('not a line-input 4', t => { const {contents} = renderRaw(` [___ Not a line input ]`); - t.is(null, dom5.query(parse5.parse(contents), - dom5.predicates.hasTagName('input'))); + t.is(null, dom5.query(parse5.parse(contents), dom5.predicates.hasTagName('input'))); }); test('is a line-input', t => { const {contents} = renderRaw(`a[___This is a text___]qsd`); - t.not(null, dom5.query(parse5.parse(contents), - dom5.predicates.hasTagName('input'))); + t.not(null, dom5.query(parse5.parse(contents), dom5.predicates.hasTagName('input'))); }); + test('is line-input 2', t => { const {contents} = renderRaw(` [____]`); - t.not(null, dom5.query(parse5.parse(contents), - dom5.predicates.hasTagName('input'))); + t.not(null, dom5.query(parse5.parse(contents), dom5.predicates.hasTagName('input'))); }); diff --git a/__tests__/input-simple.md b/__tests__/input-simple.md index 4816cd8..005e724 100644 --- a/__tests__/input-simple.md +++ b/__tests__/input-simple.md @@ -2,5 +2,5 @@ This is a input line in a paragraph [___Type here___]. That's all forks. This is a formulay : -Login : [__Login__] -Password : [__Password__]{type=password} +Login : [__Login__] +Password : [__Password__]{type=password} -- cgit v1.2.3