root/livinglogic.python.xist/test/test_xist_pretty.py @ 4440:b0c1a4ec589a

Revision 4440:b0c1a4ec589a, 1.3 KB (checked in by Walter Doerwald <walter@…>, 8 years ago)

Add a test for pretty printing UL4.

Line 
1#! /usr/bin/env/python
2# -*- coding: utf-8 -*-
3
4## Copyright 1999-2011 by LivingLogic AG, Bayreuth/Germany
5## Copyright 1999-2011 by Walter Dörwald
6##
7## All Rights Reserved
8##
9## See ll/__init__.py for the license
10
11
12from ll.xist import xsc
13from ll.xist.ns import html, php, ul4
14
15
16def test_pretty():
17    def check(node, result):
18        assert node.pretty().bytes() == result
19
20    tests = [
21        (html.p(u"apple", u"tree"), b"<p>appletree</p>"),
22        (html.p(u"apple", html.br(), u"tree"), b"<p>apple<br />tree</p>"),
23        (html.p(php.php(u"apple")), b"<p>\n\t<?php apple?>\n</p>"),
24        (html.p(php.php(u"apple"), u"tree"), b"<p><?php apple?>tree</p>"),
25        (
26            html.div(2*html.p(u"apple", u"tree"), html.br()),
27            b"<div>\n\t<p>appletree</p>\n\t<p>appletree</p>\n\t<br />\n</div>"
28        ),
29        (
30            html.div(
31                php.php(u"apple"),
32                html.p(u"apple", u"tree"),
33                html.div(
34                    html.p(u"apple"),
35                    html.p(u"tree"),
36                ),
37                html.br()
38            ),
39            b"<div>\n\t<?php apple?>\n\t<p>appletree</p>\n\t<div>\n\t\t<p>apple</p>\n\t\t<p>tree</p>\n\t</div>\n\t<br />\n</div>"
40        ),
41        (
42            html.ul(
43                ul4.for_("name in names"),
44                html.li(
45                    ul4.printx("name"),
46                ),
47                ul4.end("for"),
48            ),
49            b"<ul>\n\t<?for name in names?>\n\t\t<li>\n\t\t\t<?printx name?>\n\t\t</li>\n\t<?end for?>\n</ul>"
50        ),
51    ]
52    for (got, exp) in tests:
53        yield check, got, exp
Note: See TracBrowser for help on using the browser.