Added testing suite

This commit is contained in:
tstone 2012-06-13 23:05:31 -06:00
parent c37d77a31d
commit d16e675ae8
86 changed files with 473 additions and 0 deletions

View File

@ -16,6 +16,10 @@
"type": "git",
"url": "https://github.com/coreyti/showdown.git"
},
"devDependencies": {
"mocha": "*",
"should": "*"
},
"licenses": [{ "type": "BSD" }],
"main": "./src/showdown"
}

View File

@ -0,0 +1,5 @@
<p>This is <a href="http://example.com/" title="Optional Title Here">an example</a> reference-style link.
This is <a href="http://example.com/" title="Optional Title Here">another</a> reference-style link.
This is <a href="http://example.com/" title="Optional Title Here">a third</a> reference-style link.
This is <a href="http://example.com/" title="Optional Title Here">a fourth</a> reference-style link.</p>

View File

@ -0,0 +1,11 @@
This is [an example][id] reference-style link.
This is [another] [foo] reference-style link.
This is [a third][bar] reference-style link.
This is [a fourth][4] reference-style link.
[id]: http://example.com/ "Optional Title Here"
[foo]: http://example.com/ (Optional Title Here)
[bar]: http://example.com/ (Optional Title Here)
[4]: <http://example.com/>
"Optional Title Here"

View File

@ -0,0 +1,2 @@
<p><a href="http://example.com/">http://example.com/</a></p>

View File

@ -0,0 +1,2 @@
<http://example.com/>

View File

@ -0,0 +1,13 @@
<blockquote>
<h2 id="thisisaheader">This is a header.</h2>
<ol>
<li>This is the first list item.</li>
<li>This is the second list item.</li>
</ol>
<p>Here's some example code:</p>
<pre><code>return shell_exec("echo $input | $markdown_script");
</code></pre>
</blockquote>

View File

@ -0,0 +1,8 @@
> ## This is a header.
>
> 1. This is the first list item.
> 2. This is the second list item.
>
> Here's some example code:
>
> return shell_exec("echo $input | $markdown_script");

View File

@ -0,0 +1,5 @@
<blockquote>
<p>This is a multi line blockquote test</p>
<p>With more than one line.</p>
</blockquote>

4
test/cases/blockquote.md Normal file
View File

@ -0,0 +1,4 @@
> This is a multi line blockquote test
>
> With more than one line.

View File

@ -0,0 +1,5 @@
<p>This is some HTML:</p>
<pre><code>&lt;h1&gt;Heading&lt;/h1&gt;
</code></pre>

View File

@ -0,0 +1,4 @@
This is some HTML:
<h1>Heading</h1>

View File

@ -0,0 +1,5 @@
<p>This is a normal paragraph:</p>
<pre><code>This is a code block.
</code></pre>

4
test/cases/code-block.md Normal file
View File

@ -0,0 +1,4 @@
This is a normal paragraph:
This is a code block.

View File

@ -0,0 +1,5 @@
<ul>
<li><p>Bird</p></li>
<li><p>Magic</p></li>
</ul>

View File

@ -0,0 +1,4 @@
* Bird
* Magic

8
test/cases/emphasis.html Normal file
View File

@ -0,0 +1,8 @@
<p><em>important</em></p>
<p><em>important</em></p>
<p>this mid<em>important</em>sentence</p>
<p>*not important*</p>

8
test/cases/emphasis.md Normal file
View File

@ -0,0 +1,8 @@
*important*
_important_
this mid*important*sentence
\*not important\*

View File

@ -0,0 +1 @@
<p>It happened in 1986. What a great season.</p>

View File

@ -0,0 +1 @@
It happened in 1986\. What a great season.

32
test/cases/escaping.html Normal file
View File

