Skip to content

Commit

Permalink
+ Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jGleitz committed Nov 6, 2016
1 parent 5df911d commit 2c824a6
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -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 <kbd>x</kbd>', () => {
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'));
});
});
9 changes: 9 additions & 0 deletions testdata/expected/dangling.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h1>Test</h1>

<p>
Here are some combinations to confuse the parser:
<kbd>foo</kbd> [[
<kbd>bar</kbd> ]] hey
<kbd>this</kbd> [[ <kbd>and that</kbd>
<kbd>that</kbd> ]] <kbd>and this</kbd>
</p>
5 changes: 5 additions & 0 deletions testdata/expected/kbd.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>Test</h1>

<p>
This combination is cool: <kbd>alt</kbd>+<kbd>f4</kbd>.
</p>
5 changes: 5 additions & 0 deletions testdata/expected/kbdwithlink.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>Test</h1>

<p>
This combination is cool: <kbd>alt</kbd>+<kbd>f4</kbd>. This link still works: <a href="http://google.com">Google</a>.
</p>
5 changes: 5 additions & 0 deletions testdata/expected/markupwithin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>Test</h1>

<p>
We can do markup within tags: <kbd><em>i</em></kbd> <kbd><code>foo</code></kbd>.
</p>
7 changes: 7 additions & 0 deletions testdata/input/dangling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Test

Here are some combinations to confuse the parser:
[[foo]] [[
[[bar]] ]] hey
[[this]] [[ [[and that]]
[[that]] ]] [[and this]]
3 changes: 3 additions & 0 deletions testdata/input/kbd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Test

This combination is cool: [[alt]]+[[f4]].
3 changes: 3 additions & 0 deletions testdata/input/kbdwithlink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Test

This combination is cool: [[alt]]+[[f4]]. This link still works: [Google](http://google.com).
3 changes: 3 additions & 0 deletions testdata/input/markupwithin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Test

We can do markup within tags: [[*i*]] [[`foo`]].

0 comments on commit 2c824a6

Please sign in to comment.