changeset 2612:e3e5e2373c60

1.6 converter: cleanup link conversion, cleanup/add tests
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Wed, 08 Aug 2007 03:53:46 +0200
parents 7ed38f2af242
children ddbbf05d0eac
files MoinMoin/script/migration/_conv160_wiki.py MoinMoin/script/migration/_tests/test_conv160_wiki.py
diffstat 2 files changed, 11 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/script/migration/_conv160_wiki.py	Tue Aug 07 17:35:08 2007 +0200
+++ b/MoinMoin/script/migration/_conv160_wiki.py	Wed Aug 08 03:53:46 2007 +0200
@@ -232,17 +232,14 @@
         # Local extended link? [:page name:link text]
         if word[0] == ':':
             words = word[1:].split(':', 1)
-            words[0] = self._replace_target(words[0])
-            if len(words) == 1:
-                link = words[0]
-                link = wikiutil.quoteName(link)
-                return '[%s]' % link # use freelink
-            else:
-                link, text = words
-                link = wikiutil.quoteName(link)
-                if text:
-                    text = ' ' + text
-                return '[%s%s]' % (link, text) # use freelink with text
+            link, text = (words + ['', ''])[:2]
+            if link.strip() == text.strip():
+                text = ''
+            link = self._replace_target(link)
+            link = wikiutil.quoteName(link)
+            if text:
+                text = ' ' + text
+            return '[%s%s]' % (link, text) # use freelink with text
 
         scheme_and_rest = word.split(":", 1)
         if len(scheme_and_rest) == 2: # scheme given
--- a/MoinMoin/script/migration/_tests/test_conv160_wiki.py	Tue Aug 07 17:35:08 2007 +0200
+++ b/MoinMoin/script/migration/_tests/test_conv160_wiki.py	Wed Aug 08 03:53:46 2007 +0200
@@ -28,21 +28,16 @@
         pagename = 'TestPage'
         rename_some_page = {
                 ('PAGE', 'some_page'): 'some page',
-                # NEEDED? ('PAGE', 'RenameThis'): 'ThisRenamed',
         }
         rename_some_file = {
                 ('FILE', pagename, 'with_underscore'): 'without underscore',
                 ('FILE', pagename, 'with blank'): 'without_blank',
         }
+
         tests = [
-            # NEEDED? ('CamelCase', {}, 'CamelCase'),
-            # FAILS ('RenameThis', rename_some_page, 'ThisRenamed'),
-            # NEEDED? ('!RenameThis', {}, '!RenameThis'), # not a link
-
             # FAILING tests:
             #('[wiki:/OtherPage]', rename_some_page, '[wiki:/OtherPage]'),
             #('[wiki:/OtherPage other page]', rename_some_page, '[wiki:/OtherPage other page]'),
-            # ('[:Something:Something]', {}, '["Something"]'),
             #('[attachment:My%20Attachment.jpg:it works]', {}, '[attachment:"My Attachment.jpg" it works]'),
             #('[wiki:LinuxWiki: LinuxWiki.de]', {}, '[wiki:LinuxWiki: LinuxWiki.de]'),
             #('[:MeatBall:CleanLinking meatball-wiki: clean linking]', {}, '[:MeatBall:CleanLinking meatball-wiki: clean linking]'),
@@ -55,6 +50,7 @@
 
             # "nothing changed" checks
             ('', {}, ''),
+            ('CamelCase', {}, 'CamelCase'),
             ('MoinMaster:CamelCase', {}, 'MoinMaster:CamelCase'),
             ('some_text', {}, 'some_text'),
             ('["some_text"]', {}, '["some_text"]'),
@@ -86,6 +82,7 @@
             ('[:other page:other text]', {}, '["other page" other text]'),
             # FAILS ('Self:CamelCase', {}, 'CamelCase'),
             ('[wiki:WikiPedia:Lynx_%28web_browser%29 Lynx]', {}, '[wiki:WikiPedia:"Lynx_(web_browser)" Lynx]'),
+            ('[:Something:Something]', {}, '["Something"]'), # optimize markup
 
             # "nothing changed" checks
             ('attachment:OtherPage/with_underscore', rename_some_file, 'attachment:OtherPage/with_underscore'),