Permalink
Browse files

test suite

  • Loading branch information...
chjj committed Aug 22, 2011
1 parent 68c338b commit faa114ae67d88cb505066e15df43308f6cfce33f
Showing with 3,443 additions and 4 deletions.
  1. +2 −0 test/.gitignore
  2. +10 −0 test/README
  3. +1 −1 test/bench.js
  4. +2 −2 test/index.js
  5. 0 test/{out.html → main.html}
  6. 0 test/{in.md → main.md}
  7. +178 −0 test/test.js
  8. +17 −0 test/tests/amps_and_angles_encoding.html
  9. +21 −0 test/tests/amps_and_angles_encoding.text
  10. +18 −0 test/tests/auto_links.html
  11. +13 −0 test/tests/auto_links.text
  12. +1 −0 test/tests/backslash_escapes.html
  13. +1 −0 test/tests/backslash_escapes.text
  14. +15 −0 test/tests/blockquotes_with_code_blocks.html
  15. +11 −0 test/tests/blockquotes_with_code_blocks.text
  16. +18 −0 test/tests/code_blocks.html
  17. +14 −0 test/tests/code_blocks.text
  18. +6 −0 test/tests/code_spans.html
  19. +6 −0 test/tests/code_spans.text
  20. +71 −0 test/tests/horizontal_rules.html
  21. +67 −0 test/tests/horizontal_rules.text
  22. +11 −0 test/tests/links_inline_style.html
  23. +12 −0 test/tests/links_inline_style.text
  24. +52 −0 test/tests/links_reference_style.html
  25. +69 −0 test/tests/links_reference_style.text
  26. +3 −0 test/tests/literal_quotes_in_titles.html
  27. +7 −0 test/tests/literal_quotes_in_titles.text
  28. +314 −0 test/tests/markdown_documentation_basics.html
  29. +306 −0 test/tests/markdown_documentation_basics.text
  30. +942 −0 test/tests/markdown_documentation_syntax.html
  31. +888 −0 test/tests/markdown_documentation_syntax.text
  32. +9 −0 test/tests/nested_blockquotes.html
  33. +5 −0 test/tests/nested_blockquotes.text
  34. +148 −0 test/tests/ordered_and_unordered_lists.html
  35. +132 −0 test/tests/ordered_and_unordered_lists.text
  36. +7 −0 test/tests/strong_and_em_together.html
  37. +7 −0 test/tests/strong_and_em_together.text
  38. +25 −0 test/tests/tabs.html
  39. +21 −0 test/tests/tabs.text
  40. +8 −0 test/tests/tidyness.html
  41. +5 −0 test/tests/tidyness.text
  42. +0 −1 test/text.js
