Mercurial > p > roundup > code
diff test/test_templating.py @ 3991:13161539e5bd
improved URL matching
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Mon, 18 Aug 2008 06:03:06 +0000 |
| parents | eee76dd4a09f |
| children | e335ce40d6c8 |
line wrap: on
line diff
--- a/test/test_templating.py Mon Aug 18 05:09:00 2008 +0000 +++ b/test/test_templating.py Mon Aug 18 06:03:06 2008 +0000 @@ -88,6 +88,38 @@ cls = HTMLClass(self.client, "issue") cls["nosy"] + def test_url_match(self): + '''Test the URL regular expression in StringHTMLProperty. + ''' + def t(s, **groups): + m = StringHTMLProperty.hyper_re.search(s) + self.assertNotEquals(m, None, '%r did not match'%s) + d = m.groupdict() + for g in groups: + self.assertEquals(d[g], groups[g], '%s %r != %r in %r'%(g, d[g], + groups[g], s)) + + #t('123.321.123.321', 'url') + t('http://roundup.net/', url='http://roundup.net/') + t('<HTTP://roundup.net/>', url='HTTP://roundup.net/') + t('www.a.ex', url='www.a.ex') + t('http://a.ex', url='http://a.ex') + t('http://a.ex/?foo&bar=baz\\.@!$%()qwerty', + url='http://a.ex/?foo&bar=baz\\.@!$%()qwerty') + t('www.net', url='www.net') + t('richard@com.example', email='richard@com.example') + t('r@a.com', email='r@a.com') + t('i1', **{'class':'i', 'id':'1'}) + t('item123', **{'class':'item', 'id':'123'}) + + def test_url_replace(self): + p = StringHTMLProperty(self.client, 'test', '1', None, 'test', '') + def t(s): return p.hyper_re.sub(p._hyper_repl, s) + ae = self.assertEquals + ae(t('http://roundup.net/'), '<a href="http://roundup.net/">http://roundup.net/</a>') + ae(t('<HTTP://roundup.net/>'), '<<a href="HTTP://roundup.net/">HTTP://roundup.net/</a>>') + ae(t('<www.roundup.net>'), '<<a href="http://www.roundup.net">www.roundup.net</a>>') + ''' class HTMLPermissions: def is_edit_ok(self):
