changeset 2052:1376525701c1

wikiutil.ParameterParser: tests added and bug fixed if args is empty and parameters wanted
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 10 Jun 2007 16:13:08 +0200
parents b1046ec29bca
children 641c229599a4
files MoinMoin/_tests/test_wikiutil.py MoinMoin/wikiutil.py
diffstat 2 files changed, 39 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_wikiutil.py	Sun Jun 10 00:39:21 2007 +0200
+++ b/MoinMoin/_tests/test_wikiutil.py	Sun Jun 10 16:13:08 2007 +0200
@@ -61,3 +61,36 @@
                 '"%(name)s" is NOT a valid template name' % locals())
 
 
+class TestParmeterParser(unittest.TestCase):
+ 
+    def testNoWantedArguments(self):
+        args = ''
+        argParser = wikiutil.ParameterParser('')
+        self.arg_list, self.arg_dict = argParser.parse_parameters(args)
+        result = len(self.arg_dict) > 0
+        expected = False
+        self.assert_(result is expected,
+                     'Expected "%(expected)s" but got "%(result)s"' % locals())
+
+    def testWantedArguments(self):
+        test_args = ('', 
+                     'width=100',
+                     'width=100, height=200', )
+       
+        argParser = wikiutil.ParameterParser("%(width)s%(height)s")
+        for args in test_args: 
+            self.arg_list, self.arg_dict = argParser.parse_parameters(args)
+            result = len(self.arg_dict) == 2
+            expected = True
+            self.assert_(result is expected,
+                         'Expected "%(expected)s" but got "%(result)s"' % locals())
+      
+    def testTooMuchWantedArguments(self):
+        args = 'width=100, height=200, alt=Example'
+        argParser = wikiutil.ParameterParser("%(width)s%(height)s")
+        self.arg_list, self.arg_dict = argParser.parse_parameters(args)
+        result = len(self.arg_dict) == 2
+        expected = True
+        self.assert_(result is expected,
+                     'Expected "%(expected)s" but got "%(result)s"' % locals())  
+      
\ No newline at end of file
--- a/MoinMoin/wikiutil.py	Sun Jun 10 00:39:21 2007 +0200
+++ b/MoinMoin/wikiutil.py	Sun Jun 10 16:13:08 2007 +0200
@@ -1343,6 +1343,10 @@
         i = 0
         start = 0
         named = False
+
+        if not params:
+            params = '""'
+        
         while start < len(params):
             match = re.match(self.param_re, params[start:])
             if not match:
@@ -1366,7 +1370,7 @@
                 type = 'n'
             else:
                 value = None
-
+            
             parameter_list.append(value)
             if match.group("name"):
                 if match.group("name") not in self.param_dict:
@@ -1395,8 +1399,7 @@
             i += 1
 
         return parameter_list, parameter_dict
-
-
+    
 """ never used:
     def _check_type(value, type, format):
         if type == 'n' and 's' in format: # n as s