From 2c824a620001fd2b3f0a23dc5ead08d03a3198ab Mon Sep 17 00:00:00 2001 From: Joshua Gleitze Date: Sun, 6 Nov 2016 17:28:30 +0100 Subject: [PATCH] + Tests --- test.js | 37 +++++++++++++++++++++++++++++ testdata/expected/dangling.html | 9 +++++++ testdata/expected/kbd.html | 5 ++++ testdata/expected/kbdwithlink.html | 5 ++++ testdata/expected/markupwithin.html | 5 ++++ testdata/input/dangling.md | 7 ++++++ testdata/input/kbd.md | 3 +++ testdata/input/kbdwithlink.md | 3 +++ testdata/input/markupwithin.md | 3 +++ 9 files changed, 77 insertions(+) create mode 100644 test.js create mode 100644 testdata/expected/dangling.html create mode 100644 testdata/expected/kbd.html create mode 100644 testdata/expected/kbdwithlink.html create mode 100644 testdata/expected/markupwithin.html create mode 100644 testdata/input/dangling.md create mode 100644 testdata/input/kbd.md create mode 100644 testdata/input/kbdwithlink.md create mode 100644 testdata/input/markupwithin.md diff --git a/test.js b/test.js new file mode 100644 index 00000000..c8ff9f47 --- /dev/null +++ b/test.js @@ -0,0 +1,37 @@ +/* eslint-env mocha */ + +import chai, {expect} from 'chai'; +import chaiString from 'chai-string'; +import markdownit from 'markdown-it'; +import markdownItKbd from './index'; +import fs from 'fs'; + +chai.use(chaiString); + +const read = path => fs.readFileSync(`testdata/${path}`).toString(); + +describe('markdown-it-kbd', () => { + + const md = markdownit() + .use(markdownItKbd); + + it('renders [[x]] as x', () => { + expect(md.render(read('input/kbd.md'))) + .to.equalIgnoreSpaces(read('expected/kbd.html')); + }); + + it('does not harm link rendering', () => { + expect(md.render(read('input/kbdwithlink.md'))) + .to.equalIgnoreSpaces(read('expected/kbdwithlink.html')); + }); + + it('ignores [[ and ]] if not forming a keystroke.', () => { + expect(md.render(read('input/dangling.md'))) + .to.equalIgnoreSpaces(read('expected/dangling.html')); + }); + + it('allows markup within [[ and ]]', () => { + expect(md.render(read('input/markupwithin.md'))) + .to.equalIgnoreSpaces(read('expected/markupwithin.html')); + }); +}); diff --git a/testdata/expected/dangling.html b/testdata/expected/dangling.html new file mode 100644 index 00000000..dc86a2b4 --- /dev/null +++ b/testdata/expected/dangling.html @@ -0,0 +1,9 @@ +

Test

+ +

+ Here are some combinations to confuse the parser: + foo [[ + bar ]] hey + this [[ and that + that ]] and this +

diff --git a/testdata/expected/kbd.html b/testdata/expected/kbd.html new file mode 100644 index 00000000..b8e374ef --- /dev/null +++ b/testdata/expected/kbd.html @@ -0,0 +1,5 @@ +

Test

+ +

+ This combination is cool: alt+f4. +

diff --git a/testdata/expected/kbdwithlink.html b/testdata/expected/kbdwithlink.html new file mode 100644 index 00000000..a3fda66d --- /dev/null +++ b/testdata/expected/kbdwithlink.html @@ -0,0 +1,5 @@ +

Test

+ +

+ This combination is cool: alt+f4. This link still works: Google. +

diff --git a/testdata/expected/markupwithin.html b/testdata/expected/markupwithin.html new file mode 100644 index 00000000..335774e8 --- /dev/null +++ b/testdata/expected/markupwithin.html @@ -0,0 +1,5 @@ +

Test

+ +

+ We can do markup within tags: i foo. +

diff --git a/testdata/input/dangling.md b/testdata/input/dangling.md new file mode 100644 index 00000000..71157d06 --- /dev/null +++ b/testdata/input/dangling.md @@ -0,0 +1,7 @@ +# Test + +Here are some combinations to confuse the parser: +[[foo]] [[ +[[bar]] ]] hey +[[this]] [[ [[and that]] +[[that]] ]] [[and this]] diff --git a/testdata/input/kbd.md b/testdata/input/kbd.md new file mode 100644 index 00000000..b656ec91 --- /dev/null +++ b/testdata/input/kbd.md @@ -0,0 +1,3 @@ +# Test + +This combination is cool: [[alt]]+[[f4]]. diff --git a/testdata/input/kbdwithlink.md b/testdata/input/kbdwithlink.md new file mode 100644 index 00000000..90388b99 --- /dev/null +++ b/testdata/input/kbdwithlink.md @@ -0,0 +1,3 @@ +# Test + +This combination is cool: [[alt]]+[[f4]]. This link still works: [Google](http://google.com). diff --git a/testdata/input/markupwithin.md b/testdata/input/markupwithin.md new file mode 100644 index 00000000..27494845 --- /dev/null +++ b/testdata/input/markupwithin.md @@ -0,0 +1,3 @@ +# Test + +We can do markup within tags: [[*i*]] [[`foo`]].