changeset 4849:0988f3da0c95

Groups2009: formatter.groups for links collects links, not labels. Creole tets for a MoinMoin.formatter.groups
author Dmitrijs Milajevs <dimazest@gmail.com>
date Tue, 14 Jul 2009 09:26:14 +0200
parents f1e75133ab7b
children 6241e92270b6
files MoinMoin/formatter/_tests/test_groups.py MoinMoin/formatter/groups.py
diffstat 2 files changed, 124 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/formatter/_tests/test_groups.py	Mon Jul 13 16:55:21 2009 +0200
+++ b/MoinMoin/formatter/_tests/test_groups.py	Tue Jul 14 09:26:14 2009 +0200
@@ -10,7 +10,7 @@
 from MoinMoin.Page import Page
 from MoinMoin._tests import become_trusted, create_page, nuke_page
 
-class TestGroupFormatter(object):
+class TestGroupFormatterWikiMarkup(object):
 
     def get_members(self, text):
         request = self.request
@@ -54,7 +54,7 @@
 """
         members = self.get_members(text)
         assert len(members) == 1
-        assert u'label' in members
+        assert u'extended link' in members
 
     def test_extended_link_and_text(self):
         text = """
@@ -87,7 +87,7 @@
         text = """
     * first level
      * second level
-      * [[SomeLink]]
+      * [[SomeLink|label]]
        * forth level
         * and then some...
     * again first level
@@ -116,5 +116,112 @@
         assert len(members) == 1
         assert u'take this' in members
 
+
+class TestGroupFormatterCreole(object):
+
+    def get_members(self, text):
+        request = self.request
+        formatter = Formatter(self.request)
+
+        become_trusted(request)
+        create_page(request, u'TestPageGroup', "#FORMAT creole \n" + text)
+        page = Page(request, 'TestPageGroup', formatter=formatter)
+        page.send_page(content_only=True)
+        nuke_page(request, u'TestPageGroup')
+
+        return formatter.members
+
+    def test_CamelCase(self):
+        text = """
+ * CamelCase
+"""
+        members = self.get_members(text)
+        assert len(members) == 1
+        assert u'CamelCase' in members
+
+    def test_extended_name(self):
+        text = """
+ * extended name
+"""
+        members = self.get_members(text)
+        assert len(members) == 1
+        assert u'extended name' in members
+
+    def test_extended_link(self):
+        text = """
+ * [[extended link]]
+"""
+        members = self.get_members(text)
+        assert len(members) == 1
+        assert u'extended link' in members
+
+    def test_extended_link_with_label(self):
+        text = """
+ * [[FrontPage|named link]]
+"""
+        members = self.get_members(text)
+        assert len(members) == 1
+        assert u'FrontPage' in members
+
+    def test_extended_link_and_text(self):
+        text = """
+ * [[extended link]] other text
+ * other text [[extended link]]
+ * other text [[extended link]] other text
+
+"""
+        members = self.get_members(text)
+        assert len(members) == 3
+        assert u'extended link other text' in members
+        assert u'other text extended link' in members
+        assert u'other text extended link other text' in members
+
+    def test_ignore_not_first_level_list(self):
+        text = """
+ * first level
+ ** second level
+ *** [[SomeLink]]
+ **** forth level
+ ***** and then some...
+ * again first level
+"""
+        members = self.get_members(text)
+        assert len(members) == 2
+        assert 'first level' in members
+        assert 'again first level' in members
+
+    def test_intended_list(self):
+        text = """
+    * first level
+    ** second level
+    *** [[SomeLink|label]]
+    **** forth level
+    ***** and then some...
+    * again first level
+"""
+        members = self.get_members(text)
+        assert len(members) == 2
+        assert 'first level' in members
+        assert 'again first level' in members
+
+    def test_ignore_other(self):
+        text = """
+= ignore this =
+ * take this
+
+Ignore previous line and this text.
+"""
+        members = self.get_members(text)
+        assert len(members) == 1
+        assert u'take this' in members
+
+    def test_strip_whitespace(self):
+        text = """
+ *   take this
+"""
+        members = self.get_members(text)
+        assert len(members) == 1
+        assert u'take this' in members
+
+
 coverage_modules = ['MoinMoin.formtter.groups']
-
--- a/MoinMoin/formatter/groups.py	Mon Jul 13 16:55:21 2009 +0200
+++ b/MoinMoin/formatter/groups.py	Tue Jul 14 09:26:14 2009 +0200
@@ -17,7 +17,6 @@
     def __init__(self, request, **kw):
         FormatterBase.__init__(self, request, **kw)
         self.bullet_list_level = 0
-        self.inside_list_item = False
         self.inside_link = False
         self.members = []
         self.new_member = ''
@@ -34,19 +33,28 @@
 
     def listitem(self, on, **kw):
         if self.bullet_list_level == 1:
-            self.inside_list_item = on
             if not on:
                 stripped_new_member = self.new_member.strip()
-                if stripped_new_member:
+                if stripped_new_member and not on:
                     self.members.append(stripped_new_member)
             self.new_member = ''
         return self.null()
 
     def text(self, text, **kw):
-        if self.bullet_list_level == 1 and self.inside_list_item: #and not self.inside_link:
+        if self.bullet_list_level == 1 and not self.inside_link:
             self.new_member += text
         return self.null()
 
+    def pagelink(self, on, pagename='', page=None, **kw):
+        if self.bullet_list_level == 1:
+            self.inside_link = on
+            if not on:
+                if not pagename and page:
+                    pagename = page.page_name
+                pagename = wikiutil.normalize_pagename(pagename, self.request.cfg)
+                self.new_member += pagename
+        return self.null()
+
     def null(self, *args, **kw):
         return ''
 
@@ -57,7 +65,7 @@
     code = preformatted = small = big = code_area = code_line = null
     code_token = linebreak = paragraph = rule = icon = null
     number_list = definition_list = definition_term = definition_desc = null
-    heading = table = pagelink = null
+    heading = table = null
     table_row = table_cell = attachment_link = attachment_image = attachment_drawing = null
     transclusion = transclusion_param = null