<commit_before># -*- coding: utf-8 -*-

from __future__ import unicode_literals

from nose.tools import assert_equal

from HTMLMinifier import minify


class TestMinifier(object):

    def test_simplest_html(self):
        html = """
        <!DOCTYPE html>
        <html>
          <head>
            <title>Hello</title>
          </head>
          <body>
            <p>hello, world</p>
          </body>
        </html>
        """
        minified_html = '<!DOCTYPE html>' \
                        '<html><head><title>Hello</title></head>' \
                        '<body><p>hello, world</p></body></html>'
        assert_equal(minified_html, minify(html))

    def test_remove_comments(self):
        html = """
        <!--
        this comment will be removed.
        -->
        """
        assert_equal('', minify(html))

    def test_preserve_comments(self):
        html = """
        <!--
        this comment will be removed.
        -->
        """
        assert_equal(html.strip(), minify(html, remove_comments=False))

    def test_ie_cond_comment(self):
        html = """
        <!--[if lt IE 9]>
          <p>  This is a paragraph  </p>
          <p>  This is another paragraph  </p>
        <![endif]-->
        """
        minified_html = '<!--[if lt IE 9]>' \
                        '<p>This is a paragraph</p>' \
                        '<p>This is another paragraph</p>' \
                        '<![endif]-->'
        assert_equal(minified_html, minify(html))

    def test_tag_with_attrs(self):
        html = """
        <div class="field required">
          <label for=username>User Name: </label>
          <input type  =  "text"    id="username">
        </div>
        """
        minified_html = '<div class="field required">' \
                        '<label for="username">User Name: </label>' \
                        '<input type="text" id="username">' \
                        '</div>'
        assert_equal(minified_html, minify(html))

        minified_html = '<div class="field required">' \
                        '<label for=username>User Name: </label>' \
                        '<input type=text id=username>' \
                        '</div>'
        assert_equal(minified_html, minify(html, remove_quotes=True))

    def test_self_closing_tags(self):
        html = """
        <div class="clearfix" />
        <img src="test.jpg" />
        """
        minified_html = '<div class="clearfix"/>' \
                        '<img src="test.jpg">'
        assert_equal(minified_html, minify(html))

    def test_pre_ws_elements(self):
        html = """
        <script>
          var sum = 0;
          for (var i = 0; i < 10; i++) {
              sum += i;
          }
          console.log(i);
        </script>
        """
        assert_equal(html.strip(), minify(html))

    def test_collapseing_spaces(self):
        html = """
        <p>  This is a [ <a href="index.html"> link </a> ]  </p>
        <p>  Some <b> highlighted </b> <i> text </i>  </p>
        <p>  More <b> complex <i> example </i> </b> ! </p>
        """
        minified_html = '<p>This is a [ <a href="index.html">link </a>]</p>' \
                        '<p>Some <b>highlighted </b><i>text</i></p>' \
                        '<p>More <b>complex <i>example </i></b>!</p>'
        assert_equal(minified_html, minify(html))

    def test_entity(self):
        html = """
        <p> &lt; html &gt; </p>
        """
        minified_html = '<p>&lt; html &gt;</p>'
        assert_equal(minified_html, minify(html))<commit_msg>Refine test cases<commit_after># -*- coding: utf-8 -*-

from __future__ import unicode_literals

from nose.tools import assert_equal

from HTMLMinifier import minify


class TestMinifier(object):

    def test_simplest_html(self):
        html = """
        <!DOCTYPE html>
        <html>
          <head>
            <title>Hello</title>
          </head>
          <body>
            <p>hello, world</p>
          </body>
        </html>
        """
        minified_html = '<!DOCTYPE html>' \
                        '<html><head><title>Hello</title></head>' \
                        '<body><p>hello, world</p></body></html>'
        assert_equal(minified_html, minify(html))

    def test_comment(self):
        html = """
        <!--
        this comment will be removed.
        -->
        """
        assert_equal('', minify(html))
        assert_equal(html.strip(), minify(html, remove_comments=False))

    def test_cond_comment(self):
        html = """
        <!--[if lt IE 9]>
          <p>  This is a paragraph  </p>
          <p>  This is another paragraph  </p>
        <![endif]-->
        """
        minified_html = '<!--[if lt IE 9]>' \
                        '<p>This is a paragraph</p>' \
                        '<p>This is another paragraph</p>' \
                        '<![endif]-->'
        assert_equal(minified_html, minify(html))

    def test_tag_with_attr(self):
        html = """
        <div class="field required">
          <label for=username>User Name: </label>
          <input type  =  "text"    id="username">
        </div>
        """
        minified_html = '<div class="field required">' \
                        '<label for="username">User Name: </label>' \
                        '<input type="text" id="username">' \
                        '</div>'
        assert_equal(minified_html, minify(html))

        minified_html = '<div class="field required">' \
                        '<label for=username>User Name: </label>' \
                        '<input type=text id=username>' \
                        '</div>'
        assert_equal(minified_html, minify(html, remove_quotes=True))

    def test_self_closing_tag(self):
        html = """
        <div class="clearfix" />
        <img src="test.jpg" />
        """
        minified_html = '<div class="clearfix"/>' \
                        '<img src="test.jpg">'
        assert_equal(minified_html, minify(html))

    def test_space_preserved_element(self):
        html = """
        <script>
          var sum = 0;
          for (var i = 0; i < 10; i++) {
              sum += i;
          }
          console.log(i);
        </script>
        """
        assert_equal(html.strip(), minify(html))

    def test_collapseing_spaces(self):
        html = """
        <p>  This is a [ <a href="index.html"> link </a> ]  </p>
        <p>  Some <b> highlighted </b> <i> text </i>  </p>
        <p>  More <b> complex <i> example </i> </b> ! </p>
        """
        minified_html = '<p>This is a [ <a href="index.html">link </a>]</p>' \
                        '<p>Some <b>highlighted </b><i>text</i></p>' \
                        '<p>More <b>complex <i>example </i></b>!</p>'
        assert_equal(minified_html, minify(html))

    def test_entity(self):
        html = """
        <p> &lt; html &#x3E; </p>
        """
        minified_html = '<p>&lt; html &#x3E;</p>'
        assert_equal(minified_html, minify(html))
{'fraction_non_alphanumeric': 0.1640893470790378, 'fraction_numerical': 0.002290950744558992, 'mean_word_length': 1.560483870967742, 'pattern_counts': {'":': 0, '<': 190, '<?xml version=': 0, '>': 188, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7290212', 'n_tokens_mistral': 2166, 'n_tokens_neox': 2099, 'n_words': 461}