@ -0,0 +1,32 @@
<p>These should all be escaped:</p>
<p>\</p>
<p>`</p>
<p>*</p>
<p>_</p>
<p>{</p>
<p>}</p>
<p>[</p>
<p>]</p>
<p>(</p>
<p>)</p>
<p>#</p>
<p>+</p>
<p>-</p>
<p>.</p>
<p>!</p>

32
test/cases/escaping.md Normal file
View File

@ -0,0 +1,32 @@
These should all be escaped:
\\
\`
\*
\_
\{
\}
\[
\]
\(
\)
\#
\+
\-
\.
\!

View File

@ -0,0 +1,13 @@
<p>Define a function in javascript:</p>
<pre><code>function MyFunc(a) {
// ...
}
</code></pre>
And some HTML
<pre><code class="html">&lt;div&gt;HTML!&lt;/div&gt;
</code></pre>

View File

@ -0,0 +1,14 @@
Define a function in javascript:
```
function MyFunc(a) {
// ...
}
```
And some HTML
```html
<div>HTML!</div>
```

View File

@ -0,0 +1 @@
<h1 id="thisisanh1">This is an H1</h1>

View File

@ -0,0 +1 @@
# This is an H1 #

View File

@ -0,0 +1 @@
<h1 id="thisisanh1">This is an H1</h1>

View File

@ -0,0 +1,2 @@
This is an H1
=============

View File

@ -0,0 +1 @@
<h1 id="thisisanh1">This is an H1</h1>

View File

@ -0,0 +1 @@
# This is an H1

View File

@ -0,0 +1 @@
<h2 id="thisisanh2">This is an H2</h2>

View File

@ -0,0 +1,2 @@
This is an H2
-------------

View File

@ -0,0 +1 @@
<h2 id="thisisanh2">This is an H2</h2>

View File

@ -0,0 +1 @@
## This is an H2 ##

View File

@ -0,0 +1 @@
<h2 id="thisisanh2">This is an H2</h2>

View File

@ -0,0 +1 @@
## This is an H2

View File

@ -0,0 +1 @@
<h3 id="thisisanh3">This is an H3</h3>

View File

@ -0,0 +1 @@
### This is an H3 ###

View File

@ -0,0 +1 @@
<h3 id="thisisanh3">This is an H3</h3>

View File

@ -0,0 +1 @@
### This is an H3

View File

@ -0,0 +1 @@
<h4 id="thisisanh4">This is an H4</h4>

View File

@ -0,0 +1 @@
#### This is an H4

View File

@ -0,0 +1 @@
<h5 id="thisisanh5">This is an H5</h5>

View File

@ -0,0 +1 @@
##### This is an H5

View File

@ -0,0 +1 @@
<h6 id="thisisanh6">This is an H6</h6>

View File

@ -0,0 +1 @@
###### This is an H6

View File

@ -0,0 +1,10 @@
<hr />
<hr />
<hr />
<hr />
<hr />

View File

@ -0,0 +1,10 @@
* * *
***
*****
- - -
---------------------------------------

6
test/cases/images.html Normal file
View File

@ -0,0 +1,6 @@
<p><img src="/path/to/img.jpg" alt="Alt text" title="" /></p>
<p><img src="/path/to/img.jpg" alt="Alt text" title="Optional title" /></p>
<p><img src="url/to/image" alt="Alt text" title="Optional title attribute" /></p>

8
test/cases/images.md Normal file
View File

@ -0,0 +1,8 @@
![Alt text](/path/to/img.jpg)
![Alt text](/path/to/img.jpg "Optional title")
![Alt text][id]
[id]: url/to/image "Optional title attribute"

View File

@ -0,0 +1,2 @@
<p>Search the web at <a href="http://google.com/">Google</a> or <a href="http://daringfireball.net/">Daring Fireball</a>.</p>

View File

@ -0,0 +1,5 @@
Search the web at [Google][] or [Daring Fireball][].
[Google]: http://google.com/
[Daring Fireball]: http://daringfireball.net/

View File

@ -0,0 +1,4 @@
<p>This is <a href="http://example.com/" title="Title">an example</a> inline link.</p>
<p><a href="http://example.net/">This link</a> has no title attribute.</p>

View File

@ -0,0 +1,4 @@
This is [an example](http://example.com/ "Title") inline link.
[This link](http://example.net/) has no title attribute.

View File

@ -0,0 +1,12 @@
<p>Create a new <code>function</code>.</p>
<p>Use the backtick in MySQL syntax <code>SELECT `column` FROM whatever</code>.</p>
<p>A single backtick in a code span: <code>`</code></p>
<p>A backtick-delimited string in a code span: <code>`foo`</code></p>
<p>Please don't use any <code>&lt;blink&gt;</code> tags.</p>
<p><code>&amp;#8212;</code> is the decimal-encoded equivalent of <code>&amp;mdash;</code>.</p>

12
test/cases/inline-code.md Normal file
View File

@ -0,0 +1,12 @@
Create a new `function`.
Use the backtick in MySQL syntax ``SELECT `column` FROM whatever``.
A single backtick in a code span: `` ` ``
A backtick-delimited string in a code span: `` `foo` ``
Please don't use any `<blink>` tags.
`&#8212;` is the decimal-encoded equivalent of `&mdash;`.

View File

@ -0,0 +1,5 @@
<blockquote>
<p>This is a multi line blockquote test</p>
<p>With more than one line.</p>
</blockquote>

View File

@ -0,0 +1,4 @@
> This is a multi line blockquote test
> With more than one line.

View File

@ -0,0 +1,8 @@
<ul>
<li><p>A list item with a blockquote:</p>
<blockquote>
<p>This is a blockquote
inside a list item.</p>
</blockquote></li>
</ul>

View File

