"""
open/DurusWorks/qp/fill/test/utest_html.py

"""
from sancho.utest import UTest
from qp.fill.html import href, div, ol, ul, dl, nl2br, url_with_query, htmltag
from qp.fill.html import nlnl2brbr
from qpy import xml

class HTMLTest(UTest):

    def a(self):
        result = href('a', 'b', name="c")
        assert isinstance(result, xml)
        assert result == '<a href="a" name="c">b</a>', repr(result)

    def b(self):
        result = div('a', 'b', c="d")
        assert isinstance(result, xml)
        assert result == '<div c="d">ab</div>'

    def c(self):
        result = ol(['a', 'b'], c="d")
        assert isinstance(result, xml)
        assert result == '<ol c="d"><li>a</li><li>b</li></ol>'

    def d(self):
        result = ul(['a', 'b'], c="d")
        assert isinstance(result, xml)
        assert result == '<ul c="d"><li>a</li><li>b</li></ul>'

    def e(self):
        result = dl([('a', 'b'), ('e', None)], c="d")
        assert isinstance(result, xml)
        assert result == '<dl c="d"><dt>a</dt><dd>b</dd><dt>e</dt></dl>'

    def f(self):
        result = nl2br('')
        assert isinstance(result, xml)
        result = nl2br('a\nb\n')
        assert isinstance(result, xml)
        assert result == 'a<br />b<br />', result

    def test_nlnl2brbr(self):
        result = nlnl2brbr('')
        assert isinstance(result, xml)
        result = nlnl2brbr('a\nb\n')
        assert isinstance(result, xml)
        assert result == 'a\nb\n'
        result = nlnl2brbr('a\n\nb\n\nc\n')
        assert result == 'a<br /><br />b<br /><br />c\n', result

    def test_url_with_query(self):
        result = url_with_query('/foo', x=1, y='A<')
        assert isinstance(result, xml)
        assert result == '/foo?x=1&y=A%3C', result

    def g(self):
        result = htmltag('a', name="\xe1\x88\xb4")


if __name__ == '__main__':
    HTMLTest()