View
@@ -0,0 +1,2 @@
+bak
+bak.js
View
@@ -0,0 +1,10 @@
+In this directory:
+
+#
+# MarkdownTester -- Run tests for Markdown implementations
+#
+# Copyright (c) 2004-2005 John Gruber
+# <http://daringfireball.net/projects/markdown/>
+#
+
+Partially modified for testing purposes.
View
@@ -1,5 +1,5 @@
var fs = require('fs')
- , text = fs.readFileSync(__dirname + '/in.md', 'utf8');
+ , text = fs.readFileSync(__dirname + '/main.md', 'utf8');
var benchmark = function(func, t) {
var start = new Date()
View
@@ -5,10 +5,10 @@
var marked = require('../')
, assert = require('assert')
, fs = require('fs')
- , text = fs.readFileSync(__dirname + '/in.md', 'utf8');
+ , text = fs.readFileSync(__dirname + '/main.md', 'utf8');
var a = marked(text)
- , b = fs.readFileSync(__dirname + '/out.html', 'utf8');
+ , b = fs.readFileSync(__dirname + '/main.html', 'utf8');
console.log(a);
console.log('----------------------------------------------------------------');
File renamed without changes.
File renamed without changes.
View
@@ -0,0 +1,178 @@
+#!/usr/bin/env node
+
+var fs = require('fs')
+ , path = require('path')
+ , marked = require('marked')
+ , dir = __dirname + '/tests';
+
+var breakOnError = true;
+
+var main = function() {
+ var list = fs.readdirSync(dir)
+ , complete = 0;
+
+ list = list.filter(function(file) {
+ return path.extname(file) === '.text';
+ });
+
+main:
+ for (var i_ = 0, l_ = list.length, file; i_ < l_; i_++) {
+ file = list[i_];
+ file = path.join(dir, file);
+
+ var text = fs.readFileSync(file, 'utf8')
+ , html = fs.readFileSync(file.replace('.text', '.html'), 'utf8');
+
+ try { // this was messing with `node test | less` on sakura
+ text = marked(text).replace(/\s/g, '');
+ html = html.replace(/\s/g, '');
+ } catch(e) {
+ console.log(list[i_]);
+ throw e;
+ }
+
+ for (var i = 0, l = html.length; i < l; i++) {
+ if (text[i] !== html[i]) {
+ text = text.substring(
+ Math.max(i - 30, 0),
+ Math.min(i + 30, text.length));
+ html = html.substring(
+ Math.max(i - 30, 0),
+ Math.min(i + 30, html.length));
+ console.log(
+ '\n#%d. %s failed at offset %d. Near: "%s".\n',
+ i_ + 1, list[i_], i, text);
+ console.log('\nGot:\n%s\n',
+ pretty(text).trim() || text);
+ console.log('\nExpected:\n%s\n',
+ pretty(html).trim() || chunk2);
+ if (breakOnError) {
+ break main;
+ } else {
+ break;
+ }
+ }
+ }
+
+ if (i === l) {
+ complete++;
+ console.log('#%d. %s completed.', i_ + 1, list[i_]);
+ }
+ }
+
+ console.log('%d/%d tests completed successfully.', complete, l_);
+};
+
+if (!module.parent) {
+ process.nextTick(main);
+} else {
+ module.exports = main;
+}
+
+/**
+ * Pretty print HTML
+ * Copyright (c) 2011, Christopher Jeffrey
+ */
+
+var pretty = (function() {
+ var indent = function(num) {
+ return Array((num >= 0 ? num : 0) + 1).join(' ');
+ };
+
+ var closing = {
+ base: true,
+ link: true,
+ meta: true,
+ hr: true,
+ br: true,
+ wbr: true,
+ img: true,
+ embed: true,
+ param: true,
+ source: true,
+ track: true,
+ area: true,
+ col: true,
+ input: true,
+ keygen: true,
+ command: true
+ };
+
+ var remove = /<(pre|textarea|title|p|li|a)(?:\s[^>]+)?>[\s\S]+?<\/\1>/g
+ , replace = /<!(\d+)%*\/>/g
+ , wrap = /([ \t]*)<p>([\s\S]+?)<\/p>/g;
+
+ return function(str) {
+ var hash = []
+ , out = []
+ , cap
+ , depth = 0
+ , text
+ , full
+ , tag
+ , name;
+
+ // temporarily remove elements before
+ // processing, also remove whitespace
+ str = str.replace(remove, function(element, name) {
+ element = element
+ .replace(/(<[^\/][^>]*>)\s+|\s+(<\/)/g, '$1$2')
+ .replace(/[\r\n]/g, '');
+ return '<!' + (hash.push(element) - 1)
+ + (Array(element.length - 3).join('%')) + '/>';
+ });
+
+ // indent elements
+ str = str
+ .replace(/(>)\s+|\s+(<)/g, '$1$2')
+ .replace(/[\r\n]/g, '');
+
+ while (cap = /^([\s\S]*?)(<([^>]+)>)/.exec(str)) {
+ str = str.substring(cap[0].length);
+ text = cap[1];
+ full = cap[2];
+ tag = cap[3];
+ name = tag.split(' ')[0];
+
+ if (text) {
+ out.push(indent(depth) + text);
+ }
+
+ if (name[0] !== '/') {
+ out.push(indent(depth) + full);
+ if (!closing[name]
+ && name[0] !== '!'
+ && name[0] !== '?'
+ && tag[tag.length-1] !== '/') {
+ depth++;
+ }
+ } else {
+ depth--;
+ out.push(indent(depth) + full);
+ }
+ }
+ str = out.join('\n');
+
+ // restore the elements to
+ // their original locations
+ str = str.replace(replace, function($0, $1) {
+ return hash[$1];
+ });
+
+ // wrap paragraphs
+ str = str.replace(wrap, function($0, $1, $2) {
+ var indent = $1 + ' '
+ , text = indent + $2;
+
+ text = text
+ .replace(/[\t\r\n]+/g, '')
+ .replace(/(<\/[^>]+>|\/>)(?=\s*<\w)/g, '$1\n' + indent)
+ .replace(/(.{75,}?\s+(?![^<]+>))/g, '$1\n' + indent)
+ .replace(/([^<>\n]{50,}?)(<[^<]{15,}>)/g, '$1\n' + indent + '$2');
+
+ return $1 + '<p>\n' + text + '\n' + $1 + '</p>';
+ });
+
+ return str;
+ };
+})();
@@ -0,0 +1,17 @@
+<p>AT&amp;T has an ampersand in their name.</p>
+
+<p>AT&amp;amp;T is another way to write it.</p>
+
+<p>This &amp; that.</p>
+
+<p>4 &lt; 5.</p>
+
+<p>6 &gt; 5.</p>
+
+<p>Here&apos;s a <a href="http://example.com/?foo=1&amp;bar=2">link</a> with an ampersand in the URL.</p>
+
+<p>Here&apos;s a link with an amersand in the link text: <a href="http://att.com/" title="AT&amp;T">AT&amp;T</a>.</p>
+
+<p>Here&apos;s an inline <a href="/script?foo=1&amp;bar=2">link</a>.</p>
+
+<p>Here&apos;s an inline <a href="/script?foo=1&amp;bar=2">link</a>.</p>
@@ -0,0 +1,21 @@
+AT&T has an ampersand in their name.
+
+AT&amp;T is another way to write it.
+
+This & that.
+
+4 < 5.
+
+6 > 5.
+
+Here's a [link] [1] with an ampersand in the URL.
+
+Here's a link with an amersand in the link text: [AT&T] [2].
+
+Here's an inline [link](/script?foo=1&bar=2).
+
+Here's an inline [link](/script?foo=1&bar=2).
+
+
+[1]: http://example.com/?foo=1&bar=2
+[2]: http://att.com/ "AT&T"
View
@@ -0,0 +1,18 @@
+<p>Link: <a href="http://example.com/">http://example.com/</a>.</p>
+
+<p>With an ampersand: <a href="http://example.com/?foo=1&amp;bar=2">http://example.com/?foo=1&amp;bar=2</a></p>
+
+<ul>
+<li>In a list?</li>
+<li><a href="http://example.com/">http://example.com/</a></li>
+<li>It should.</li>
+</ul>
+
+<blockquote>
+ <p>Blockquoted: <a href="http://example.com/">http://example.com/</a></p>
+</blockquote>
+
+<p>Auto-links should not occur here: <code>&lt;http://example.com/&gt;</code></p>
+
+<pre><code>or here: &lt;http://example.com/&gt;
+</code></pre>
View
@@ -0,0 +1,13 @@
+Link: <http://example.com/>.
+
+With an ampersand: <http://example.com/?foo=1&bar=2>
+
+* In a list?
+* <http://example.com/>
+* It should.
+
+> Blockquoted: <http://example.com/>
+
+Auto-links should not occur here: `<http://example.com/>`
+
+ or here: <http://example.com/>
@@ -0,0 +1 @@
+<p>hello world [how](are you) today</p>
@@ -0,0 +1 @@
+hello world \[how](are you) today
@@ -0,0 +1,15 @@
+<blockquote>
+ <p>Example:</p>
+
+<pre><code>sub status {
+ print &quot;working&quot;;
+}
+</code></pre>
+
+ <p>Or:</p>
+
+<pre><code>sub status {
+ return &quot;working&quot;;
+}
+</code></pre>
+</blockquote>
@@ -0,0 +1,11 @@
+> Example:
+>
+> sub status {
+> print "working";
+> }
+>
+> Or:
+>
+> sub status {
+> return "working";
+> }
@@ -0,0 +1,18 @@
+<pre><code>code block on the first line
+</code></pre>
+
+<p>Regular text.</p>
+
+<pre><code>code block indented by spaces
+</code></pre>
+
+<p>Regular text.</p>
+
+<pre><code>the lines in this block
+all contain trailing spaces
+</code></pre>
+
+<p>Regular Text.</p>
+
+<pre><code>code block on the last line
+</code></pre>
@@ -0,0 +1,14 @@
+ code block on the first line
+
+Regular text.
+
+ code block indented by spaces
+
+Regular text.
+
+ the lines in this block
+ all contain trailing spaces
+
+Regular Text.
+
+ code block on the last line
@@ -0,0 +1,6 @@
+<p><code>&lt;test a=&quot;</code> content of attribute <code>&quot;&gt;</code></p>
+
+<p>Fix for backticks within HTML tag: <span attr='`ticks`'>like this</span></p>
+
+<p>Here&apos;s how you put <code>`backticks`</code> in a code span.</p>
+
@@ -0,0 +1,6 @@
+`<test a="` content of attribute `">`
+
+Fix for backticks within HTML tag: <span attr='`ticks`'>like this</span>
+
+Here's how you put `` `backticks` `` in a code span.
+
Oops, something went wrong.

0 comments on commit faa114a

Please sign in to comment.