Selaa lähdekoodia

Added testing suite

tstone 13 vuotta sitten
vanhempi
sitoutus
d16e675ae8
86 muutettua tiedostoa jossa 473 lisäystä ja 0 poistoa
  1. 4 0
      package.json
  2. 5 0
      test/cases/anchors-by-reference.html
  3. 11 0
      test/cases/anchors-by-reference.md
  4. 2 0
      test/cases/automatic-anchors.html
  5. 2 0
      test/cases/automatic-anchors.md
  6. 13 0
      test/cases/blockquote-nested-markdown.html
  7. 8 0
      test/cases/blockquote-nested-markdown.md
  8. 5 0
      test/cases/blockquote.html
  9. 4 0
      test/cases/blockquote.md
  10. 5 0
      test/cases/code-block-html-escape.html
  11. 4 0
      test/cases/code-block-html-escape.md
  12. 5 0
      test/cases/code-block.html
  13. 4 0
      test/cases/code-block.md
  14. 5 0
      test/cases/doubline-list.html
  15. 4 0
      test/cases/doubline-list.md
  16. 8 0
      test/cases/emphasis.html
  17. 8 0
      test/cases/emphasis.md
  18. 1 0
      test/cases/escaped-number-period.html
  19. 1 0
      test/cases/escaped-number-period.md
  20. 32 0
      test/cases/escaping.html
  21. 32 0
      test/cases/escaping.md
  22. 13 0
      test/cases/github-style-codeblock.html
  23. 14 0
      test/cases/github-style-codeblock.md
  24. 1 0
      test/cases/h1-with-double-hash.html
  25. 1 0
      test/cases/h1-with-double-hash.md
  26. 1 0
      test/cases/h1-with-equals.html
  27. 2 0
      test/cases/h1-with-equals.md
  28. 1 0
      test/cases/h1-with-single-hash.html
  29. 1 0
      test/cases/h1-with-single-hash.md
  30. 1 0
      test/cases/h2-with-dashes.html
  31. 2 0
      test/cases/h2-with-dashes.md
  32. 1 0
      test/cases/h2-with-double-hash.html
  33. 1 0
      test/cases/h2-with-double-hash.md
  34. 1 0
      test/cases/h2-with-single-hash.html
  35. 1 0
      test/cases/h2-with-single-hash.md
  36. 1 0
      test/cases/h3-with-double-hash.html
  37. 1 0
      test/cases/h3-with-double-hash.md
  38. 1 0
      test/cases/h3-with-single-hash.html
  39. 1 0
      test/cases/h3-with-single-hash.md
  40. 1 0
      test/cases/h4-with-single-hash.html
  41. 1 0
      test/cases/h4-with-single-hash.md
  42. 1 0
      test/cases/h5-with-single-hash.html
  43. 1 0
      test/cases/h5-with-single-hash.md
  44. 1 0
      test/cases/h6-with-single-hash.html
  45. 1 0
      test/cases/h6-with-single-hash.md
  46. 10 0
      test/cases/horizontal-rules.html
  47. 10 0
      test/cases/horizontal-rules.md
  48. 6 0
      test/cases/images.html
  49. 8 0
      test/cases/images.md
  50. 2 0
      test/cases/implicit-anchors.html
  51. 5 0
      test/cases/implicit-anchors.md
  52. 4 0
      test/cases/inline-anchors.html
  53. 4 0
      test/cases/inline-anchors.md
  54. 12 0
      test/cases/inline-code.html
  55. 12 0
      test/cases/inline-code.md
  56. 5 0
      test/cases/lazy-blockquote.html
  57. 4 0
      test/cases/lazy-blockquote.md
  58. 8 0
      test/cases/list-with-blockquote.html
  59. 4 0
      test/cases/list-with-blockquote.md
  60. 6 0
      test/cases/list-with-code.html
  61. 3 0
      test/cases/list-with-code.md
  62. 6 0
      test/cases/multi-paragraph-list.html
  63. 6 0
      test/cases/multi-paragraph-list.md
  64. 5 0
      test/cases/multiline-unordered-list.html
  65. 4 0
      test/cases/multiline-unordered-list.md
  66. 9 0
      test/cases/nested-blockquote.html
  67. 4 0
      test/cases/nested-blockquote.md
  68. 5 0
      test/cases/ordered-list-same-number.html
  69. 4 0
      test/cases/ordered-list-same-number.md
  70. 5 0
      test/cases/ordered-list-wrong-numbers.html
  71. 4 0
      test/cases/ordered-list-wrong-numbers.md
  72. 5 0
      test/cases/ordered-list.html
  73. 4 0
      test/cases/ordered-list.md
  74. 2 0
      test/cases/relative-anchors.html
  75. 2 0
      test/cases/relative-anchors.md
  76. 1 0
      test/cases/simple-paragraph.html
  77. 2 0
      test/cases/simple-paragraph.md
  78. 6 0
      test/cases/strong.html
  79. 6 0
      test/cases/strong.md
  80. 5 0
      test/cases/unordered-list-asterisk.html
  81. 4 0
      test/cases/unordered-list-asterisk.md
  82. 5 0
      test/cases/unordered-list-minus.html
  83. 4 0
      test/cases/unordered-list-minus.md
  84. 5 0
      test/cases/unordered-list-plus.html
  85. 4 0
      test/cases/unordered-list-plus.md
  86. 49 0
      test/run.js

+ 4 - 0
package.json

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

+ 5 - 0
test/cases/anchors-by-reference.html

@@ -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>

+ 11 - 0
test/cases/anchors-by-reference.md

@@ -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"

