From d7d9fe9ec6252bbbbf430cb95f8ea4d6ded1cc2a Mon Sep 17 00:00:00 2001 From: ache Date: Wed, 23 May 2018 11:19:12 +0200 Subject: Add more tests --- __tests__/index.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- package.json | 6 ++++-- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/__tests__/index.js b/__tests__/index.js index 498b393..7deab30 100644 --- a/__tests__/index.js +++ b/__tests__/index.js @@ -7,9 +7,12 @@ import raw from 'rehype-raw'; import reParse from 'remark-parse'; import stringify from 'rehype-stringify'; import remark2rehype from 'remark-rehype'; +import parse5 from 'parse5'; import plugin from '../app'; +const dom5 = require('dom5'); + const render = text => unified() .use(reParse) .use(plugin) @@ -55,7 +58,7 @@ test('line-input-id', t => { }); test('line-input-class', t => { - const {contents} = render('[__panda__]{.unicorn}'); + const {contents} = render('[_______panda__]{.unicorn}'); t.is(contents, '

'); }); @@ -104,3 +107,49 @@ test('line-input-password', t => { t.is(contents, '

'); }); +test('not a line-input', t => { + const {contents} = renderRaw(` +[_ text line_______]`); + + 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'))); +}); + +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'))); +}); + +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'))); +}); + +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'))); +}); +test('is line-input 2', t => { + const {contents} = renderRaw(` +[____]`); + + t.not(null, dom5.query(parse5.parse(contents), + dom5.predicates.hasTagName('input'))); +}); + diff --git a/package.json b/package.json index 1ab002f..7199794 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,8 @@ "start": "node app.js" }, "dependencies": { - "unist-util-visit": "^1.1.3", - "md-attr-parser": "^1.0.0" + "md-attr-parser": "^1.0.0", + "unist-util-visit": "^1.1.3" }, "author": "ache", "license": "MIT", @@ -21,6 +21,8 @@ ], "devDependencies": { "ava": "^0.25.0", + "dom5": "^3.0.0", + "parse5": "^4.0.0", "rehype-raw": "^2.0.0", "rehype-stringify": "^3.0.0", "remark-parse": "^5.0.0", -- cgit v1.2.3