From cc452998dc1af441cf3f9c5d0c7287cb5de48c4a Mon Sep 17 00:00:00 2001
From: Waylan Limberg
That is:
The link URL may, optionally, be surrounded by angle brackets:
[id]: <http://example.com/> "Optional Title Here"
@@ -660,10 +660,10 @@ for links, allowing for two styles: inline and reference.
- An exclamation mark:
!
;
- followed by a set of square brackets, containing the
alt
-attribute text for the image;
+ attribute text for the image;
- followed by a set of parentheses, containing the URL or path to
-the image, and an optional
title
attribute enclosed in double
-or single quotes.
+ the image, and an optional title
attribute enclosed in double
+ or single quotes.
Reference-style image syntax looks like this:
![Alt text][id]
diff --git a/tests/extensions-x-def_list/test.cfg b/tests/extensions-x-def_list/test.cfg
new file mode 100644
index 0000000..c9f352d
--- /dev/null
+++ b/tests/extensions-x-def_list/test.cfg
@@ -0,0 +1,2 @@
+[DEFAULT]
+extensions=def_list
diff --git a/tests/extensions-x-footnotes/test.cfg b/tests/extensions-x-footnotes/test.cfg
new file mode 100644
index 0000000..a5f0818
--- /dev/null
+++ b/tests/extensions-x-footnotes/test.cfg
@@ -0,0 +1,2 @@
+[DEFAULT]
+extensions=footnotes
diff --git a/tests/extensions-x-tables/test.cfg b/tests/extensions-x-tables/test.cfg
new file mode 100644
index 0000000..ce5a83d
--- /dev/null
+++ b/tests/extensions-x-tables/test.cfg
@@ -0,0 +1,2 @@
+[DEFAULT]
+extensions=tables
diff --git a/tests/extensions-x-toc/syntax-toc.html b/tests/extensions-x-toc/syntax-toc.html
index eea5347..3559d45 100644
--- a/tests/extensions-x-toc/syntax-toc.html
+++ b/tests/extensions-x-toc/syntax-toc.html
@@ -461,12 +461,12 @@ on a line by itself:
That is:
- Square brackets containing the link identifier (optionally
-indented from the left margin using up to three spaces);
+ indented from the left margin using up to three spaces);
- followed by a colon;
- followed by one or more spaces (or tabs);
- followed by the URL for the link;
- optionally followed by a title attribute for the link, enclosed
-in double or single quotes.
+ in double or single quotes.
The link URL may, optionally, be surrounded by angle brackets:
[id]: <http://example.com/> "Optional Title Here"
@@ -634,10 +634,10 @@ for links, allowing for two styles: inline and reference.
- An exclamation mark:
!
;
- followed by a set of square brackets, containing the
alt
-attribute text for the image;
+ attribute text for the image;
- followed by a set of parentheses, containing the URL or path to
-the image, and an optional
title
attribute enclosed in double
-or single quotes.
+ the image, and an optional title
attribute enclosed in double
+ or single quotes.
Reference-style image syntax looks like this:
![Alt text][id]
diff --git a/tests/extensions-x-toc/test.cfg b/tests/extensions-x-toc/test.cfg
new file mode 100644
index 0000000..e4bc0fe
--- /dev/null
+++ b/tests/extensions-x-toc/test.cfg
@@ -0,0 +1,2 @@
+[DEFAULT]
+extensions=toc
diff --git a/tests/extensions-x-wikilinks/test.cfg b/tests/extensions-x-wikilinks/test.cfg
new file mode 100644
index 0000000..959f38a
--- /dev/null
+++ b/tests/extensions-x-wikilinks/test.cfg
@@ -0,0 +1,2 @@
+[DEFAULT]
+extensions=wikilinks
diff --git a/tests/extensions-x-wikilinks/wikilinks.html b/tests/extensions-x-wikilinks/wikilinks.html
index 1a38535..a76a693 100644
--- a/tests/extensions-x-wikilinks/wikilinks.html
+++ b/tests/extensions-x-wikilinks/wikilinks.html
@@ -1,5 +1,8 @@
Some text with a WikiLink.
A link with white space and_underscores and a empty one.
+Another with double spaces and double__underscores and
+one that has emphasis inside and one with_multiple_underscores
+and one that is emphasised.
And a RealLink.
http://example.com/And_A_AutoLink
And a MarkdownLink for
diff --git a/tests/html4/test.cfg b/tests/html4/test.cfg
new file mode 100644
index 0000000..a3fc498
--- /dev/null
+++ b/tests/html4/test.cfg
@@ -0,0 +1,2 @@
+[DEFAULT]
+output_format=html4
diff --git a/tests/markdown-test/markdown-syntax.html b/tests/markdown-test/markdown-syntax.html
index 2f63b4b..038c9d1 100644
--- a/tests/markdown-test/markdown-syntax.html
+++ b/tests/markdown-test/markdown-syntax.html
@@ -484,12 +484,12 @@ on a line by itself:
That is:
- Square brackets containing the link identifier (optionally
-indented from the left margin using up to three spaces);
+ indented from the left margin using up to three spaces);
- followed by a colon;
- followed by one or more spaces (or tabs);
- followed by the URL for the link;
- optionally followed by a title attribute for the link, enclosed
-in double or single quotes.
+ in double or single quotes.
The link URL may, optionally, be surrounded by angle brackets:
[id]: <http://example.com/> "Optional Title Here"
@@ -660,10 +660,10 @@ for links, allowing for two styles: inline and reference.
- An exclamation mark:
!
;
- followed by a set of square brackets, containing the
alt
-attribute text for the image;
+ attribute text for the image;
- followed by a set of parentheses, containing the URL or path to
-the image, and an optional
title
attribute enclosed in double
-or single quotes.
+ the image, and an optional title
attribute enclosed in double
+ or single quotes.
Reference-style image syntax looks like this:
![Alt text][id]
diff --git a/tests/markdown-test/tabs.html b/tests/markdown-test/tabs.html
index b26391b..3c11f14 100644
--- a/tests/markdown-test/tabs.html
+++ b/tests/markdown-test/tabs.html
@@ -1,11 +1,11 @@
-
this is a list item
-indented with tabs
+ indented with tabs
-
this is a list item
-indented with spaces
+ indented with spaces
Code:
diff --git a/tests/misc/em-around-links.html b/tests/misc/em-around-links.html
index 06bfa8e..fafac28 100644
--- a/tests/misc/em-around-links.html
+++ b/tests/misc/em-around-links.html
@@ -1,16 +1,13 @@
Title
-
- - Python in Markdown by some
+
- Python in Markdown by some
great folks - This does work as expected.
- - Python in Markdown by some
+
- Python in Markdown by some
great folks - This does work as expected.
- - Python in Markdown by some
+
- Python in Markdown by some
great folks - This does work as expected.
- - Python in Markdown by some
+
- Python in Markdown by some
great folks - This does work as expected.
-
Python in Markdown by some
- great folks - This does work as expected.
-
+great folks - This does work as expected.
\ No newline at end of file
diff --git a/tests/misc/multi-paragraph-block-quote.html b/tests/misc/multi-paragraph-block-quote.html
index e13986a..f01b5e4 100644
--- a/tests/misc/multi-paragraph-block-quote.html
+++ b/tests/misc/multi-paragraph-block-quote.html
@@ -1,6 +1,6 @@
This is line one of paragraph one
- This is line two of paragraph one
+This is line two of paragraph one
This is line one of paragraph two
This is another blockquote.
\ No newline at end of file
diff --git a/tests/misc/tabs-in-lists.html b/tests/misc/tabs-in-lists.html
index a1a92ec..fdb7cb6 100644
--- a/tests/misc/tabs-in-lists.html
+++ b/tests/misc/tabs-in-lists.html
@@ -19,7 +19,7 @@
Now a list with 4 spaces and some text:
- A
-abcdef
+ abcdef
- B
Now with a tab and an extra space:
diff --git a/tests/plugins.py b/tests/plugins.py
new file mode 100644
index 0000000..d0cb7f8
--- /dev/null
+++ b/tests/plugins.py
@@ -0,0 +1,113 @@
+import traceback
+from util import MdSyntaxError
+from nose.plugins import Plugin
+from nose.plugins.errorclass import ErrorClass, ErrorClassPlugin
+
+class MdSyntaxErrorPlugin(ErrorClassPlugin):
+ """ Add MdSyntaxError and ensure proper formatting. """
+ mdsyntax = ErrorClass(MdSyntaxError, label='MdSyntaxError', isfailure=True)
+ enabled = True
+
+ def configure(self, options, conf):
+ self.conf = conf
+
+ def addError(self, test, err):
+ """ Ensure other plugins see the error by returning nothing here. """
+ pass
+
+ def formatError(self, test, err):
+ """ Remove unnessecary and unhelpful traceback from error report. """
+ et, ev, tb = err
+ if et.__name__ == 'MdSyntaxError':
+ return et, ev, ''
+ return err
+
+
+def escape(html):
+ """ Escape HTML for display as source within HTML. """
+ html = html.replace('&', '&')
+ html = html.replace('<', '<')
+ html = html.replace('>', '>')
+ return html
+
+
+class HtmlOutput(Plugin):
+ """Output test results as ugly, unstyled html. """
+
+ name = 'html-output'
+ score = 2 # run late
+ enabled = True
+
+ def __init__(self):
+ super(HtmlOutput, self).__init__()
+ self.html = [ '',
+ 'Test output ',
+ '' ]
+
+ def configure(self, options, conf):
+ self.conf = conf
+
+ def addSuccess(self, test):
+ self.html.append('ok')
+
+ def addError(self, test, err):
+ err = self.formatErr(err)
+ self.html.append('ERROR')
+ self.html.append('%s
' % escape(err))
+
+ def addFailure(self, test, err):
+ err = self.formatErr(err)
+ self.html.append('FAIL')
+ self.html.append('%s
' % escape(err))
+
+ def finalize(self, result):
+ self.html.append('')
+ self.html.append("Ran %d test%s" %
+ (result.testsRun, result.testsRun != 1 and "s"
+or ""))
+ self.html.append('')
+ self.html.append('')
+ if not result.wasSuccessful():
+ self.html.extend(['FAILED (',
+ 'failures=%d ' % len(result.failures),
+ 'errors=%d' % len(result.errors)])
+ for cls in result.errorClasses.keys():
+ storage, label, isfail = result.errorClasses[cls]
+ if isfail:
+ self.html.append(' %ss=%d' % (label, len(storage)))
+ self.html.append(')')
+ else:
+ self.html.append('OK')
+ self.html.append('')
+ f = open('tmp/test-output.html', 'w')
+ for l in self.html:
+ f.write(l)
+ f.close()
+
+ def formatErr(self, err):
+ exctype, value, tb = err
+ return ''.join(traceback.format_exception(exctype, value, tb))
+
+ def startContext(self, ctx):
+ try:
+ n = ctx.__name__
+ except AttributeError:
+ n = str(ctx).replace('<', '').replace('>', '')
+ self.html.extend(['')
+
+ def startTest(self, test):
+ self.html.extend([ '',
+ test.shortDescription() or str(test),
+ '' ])
+
+ def stopTest(self, test):
+ self.html.append('')
+
diff --git a/tests/safe_mode/test.cfg b/tests/safe_mode/test.cfg
new file mode 100644
index 0000000..d23e418
--- /dev/null
+++ b/tests/safe_mode/test.cfg
@@ -0,0 +1,2 @@
+[DEFAULT]
+safe_mode=escape
diff --git a/tests/test_apis.py b/tests/test_apis.py
new file mode 100755
index 0000000..59b5a2e
--- /dev/null
+++ b/tests/test_apis.py
@@ -0,0 +1,234 @@
+#!/usr/bin/python
+"""
+Python-Markdown Regression Tests
+================================
+
+Tests of the various APIs with the python markdown lib.
+
+"""
+
+import unittest
+from doctest import DocTestSuite
+import os
+import markdown
+
+class TestMarkdownBasics(unittest.TestCase):
+ """ Tests basics of the Markdown class. """
+
+ def setUp(self):
+ """ Create instance of Markdown. """
+ self.md = markdown.Markdown()
+
+ def testBlankInput(self):
+ """ Test blank input. """
+ self.assertEqual(self.md.convert(''), '')
+
+ def testWhitespaceOnly(self):
+ """ Test input of only whitespace. """
+ self.assertEqual(self.md.convert(' '), '')
+
+ def testSimpleInput(self):
+ """ Test simple input. """
+ self.assertEqual(self.md.convert('foo'), 'foo
')
+
+class TestBlockParser(unittest.TestCase):
+ """ Tests of the BlockParser class. """
+
+ def setUp(self):
+ """ Create instance of BlockParser. """
+ self.parser = markdown.Markdown().parser
+
+ def testParseChunk(self):
+ """ Test BlockParser.parseChunk. """
+ root = markdown.etree.Element("div")
+ text = 'foo'
+ self.parser.parseChunk(root, text)
+ self.assertEqual(markdown.etree.tostring(root), "foo
")
+
+ def testParseDocument(self):
+ """ Test BlockParser.parseDocument. """
+ lines = ['#foo', '', 'bar', '', ' baz']
+ tree = self.parser.parseDocument(lines)
+ self.assert_(isinstance(tree, markdown.etree.ElementTree))
+ self.assert_(markdown.etree.iselement(tree.getroot()))
+ self.assertEqual(markdown.etree.tostring(tree.getroot()),
+ "foo
bar
baz\n
")
+
+
+class TestBlockParserState(unittest.TestCase):
+ """ Tests of the State class for BlockParser. """
+
+ def setUp(self):
+ self.state = markdown.blockparser.State()
+
+ def testBlankState(self):
+ """ Test State when empty. """
+ self.assertEqual(self.state, [])
+
+ def testSetSate(self):
+ """ Test State.set(). """
+ self.state.set('a_state')
+ self.assertEqual(self.state, ['a_state'])
+ self.state.set('state2')
+ self.assertEqual(self.state, ['a_state', 'state2'])
+
+ def testIsSate(self):
+ """ Test State.isstate(). """
+ self.assertEqual(self.state.isstate('anything'), False)
+ self.state.set('a_state')
+ self.assertEqual(self.state.isstate('a_state'), True)
+ self.state.set('state2')
+ self.assertEqual(self.state.isstate('state2'), True)
+ self.assertEqual(self.state.isstate('a_state'), False)
+ self.assertEqual(self.state.isstate('missing'), False)
+
+ def testReset(self):
+ """ Test State.reset(). """
+ self.state.set('a_state')
+ self.state.reset()
+ self.assertEqual(self.state, [])
+ self.state.set('state1')
+ self.state.set('state2')
+ self.state.reset()
+ self.assertEqual(self.state, ['state1'])
+
+class TestHtmlStash(unittest.TestCase):
+ """ Test Markdown's HtmlStash. """
+
+ def setUp(self):
+ self.stash = markdown.preprocessors.HtmlStash()
+ self.placeholder = self.stash.store('foo')
+
+ def testSimpleStore(self):
+ """ Test HtmlStash.store. """
+ self.assertEqual(self.placeholder,
+ markdown.preprocessors.HTML_PLACEHOLDER % 0)
+ self.assertEqual(self.stash.html_counter, 1)
+ self.assertEqual(self.stash.rawHtmlBlocks, [('foo', False)])
+
+ def testStoreMore(self):
+ """ Test HtmlStash.store with additional blocks. """
+ placeholder = self.stash.store('bar')
+ self.assertEqual(placeholder,
+ markdown.preprocessors.HTML_PLACEHOLDER % 1)
+ self.assertEqual(self.stash.html_counter, 2)
+ self.assertEqual(self.stash.rawHtmlBlocks,
+ [('foo', False), ('bar', False)])
+
+ def testSafeStore(self):
+ """ Test HtmlStash.store with 'safe' html. """
+ self.stash.store('bar', True)
+ self.assertEqual(self.stash.rawHtmlBlocks,
+ [('foo', False), ('bar', True)])
+
+ def testReset(self):
+ """ Test HtmlStash.reset. """
+ self.stash.reset()
+ self.assertEqual(self.stash.html_counter, 0)
+ self.assertEqual(self.stash.rawHtmlBlocks, [])
+
+class TestOrderedDict(unittest.TestCase):
+ """ Test OrderedDict storage class. """
+
+ def setUp(self):
+ self.odict = markdown.odict.OrderedDict()
+ self.odict['first'] = 'This'
+ self.odict['third'] = 'a'
+ self.odict['fourth'] = 'self'
+ self.odict['fifth'] = 'test'
+
+ def testValues(self):
+ """ Test output of OrderedDict.values(). """
+ self.assertEqual(self.odict.values(), ['This', 'a', 'self', 'test'])
+
+ def testKeys(self):
+ """ Test output of OrderedDict.keys(). """
+ self.assertEqual(self.odict.keys(),
+ ['first', 'third', 'fourth', 'fifth'])
+
+ def testItems(self):
+ """ Test output of OrderedDict.items(). """
+ self.assertEqual(self.odict.items(),
+ [('first', 'This'), ('third', 'a'),
+ ('fourth', 'self'), ('fifth', 'test')])
+
+ def testAddBefore(self):
+ """ Test adding an OrderedDict item before a given key. """
+ self.odict.add('second', 'is', 'first')
+ self.assertEqual(self.odict.items(),
+ [('first', 'This'), ('second', 'is'), ('third', 'a'),
+ ('fourth', 'self'), ('fifth', 'test')])
+
+ def testAddAfterEnd(self):
+ """ Test adding an OrderedDict item after the last key. """
+ self.odict.add('sixth', '.', '>fifth')
+ self.assertEqual(self.odict.items(),
+ [('first', 'This'), ('third', 'a'),
+ ('fourth', 'self'), ('fifth', 'test'), ('sixth', '.')])
+
+ def testAdd_begin(self):
+ """ Test adding an OrderedDict item using "_begin". """
+ self.odict.add('zero', 'CRAZY', '_begin')
+ self.assertEqual(self.odict.items(),
+ [('zero', 'CRAZY'), ('first', 'This'), ('third', 'a'),
+ ('fourth', 'self'), ('fifth', 'test')])
+
+ def testAdd_end(self):
+ """ Test adding an OrderedDict item using "_end". """
+ self.odict.add('sixth', '.', '_end')
+ self.assertEqual(self.odict.items(),
+ [('first', 'This'), ('third', 'a'),
+ ('fourth', 'self'), ('fifth', 'test'), ('sixth', '.')])
+
+ def testAddBadLocation(self):
+ """ Test Error on bad location in OrderedDict.add(). """
+ self.assertRaises(ValueError, self.odict.add, 'sixth', '.', '