+ 2 - 0
test/cases/automatic-anchors.html

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

+ 2 - 0
test/cases/automatic-anchors.md

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

+ 13 - 0
test/cases/blockquote-nested-markdown.html

@@ -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>

+ 8 - 0
test/cases/blockquote-nested-markdown.md

@@ -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");

+ 5 - 0
test/cases/blockquote.html

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

+ 4 - 0
test/cases/blockquote.md

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

+ 5 - 0
test/cases/code-block-html-escape.html

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

+ 4 - 0
test/cases/code-block-html-escape.md

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

+ 5 - 0
test/cases/code-block.html

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

+ 4 - 0
test/cases/code-block.md

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

+ 5 - 0
test/cases/doubline-list.html

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

+ 4 - 0
test/cases/doubline-list.md

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

+ 8 - 0
test/cases/emphasis.html

@@ -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 - 0
test/cases/emphasis.md

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

+ 1 - 0
test/cases/escaped-number-period.html

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

+ 1 - 0
test/cases/escaped-number-period.md

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

+ 32 - 0
test/cases/escaping.html

@@ -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 - 0
test/cases/escaping.md

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

+ 13 - 0
test/cases/github-style-codeblock.html

@@ -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>

+ 14 - 0
test/cases/github-style-codeblock.md

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

+ 1 - 0
test/cases/h1-with-double-hash.html

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

+ 1 - 0
test/cases/h1-with-double-hash.md

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

+ 1 - 0
test/cases/h1-with-equals.html

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

+ 2 - 0
test/cases/h1-with-equals.md

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

+ 1 - 0
test/cases/h1-with-single-hash.html

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

+ 1 - 0
test/cases/h1-with-single-hash.md

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

+ 1 - 0
test/cases/h2-with-dashes.html

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

+ 2 - 0
test/cases/h2-with-dashes.md

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

+ 1 - 0
test/cases/h2-with-double-hash.html

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

+ 1 - 0
test/cases/h2-with-double-hash.md

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

+ 1 - 0
test/cases/h2-with-single-hash.html

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

+ 1 - 0
test/cases/h2-with-single-hash.md

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

+ 1 - 0
test/cases/h3-with-double-hash.html

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

+ 1 - 0
test/cases/h3-with-double-hash.md

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

+ 1 - 0
test/cases/h3-with-single-hash.html

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

+ 1 - 0
test/cases/h3-with-single-hash.md

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

+ 1 - 0
test/cases/h4-with-single-hash.html

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

+ 1 - 0
test/cases/h4-with-single-hash.md

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

+ 1 - 0
test/cases/h5-with-single-hash.html

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

+ 1 - 0
test/cases/h5-with-single-hash.md

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

+ 1 - 0
test/cases/h6-with-single-hash.html

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

+ 1 - 0
test/cases/h6-with-single-hash.md

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

+ 10 - 0
test/cases/horizontal-rules.html

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

+ 10 - 0
test/cases/horizontal-rules.md

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

+ 6 - 0
test/cases/images.html

@@ -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 - 0
test/cases/images.md

@@ -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"

+ 2 - 0
test/cases/implicit-anchors.html

@@ -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>

+ 5 - 0
test/cases/implicit-anchors.md

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

+ 4 - 0
test/cases/inline-anchors.html

@@ -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>

+ 4 - 0
test/cases/inline-anchors.md

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

+ 12 - 0
test/cases/inline-code.html

@@ -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 - 0
test/cases/inline-code.md

@@ -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;`.

+ 5 - 0
test/cases/lazy-blockquote.html

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

+ 4 - 0
test/cases/lazy-blockquote.md

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

+ 8 - 0
test/cases/list-with-blockquote.html

@@ -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>

+ 4 - 0
test/cases/list-with-blockquote.md

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

+ 6 - 0
test/cases/list-with-code.html

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

+ 3 - 0
test/cases/list-with-code.md

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

+ 6 - 0
test/cases/multi-paragraph-list.html

@@ -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>

+ 6 - 0
test/cases/multi-paragraph-list.md

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

+ 5 - 0
test/cases/multiline-unordered-list.html

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

+ 4 - 0
test/cases/multiline-unordered-list.md

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

+ 9 - 0
test/cases/nested-blockquote.html

@@ -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>

+ 4 - 0
test/cases/nested-blockquote.md

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

+ 5 - 0
test/cases/ordered-list-same-number.html

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

+ 4 - 0
test/cases/ordered-list-same-number.md

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

+ 5 - 0
test/cases/ordered-list-wrong-numbers.html

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

+ 4 - 0
test/cases/ordered-list-wrong-numbers.md

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

+ 5 - 0
test/cases/ordered-list.html

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

+ 4 - 0
test/cases/ordered-list.md

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

+ 2 - 0
test/cases/relative-anchors.html

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

+ 2 - 0
test/cases/relative-anchors.md

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

+ 1 - 0
test/cases/simple-paragraph.html

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

+ 2 - 0
test/cases/simple-paragraph.md

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

+ 6 - 0
test/cases/strong.html

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

+ 6 - 0
test/cases/strong.md

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

+ 5 - 0
test/cases/unordered-list-asterisk.html

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

+ 4 - 0
test/cases/unordered-list-asterisk.md

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

+ 5 - 0
test/cases/unordered-list-minus.html

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

+ 4 - 0
test/cases/unordered-list-minus.md

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

+ 5 - 0
test/cases/unordered-list-plus.html

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

+ 4 - 0
test/cases/unordered-list-plus.md

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

+ 49 - 0
test/run.js

@@ -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);
+    });
+});