@ -0,0 +1,4 @@
* A list item with a blockquote:
> This is a blockquote
> inside a list item.

View File

@ -0,0 +1,6 @@
<ul>
<li><p>A list item with code:</p>
<pre><code>alert('Hello world!');
</code></pre></li>
</ul>

View File

@ -0,0 +1,3 @@
* A list item with code:
alert('Hello world!');

View File

@ -0,0 +1,6 @@
<ol>
<li><p>This is a major bullet point.</p>
<p>That contains multiple paragraphs.</p></li>
<li><p>And another line</p></li>
</ol>

View File

@ -0,0 +1,6 @@
1. This is a major bullet point.
That contains multiple paragraphs.
2. And another line

View File

@ -0,0 +1,5 @@
<ul>
<li>This line spans
more than one line and is lazy</li>
<li>Similar to this line</li>
</ul>

View File

@ -0,0 +1,4 @@
- This line spans
more than one line and is lazy
- Similar to this line

View File

@ -0,0 +1,9 @@
<blockquote>
<p>This is a multi line blockquote test</p>
<blockquote>
<p>And nesting!
</blockquote>
<p>With more than one line.</p>
</blockquote>

View File

@ -0,0 +1,4 @@
> This is a multi line blockquote test
> > And nesting!
> With more than one line.

View File

@ -0,0 +1,5 @@
<ol>
<li>Red</li>
<li>Green</li>
<li>Blue</li>
</ol>

View File

@ -0,0 +1,4 @@
1. Red
1. Green
1. Blue

View File

@ -0,0 +1,5 @@
<ol>
<li>Red</li>
<li>Green</li>
<li>Blue</li>
</ol>

View File

@ -0,0 +1,4 @@
8. Red
1. Green
3. Blue

View File

@ -0,0 +1,5 @@
<ol>
<li>Red</li>
<li>Green</li>
<li>Blue</li>
</ol>

View File

@ -0,0 +1,4 @@
1. Red
2. Green
3. Blue

View File

@ -0,0 +1,2 @@
<p>See my <a href="/about/">About</a> page for details.</p>

View File

@ -0,0 +1,2 @@
See my [About](/about/) page for details.

View File

@ -0,0 +1 @@
<p>Hello, world!</p>

View File

@ -0,0 +1,2 @@
Hello, world!

6
test/cases/strong.html Normal file
View File

@ -0,0 +1,6 @@
<p><strong>important</strong></p>
<p><strong>important</strong></p>
<p>really <strong>freaking</strong>strong</p>

6
test/cases/strong.md Normal file
View File

@ -0,0 +1,6 @@
**important**
__important__
really **freaking**strong

View File

@ -0,0 +1,5 @@
<ul>
<li>Red</li>
<li>Green</li>
<li>Blue</li>
</ul>

View File

@ -0,0 +1,4 @@
* Red
* Green
* Blue

View File

@ -0,0 +1,5 @@
<ul>
<li>Red</li>
<li>Green</li>
<li>Blue</li>
</ul>

View File

@ -0,0 +1,4 @@
- Red
- Green
- Blue

View File

@ -0,0 +1,5 @@
<ul>
<li>Red</li>
<li>Green</li>
<li>Blue</li>
</ul>

View File

@ -0,0 +1,4 @@
+ Red
+ Green
+ Blue

49
test/run.js Normal file
View File

@ -0,0 +1,49 @@
var showdown = new require('../src/showdown').Showdown,
convertor = new showdown.converter(),
fs = require('fs'),
path = require('path'),
should = require('should');
// Load test cases from disk
var cases = fs.readdirSync('test/cases').filter(function(file){
return ~file.indexOf('.md');
}).map(function(file){
return file.replace('.md', '');
});
// Run each test case
cases.forEach(function(test){
var name = test.replace(/[-.]/g, ' ');
it (name, function(){
var mdpath = path.join('test/cases', test + '.md'),
htmlpath = path.join('test/cases', test + '.html'),
md = fs.readFileSync(mdpath, 'utf8'),
expected = fs.readFileSync(htmlpath, 'utf8').trim(),
actual = convertor.makeHtml(md).trim();
// Normalize line returns
expected = expected.replace(/\r/g, '');
// Ignore all leading/trailing whitespace
expected = expected.split('\n').map(function(x){
return x.trim();
}).join('\n');
actual = actual.split('\n').map(function(x){
return x.trim();
}).join('\n');
// Convert whitespace to a visible character so that it shows up on error reports
expected = expected.replace(/ /g, '·');
expected = expected.replace(/\n/g, '•\n');
actual = actual.replace(/ /g, '·');
actual = actual.replace(/\n/g, '•\n');
if (test == 'github-style-codeblock') {
console.log(actual);
}
// Compare
actual.should.equal(expected);
});
});