changeset 6:0cd69fa6751c

add test for decomposition; stub diff, will have to move to 2-tuples to do this properly
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 27 Jun 2011 07:16:46 -0700
parents 6b99523536ee
children ef0553c4bbcd
files tests/doctest.txt urlmatch.py
diffstat 2 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/tests/doctest.txt	Fri Jun 17 10:52:29 2011 -0700
+++ b/tests/doctest.txt	Mon Jun 27 07:16:46 2011 -0700
@@ -20,6 +20,12 @@
     >>> sorted(matcher.match('example')) # -> example.*
     ['http://www.example.com/foo/bar/fleem', 'http://www.example.com/foo/blah', 'https://www.example.com/foo/', 'https://www.example.net/foo/']
 
+Test decomposition::
+   
+    >>> matcher = UrlMatcher()
+    >>> sorted(matcher.decompose('http://www.example.com/foo').items())
+    [('domain', ['example', 'com', 'www']), ('path', ['foo']), ('scheme', 'http')]
+
 Test url diffs::
 
     >>> matcher = UrlMatcher()
--- a/urlmatch.py	Fri Jun 17 10:52:29 2011 -0700
+++ b/urlmatch.py	Mon Jun 27 07:16:46 2011 -0700
@@ -52,7 +52,18 @@
             url2 = self.decompose(url)
 
         # TODO: finish
-        raise NotImplementedError
+        for i in self.order:
+            if i in url1 and i in url2:
+                if url1[i] == url2[i]:
+                    continue
+                if isinstance(url1[i], basestring):
+                    raise NotImplementedError
+            else:
+                retval = url1.get(i, url2[i])
+                if isinstance(retval, basestring):
+                    return {i: retval}
+                return {i: retval[0]}
+                    
 
     def match(self, url):
         if '://' not in url: