changeset 2258:9c66c14f6b62

text_moin_wiki: completing nesting for colorized parsers and some tests
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Tue, 26 Jun 2007 20:46:11 +0200
parents 6327a199c666
children 709eea9354c7
files MoinMoin/_tests/parser/test_text_moin_wiki.py MoinMoin/parser/text_moin_wiki.py
diffstat 2 files changed, 81 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/parser/test_text_moin_wiki.py	Sun Jun 24 21:27:09 2007 +0200
+++ b/MoinMoin/_tests/parser/test_text_moin_wiki.py	Tue Jun 26 20:46:11 2007 +0200
@@ -487,4 +487,64 @@
         expected = True
 
         assert expected == result
+        
+    def testColorizedPythonParserAndNestingPreBracketsWithLinebreak(self):
+        """ tests nested {{{ }}} for the python colorized parser 
+        """
 
+        raw = """{{{
+#!python
+import re
+pattern = re.compile(r'{{{This is some nested text}}}')
+}}}"""
+        output = self.parse(raw)
+        output = ''.join(output)
+        print output
+        result = "r'{{{This is some nested text}}}'" in output
+        expected = True
+
+        assert expected == result
+
+    def testNestingPreBrackets(self):
+        """ tests nested {{{ }}} for the wiki parser 
+        """
+
+        raw = """{{{
+Example
+You can use {{{brackets}}}}}}"""
+        output = self.parse(raw)
+        output = ''.join(output)
+        result = 'You can use {{{brackets}}}' in output
+        expected = True
+
+        assert expected == result
+        
+    def testNestingPreBracketsWithLinebreak(self):
+        """ tests nested {{{ }}} for the wiki parser 
+        """
+
+        raw = """{{{
+Example
+You can use {{{brackets}}}
+}}}"""
+        output = self.parse(raw)
+        output = ''.join(output)
+        print output
+        result = 'You can use {{{brackets}}}' in output
+        expected = True
+
+        assert expected == result
+
+    def testTextBeforeNestingPreBrackets(self):
+        """ tests text before nested {{{ }}} for the wiki parser 
+        """
+
+        raw = """Example
+        {{{
+You can use {{{brackets}}}}}}"""
+        output = self.parse(raw)
+        output = ''.join(output)
+        result = 'Example <span class="anchor" id="line-0"></span><ul><li style="list-style-type:none"><span class="anchor" id="line-0"></span><pre>You can use {{{brackets}}}</pre>' in output
+        expected = True
+
+        assert expected == result
\ No newline at end of file
--- a/MoinMoin/parser/text_moin_wiki.py	Sun Jun 24 21:27:09 2007 +0200
+++ b/MoinMoin/parser/text_moin_wiki.py	Tue Jun 26 20:46:11 2007 +0200
@@ -1010,7 +1010,7 @@
         for line in self.lines:
             if ']][[' in line.replace(' ',''):
                 self.no_862 = True
-            self.lineno += 1
+
             self.line_anchor_printed = 0
             if not self.in_table:
                 self.request.write(self._line_anchordef())
@@ -1052,13 +1052,30 @@
                         self.request.write(self._closeP() +
                                            self.formatter.preformatted(1))
                         self.in_pre = 'no_parser'
+
                 if self.in_pre == 'found_parser':
+                    self.in_nested_pre += line.count('{{{')
+                    if self.in_nested_pre - line.count('}}}') == 0:
+                        self.in_nested_pre = 1
                     # processing mode
                     try:
                         if line.endswith("}}}"):
-                            endpos = len(line) - 3
+                            if self.in_nested_pre == 1:
+                                endpos = len(line) - 3
+                            else:
+                                self.parser_lines.append(line)
+                                self.in_nested_pre -= 1
+                                continue
                         else:
-                            endpos = line.index("}}}")
+                            if self.in_nested_pre == 1:
+                                endpos = line.index("}}}")
+
+                            else:
+                                self.parser_lines.append(line)
+                                if "}}}" in line:
+                                    self.in_nested_pre -= 1
+                                continue
+
                     except ValueError:
                         self.parser_lines.append(line)
                         continue
@@ -1170,6 +1187,7 @@
         if self.wrapping_div_class:
             self.request.write(self.formatter.div(0))
 
+
     # Private helpers ------------------------------------------------------------
 
     def setParser(self, name):