David Chambers avatar David Chambers committed f69705f

Added unit tests for excerpts.

Comments (0)

Files changed (1)

 {% firstof body 'Mango attempts to make blogging fun again.' %}
 ''')
 
-def create_document(filename='test.text', context=None):
+def create_document(filename='test.text', context=None, body=None):
+    if context is None:
+        context = {}
+    if body is not None:
+        context['body'] = re.sub(r'(?m)^ +', '', body)
     filepath = os.path.join(mango.settings.MANGO_PATH, 'examples', filename)
     with open(filepath, 'w') as f:
         f.write(document_template.render(Context(context)))
     return document
 
 
+class ExcerptTestCase(unittest.TestCase):
+
+    def test_basic_functionality(self):
+        document = create_document(body='''
+            | Excerpt.
+            
+            More text.
+        ''')
+        self.assertEqual(document.excerpt, '<p>Excerpt.</p>')
+
+    def test_link_id_defined_in_inner_scope(self):
+        document = create_document(body='''
+            | [Mango][1].
+            | 
+            | [1]: http://mango.io/
+            
+            More text.
+        ''')
+        self.assertEqual(document.excerpt, '<p><a href="http://mango.io/">Mango</a>.</p>')
+
+    def test_link_id_defined_in_outer_scope(self):
+        document = create_document(body='''
+            | [Mango][1].
+            
+            More text.
+            
+            [1]: http://mango.io/
+        ''')
+        self.assertEqual(document.excerpt, '<p><a href="http://mango.io/">Mango</a>.</p>')
+
+    def test_link_id_defined_in_both_scopes(self):
+        document = create_document(body='''
+            | [Mango][1].
+            | 
+            | [1]: http://mango.io/
+            
+            [Django][1].
+            
+            [1]: http://www.djangoproject.com/
+        ''')
+        self.assertEqual(document.excerpt, '<p><a href="http://mango.io/">Mango</a>.</p>')
+
+
 class FileNameTestCase(unittest.TestCase):
 
     def setUp(self):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.