from __future__ import absolute_import from __future__ import print_function import unittest from tools.lib.pretty_print import pretty_print_html # Note that GOOD_HTML isn't necessarily beautiful HTML. Apart # from adjusting indentation, we mostly leave things alone to # respect whatever line-wrapping styles were in place before. BAD_HTML = """ Test

Hello
world!

Goodbyeworld!

5
            print 'hello world'
    
{{ bla }}
""" GOOD_HTML = """ Test

Hello
world!

Goodbyeworld!

5
                print 'hello world'
        
{{ bla }}
""" BAD_HTML1 = """ foobarfoobarfoobar """ GOOD_HTML1 = """ foobarfoobarfoobar """ BAD_HTML2 = """ {{# foobar area}} foobarfoobarfoobar {{/ foobar area}} """ GOOD_HTML2 = """ {{# foobar area}} foobarfoobarfoobar {{/ foobar area}} """ BAD_HTML3 = """ {{# foobar area}} foobarfoobar

FOOBAR

{{/ foobar area}} """ GOOD_HTML3 = """ {{# foobar area}} foobarfoobar

FOOBAR

{{/ foobar area}} """ BAD_HTML4 = """
foo

hello

bar
""" GOOD_HTML4 = """
foo

hello

bar
""" BAD_HTML5 = """
foo {{#if foobar}} hello {{else}} bye {{/if}} bar
""" GOOD_HTML5 = """
foo {{#if foobar}} hello {{else}} bye {{/if}} bar
""" BAD_HTML6 = """

foobar

""" GOOD_HTML6 = """

foobar

""" class TestPrettyPrinter(unittest.TestCase): def compare(self, a, b): # type: (str, str) -> None self.assertEqual(a.split('\n'), b.split('\n')) def test_pretty_print(self): # type: () -> None self.compare(pretty_print_html(GOOD_HTML), GOOD_HTML) self.compare(pretty_print_html(BAD_HTML), GOOD_HTML) self.compare(pretty_print_html(BAD_HTML1), GOOD_HTML1) self.compare(pretty_print_html(BAD_HTML2), GOOD_HTML2) self.compare(pretty_print_html(BAD_HTML3), GOOD_HTML3) self.compare(pretty_print_html(BAD_HTML4), GOOD_HTML4) self.compare(pretty_print_html(BAD_HTML5), GOOD_HTML5) self.compare(pretty_print_html(BAD_HTML6), GOOD_HTML6)