Olemis Lang avatar Olemis Lang committed 0d5769d

Brython #26 : Test cases for unmatched groups . Add default parameter in MatchObject.groups (FAIL)

Comments (0)

Files changed (1)

t26/t26_r4181bd84a226_re.match.diff

 
 diff -r 4181bd84a226 site/tests/index.html
 --- a/site/tests/index.html	Sat Apr 06 12:04:19 2013 -0500
-+++ b/site/tests/index.html	Sun Apr 07 01:05:59 2013 -0500
++++ b/site/tests/index.html	Sun Apr 07 01:39:14 2013 -0500
 @@ -84,20 +84,27 @@
  
  Test suite:
    <div id="editor"></div>
 diff -r 4181bd84a226 site/tests/test_re.py
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/site/tests/test_re.py	Sun Apr 07 01:05:59 2013 -0500
-@@ -0,0 +1,32 @@
++++ b/site/tests/test_re.py	Sun Apr 07 01:39:14 2013 -0500
+@@ -0,0 +1,42 @@
 +import re
 +
 +m = re.search('world', 'hello world')
 +assert m.string == 'hello world'
 +assert m.groups() == ()
 +
-+# Samples code in Python 3 doc
++# Samples code in Python 3 doc MatchObject.groups
 +
 +m = re.match(r"(\d+)\.(\d+)", "24.1632")
 +assert m.groups() == ('24', '1632')
 +
++m = re.match(r"(\d+)\.?(\d+)?", "24")
++assert m.groups() == ('24', None)
++assert m.groups('0') == ('24', '0')
++
++m = re.match(r"(\d+)\.?(\d+)? --", "24 --")
++assert m.groups() == ('24', None, '--')
++assert m.groups('0') == ('24', '0', '--')
++
++# Samples code in Python 3 doc MatchObject.group
++
 +m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist")
 +assert m.group(0) == 'Isaac Newton'
 +assert m.group(1) == 'Isaac'
 +
 diff -r 4181bd84a226 src/Lib/re.py
 --- a/src/Lib/re.py	Sat Apr 06 12:04:19 2013 -0500
-+++ b/src/Lib/re.py	Sun Apr 07 01:05:59 2013 -0500
++++ b/src/Lib/re.py	Sun Apr 07 01:39:14 2013 -0500
 @@ -2,20 +2,38 @@
  
  class MatchObject:
 -        self.mo = mo
 +    def __init__(self,jsmatch):
 +        self._jsmatch = jsmatch
-+
+ 
+-    def groups(self):
+-        return self.mo[1:]
 +    def group(self, *args):
 +        # FIXME: Support for group names ?
 +        if len(args) == 0:
 +            return self._jsmatch[args[0]]
 +        else:
 +            return tuple(self._jsmatch[x] for x in args)
- 
-     def groups(self):
--        return self.mo[1:]
++
++    def groups(self, default_=None):
 +        return tuple(self._jsmatch[1:])
  
  def search(pattern,src,flags=None):
          return None
      else:
 -        return MatchObject(mo)
+-        
+-    
+\ No newline at end of file
 +        mo = MatchObject(jsmatch)
 +        # FIXME : move to MatchObject.__init__
 +        mo.string = src
 +        return mo
-         
--    
-\ No newline at end of file
++
 +def match(pattern, src, flags=None):
 +    if pattern[0] != '^':
 +        pattern = '^' + pattern
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.