[py-svn] r33403 - in py/dist/py/rst: . testing

guido at codespeak.net guido at codespeak.net
Wed Oct 18 15:34:25 CEST 2006


Author: guido
Date: Wed Oct 18 15:34:21 2006
New Revision: 33403

Modified:
   py/dist/py/rst/rst.py
   py/dist/py/rst/testing/test_rst.py
Log:
Some whitespace and indentation fixes, splitting on all whitespace instead
of just single space for the wordlist now (fixes formatting problems in e.g.
Paragraph code), making BlockQuote put its :: on a seperate line instead of
the previous (fixes problems with e.g. a BlockQuote following a Title node).


Modified: py/dist/py/rst/rst.py
==============================================================================
--- py/dist/py/rst/rst.py	(original)
+++ py/dist/py/rst/rst.py	Wed Oct 18 15:34:21 2006
@@ -137,19 +137,19 @@
                 buf = []
         grab(buf)
         return "\n".join(outcome)
-
+    
 class SubParagraph(Paragraph):
     indent = " "
     
 class BlockQuote(Paragraph):
     indent = " "
-    previous_paragraph = "::"
+    previous_paragraph = "\n::"
     sep = ""
     
     def text(self):
         all_txt = AbstractNode.text(self)
         all_txts = all_txt.split("\n")
-        return "\n".join([self.indent + i for i in all_txts])
+        return '%s\n' % ("\n".join([self.indent + i for i in all_txts]),)
 
 class Title(Paragraph):
     parentclass = Rest
@@ -178,8 +178,9 @@
         return self.start + self._text + self.end
     
 class Text(AbstractText):
+    _reg_whitespace = py.std.re.compile('\s+')
     def wordlist(self):
-        return self._text.split(" ")
+        return self._reg_whitespace.split(self._text)
 
 class Emph(AbstractText):
     start = "*"
@@ -192,7 +193,7 @@
         self.indent = self.indent + "  "
         txt = Paragraph.text(self)
         txt = self.item_char + txt[1:]
-        del self.indent
+        del self.indent # XXX ?
         return txt
 
 class Link(AbstractText):

Modified: py/dist/py/rst/testing/test_rst.py
==============================================================================
--- py/dist/py/rst/testing/test_rst.py	(original)
+++ py/dist/py/rst/testing/test_rst.py	Wed Oct 18 15:34:21 2006
@@ -15,15 +15,19 @@
     assert txt == ' a\n b\n c\n d\n e\n f\n'
 
 def test_blockquote():
-    expected = """Text::
+    expected = """\
+Text
+::
 
  def fun():
   some
 
+
 Paragraph
 """
     txt = Rest(Paragraph("Text"), BlockQuote("def fun():\n some"), \
         Paragraph("Paragraph")).text()
+    print repr(txt)
     assert txt == expected
 
 def test_title():
@@ -41,7 +45,66 @@
     txt = Rest(Paragraph("This is a test!")).text()
     assert txt == expected
 
+def test_text_multiline():
+    expected = """\
+Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vestibulum malesuada
+eleifend leo. Sed faucibus commodo libero. Mauris elementum fringilla velit. Ut
+sem urna, aliquet sed, molestie at, viverra id, justo. In ornare lacinia
+turpis. Etiam et ipsum. Quisque at lacus. Etiam pellentesque, enim porta
+pulvinar viverra, libero elit iaculis justo, vitae convallis pede purus vel
+arcu. Morbi aliquam lacus et urna. Donec commodo pellentesque mi.
+"""
+    txt = Rest(Paragraph('Lorem ipsum dolor sit amet, consectetuer adipiscing '
+                         'elit. Vestibulum malesuada eleifend leo. Sed '
+                         'faucibus commodo libero. Mauris elementum fringilla '
+                         'velit. Ut sem urna, aliquet sed, molestie at, '
+                         'viverra id, justo. In ornare lacinia turpis. Etiam '
+                         'et ipsum. Quisque at lacus. Etiam pellentesque, '
+                         'enim porta pulvinar viverra, libero elit iaculis '
+                         'justo, vitae convallis pede purus vel arcu. Morbi '
+                         'aliquam lacus et urna. Donec commodo pellentesque '
+                         'mi.')).text()
+    assert txt == expected
+
+def test_text_indented():
+    expected = """\
+This is a paragraph with some indentation. The indentation should be removed
+and the lines split up nicely. This is still part of the first paragraph.
+"""
+    txt = Rest(Paragraph('This is a paragraph with some\n'
+                         '    indentation. The indentation\n'
+                         ' should be removed and the lines split up nicely.\n'
+                         '\nThis is still part of the first paragraph.')
+                         ).text()
+    assert txt == expected
+
 def test_list():
     expected = "* a\n\n* b\n"
     txt = Rest(ListItem("a"), ListItem("b")).text()
     assert txt == expected
+
+def test_list_multiline():
+    expected = """\
+* Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vestibulum
+  malesuada eleifend leo. Sed faucibus commodo libero.
+
+* Mauris elementum fringilla velit. Ut sem urna, aliquet sed, molestie at,
+  viverra id, justo. In ornare lacinia turpis. Etiam et ipsum. Quisque at
+  lacus.
+
+* Etiam pellentesque, enim porta pulvinar viverra, libero elit iaculis justo,
+  vitae convallis pede purus vel arcu. Morbi aliquam lacus et urna. Donec
+  commodo pellentesque mi.
+"""
+    txt = Rest(ListItem('Lorem ipsum dolor sit amet, consectetuer adipiscing '
+                        'elit. Vestibulum malesuada eleifend leo. Sed '
+                        'faucibus commodo libero.'),
+               ListItem('Mauris elementum fringilla velit. Ut sem urna, '
+                        'aliquet sed, molestie at, viverra id, justo. In '
+                        'ornare lacinia turpis. Etiam et ipsum. Quisque at '
+                        'lacus.'),
+               ListItem('Etiam pellentesque, enim porta pulvinar viverra, '
+                        'libero elit iaculis justo, vitae convallis pede '
+                        'purus vel arcu. Morbi aliquam lacus et urna. Donec '
+                        'commodo pellentesque mi.')).text()
+    assert txt == expected


More information about the py-svn mailing list