cmlenz@1: # -*- coding: utf-8 -*-
cmlenz@1: #
cmlenz@1: # Copyright (C) 2006 Christopher Lenz
cmlenz@1: # All rights reserved.
cmlenz@1: #
cmlenz@1: # This software is licensed as described in the file COPYING, which
cmlenz@1: # you should have received as part of this distribution. The terms
cmlenz@1: # are also available at http://trac.edgewall.com/license.html.
cmlenz@1: #
cmlenz@1: # This software consists of voluntary contributions made by many
cmlenz@1: # individuals. For the exact contribution history, see the revision
cmlenz@1: # history and logs, available at http://projects.edgewall.com/trac/.
cmlenz@1:
cmlenz@1: import doctest
cmlenz@1: from HTMLParser import HTMLParseError
cmlenz@1: import unittest
cmlenz@1:
cmlenz@1: from markup.core import Markup, escape, unescape
cmlenz@1:
cmlenz@1:
cmlenz@1: class MarkupTestCase(unittest.TestCase):
cmlenz@1:
cmlenz@1: def test_escape(self):
cmlenz@1: markup = escape('"&"')
cmlenz@1: assert isinstance(markup, Markup)
cmlenz@1: self.assertEquals('<b>"&"</b>', markup)
cmlenz@1:
cmlenz@1: def test_escape_noquotes(self):
cmlenz@1: markup = escape('"&"', quotes=False)
cmlenz@1: assert isinstance(markup, Markup)
cmlenz@1: self.assertEquals('<b>"&"</b>', markup)
cmlenz@1:
cmlenz@1: def test_unescape_markup(self):
cmlenz@1: string = '"&"'
cmlenz@1: markup = Markup.escape(string)
cmlenz@1: assert isinstance(markup, Markup)
cmlenz@1: self.assertEquals(string, unescape(markup))
cmlenz@1:
cmlenz@1: def test_add_str(self):
cmlenz@1: markup = Markup('foo') + '
'
cmlenz@1: assert isinstance(markup, Markup)
cmlenz@1: self.assertEquals('foo<br/>', markup)
cmlenz@1:
cmlenz@1: def test_add_markup(self):
cmlenz@1: markup = Markup('foo') + Markup('
')
cmlenz@1: assert isinstance(markup, Markup)
cmlenz@1: self.assertEquals('foo
', markup)
cmlenz@1:
cmlenz@1: def test_add_reverse(self):
cmlenz@1: markup = 'foo' + Markup('bar')
cmlenz@1: assert isinstance(markup, unicode)
cmlenz@1: self.assertEquals('foobar', markup)
cmlenz@1:
cmlenz@1: def test_mod(self):
cmlenz@1: markup = Markup('%s') % '&'
cmlenz@1: assert isinstance(markup, Markup)
cmlenz@1: self.assertEquals('&', markup)
cmlenz@1:
cmlenz@1: def test_mod_multi(self):
cmlenz@1: markup = Markup('%s %s') % ('&', 'boo')
cmlenz@1: assert isinstance(markup, Markup)
cmlenz@1: self.assertEquals('& boo', markup)
cmlenz@1:
cmlenz@1: def test_mul(self):
cmlenz@1: markup = Markup('foo') * 2
cmlenz@1: assert isinstance(markup, Markup)
cmlenz@1: self.assertEquals('foofoo', markup)
cmlenz@1:
cmlenz@1: def test_join(self):
cmlenz@1: markup = Markup('
').join(['foo', '
<bar />
o').striptags()
cmlenz@1: assert isinstance(markup, Markup)
cmlenz@1: self.assertEquals('foo', markup)
cmlenz@1:
cmlenz@1: def test_striptags_empty(self):
cmlenz@1: markup = Markup('
').striptags()
cmlenz@1: assert isinstance(markup, Markup)
cmlenz@1: self.assertEquals('', markup)
cmlenz@1:
cmlenz@1: def test_striptags_mid(self):
cmlenz@1: markup = Markup('fo
o').striptags()
cmlenz@1: assert isinstance(markup, Markup)
cmlenz@1: self.assertEquals('foo', markup)
cmlenz@1:
cmlenz@1: def test_sanitize_unchanged(self):
cmlenz@1: markup = Markup('fo
o')
cmlenz@1: self.assertEquals('fo
o', str(markup.sanitize()))
cmlenz@1:
cmlenz@1: def test_sanitize_escape_text(self):
cmlenz@1: markup = Markup('fo&')
cmlenz@1: self.assertEquals('fo&', str(markup.sanitize()))
cmlenz@1: markup = Markup('<foo>')
cmlenz@1: self.assertEquals('<foo>', str(markup.sanitize()))
cmlenz@1:
cmlenz@1: def test_sanitize_entityref_text(self):
cmlenz@1: markup = Markup('foö')
cmlenz@1: self.assertEquals(u'foƶ', unicode(markup.sanitize()))
cmlenz@1:
cmlenz@1: def test_sanitize_escape_attr(self):
cmlenz@1: markup = Markup('