changeset 2267:463f3de3f981

more wikiutil tests, minor bugfix
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 01 Jul 2007 01:23:48 +0200
parents 3318504c5dd5
children e6792cdb3e83
files MoinMoin/_tests/test_wikiutil.py MoinMoin/wikiutil.py
diffstat 2 files changed, 50 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_wikiutil.py	Sun Jul 01 00:08:51 2007 +0200
+++ b/MoinMoin/_tests/test_wikiutil.py	Sun Jul 01 01:23:48 2007 +0200
@@ -32,6 +32,7 @@
             assert wikiutil.parseQueryString(wikiutil.makeQueryString(in_unicode, want_unicode=True), want_unicode=True) == in_unicode
             assert wikiutil.parseQueryString(wikiutil.makeQueryString(in_str, want_unicode=True), want_unicode=True) == in_unicode
 
+
 class TestTickets:
     def testTickets(self):
         from MoinMoin.Page import Page
@@ -53,6 +54,53 @@
         assert ticket2 != ticket3
 
 
+class TestCleanInput:
+    def testCleanInput(self):
+        tests = [(u"", u""), # empty
+                 (u"aaa\r\n\tbbb", u"aaa   bbb"), # ws chars -> blanks
+                 (u"aaa\x00\x01bbb", u"aaabbb"), # strip weird chars
+                 (u"a"*500, u""), # too long
+                ]
+        for instr, outstr in tests:
+            assert wikiutil.clean_input(instr) == outstr
+
+
+class TestNameQuoting:
+    tests = [(u"", u"''"), # empty
+             (u"test", u"'test'"), # nothing special
+             (u"Sarah O'Connor", u"\"Sarah O'Connor\""), # contains ', quote with "
+             (u'Just "something" quoted', u'\'Just "something" quoted\''), # contains ", quote with '
+            ]
+    def testQuoteName(self):
+        for name, qname in self.tests:
+            assert wikiutil.quoteName(name) == qname
+
+    def testUnquoteName(self):
+        for name, qname in self.tests:
+            assert wikiutil.unquoteName(qname) == name
+
+
+class TestInterWiki:
+    def testSplitWiki(self):
+        tests = [('SomePage', ('Self', 'SomePage', '')),
+                 ('OtherWiki:OtherPage', ('OtherWiki', 'OtherPage', '')),
+                 ('MoinMoin:"Page with blanks" link title', ("MoinMoin", "Page with blanks", "link title")),
+                 ("MoinMoin:'Page with blanks' link title", ("MoinMoin", "Page with blanks", "link title")),
+                 ('attachment:"filename with blanks.txt" other title', ("attachment", "filename with blanks.txt", "other title")),
+                ]
+        for markup, (wikiname, pagename, linktext) in tests:
+            assert wikiutil.split_wiki(markup) == (wikiname, pagename, linktext)
+
+    def testJoinWiki(self):
+        tests = [(('http://example.org/', u'SomePage'), 'http://example.org/SomePage'),
+                 (('http://example.org/?page=$PAGE&action=show', u'SomePage'), 'http://example.org/?page=SomePage&action=show'),
+                 (('http://example.org/', u'Aktuelle\xc4nderungen'), 'http://example.org/Aktuelle%C3%84nderungen'),
+                 (('http://example.org/$PAGE/show', u'Aktuelle\xc4nderungen'), 'http://example.org/Aktuelle%C3%84nderungen/show'),
+                ]
+        for (baseurl, pagename), url in tests:
+            assert wikiutil.join_wiki(baseurl, pagename) == url
+
+
 class TestSystemPagesGroup:
     def testSystemPagesGroupNotEmpty(self):
         assert self.request.dicts.members('SystemPagesGroup')
--- a/MoinMoin/wikiutil.py	Sun Jul 01 00:08:51 2007 +0200
+++ b/MoinMoin/wikiutil.py	Sun Jul 01 01:23:48 2007 +0200
@@ -494,6 +494,8 @@
 
 def unquoteName(name):
     """ if there are quotes around the name, strip them """
+    if not name:
+        return name
     for quote_char in QUOTE_CHARS:
         if quote_char == name[0] == name[-1]:
             return name[1:-1]