feat(breaks): allowed p, head, and body tags that are short/empty to be on a single line

Added more tests.
This commit is contained in:
Christopher Pickering 2022-05-16 09:25:29 -05:00
parent a124a4dd6d
commit 886d59021a
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
43 changed files with 6458 additions and 218 deletions

View file

@ -726,6 +726,9 @@ class Config:
| li
| script
| style
| head
| body
| p
"""
self.always_self_closing_html_tags: str = r"""

View file

@ -1 +1 @@
{% example stuff %}<p>this is a long paragraph</p>{% endexample %}
{% example stuff %}<p>this is a very very long paragraph that does nothing except be a long paragraph asdfasdfasdfasdfasdf fasdf asdfasdfasdf</p>{% endexample %}

View file

@ -2,13 +2,12 @@
run::
pytest tests/test_config.py --cov=src/djlint --cov-branch \
pytest tests/test_config/test_custom_tags/test_config.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
for a single test, run::
pytest tests/test_config.py::test_custom_html --cov=src/djlint \
--cov-branch --cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_config/test_custom_tags/test_config.py::test_custom_tags
"""
# pylint: disable=C0116
@ -23,12 +22,12 @@ def test_custom_tags(runner: CliRunner) -> None:
result = runner.invoke(
djlint, ["tests/test_config/test_custom_tags/html.html", "--check"]
)
print(result.output)
assert (
"""-{% example stuff %}<p>this is a long paragraph</p>{% endexample %}
"""-{% example stuff %}<p>this is a very very long paragraph that does nothing except be a long paragraph asdfasdfasdfasdfasdf fasdf asdfasdfasdf</p>{% endexample %}
+{% example stuff %}
+ <p>
+ this is a long paragraph
+ this is a very very long paragraph that does nothing except be a long paragraph asdfasdfasdfasdfasdf fasdf asdfasdfasdf
+ </p>
+{% endexample %}
"""

View file

@ -2,13 +2,10 @@
run::
pytest tests/test_config_json.py --cov=src/djlint --cov-branch \
pytest tests/test_config/test_json/test_config.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
for a single test, run::
pytest tests/test_config_json.py::test_custom_html --cov=src/djlint \
--cov-branch --cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_config/test_json/test_config.py::test_config
"""
# pylint: disable=C0116
@ -26,9 +23,7 @@ def test_config(runner: CliRunner) -> None:
assert (
"""-{% example stuff %}<p>this is a long paragraph</p>{% endexample %}
+{% example stuff %}
+ <p>
+ this is a long paragraph
+ </p>
+ <p>this is a long paragraph</p>
+{% endexample %}
"""
in result.output

View file

@ -2,13 +2,10 @@
run::
pytest tests/test_config.py --cov=src/djlint --cov-branch \
pytest tests/test_config/test_pragmas/test_config.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
for a single test, run::
pytest tests/test_config.py::test_custom_html --cov=src/djlint \
--cov-branch --cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_config/test_pragmas/test_config.py::test_require_pragma
"""
# pylint: disable=C0116
@ -68,14 +65,11 @@ def test_require_pragma(runner: CliRunner) -> None:
assert (
""" {{!-- djlint:on --}}
<p>
-<p>
-
-{{firstname}} </p><p>{{lastname}}</p>
+ {{firstname}}
+</p>
+<p>
+ {{lastname}}
+</p>"""
+<p>{{firstname}}</p>
+<p>{{lastname}}</p>"""
in result.output
)
assert """1 file would be updated.""" in result.output
@ -98,13 +92,9 @@ def test_require_pragma(runner: CliRunner) -> None:
-
-</p>{{ end }}
+<h1>Test</h1>
+<p>
+ {{ .Variable }}
+</p>
+<p>{{ .Variable }}</p>
+{{ range .Items }}
+<p>
+ {{ . }}
+</p>
+<p>{{ . }}</p>
+{{ end }}
1 file would be updated."""

View file

@ -2,13 +2,10 @@
run::
pytest tests/test_django.py --cov=src/djlint --cov-branch \
pytest tests/test_django/test_comments.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
for a single test, run::
pytest tests/test_django.py::test_alpine_js --cov=src/djlint \
--cov-branch --cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_django/test_comments.py::test_comment
"""
# pylint: disable=C0116
@ -100,8 +97,7 @@ def test_comment(runner: CliRunner, tmp_file: TextIO) -> None:
{% endcomment %}
<script src="file5.js"></script>
</head>
<body>
</body>
<body></body>
</html>
""",
)
@ -123,8 +119,7 @@ def test_comment(runner: CliRunner, tmp_file: TextIO) -> None:
{# djlint:on #}
<script src="file5.js"></script>
</head>
<body>
</body>
<body></body>
</html>
""",
)

View file

@ -5,9 +5,7 @@ run::
pytest tests/test_djlint/test_djlint.py --cov=src/djlint --cov-branch --cov-report xml:coverage.xml --cov-report term-missing
for a single test::
pytest tests/test_djlint/test_djlint.py::test_version
pytest tests/test_djlint/test_djlint.py::test_check_reformatter_no_error
or::
@ -162,9 +160,7 @@ def test_check_reformatter_simple_error_quiet(
def test_check_reformatter_no_error(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(
tmp_file.name, b"<div>\n <p>\n nice stuff here\n </p>\n</div>"
)
write_to_file(tmp_file.name, b"<div>\n <p>nice stuff here</p>\n</div>")
result = runner.invoke(djlint, [tmp_file.name, "--check"])
assert result.exit_code == 0
assert "0 files would be updated." in result.output

View file

@ -30,9 +30,7 @@ def test_each(runner: CliRunner, tmp_file: TextIO) -> None:
output.text
== r"""{{#each people }}
{{ print_person }}
<p>
and more long stuff
</p>
<p>and more long stuff</p>
{{/each }}
"""
)

View file

@ -0,0 +1,63 @@
"""Djlint tests for handlebars.
Some tests may be from prettier.io's html test suite.
Where applicable this notice may be needed:
#### Prettier.io license ####
Copyright © James Long and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
run::
pytest tests/test_html/test_handlebars_venerable.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_handlebars_venerable.py::test_long_attributes --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
"""
# from typing import TextIO
# from click.testing import CliRunner
# from tests.conftest import reformat
# def test_template(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <script id="entry-template" type="text/x-handlebars-template">
# <div class="entry">
# <h1>{{title}}</h1>
# <div class="body">{{body}}</div></div>
# </script>
# <script type="text/x-handlebars-template">
# {{component arg1='hey' arg2=(helper this.arg7 this.arg4) arg3=anotherone arg6=this.arg8}}
# </script>
# """
# ).strip()
# html_out = (
# """
# <script id="entry-template" type="text/x-handlebars-template">
# <div class="entry">
# <h1>{{title}}</h1>
# <div class="body">{{body}}</div></div>
# </script>
# <script type="text/x-handlebars-template">
# {{component
# arg1="hey"
# arg2=(helper this.arg7 this.arg4)
# arg3=anotherone
# arg6=this.arg8
# }}
# </script>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)

View file

@ -28,9 +28,7 @@ def test_with(runner: CliRunner, tmp_file: TextIO) -> None:
assert (
output.text
== r"""{{#with person }}
<p>
{{ firstname }} {{ lastname }}
</p>
<p>{{ firstname }} {{ lastname }}</p>
{{/with }}
"""
)

View file

@ -1,4 +1,13 @@
"""DjLint tests for alpine.js."""
"""DjLint tests for alpine.js.
run:
pytest tests/test_html/test_alpinejs.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_alpinejs.py::test_alpine_js
"""
# pylint: disable=C0116
from typing import TextIO

View file

@ -1,14 +1,23 @@
"""Djlint tests specific to html.
"""Djlint tests for html attributes.
run::
pytest tests/test_html.py --cov=src/djlint --cov-branch \
pytest tests/test_html/test_attributes.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_attributes.py::test_long_attributes
Some tests may be from prettier.io's html test suite.
Where applicable this notice may be needed:
#### Prettier.io license ####
Copyright © James Long and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
# pylint: disable=C0116
from typing import TextIO
@ -99,3 +108,861 @@ def test_ignored_attributes(runner: CliRunner, tmp_file: TextIO) -> None:
json-data='{"menu":{"header":"SVG Viewer","items":[{"id":"Open"}]}}'>\n</div>
"""
)
# def test_attributes(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <input name=address maxlength=200>
# <input name='address' maxlength='200'>
# <input name="address" maxlength="200">
# <div class="foo"></div>
# <div class="foo" ></div>
# <div class="foo bar"></div>
# <div class="foo bar" id="header"></div>
# <div class="foo bar" id="header" ></div>
# <div data-prettier></div>
# <div data-prettier="true"></div>
# <meta property="og:description" content="The Mozilla Developer Network (MDN) provides
# information about Open Web technologies including HTML, CSS, and APIs for both Web sites
# and HTML5 Apps. It also documents Mozilla products, like Firefox OS.">
# <div attribute>String</div>
# <div attribute="">String</div>
# <div attribute=''>String</div>
# <div attribute >String</div>
# <div attribute = "" >String</div>
# <div attribute = '' >String</div>
# <div attribute >String</div>
# <div attribute = "" >String</div>
# <div attribute = '' >String</div>
# <div attribute="attribute = attribute"></div>
# <div ATTRIBUTE>String</div>
# <div ATTRIBUTE="">String</div>
# <div ATTRIBUTE=''>String</div>
# <article
# id="electriccars"
# data-columns="3"
# data-index-number="12314"
# data-parent="cars">
# </article>
# <article
# id="electriccars"
# data-columns="3"
# data-index-number="12314"
# data-parent="cars">...</article>
# <article
# id="electriccars"
# data-columns="3"
# data-index-number="12314"
# data-parent="cars">
# ...
# </article>
# <article
# id="electriccars"
# data-columns="3"
# data-index-number="12314"
# data-parent="cars">
# </article>
# <article
# id="electriccars"
# data-columns="3"
# data-index-number="12314"
# data-parent="cars">
# </article>
# <X>
# </X>
# <X a="1">
# </X>
# <X a="1" b="2">
# </X>
# <X a="1" b="2" c="3">
# </X>
# <p
# class="
# foo
# bar
# baz
# "
# >
# </p>
# """
# ).strip()
# html_out = (
# """
# <input name="address" maxlength="200" />
# <input name="address" maxlength="200" />
# <input name="address" maxlength="200" />
# <div class="foo"></div>
# <div class="foo"></div>
# <div class="foo bar"></div>
# <div class="foo bar" id="header"></div>
# <div class="foo bar" id="header"></div>
# <div data-prettier></div>
# <div data-prettier="true"></div>
# <meta
# property="og:description"
# content="The Mozilla Developer Network (MDN) provides
# information about Open Web technologies including HTML, CSS, and APIs for both Web sites
# and HTML5 Apps. It also documents Mozilla products, like Firefox OS." />
# <div attribute>String</div>
# <div attribute="">String</div>
# <div attribute="">String</div>
# <div attribute>String</div>
# <div attribute="">String</div>
# <div attribute="">String</div>
# <div attribute>String</div>
# <div attribute="">String</div>
# <div attribute="">String</div>
# <div attribute="attribute = attribute"></div>
# <div ATTRIBUTE>String</div>
# <div ATTRIBUTE="">String</div>
# <div ATTRIBUTE="">String</div>
# <article
# id="electriccars"
# data-columns="3"
# data-index-number="12314"
# data-parent="cars"
# ></article>
# <article
# id="electriccars"
# data-columns="3"
# data-index-number="12314"
# data-parent="cars"
# >
# ...
# </article>
# <article
# id="electriccars"
# data-columns="3"
# data-index-number="12314"
# data-parent="cars"
# >
# ...
# </article>
# <article
# id="electriccars"
# data-columns="3"
# data-index-number="12314"
# data-parent="cars"
# ></article>
# <article
# id="electriccars"
# data-columns="3"
# data-index-number="12314"
# data-parent="cars"
# ></article>
# <X> </X>
# <X a="1"> </X>
# <X a="1" b="2"> </X>
# <X a="1" b="2" c="3"> </X>
# <p class="foo bar baz"></p>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_boolean(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <button type="submit">This is valid.</button>
# <button type="submit" disabled>This is valid.</button>
# <button type="submit" disabled="">This is valid.</button>
# <button type="submit" disabled="disabled">This is valid.</button>
# <button type="submit" disabled=true>This is valid. This will be disabled.</button>
# <button type="submit" disabled='true'>This is valid. This will be disabled.</button>
# <button type="submit" disabled="true">This is valid. This will be disabled.</button>
# <button type="submit" disabled=false>This is valid. This will be disabled.</button>
# <button type="submit" disabled="false">This is valid. This will be disabled.</button>
# <button type="submit" disabled='false'>This is valid. This will be disabled.</button>
# <button type="submit" disabled=hahah>This is valid. This will be disabled.</button>
# <button type="submit" disabled='hahah'>This is valid. This will be disabled.</button>
# <button type="submit" disabled="hahah">This is valid. This will be disabled.</button>
# <input type="checkbox" checked disabled name="cheese">
# <input type="checkbox" checked="checked" disabled="disabled" name="cheese">
# <input type='checkbox' checked="" disabled="" name=cheese >
# <div lang=""></div>
# """
# ).strip()
# html_out = (
# """
# <button type="submit">This is valid.</button>
# <button type="submit" disabled>This is valid.</button>
# <button type="submit" disabled="">This is valid.</button>
# <button type="submit" disabled="disabled">This is valid.</button>
# <button type="submit" disabled="true">
# This is valid. This will be disabled.
# </button>
# <button type="submit" disabled="true">
# This is valid. This will be disabled.
# </button>
# <button type="submit" disabled="true">
# This is valid. This will be disabled.
# </button>
# <button type="submit" disabled="false">
# This is valid. This will be disabled.
# </button>
# <button type="submit" disabled="false">
# This is valid. This will be disabled.
# </button>
# <button type="submit" disabled="false">
# This is valid. This will be disabled.
# </button>
# <button type="submit" disabled="hahah">
# This is valid. This will be disabled.
# </button>
# <button type="submit" disabled="hahah">
# This is valid. This will be disabled.
# </button>
# <button type="submit" disabled="hahah">
# This is valid. This will be disabled.
# </button>
# <input type="checkbox" checked disabled name="cheese" />
# <input type="checkbox" checked="checked" disabled="disabled" name="cheese" />
# <input type="checkbox" checked="" disabled="" name="cheese" />
# <div lang=""></div>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_case_sensitive(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <div CaseSensitive></div>
# """
# ).strip()
# html_out = (
# """
# <div CaseSensitive></div>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_class_bem1(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <div class="ProviderMeasuresContainer__heading-row
# d-flex
# flex-column flex-lg-row
# justify-content-start justify-content-lg-between
# align-items-start align-items-lg-center">Foo</div>
# <div class="a-bem-block a-bem-block--with-modifer ">
# <div class="a-bem-block__element a-bem-block__element--with-modifer also-another-block" >
# <div class="a-bem-block__element a-bem-block__element--with-modifer also-another-block__element">
# </div></div> </div>
# """
# ).strip()
# html_out = (
# """
# <div
# class="ProviderMeasuresContainer__heading-row d-flex flex-column flex-lg-row justify-content-start justify-content-lg-between align-items-start align-items-lg-center"
# >
# Foo
# </div>
# <div class="a-bem-block a-bem-block--with-modifer">
# <div
# class="a-bem-block__element a-bem-block__element--with-modifer also-another-block">
# <div
# class="a-bem-block__element a-bem-block__element--with-modifer also-another-block__element"
# ></div>
# </div>
# </div>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_class_bem2(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <div class="news__header widget__content">
# <div class="news__tabs">
# <h1 class="news__tab-wrapper news__head-item">
# <a
# class="home-link home-link_blue_yes news__tab news__tab_selected_yes mix-tabber__tab mix-tabber__tab_selected_yes"
# tabindex="0"
# aria-selected="true"
# aria-controls="news_panel_news"
# data-key="news"
# id="news_tab_news"
# data-stat-link="news.tab.link.news"
# data-stat-select="news.tab.select.news"
# target="_blank"
# role="tab"
# href="https://yandex.ru/news?msid=1581089780.29024.161826.172442&mlid=1581088893.glob_225"
# rel="noopener"
# >...</a
# >
# </h1>
# </div>
# </div>
# """
# ).strip()
# html_out = (
# """
# <div class="news__header widget__content">
# <div class="news__tabs">
# <h1 class="news__tab-wrapper news__head-item">
# <a class="home-link home-link_blue_yes news__tab news__tab_selected_yes mix-tabber__tab mix-tabber__tab_selected_yes"
# tabindex="0"
# aria-selected="true"
# aria-controls="news_panel_news"
# data-key="news"
# id="news_tab_news"
# data-stat-link="news.tab.link.news"
# data-stat-select="news.tab.select.news"
# target="_blank"
# role="tab"
# href="https://yandex.ru/news?msid=1581089780.29024.161826.172442&mlid=1581088893.glob_225"
# rel="noopener"
# >...</a>
# </h1>
# </div>
# </div>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_class_colon(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <my-tag class="md:foo-bg md:foo-color md:foo--sub-bg md:foo--sub-color xl:foo xl:prefix2 --prefix2--something-else unrelated_class_to_fill_80_chars"></my-tag>
# """
# ).strip()
# html_out = (
# """
# <my-tag
# class="md:foo-bg md:foo-color md:foo--sub-bg md:foo--sub-color xl:foo xl:prefix2 --prefix2--something-else unrelated_class_to_fill_80_chars"
# ></my-tag>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_class_leading_dashes(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <my-tag class="__prefix1__foo __prefix1__bar __prefix2__foo prefix2 prefix2--something --prefix2--something-else"></my-tag>
# <my-tag class="--prefix1--foo --prefix1--bar --prefix2--foo prefix2 prefix2__something __prefix2__something_else"></my-tag>
# """
# ).strip()
# html_out = (
# """
# <my-tag
# class="__prefix1__foo __prefix1__bar __prefix2__foo prefix2 prefix2--something --prefix2--something-else"
# ></my-tag>
# <my-tag
# class="--prefix1--foo --prefix1--bar --prefix2--foo prefix2 prefix2__something __prefix2__something_else"
# ></my-tag>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_class_many_short_names(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <div aria-hidden="true" class="border rounded-1 flex-shrink-0 bg-gray px-1 text-gray-light ml-1 f6 d-none d-on-nav-focus js-jump-to-badge-jump">
# Jump to
# <span class="d-inline-block ml-1 v-align-middle">x</span>
# </div>
# """
# ).strip()
# html_out = (
# """
# <div
# aria-hidden="true"
# class="border rounded-1 flex-shrink-0 bg-gray px-1 text-gray-light ml-1 f6 d-none d-on-nav-focus js-jump-to-badge-jump"
# >
# Jump to
# <span class="d-inline-block ml-1 v-align-middle">x</span>
# </div>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_class_names(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <img class="
# foo
# bar
# ">
# <img class=" ">
# <img class>
# <img class="
# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong
# a-long-long-long-long-long-class-name
# another-long-long-long-class-name
# foo bar
# foo bar
# foo bar
# foo bar
# foo bar
# foo bar
# foo bar
# foo bar
# foo bar
# foo bar
# foo bar
# foo bar
# foo bar
# ">
# <img
# class="{{ ...classes }}">
# <img
# class="foo bar {{ otherClass }}">
# <!-- escaped -->
# <!-- from: https://developer.mozilla.org/en-US/docs/Web/API/CSS/escape#Basic_results -->
# <img class="
# \\.foo\\#bar
# \\(\\)\\[\\]\\{\\}
# --a
# \\30
# \\ufffd
# ">
# <!-- from yahoo website -->
# <div id="header-wrapper" class="Bgc(#fff) Bdbc(t) Bdbs(s) Bdbw(1px) D(tb) Pos(f) Tbl(f) W(100%) Z(4)
# has-scrolled_Bdc($c-fuji-grey-d) Scrolling_Bdc($c-fuji-grey-d) has-scrolled_Bxsh($headerShadow)
# Scrolling_Bxsh($headerShadow) ">
# <div class="Bgc(#fff) M(a) Maw(1301px) Miw(1000px) Pb(12px) Pt(22px) Pos(r) TranslateZ(0) Z(6)"
# ><h1 class="Fz(0) Pstart(15px) Pos(a)"><a id="header-logo"
# href="https://www.yahoo.com/" class="D(b) Pos(r)" data-ylk="elm:img;elmt:logo;sec:hd;slk:logo">
# <img class="H(27px)!--sm1024 Mt(9px)!--sm1024 W(90px)!--sm1024"
# src="https://s.yimg.com/rz/p/yahoo_frontpage_en-US_s_f_p_205x58_frontpage_2x.png" height="58px"
# width="205px" alt="Yahoo"/></a></h1></div></div>
# """
# ).strip()
# html_out = (
# """
# <img class="foo bar" />
# <img class=" " />
# <img class />
# <img
# class="looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong a-long-long-long-long-long-class-name another-long-long-long-class-name foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar"
# />
# <img class="{{ ...classes }}" />
# <img class="foo bar {{ otherClass }}" />
# <!-- escaped -->
# <!-- from: https://developer.mozilla.org/en-US/docs/Web/API/CSS/escape#Basic_results -->
# <img class="\\.foo\\#bar \\(\\)\\[\\]\\{\\} --a \\30 \\ufffd" />
# <!-- from yahoo website -->
# <div
# id="header-wrapper"
# class="Bgc(#fff) Bdbc(t) Bdbs(s) Bdbw(1px) D(tb) Pos(f) Tbl(f) W(100%) Z(4) has-scrolled_Bdc($c-fuji-grey-d) Scrolling_Bdc($c-fuji-grey-d) has-scrolled_Bxsh($headerShadow) Scrolling_Bxsh($headerShadow)"
# >
# <div
# class="Bgc(#fff) M(a) Maw(1301px) Miw(1000px) Pb(12px) Pt(22px) Pos(r) TranslateZ(0) Z(6)"
# >
# <h1 class="Fz(0) Pstart(15px) Pos(a)">
# <a
# id="header-logo"
# href="https://www.yahoo.com/"
# class="D(b) Pos(r)"
# data-ylk="elm:img;elmt:logo;sec:hd;slk:logo"
# >
# <img
# class="H(27px)!--sm1024 Mt(9px)!--sm1024 W(90px)!--sm1024"
# src="https://s.yimg.com/rz/p/yahoo_frontpage_en-US_s_f_p_205x58_frontpage_2x.png"
# height="58px"
# width="205px"
# alt="Yahoo"
# /></a>
# </h1>
# </div>
# </div>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_class_print_width_edge(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <div aria-hidden="true" class="border rounded-1 flex-shrink-0 bg-gray px-1 loooooooooooooooooooooooong">
# </div>
# """
# ).strip()
# html_out = (
# """
# <div
# aria-hidden="true"
# class="border rounded-1 flex-shrink-0 bg-gray px-1 loooooooooooooooooooooooong"
# ></div>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_dobule_quotes(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <img src="test.png" alt="John 'ShotGun' Nelson">
# """
# ).strip()
# html_out = (
# """
# <img src="test.png" alt="John 'ShotGun' Nelson" />
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_duplicate(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <a href="1" href="2">123</a>
# """
# ).strip()
# html_out = (
# """
# <a href="1" href="2">123</a>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_single_quotes(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <img src="test.png" alt='John "ShotGun" Nelson'>
# """
# ).strip()
# html_out = (
# """
# <img src="test.png" alt='John "ShotGun" Nelson' />
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_smart_quotes(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <div
# smart-quotes='123 " 456'
# smart-quotes="123 ' 456"
# smart-quotes='123 &apos;&quot; 456'
# ></div>
# """
# ).strip()
# html_out = (
# """
# <div
# smart-quotes='123 " 456'
# smart-quotes="123 ' 456"
# smart-quotes="123 '&quot; 456"
# ></div>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_srcset(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <img src="/assets/visual.png"
# srcset="/assets/visual@0.5.png 400w, /assets/visual.png 805w"
# sizes="(max-width: 66rem) 100vw, 66rem" alt=""/>
# <img src="/assets/visual.png"
# srcset="/assets/visual@0.5.png 400w, /assets/visual.png 805w, /assets/visual@2x.png 1610w, /assets/visual@3x.png 2415w"
# sizes="(max-width: 66rem) 100vw, 66rem" alt=""/>
# <img src="/assets/visual.png"
# srcset="/assets/visual@0.5.png 0.5x, /assets/visual.png 1111x, /assets/visual@2x.png 2x, /assets/visual@3x.png 3.3333x"
# sizes="(max-width: 66rem) 100vw, 66rem" alt=""/>
# <img
# srcset="
# /media/examples/surfer-240-200.jpg
# ">
# <!-- #8150 -->
# <img
# sizes="(max-width: 1400px) 100vw, 1400px"
# srcset="
# _20200401_145009_szrhju_c_scale,w_200.jpg 200w,
# _20200401_145009_szrhju_c_scale,w_379.jpg 379w,
# _20200401_145009_szrhju_c_scale,w_515.jpg 515w,
# _20200401_145009_szrhju_c_scale,w_630.jpg 630w,
# _20200401_145009_szrhju_c_scale,w_731.jpg 731w,
# _20200401_145009_szrhju_c_scale,w_828.jpg 828w,
# _20200401_145009_szrhju_c_scale,w_921.jpg 921w,
# _20200401_145009_szrhju_c_scale,w_995.jpg 995w,
# _20200401_145009_szrhju_c_scale,w_1072.jpg 1072w,
# _20200401_145009_szrhju_c_scale,w_1145.jpg 1145w,
# _20200401_145009_szrhju_c_scale,w_1216.jpg 1216w,
# _20200401_145009_szrhju_c_scale,w_1284.jpg 1284w,
# _20200401_145009_szrhju_c_scale,w_1350.jpg 1350w,
# _20200401_145009_szrhju_c_scale,w_1398.jpg 1398w,
# _20200401_145009_szrhju_c_scale,w_1400.jpg 1400w"
# src="_20200401_145009_szrhju_c_scale,w_1400.jpg"
# alt="">
# """
# ).strip()
# html_out = (
# """
# <img
# src="/assets/visual.png"
# srcset="/assets/visual@0.5.png 400w, /assets/visual.png 805w"
# sizes="(max-width: 66rem) 100vw, 66rem"
# alt=""
# />
# <img
# src="/assets/visual.png"
# srcset="
# /assets/visual@0.5.png 400w,
# /assets/visual.png 805w,
# /assets/visual@2x.png 1610w,
# /assets/visual@3x.png 2415w
# "
# sizes="(max-width: 66rem) 100vw, 66rem"
# alt=""
# />
# <img
# src="/assets/visual.png"
# srcset="
# /assets/visual@0.5.png 0.5x,
# /assets/visual.png 1111x,
# /assets/visual@2x.png 2x,
# /assets/visual@3x.png 3.3333x
# "
# sizes="(max-width: 66rem) 100vw, 66rem"
# alt=""
# />
# <img srcset="/media/examples/surfer-240-200.jpg" />
# <!-- #8150 -->
# <img
# sizes="(max-width: 1400px) 100vw, 1400px"
# srcset="
# _20200401_145009_szrhju_c_scale,w_200.jpg 200w,
# _20200401_145009_szrhju_c_scale,w_379.jpg 379w,
# _20200401_145009_szrhju_c_scale,w_515.jpg 515w,
# _20200401_145009_szrhju_c_scale,w_630.jpg 630w,
# _20200401_145009_szrhju_c_scale,w_731.jpg 731w,
# _20200401_145009_szrhju_c_scale,w_828.jpg 828w,
# _20200401_145009_szrhju_c_scale,w_921.jpg 921w,
# _20200401_145009_szrhju_c_scale,w_995.jpg 995w,
# _20200401_145009_szrhju_c_scale,w_1072.jpg 1072w,
# _20200401_145009_szrhju_c_scale,w_1145.jpg 1145w,
# _20200401_145009_szrhju_c_scale,w_1216.jpg 1216w,
# _20200401_145009_szrhju_c_scale,w_1284.jpg 1284w,
# _20200401_145009_szrhju_c_scale,w_1350.jpg 1350w,
# _20200401_145009_szrhju_c_scale,w_1398.jpg 1398w,
# _20200401_145009_szrhju_c_scale,w_1400.jpg 1400w
# "
# src="_20200401_145009_szrhju_c_scale,w_1400.jpg"
# alt=""
# />
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_style(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <div style="
# color:
# #fFf
# "></div>
# <div style=" "></div>
# <div style></div>
# <div style="
# all: initial;display: block;
# contain: content;text-align: center;
# background: linear-gradient(to left, hotpink, #FFF00F, #ccc, hsla(240, 100%, 50%, .05), transparent);
# background: linear-gradient(to left, hsla(240, 100%, 50%, .05), red);
# max-width: 500px;margin: 0 auto;
# border-radius: 8px;transition: transform .2s ease-out;
# "></div>
# <div style="
# background: linear-gradient(to left, hotpink, hsla(240, 100%, 50%, .05), transparent);
# "></div>
# <div style=" color : red;
# display :inline ">
# </div>
# <div style="
# color: green;
# display: inline
# ">
# </div>
# <div attribute-1 attribute-2 attribute-3 attribute-4 attribute-5 attribute-6 attribute-7
# style="css-prop-1: css-value;css-prop-2: css-value;css-prop-3: css-value;css-prop-4: css-value;"
# attribute-1 attribute-2 attribute-3 attribute-4 attribute-5 attribute-6 attribute-7 >
# </div>
# <div style="{{ ...styles }}"
# ></div>
# <div style="color: red; {{ otherStyles }}"
# ></div>
# """
# ).strip()
# html_out = (
# """
# <div style="color: #fff"></div>
# <div style=""></div>
# <div style></div>
# <div
# style="
# all: initial;
# display: block;
# contain: content;
# text-align: center;
# background: linear-gradient(
# to left,
# hotpink,
# #fff00f,
# #ccc,
# hsla(240, 100%, 50%, 0.05),
# transparent
# );
# background: linear-gradient(to left, hsla(240, 100%, 50%, 0.05), red);
# max-width: 500px;
# margin: 0 auto;
# border-radius: 8px;
# transition: transform 0.2s ease-out;
# "
# ></div>
# <div
# style="
# background: linear-gradient(
# to left,
# hotpink,
# hsla(240, 100%, 50%, 0.05),
# transparent
# );
# "
# ></div>
# <div style="color: red; display: inline"></div>
# <div
# style="
# color: green;
# display: inline;
# "
# ></div>
# <div
# attribute-1
# attribute-2
# attribute-3
# attribute-4
# attribute-5
# attribute-6
# attribute-7
# style="
# css-prop-1: css-value;
# css-prop-2: css-value;
# css-prop-3: css-value;
# css-prop-4: css-value;
# "
# attribute-1
# attribute-2
# attribute-3
# attribute-4
# attribute-5
# attribute-6
# attribute-7
# ></div>
# <div style="{{ ...styles }}"></div>
# <div style="color: red; {{ otherStyles }}"></div>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_without_quotes(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <p title=Title>String</p>
# """
# ).strip()
# html_out = (
# """
# <p title="Title">String</p>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out

View file

@ -0,0 +1,980 @@
"""Djlint tests for basic stuff.
Some tests may be from prettier.io's html test suite.
Where applicable this notice may be needed:
#### Prettier.io license ####
Copyright © James Long and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
run::
poetry run pytest tests/test_html/test_basics.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
poetry run pytest tests/test_html/test_basics.py::test_brocken_html
"""
# pylint: disable=C0116
from typing import TextIO
from click.testing import CliRunner
from tests.conftest import reformat
# def test_brocken_html(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <!--
# #7241,
# reproduction:
# two different element,
# linebreak
# \\`<\\`
# extra space(s)
# -->
# <div><span>
# <
# """
# ).strip()
# html_out = (
# """
# <!--
# #7241,
# reproduction:
# two different element,
# linebreak
# \\`<\\`
# extra space(s)
# -->
# <div>
# <span> <
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
def test_comment(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
b"""<!--hello world-->""",
)
assert (
output.text
== """<!--hello world-->
"""
)
# def test_emtpy_doc(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <!doctype html>
# <html>
# <head></head>
# <body></body>
# </html>
# """
# ).strip()
# html_out = (
# """
# <!DOCTYPE html>
# <html>
# <head></head>
# <body></body>
# </html>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
def test_empty(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
b"",
)
assert (
output.text
== """
"""
)
# def test_form(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <form>
# <div class="form-group">
# <label for="exampleInputEmail1">Email address</label>
# <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
# <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
# </div>
# <div class="form-group">
# <label for="exampleInputPassword1">Password</label>
# <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
# </div>
# <div class="form-group">
# <label for="exampleSelect1">Example select</label>
# <select class="form-control" id="exampleSelect1">
# <option>1</option>
# <option>2</option>
# <option>3</option>
# <option>4</option>
# <option>5</option>
# </select>
# </div>
# <div class="form-group">
# <label for="exampleSelect2">Example multiple select</label>
# <select multiple class="form-control" id="exampleSelect2">
# <option>1</option>
# <option>2</option>
# <option>3</option>
# <option>4</option>
# <option>5</option>
# </select>
# </div>
# <div class="form-group">
# <label for="exampleTextarea">Example textarea</label>
# <textarea class="form-control" id="exampleTextarea" rows="3"></textarea>
# </div>
# <div class="form-group">
# <label for="exampleInputFile">File input</label>
# <input type="file" class="form-control-file" id="exampleInputFile" aria-describedby="fileHelp">
# <small id="fileHelp" class="form-text text-muted">This is some placeholder block-level help text for the above input. It's a bit lighter and easily wraps to a new line.</small>
# </div>
# <fieldset class="form-group">
# <legend>Radio buttons</legend>
# <div class="form-check">
# <label class="form-check-label">
# <input type="radio" class="form-check-input" name="optionsRadios" id="optionsRadios1" value="option1" checked>
# Option one is this and that&mdash;be sure to include why it's great
# </label>
# </div>
# <div class="form-check">
# <label class="form-check-label">
# <input type="radio" class="form-check-input" name="optionsRadios" id="optionsRadios2" value="option2">
# Option two can be something else and selecting it will deselect option one
# </label>
# </div>
# <div class="form-check disabled">
# <label class="form-check-label">
# <input type="radio" class="form-check-input" name="optionsRadios" id="optionsRadios3" value="option3" disabled>
# Option three is disabled
# </label>
# </div>
# </fieldset>
# <div class="form-check">
# <label class="form-check-label">
# <input type="checkbox" class="form-check-input">
# Check me out
# </label>
# </div>
# <button type="submit" class="btn btn-primary">Submit</button>
# </form>
# """
# ).strip()
# html_out = (
# """
# <form>
# <div class="form-group">
# <label for="exampleInputEmail1">Email address</label>
# <input
# type="email"
# class="form-control"
# id="exampleInputEmail1"
# aria-describedby="emailHelp"
# placeholder="Enter email"
# />
# <small id="emailHelp" class="form-text text-muted"
# >We'll never share your email with anyone else.</small
# >
# </div>
# <div class="form-group">
# <label for="exampleInputPassword1">Password</label>
# <input
# type="password"
# class="form-control"
# id="exampleInputPassword1"
# placeholder="Password"
# />
# </div>
# <div class="form-group">
# <label for="exampleSelect1">Example select</label>
# <select class="form-control" id="exampleSelect1">
# <option>1</option>
# <option>2</option>
# <option>3</option>
# <option>4</option>
# <option>5</option>
# </select>
# </div>
# <div class="form-group">
# <label for="exampleSelect2">Example multiple select</label>
# <select multiple class="form-control" id="exampleSelect2">
# <option>1</option>
# <option>2</option>
# <option>3</option>
# <option>4</option>
# <option>5</option>
# </select>
# </div>
# <div class="form-group">
# <label for="exampleTextarea">Example textarea</label>
# <textarea class="form-control" id="exampleTextarea" rows="3"></textarea>
# </div>
# <div class="form-group">
# <label for="exampleInputFile">File input</label>
# <input
# type="file"
# class="form-control-file"
# id="exampleInputFile"
# aria-describedby="fileHelp"
# />
# <small id="fileHelp" class="form-text text-muted"
# >This is some placeholder block-level help text for the above input. It's
# a bit lighter and easily wraps to a new line.</small
# >
# </div>
# <fieldset class="form-group">
# <legend>Radio buttons</legend>
# <div class="form-check">
# <label class="form-check-label">
# <input
# type="radio"
# class="form-check-input"
# name="optionsRadios"
# id="optionsRadios1"
# value="option1"
# checked
# />
# Option one is this and that&mdash;be sure to include why it's great
# </label>
# </div>
# <div class="form-check">
# <label class="form-check-label">
# <input
# type="radio"
# class="form-check-input"
# name="optionsRadios"
# id="optionsRadios2"
# value="option2"
# />
# Option two can be something else and selecting it will deselect option
# one
# </label>
# </div>
# <div class="form-check disabled">
# <label class="form-check-label">
# <input
# type="radio"
# class="form-check-input"
# name="optionsRadios"
# id="optionsRadios3"
# value="option3"
# disabled
# />
# Option three is disabled
# </label>
# </div>
# </fieldset>
# <div class="form-check">
# <label class="form-check-label">
# <input type="checkbox" class="form-check-input" />
# Check me out
# </label>
# </div>
# <button type="submit" class="btn btn-primary">Submit</button>
# </form>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
def test_hello_world(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
b"""<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<!-- A comment -->
<h1>Hello World</h1>
</body>
</html>
""",
)
assert output.exit_code == 0
def test_html_comments(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
b"""<!-- htmlhint attr-lowercase: false -->
<html>
<body>
<a href="#">Anchor</a>
<div hidden class="foo" id=bar></div>
</body>
</html>
""",
)
assert output.exit_code == 0
# def test_html5_boilerplate(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <!doctype html>
# <html class="no-js" lang="">
# <head>
# <meta charset="utf-8">
# <meta http-equiv="x-ua-compatible" content="ie=edge">
# <title></title>
# <meta name="description" content="">
# <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
# <link rel="manifest" href="site.webmanifest">
# <link rel="apple-touch-icon" href="icon.png">
# <!-- Place favicon.ico in the root directory -->
# <link rel="stylesheet" href="css/normalize.css">
# <link rel="stylesheet" href="css/main.css">
# </head>
# <body>
# <!--[if lte IE 9]>
# <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="https://browsehappy.com/">upgrade your browser</a> to improve your experience and security.</p>
# <![endif]-->
# <!-- Add your site or application content here -->
# <p>Hello world! This is HTML5 Boilerplate.</p>
# <script src="js/vendor/modernizr-3.6.0.min.js"></script>
# <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
# <script>window.jQuery || document.write('<script src="js/vendor/jquery-3.3.1.min.js"><\\/script>')</script>
# <script src="js/plugins.js"></script>
# <script src="js/main.js"></script>
# <!-- Google Analytics: change UA-XXXXX-Y to be your site's ID. -->
# <script>
# window.ga = function () { ga.q.push(arguments) }; ga.q = []; ga.l = +new Date;
# ga('create', 'UA-XXXXX-Y', 'auto'); ga('send', 'pageview')
# </script>
# <script src="https://www.google-analytics.com/analytics.js" async defer></script>
# </body>
# </html>
# """
# ).strip()
# html_out = (
# """
# <!DOCTYPE html>
# <html class="no-js" lang="">
# <head>
# <meta charset="utf-8" />
# <meta http-equiv="x-ua-compatible" content="ie=edge" />
# <title></title>
# <meta name="description" content="" />
# <meta
# name="viewport"
# content="width=device-width, initial-scale=1, shrink-to-fit=no"
# />
# <link rel="manifest" href="site.webmanifest" />
# <link rel="apple-touch-icon" href="icon.png" />
# <!-- Place favicon.ico in the root directory -->
# <link rel="stylesheet" href="css/normalize.css" />
# <link rel="stylesheet" href="css/main.css" />
# </head>
# <body>
# <!--[if lte IE 9]>
# <p class="browserupgrade">
# You are using an <strong>outdated</strong> browser. Please
# <a href="https://browsehappy.com/">upgrade your browser</a> to improve
# your experience and security.
# </p>
# <![endif]-->
# <!-- Add your site or application content here -->
# <p>Hello world! This is HTML5 Boilerplate.</p>
# <script src="js/vendor/modernizr-3.6.0.min.js"></script>
# <script
# src="https://code.jquery.com/jquery-3.3.1.min.js"
# integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
# crossorigin="anonymous"
# ></script>
# <script>
# window.jQuery ||
# document.write(
# '<script src="js/vendor/jquery-3.3.1.min.js"><\\/script>'
# );
# </script>
# <script src="js/plugins.js"></script>
# <script src="js/main.js"></script>
# <!-- Google Analytics: change UA-XXXXX-Y to be your site's ID. -->
# <script>
# window.ga = function () {
# ga.q.push(arguments);
# };
# ga.q = [];
# ga.l = +new Date();
# ga("create", "UA-XXXXX-Y", "auto");
# ga("send", "pageview");
# </script>
# <script
# src="https://www.google-analytics.com/analytics.js"
# async
# defer
# ></script>
# </body>
# </html>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_issue_9368_2(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <strong>a</strong>-<strong>b</strong>-
# """
# ).strip()
# html_out = (
# """
# <strong>a</strong>-<strong>b</strong>-
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
def test_issue_9368_3(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
b"""a track<strong>pad</strong>, or a <strong>gyro</strong>scope.
""",
)
assert output.exit_code == 0
def test_issue_9368(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
b"""<strong>a</strong>-&gt;<strong>b</strong>-&gt;
""",
)
assert output.exit_code == 0
# def test_more_html(runner: CliRunner, tmp_file: TextIO) -> None:
# output = reformat(
# tmp_file,
# runner,
# b"""
# <html>
# <head></head>
# <body>
# <a href="#">Anchor</a>
# <div hidden class="foo" id=bar></div>
# </body>
# </html>
# """
# )
# assert output.text == """<html>
# <head></head>
# <body>
# <a href="#">Anchor</a>
# <div hidden class="foo" id="bar"></div>
# </body>
# </html>
# """
def test_void_elements(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
b"""<html>
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="code-guide.css" />
</head>
<body></body>
</html>
""",
)
assert output.exit_code == 0
# def test_void_elements_2(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <video controls width="250">
# <source src="/media/examples/flower.webm"
# type="video/webm">
# <source src="/media/examples/flower.mp4"
# type="video/mp4"
# ></video>text after
# <!-- #8626 -->
# <object data="horse.wav"><param name="autoplay" value="true"
# ><param name="autoplay" value="true"
# ></object>1
# <span><img src="1.png"
# ><img src="1.png"
# ></span>1
# """
# ).strip()
# html_out = (
# """
# <video controls width="250">
# <source src="/media/examples/flower.webm" type="video/webm" />
# <source src="/media/examples/flower.mp4" type="video/mp4" /></video
# >text after
# <!-- #8626 -->
# <object data="horse.wav">
# <param name="autoplay" value="true" />
# <param name="autoplay" value="true" /></object
# >1
# <span><img src="1.png" /><img src="1.png" /></span>1
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_with_colon(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <!-- unknown tag with colon -->
# <div>
# <foo:bar>
# <div> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block </div>
# <div> block </div><DIV> BLOCK </DIV> <div> block </div><div> block </div><div> block </div>
# <pre> pre pr
# e</pre>
# <textarea> pre-wrap pr
# e-wrap </textarea>
# <span> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline </span>
# <span> inline </span><span> inline </span> <span> inline </span><span> inline </span>
# <html:div> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block </html:div>
# <html:DIV> block </html:DIV><HTML:DIV> BLOCK </HTML:DIV> <html:div> block </html:div><html:div> block </html:div><html:div> block </html:div>
# <html:pre> pre pr
# e</html:pre>
# <html:textarea> pre-wrap pr
# e-wrap </html:textarea>
# <html:span> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline </html:span>
# <html:span> inline </html:span><html:span> inline </html:span> <html:span> inline </html:span><html:span> inline </html:span></foo:bar>
# </div>
# <!-- block tag with colon -->
# <div>
# <foo:div>
# <div> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block </div>
# <div> block </div><DIV> BLOCK </DIV> <div> block </div><div> block </div><div> block </div>
# <pre> pre pr
# e</pre>
# <textarea> pre-wrap pr
# e-wrap </textarea>
# <span> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline </span>
# <span> inline </span><span> inline </span> <span> inline </span><span> inline </span>
# <html:div> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block </html:div>
# <html:DIV> block </html:DIV><HTML:DIV> BLOCK </HTML:DIV> <html:div> block </html:div><html:div> block </html:div><html:div> block </html:div>
# <html:pre> pre pr
# e</html:pre>
# <html:textarea> pre-wrap pr
# e-wrap </html:textarea>
# <html:span> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline </html:span>
# <html:span> inline </html:span><html:span> inline </html:span> <html:span> inline </html:span><html:span> inline </html:span></foo:div>
# </div>
# <!-- inline tag with colon -->
# <div>
# <foo:span>
# <div> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block </div>
# <div> block </div><DIV> BLOCK </DIV> <div> block </div><div> block </div><div> block </div>
# <pre> pre pr
# e</pre>
# <textarea> pre-wrap pr
# e-wrap </textarea>
# <span> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline </span>
# <span> inline </span><span> inline </span> <span> inline </span><span> inline </span>
# <html:div> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block </html:div>
# <html:DIV> block </html:DIV><HTML:DIV> BLOCK </HTML:DIV> <html:div> block </html:div><html:div> block </html:div><html:div> block </html:div>
# <html:pre> pre pr
# e</html:pre>
# <html:textarea> pre-wrap pr
# e-wrap </html:textarea>
# <html:span> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline </html:span>
# <html:span> inline </html:span><html:span> inline </html:span> <html:span> inline </html:span><html:span> inline </html:span></foo:span>
# </div>
# <!-- unknown -->
# <div>
# <foo-bar>
# <div> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block </div>
# <div> block </div><DIV> BLOCK </DIV> <div> block </div><div> block </div><div> block </div>
# <pre> pre pr
# e</pre>
# <textarea> pre-wrap pr
# e-wrap </textarea>
# <span> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline </span>
# <span> inline </span><span> inline </span> <span> inline </span><span> inline </span>
# <html:div> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block </html:div>
# <html:DIV> block </html:DIV><HTML:DIV> BLOCK </HTML:DIV> <html:div> block </html:div><html:div> block </html:div><html:div> block </html:div>
# <html:pre> pre pr
# e</html:pre>
# <html:textarea> pre-wrap pr
# e-wrap </html:textarea>
# <html:span> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline </html:span>
# <html:span> inline </html:span><html:span> inline </html:span> <html:span> inline </html:span><html:span> inline </html:span></foo-bar>
# </div>
# <!-- without colon -->
# <div>
# <div>
# <div> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block </div>
# <div> block </div><DIV> BLOCK </DIV> <div> block </div><div> block </div><div> block </div>
# <pre> pre pr
# e</pre>
# <textarea> pre-wrap pr
# e-wrap </textarea>
# <span> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline </span>
# <span> inline </span><span> inline </span> <span> inline </span><span> inline </span>
# <html:div> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block </html:div>
# <html:DIV> block </html:DIV><HTML:DIV> BLOCK </HTML:DIV> <html:div> block </html:div><html:div> block </html:div><html:div> block </html:div>
# <html:pre> pre pr
# e</html:pre>
# <html:textarea> pre-wrap pr
# e-wrap </html:textarea>
# <html:span> looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline </html:span>
# <html:span> inline </html:span><html:span> inline </html:span> <html:span> inline </html:span><html:span> inline </html:span></div>
# </div>
# <!-- #7236 -->
# <with:colon>
# <div><h1> text text text text text text text text text text text text text text </h1></div>
# <script>
# const func = function() { console.log('Hello, there');}
# </script>
# </with:colon>
# <!-- script like -->
# <with:colon>
# <style>.a{color:#f00}</style>
# <SCRIPT>
# const func = function() { console.log('Hello, there');}
# </SCRIPT>
# <STYLE>.A{COLOR:#F00}</STYLE>
# <html:script>const func = function() { console.log('Hello, there');}</html:script>
# <html:style>.a{color:#f00}</html:style>
# <svg><style>.a{color:#f00}</style></svg>
# <svg><style>.a{color:#f00}</style></svg>
# </with:colon>
# <html:script>const func = function() { console.log('Hello, there');}</html:script>
# <html:style>.a{color:#f00}</html:style>
# """
# ).strip()
# html_out = (
# """
# <!-- unknown tag with colon -->
# <div>
# <foo:bar>
# <div>
# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block
# </div>
# <div>block</div>
# <div>BLOCK</div>
# <div>block</div>
# <div>block</div>
# <div>block</div>
# <pre>
# pre pr
# e</pre
# >
# <textarea>
# pre-wrap pr
# e-wrap </textarea
# >
# <span>
# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline
# </span>
# <span> inline </span><span> inline </span> <span> inline </span
# ><span> inline </span>
# <html:div>
# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block
# </html:div>
# <html:DIV> block </html:DIV><HTML:DIV> BLOCK </HTML:DIV>
# <html:div> block </html:div><html:div> block </html:div
# ><html:div> block </html:div>
# <html:pre> pre pr e</html:pre>
# <html:textarea> pre-wrap pr e-wrap </html:textarea>
# <html:span>
# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline
# </html:span>
# <html:span> inline </html:span><html:span> inline </html:span>
# <html:span> inline </html:span><html:span> inline </html:span></foo:bar
# >
# </div>
# <!-- block tag with colon -->
# <div>
# <foo:div>
# <div>
# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block
# </div>
# <div>block</div>
# <div>BLOCK</div>
# <div>block</div>
# <div>block</div>
# <div>block</div>
# <pre>
# pre pr
# e</pre
# >
# <textarea>
# pre-wrap pr
# e-wrap </textarea
# >
# <span>
# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline
# </span>
# <span> inline </span><span> inline </span> <span> inline </span
# ><span> inline </span>
# <html:div>
# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block
# </html:div>
# <html:DIV> block </html:DIV><HTML:DIV> BLOCK </HTML:DIV>
# <html:div> block </html:div><html:div> block </html:div
# ><html:div> block </html:div>
# <html:pre> pre pr e</html:pre>
# <html:textarea> pre-wrap pr e-wrap </html:textarea>
# <html:span>
# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline
# </html:span>
# <html:span> inline </html:span><html:span> inline </html:span>
# <html:span> inline </html:span><html:span> inline </html:span></foo:div
# >
# </div>
# <!-- inline tag with colon -->
# <div>
# <foo:span>
# <div>
# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block
# </div>
# <div>block</div>
# <div>BLOCK</div>
# <div>block</div>
# <div>block</div>
# <div>block</div>
# <pre>
# pre pr
# e</pre
# >
# <textarea>
# pre-wrap pr
# e-wrap </textarea
# >
# <span>
# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline
# </span>
# <span> inline </span><span> inline </span> <span> inline </span
# ><span> inline </span>
# <html:div>
# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block
# </html:div>
# <html:DIV> block </html:DIV><HTML:DIV> BLOCK </HTML:DIV>
# <html:div> block </html:div><html:div> block </html:div
# ><html:div> block </html:div>
# <html:pre> pre pr e</html:pre>
# <html:textarea> pre-wrap pr e-wrap </html:textarea>
# <html:span>
# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline
# </html:span>
# <html:span> inline </html:span><html:span> inline </html:span>
# <html:span> inline </html:span><html:span> inline </html:span></foo:span
# >
# </div>
# <!-- unknown -->
# <div>
# <foo-bar>
# <div>
# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block
# </div>
# <div>block</div>
# <div>BLOCK</div>
# <div>block</div>
# <div>block</div>
# <div>block</div>
# <pre>
# pre pr
# e</pre
# >
# <textarea>
# pre-wrap pr
# e-wrap </textarea
# >
# <span>
# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline
# </span>
# <span> inline </span><span> inline </span> <span> inline </span
# ><span> inline </span>
# <html:div>
# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block
# </html:div>
# <html:DIV> block </html:DIV><HTML:DIV> BLOCK </HTML:DIV>
# <html:div> block </html:div><html:div> block </html:div
# ><html:div> block </html:div>
# <html:pre> pre pr e</html:pre>
# <html:textarea> pre-wrap pr e-wrap </html:textarea>
# <html:span>
# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline
# </html:span>
# <html:span> inline </html:span><html:span> inline </html:span>
# <html:span> inline </html:span><html:span> inline </html:span></foo-bar
# >
# </div>
# <!-- without colon -->
# <div>
# <div>
# <div>
# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block
# </div>
# <div>block</div>
# <div>BLOCK</div>
# <div>block</div>
# <div>block</div>
# <div>block</div>
# <pre>
# pre pr
# e</pre
# >
# <textarea>
# pre-wrap pr
# e-wrap </textarea
# >
# <span>
# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline
# </span>
# <span> inline </span><span> inline </span> <span> inline </span
# ><span> inline </span>
# <html:div>
# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog block
# </html:div>
# <html:DIV> block </html:DIV><HTML:DIV> BLOCK </HTML:DIV>
# <html:div> block </html:div><html:div> block </html:div
# ><html:div> block </html:div>
# <html:pre> pre pr e</html:pre>
# <html:textarea> pre-wrap pr e-wrap </html:textarea>
# <html:span>
# looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog inline
# </html:span>
# <html:span> inline </html:span><html:span> inline </html:span>
# <html:span> inline </html:span><html:span> inline </html:span>
# </div>
# </div>
# <!-- #7236 -->
# <with:colon>
# <div>
# <h1>
# text text text text text text text text text text text text text text
# </h1>
# </div>
# <script>
# const func = function () {
# console.log("Hello, there");
# };
# </script>
# </with:colon>
# <!-- script like -->
# <with:colon>
# <style>
# .a {
# color: #f00;
# }
# </style>
# <script>
# const func = function () {
# console.log("Hello, there");
# };
# </script>
# <style>
# .A {
# color: #f00;
# }
# </style>
# <html:script
# >const func = function() { console.log('Hello, there');}</html:script
# >
# <html:style
# >.a{color:#f00}</html:style
# >
# <svg>
# <style>
# .a {
# color: #f00;
# }
# </style>
# </svg>
# <svg>
# <style>
# .a {
# color: #f00;
# }
# </style>
# </svg>
# </with:colon>
# <html:script
# >const func = function() { console.log('Hello, there');}</html:script
# >
# <html:style
# >.a{color:#f00}</html:style
# >
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out

View file

@ -0,0 +1,311 @@
"""Djlint tests for brackets same line.
Some tests may be from prettier.io's html test suite.
Where applicable this notice may be needed:
#### Prettier.io license ####
Copyright © James Long and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
run::
poetry run pytest tests/test_html/test_bracket_same_line.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
poetry run pytest tests/test_html/test_bracket_same_line.py::test_block
"""
# from typing import TextIO
# from click.testing import CliRunner
# from ..conftest import reformat
# def test_block(runner: CliRunner, tmp_file: TextIO) -> None:
# # set bracket-same-line: false
# html_in = (
# b"""
# <div long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value">
# text
# </div>
# <div long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value"></div>
# <div class="a">
# text
# </div>
# <div class="a">text</div>
# """
# ).strip()
# html_out = (
# """
# <div
# long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value"
# >
# text
# </div>
# <div
# long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value"
# ></div>
# <div class="a">text</div>
# <div class="a">text</div>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# # set bracket-same-line: true
# html_in = (
# b"""
# <div long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value">
# text
# </div>
# <div long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value"></div>
# <div class="a">
# text
# </div>
# <div class="a">text</div>
# """
# ).strip()
# html_out = (
# """
# <div
# long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value">
# text
# </div>
# <div
# long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value"></div>
# <div class="a">text</div>
# <div class="a">text</div>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_embed(runner: CliRunner, tmp_file: TextIO) -> None:
# # set bracket-same-line: false
# html_in = (
# b"""
# <script long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value">
# alert(1)</script>
# <style long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value">
# .a{color: #f00}</style>
# <script>
# alert(1)</script>
# <style>
# .a{color: #f00}</style>
# """
# ).strip()
# html_out = (
# """
# <script
# long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value"
# >
# alert(1);
# </script>
# <style
# long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value"
# >
# .a {
# color: #f00;
# }
# </style>
# <script>
# alert(1);
# </script>
# <style>
# .a {
# color: #f00;
# }
# </style>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# # set bracket-same-line: true
# html_in = (
# b"""
# <script long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value">
# alert(1)</script>
# <style long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value">
# .a{color: #f00}</style>
# <script>
# alert(1)</script>
# <style>
# .a{color: #f00}</style>
# """
# ).strip()
# html_out = (
# """
# <script
# long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value">
# alert(1);
# </script>
# <style
# long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value">
# .a {
# color: #f00;
# }
# </style>
# <script>
# alert(1);
# </script>
# <style>
# .a {
# color: #f00;
# }
# </style>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_inline(runner: CliRunner, tmp_file: TextIO) -> None:
# # set bracket-same-line: false
# html_in = (
# b"""
# <span long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value">
# text
# </span>
# <span long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value"></span>
# <span class="a">text</span>
# <span long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value">
# text
# </span>
# <span class="a">text</span><span long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value">
# text
# </span>
# <span class="a">text</span><span class="a">text</span><span class="a">text</span><span class="a">text</span><span class="a">text</span>
# """
# ).strip()
# html_out = (
# """
# <span
# long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value"
# >
# text
# </span>
# <span
# long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value"
# ></span>
# <span class="a">text</span>
# <span
# long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value"
# >
# text
# </span>
# <span class="a">text</span
# ><span
# long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value"
# >
# text
# </span>
# <span class="a">text</span><span class="a">text</span><span class="a">text</span
# ><span class="a">text</span><span class="a">text</span>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# # set bracket-same-line: true
# html_in = (
# b"""
# <span long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value">
# text
# </span>
# <span long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value"></span>
# <span class="a">text</span>
# <span long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value">
# text
# </span>
# <span class="a">text</span><span long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value">
# text
# </span>
# <span class="a">text</span><span class="a">text</span><span class="a">text</span><span class="a">text</span><span class="a">text</span>
# """
# ).strip()
# html_out = (
# """
# <span
# long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value">
# text
# </span>
# <span
# long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value"></span>
# <span class="a">text</span>
# <span
# long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value">
# text
# </span>
# <span class="a">text</span
# ><span
# long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value">
# text
# </span>
# <span class="a">text</span><span class="a">text</span><span class="a">text</span
# ><span class="a">text</span><span class="a">text</span>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_void_elements(runner: CliRunner, tmp_file: TextIO) -> None:
# # set bracket-same-line: false
# html_in = (
# b"""
# <img long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value" src="./1.jpg"/>
# <img src="./1.jpg"/><img src="./1.jpg"/><img src="./1.jpg"/><img src="./1.jpg"/><img src="./1.jpg"/>
# """
# ).strip()
# html_out = (
# """
# <img
# long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value"
# src="./1.jpg"
# />
# <img src="./1.jpg" /><img src="./1.jpg" /><img src="./1.jpg" /><img
# src="./1.jpg"
# /><img src="./1.jpg" />
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# # set bracket-same-line: true
# html_in = (
# b"""
# <img long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value" src="./1.jpg"/>
# <img src="./1.jpg"/><img src="./1.jpg"/><img src="./1.jpg"/><img src="./1.jpg"/><img src="./1.jpg"/>
# """
# ).strip()
# html_out = (
# """
# <img
# long_long_attribute="long_long_long_long_long_long_long_long_long_long_long_value"
# src="./1.jpg" />
# <img src="./1.jpg" /><img src="./1.jpg" /><img src="./1.jpg" /><img
# src="./1.jpg" /><img src="./1.jpg" />
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)

View file

@ -0,0 +1,82 @@
"""Djlint tests for case.
Some tests may be from prettier.io's html test suite.
Where applicable this notice may be needed:
#### Prettier.io license ####
Copyright © James Long and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
run::
poetry run pytest tests/test_html/test_case.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
poetry run pytest tests/test_html/test_case.py::test_case
"""
# from typing import TextIO
# from click.testing import CliRunner
# from ..conftest import reformat
# def test_case(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <!DOCTYPE html>
# <HTML CLASS="no-js mY-ClAsS">
# <HEAD>
# <META CHARSET="utf-8">
# <TITLE>My tITlE</TITLE>
# <META NAME="description" content="My CoNtEnT">
# </HEAD>
# <body>
# <P>Hello world!<BR> This is HTML5 Boilerplate.</P>
# <SCRIPT>
# window.ga = function () { ga.q.push(arguments) }; ga.q = []; ga.l = +new Date;
# ga('create', 'UA-XXXXX-Y', 'auto'); ga('send', 'pageview')
# </SCRIPT>
# <SCRIPT src="https://www.google-analytics.com/analytics.js" ASYNC DEFER></SCRIPT>
# </body>
# </HTML>
# """
# ).strip()
# html_out = (
# """
# <!DOCTYPE html>
# <html class="no-js mY-ClAsS">
# <head>
# <meta charset="utf-8" />
# <title>My tITlE</title>
# <meta name="description" content="My CoNtEnT" />
# </head>
# <body>
# <p>
# Hello world!<br />
# This is HTML5 Boilerplate.
# </p>
# <script>
# window.ga = function () { ga.q.push(arguments) }; ga.q = []; ga.l = +new Date;
# ga('create', 'UA-XXXXX-Y', 'auto'); ga('send', 'pageview')
# </script>
# <script
# src="https://www.google-analytics.com/analytics.js"
# async
# defer
# ></script>
# </body>
# </html>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out

View file

@ -0,0 +1,52 @@
"""Djlint tests for cdata.
Some tests may be from prettier.io's html test suite.
Where applicable this notice may be needed:
#### Prettier.io license ####
Copyright © James Long and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
run::
poetry run pytest tests/test_html/test_cdata.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
poetry run pytest tests/test_html/test_cdata.py::test_example
"""
# from typing import TextIO
# from click.testing import CliRunner
# from tests.conftest import reformat
# def test_example(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <span><![CDATA[<sender>John Smith</sender>]]></span>
# <span><![CDATA[1]]> a <![CDATA[2]]></span>
# <span><![CDATA[1]]> <br> <![CDATA[2]]></span>
# """
# ).strip()
# html_out = (
# """
# <span><![CDATA[<sender>John Smith</sender>]]></span>
# <span><![CDATA[1]]> a <![CDATA[2]]></span>
# <span
# ><![CDATA[1]]> <br />
# <![CDATA[2]]></span
# >
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out

View file

@ -1,12 +1,21 @@
"""Djlint tests specific to html.
"""Djlint tests for comments.
run::
Some tests may be from prettier.io's html test suite.
pytest tests/test_html.py --cov=src/djlint --cov-branch \
Where applicable this notice may be needed:
#### Prettier.io license ####
Copyright © James Long and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
run:
pytest tests/test_html/test_comments.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_comments.py::test_html_comments_tag
"""
@ -17,7 +26,7 @@ from typing import TextIO
from click.testing import CliRunner
from src.djlint import main as djlint
from tests.conftest import write_to_file
from tests.conftest import reformat, write_to_file
def test_html_comments_tag(runner: CliRunner, tmp_file: TextIO) -> None:
@ -37,3 +46,369 @@ comment-->
</div>
"""
)
def test_before_text(runner: CliRunner, tmp_file: TextIO) -> None:
html_in = (
b"""
<!-- hello -->
123
"""
).strip()
html_out = """<!-- hello -->
123
"""
output = reformat(tmp_file, runner, html_in)
assert output.text == html_out
def test_bogus(runner: CliRunner, tmp_file: TextIO) -> None:
html_in = (
b"""
<? hello ?>
<!- world ->
"""
).strip()
html_out = """<? hello ?>
<!- world ->
"""
output = reformat(tmp_file, runner, html_in)
assert output.text == html_out
# def test_conditional(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <!DOCTYPE html>
# <html>
# <body>
# <!--[if IE 5]>This is IE 5<br><![endif]-->
# <!--[if IE 6]>This is IE 6<br><![endif]-->
# <!--[if IE 7]>This is IE 7<br><![endif]-->
# <!--[if IE 8]>This is IE 8<br><![endif]-->
# <!--[if IE 9]>This is IE 9<br><![endif]-->
# </body>
# </html>
# <!DOCTYPE html>
# <!--[if lt IE 9]><html lang="zh-CN"><![endif]-->
# <html lang="zh-CN">
# <head></head>
# <body></body>
# </html>
# <!DOCTYPE html>
# <!--[if lt IE 9]><html lang="zh-CN"><div><![endif]-->
# <html lang="zh-CN">
# <head></head>
# <body></body>
# </html>
# <!DOCTYPE html>
# <!--[if lt IE 9]><html lang="zh-CN"><div></div><![endif]-->
# <html lang="zh-CN">
# <head></head>
# <body></body>
# </html>
# <body width="100%" align="center">
# <center >
# <!--[if (gte mso 9)|(IE)]><table cellpadding="0" cellspacing="0" border="0" width="600" align="center"><tr><td><![endif]-->
# <div> </div>
# <!--[if (gte mso 9)|(IE)]></td></tr></table><![endif]-->
# </center >
# </body>
# <!DOCTYPE html>
# <!--[if lt IE 9]><html class="legacy-ie"><![endif]-->
# <!--[if gte IE 9]><!--><html><!--<![endif]-->
# <head></head>
# <body></body>
# </html>
# <!DOCTYPE html>
# <!--[if lt IE 9]><html class="legacy-ie"><![endif]-->
# <!--[if gte IE 9]><!--><html hello><!--<![endif]-->
# <head></head>
# <body></body>
# </html>
# <!DOCTYPE html>
# <!--[if lt IE 9]><html class="legacy-ie"><head><![endif]-->
# <!--[if gte IE 9]><!--><html><head><!--<![endif]-->
# </head>
# <body></body>
# </html>
# <!DOCTYPE html>
# <!--[if lt IE 9]><html class="legacy-ie"><![endif]-->
# <!--[if gte IE 9
# ]><!--><html><!--<![endif]-->
# <head></head>
# <body></body>
# </html>
# """
# ).strip()
# html_out = (
# """
# <!DOCTYPE html>
# <html>
# <body>
# <!--[if IE 5]>This is IE 5<br /><![endif]-->
# <!--[if IE 6]>This is IE 6<br /><![endif]-->
# <!--[if IE 7]>This is IE 7<br /><![endif]-->
# <!--[if IE 8]>This is IE 8<br /><![endif]-->
# <!--[if IE 9]>This is IE 9<br /><![endif]-->
# </body>
# </html>
# <!DOCTYPE html>
# <!--[if lt IE 9]><html lang="zh-CN"><![endif]-->
# <html lang="zh-CN">
# <head></head>
# <body></body>
# </html>
# <!DOCTYPE html>
# <!--[if lt IE 9]><html lang="zh-CN"><div><![endif]-->
# <html lang="zh-CN">
# <head></head>
# <body></body>
# </html>
# <!DOCTYPE html>
# <!--[if lt IE 9]><html lang="zh-CN"><div></div><![endif]-->
# <html lang="zh-CN">
# <head></head>
# <body></body>
# </html>
# <body width="100%" align="center">
# <center>
# <!--[if (gte mso 9)|(IE)]><table cellpadding="0" cellspacing="0" border="0" width="600" align="center"><tr><td><![endif]-->
# <div></div>
# <!--[if (gte mso 9)|(IE)]></td></tr></table><![endif]-->
# </center>
# </body>
# <!DOCTYPE html>
# <!--[if lt IE 9]><html class="legacy-ie"><![endif]-->
# <!--[if gte IE 9]><!--><html><!--<![endif]-->
# <head></head>
# <body></body>
# </html>
# <!DOCTYPE html>
# <!--[if lt IE 9]><html class="legacy-ie"><![endif]-->
# <!--[if gte IE 9]><!--><html hello><!--<![endif]-->
# <head></head>
# <body></body>
# </html>
# <!DOCTYPE html>
# <!--[if lt IE 9]><html class="legacy-ie"><head><![endif]-->
# <!--[if gte IE 9]><!-->
# <html>
# <head>
# <!--<![endif]-->
# </head>
# <body></body>
# </html>
# <!DOCTYPE html>
# <!--[if lt IE 9]><html class="legacy-ie"><![endif]-->
# <!--[if gte IE 9]><!--><html><!--<![endif]-->
# <head></head>
# <body></body>
# </html>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_for_debugging(runner: CliRunner, tmp_file: TextIO) -> None:
# # opened https://github.com/Riverside-Healthcare/djLint/issues/247
# html_in = (
# b"""
# <!DOCTYPE html>
# <html>
# <body>
# <!-- Do not display this at the moment
# <img border="0" src="pic_trulli.jpg" alt="Trulli">
# -->
# <!-- Do not display this at the moment
# <img border="0" src="pic_trulli.jpg" alt="Trulli">
# -->
# <!-- Do not display this at the moment
# <img border="0" src="pic_trulli.jpg" alt="Trulli">
# -->
# </body>
# </html>
# """
# ).strip()
# html_out = (
# """<!DOCTYPE html>
# <html>
# <body>
# <!-- Do not display this at the moment
# <img border="0" src="pic_trulli.jpg" alt="Trulli">
# -->
# <!-- Do not display this at the moment
# <img border="0" src="pic_trulli.jpg" alt="Trulli">
# -->
# <!-- Do not display this at the moment
# <img border="0" src="pic_trulli.jpg" alt="Trulli">
# -->
# </body>
# </html>
# """
# )
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
def test_hidden(runner: CliRunner, tmp_file: TextIO) -> None:
html_in = (
b"""
<!DOCTYPE html>
<html>
<body>
<!--This is a comment-->
<!-- This is a comment -->
<!-- This is a comment -->
<!-- This is a comment -->
<p>This is a paragraph.</p>
<!-- Comments are not displayed in the browser -->
</body>
</html>
"""
).strip()
html_out = """<!DOCTYPE html>
<html>
<body>
<!--This is a comment-->
<!-- This is a comment -->
<!-- This is a comment -->
<!-- This is a comment -->
<p>This is a paragraph.</p>
<!-- Comments are not displayed in the browser -->
</body>
</html>
"""
output = reformat(tmp_file, runner, html_in)
assert output.text == html_out
# def test_surrounding_empty_line(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <ul><!-- 123
# --><li>First</li><!-- 123
# 456
# 789
# --><li>Second</li><!--
# 123
# 456
# 789
# --><li>Second</li><!--
# 123
# 456
# 789
# --></ul>
# <span><!--
# --><span>a</span><!--
# --><span>b</span><!--
# --></span>
# <span><!-- 1
# --><span>a</span><!-- 2
# --><span>b</span><!-- 3
# --></span>
# <span><!--
# 1 --><span>a</span><!--
# 2 --><span>b</span><!--
# 3 --></span>
# 123<!---->456
# 123<!--x-->456
# <!-- A
# B -->
# <!--
# The null hero's name is {{nullHero.name}}
# See console log:
# TypeError: Cannot read property 'name' of null in [null]
# -->
# <!--
# The null hero's name is {{nullHero.name}}
# See console log:
# TypeError: Cannot read property 'name' of null in [null]
# -->
# """
# ).strip()
# html_out = (
# """
# <ul>
# <!-- 123
# -->
# <li>First</li>
# <!-- 123
# 456
# 789
# -->
# <li>Second</li>
# <!--
# 123
# 456
# 789
# -->
# <li>Second</li>
# <!--
# 123
# 456
# 789
# --></ul>
# <span
# ><!--
# --><span>a</span
# ><!--
# --><span>b</span
# ><!--
# --></span>
# <span
# ><!-- 1
# --><span>a</span
# ><!-- 2
# --><span>b</span
# ><!-- 3
# --></span>
# <span
# ><!--
# 1 --><span>a</span
# ><!--
# 2 --><span>b</span
# ><!--
# 3 --></span
# >
# 123<!---->456 123<!--x-->456
# <!-- A
# B -->
# <!--
# The null hero's name is {{nullHero.name}}
# See console log:
# TypeError: Cannot read property 'name' of null in [null]
# -->
# <!--
# The null hero's name is {{nullHero.name}}
# See console log:
# TypeError: Cannot read property 'name' of null in [null]
# -->
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out

286
tests/test_html/test_css.py Normal file
View file

@ -0,0 +1,286 @@
"""Djlint tests for css.
Some tests may be from prettier.io's html test suite.
Where applicable this notice may be needed:
#### Prettier.io license ####
Copyright © James Long and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
run:
pytest tests/test_html/test_css.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_css.py::test_empty
"""
# from typing import TextIO
# from click.testing import CliRunner
# from ..conftest import reformat
# def test_empty(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <style></style>
# """
# ).strip()
# html_out = (
# """
# <style></style>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_less(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <style type="text/less">
# @nice-blue: #5B83AD;
# @light-blue: @nice-blue + #111;
# #header {
# color: @light-blue;
# }
# </style>
# <style lang="less">
# @nice-blue: #5B83AD;
# @light-blue: @nice-blue + #111;
# #header {
# color: @light-blue;
# }
# </style>
# """
# ).strip()
# html_out = (
# """
# <style type="text/less">
# @nice-blue: #5B83AD;
# @light-blue: @nice-blue + #111;
# #header {
# color: @light-blue;
# }
# </style>
# <style lang="less">
# @nice-blue: #5b83ad;
# @light-blue: @nice-blue + #111;
# #header {
# color: @light-blue;
# }
# </style>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_postcss(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <style type="text/css">
# body { background: navy; color: yellow; }
# </style>
# <style lang="postcss">
# body { background: navy; color: yellow; }
# </style>
# """
# ).strip()
# html_out = (
# """
# <style type="text/css">
# body {
# background: navy;
# color: yellow;
# }
# </style>
# <style lang="postcss">
# body {
# background: navy;
# color: yellow;
# }
# </style>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_scss(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <style type="text/x-scss">
# $font-stack: Helvetica, sans-serif;
# $primary-color: #333;
# body {
# font: 100% $font-stack;
# color: $primary-color;
# }
# </style>
# <style lang="scss">
# $font-stack: Helvetica, sans-serif;
# $primary-color: #333;
# body {
# font: 100% $font-stack;
# color: $primary-color;
# }
# </style>
# <style lang="scss">
# .someElement {
# @include bp-medium {
# display: flex;
# }
# @include bp-large {
# margin-top: 10px;
# margin-bottom: 10px;
# }
# }
# </style>
# """
# ).strip()
# html_out = (
# """
# <style type="text/x-scss">
# $font-stack: Helvetica, sans-serif;
# $primary-color: #333;
# body {
# font: 100% $font-stack;
# color: $primary-color;
# }
# </style>
# <style lang="scss">
# $font-stack: Helvetica, sans-serif;
# $primary-color: #333;
# body {
# font: 100% $font-stack;
# color: $primary-color;
# }
# </style>
# <style lang="scss">
# .someElement {
# @include bp-medium {
# display: flex;
# }
# @include bp-large {
# margin-top: 10px;
# margin-bottom: 10px;
# }
# }
# </style>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_simple(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <!DOCTYPE html>
# <html>
# <head>
# <title>Sample styled page</title>
# <style>a { color: red; }</style>
# <style>
# body { background: navy; color: yellow; }
# </style>
# </head>
# <body>
# <h1>Sample styled page</h1>
# <p>This page is just a demo.</p>
# </body>
# </html>
# """
# ).strip()
# html_out = (
# """
# <!DOCTYPE html>
# <html>
# <head>
# <title>Sample styled page</title>
# <style>
# a {
# color: red;
# }
# </style>
# <style>
# body {
# background: navy;
# color: yellow;
# }
# </style>
# </head>
# <body>
# <h1>Sample styled page</h1>
# <p>This page is just a demo.</p>
# </body>
# </html>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out
# def test_single_style(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <style>a { color: red; }</style>
# <style>
# h1 {
# font-size: 120%;
# font-family: Verdana, Arial, Helvetica, sans-serif;
# color: #333366;
# }
# </style>
# """
# ).strip()
# html_out = (
# """
# <style>
# a {
# color: red;
# }
# </style>
# <style>
# h1 {
# font-size: 120%;
# font-family: Verdana, Arial, Helvetica, sans-serif;
# color: #333366;
# }
# </style>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert output.text == html_out

View file

@ -0,0 +1,265 @@
"""Djlint tests for doctype.
Some tests may be from prettier.io's html test suite.
Where applicable this notice may be needed:
#### Prettier.io license ####
Copyright © James Long and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
run:
pytest tests/test_html/test_doctype_declarations.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_doctype_declarations.py::test_case
"""
# from typing import TextIO
# from click.testing import CliRunner
# from tests.conftest import reformat
# def test_case(runner: CliRunner, tmp_file: TextIO) -> None:
# output = reformat(tmp_file, runner, b"<!DocType htMl>")
# assert "<!DOCTYPE html>" == output.text
# output = reformat(tmp_file, runner, b"<!DocType htMl >")
# assert "<!DOCTYPE html>" == output.text
# def test_html4_01_frameset(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# (
# """
# <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
# "http://www.w3.org/TR/html4/frameset.dtd">
# <html>
# <head>
# <title>An HTML standard template</title>
# <meta charset="utf-8" />
# </head>
# <body>
# <p>… Your HTML content here …</p>
# </body>
# </html>
# """
# )
# .strip()
# .encode()
# )
# html_out = (
# """
# <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
# <html>
# <head>
# <title>An HTML standard template</title>
# <meta charset="utf-8" />
# </head>
# <body>
# <p>… Your HTML content here …</p>
# </body>
# </html>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert html_out == output.text
# def test_html4_01_strict(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# (
# """
# <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
# "http://www.w3.org/TR/html4/strict.dtd">
# <html>
# <head>
# <title>An HTML standard template</title>
# <meta charset="utf-8" />
# </head>
# <body>
# <p>… Your HTML content here …</p>
# </body>
# </html>
# """
# )
# .strip()
# .encode()
# )
# html_out = (
# """
# <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
# <html>
# <head>
# <title>An HTML standard template</title>
# <meta charset="utf-8" />
# </head>
# <body>
# <p>… Your HTML content here …</p>
# </body>
# </html>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert html_out == output.text
# def test_html4_01_transitional(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# (
# """
# <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
# "http://www.w3.org/TR/html4/loose.dtd">
# <html>
# <head>
# <title>An HTML standard template</title>
# <meta charset="utf-8" />
# </head>
# <body>
# <p>… Your HTML content here …</p>
# </body>
# </html>
# """
# )
# .strip()
# .encode()
# )
# html_out = (
# """
# <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
# <html>
# <head>
# <title>An HTML standard template</title>
# <meta charset="utf-8" />
# </head>
# <body>
# <p>… Your HTML content here …</p>
# </body>
# </html>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert html_out == output.text
# def test_html5(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# (
# """
# <!DOCTYPE html>
# <html>
# <head>
# <title>An HTML standard template</title>
# <meta charset="utf-8" />
# </head>
# <body>
# <p>… Your HTML content here …</p>
# </body>
# </html>
# """
# )
# .strip()
# .encode()
# )
# html_out = (
# """
# <!DOCTYPE html>
# <html>
# <head>
# <title>An HTML standard template</title>
# <meta charset="utf-8" />
# </head>
# <body>
# <p>… Your HTML content here …</p>
# </body>
# </html>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert html_out == output.text
# def test_xhtml1_1(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
# <html xmlns="http://www.w3.org/1999/xhtml">
# <head>
# <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
# <title>XHTML markup</title>
# </head>
# <body style="background-color:#ffffcc; color:#008800">
# <br />
# <h2 align="center">Sample XHTML page</h2>
# <br />
# <div align="center">
# <img src="../images/bee3.jpg" width="400" height="250" alt="Beep" vspace="20" />
# </div>
# <p align="center" style="font-size:17px">Bar Foo,<br />
# Foo,<br />
# Bar<br />
# Foo</p>
# <p align="center"><em>String</em></p>
# <br />
# <hr />
# </body>
# </html>
# """
# ).strip()
# html_out = (
# """
# <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
# <html xmlns="http://www.w3.org/1999/xhtml">
# <head>
# <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
# <title>XHTML markup</title>
# </head>
# <body style="background-color: #ffffcc; color: #008800">
# <br />
# <h2 align="center">Sample XHTML page</h2>
# <br />
# <div align="center">
# <img
# src="../images/bee3.jpg"
# width="400"
# height="250"
# alt="Beep"
# vspace="20"
# />
# </div>
# <p align="center" style="font-size: 17px">
# Bar Foo,<br />
# Foo,<br />
# Bar<br />
# Foo
# </p>
# <p align="center"><em>String</em></p>
# <br />
# <hr />
# </body>
# </html>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# assert html_out == output.text

View file

@ -1,12 +1,11 @@
"""Djlint tests specific to html.
"""Djlint tests for ignored content.
run::
run:
pytest tests/test_html.py --cov=src/djlint --cov-branch \
pytest tests/test_html/test_ignored.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_ignored.py::test_ignored_block
"""

View file

@ -0,0 +1,66 @@
"""Djlint tests for interpolation.
Some tests may be from prettier.io's html test suite.
Where applicable this notice may be needed:
#### Prettier.io license ####
Copyright © James Long and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
run:
pytest tests/test_html/test_interpolation.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_interpolation.py::test_example
"""
# from typing import TextIO
# from click.testing import CliRunner
# from tests.conftest import reformat
# def test_example(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <!--interpolations in html should be treated as normal text--><div>Fuga magnam facilis. Voluptatem quaerat porro.{{
# x => {
# const hello = 'world'
# return hello;
# }
# }} Magni consectetur in et molestias neque esse voluptatibus voluptas. {{
# some_variable
# }} Eum quia nihil nulla esse. Dolorem asperiores vero est error {{
# preserve
# invalid
# interpolation
# }} reprehenderit voluptates minus {{console.log( short_interpolation )}} nemo.</div>
# """
# ).strip()
# html_out = (
# """
# <!--interpolations in html should be treated as normal text-->
# <div>
# Fuga magnam facilis. Voluptatem quaerat porro.{{ x => { const hello = 'world'
# return hello; } }} Magni consectetur in et molestias neque esse voluptatibus
# voluptas. {{ some_variable }} Eum quia nihil nulla esse. Dolorem asperiores
# vero est error {{ preserve invalid interpolation }} reprehenderit voluptates
# minus {{console.log( short_interpolation )}} nemo.
# </div>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# print(output.text)
# assert output.exit_code == 0

View file

@ -0,0 +1,71 @@
"""Djlint tests for next line empty.
Some tests may be from prettier.io's html test suite.
Where applicable this notice may be needed:
#### Prettier.io license ####
Copyright © James Long and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
run:
pytest tests/test_html/test_next_line_empty.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_next_line_empty.py::test_standalone_end_marker
"""
# from typing import TextIO
# from click.testing import CliRunner
# from tests.conftest import reformat
# def test_standalone_end_marker(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <div></div
# >
# <span></span>
# <div></div
# >
# <span></span>
# <div></div
# >
# <span></span>
# <div>
# <a href="#123123123123123131231312321312312312312312312312312313123123123123123"
# >123123123123</a
# >
# 123123
# </div>
# """
# ).strip()
# html_out = (
# """
# <div></div>
# <span></span>
# <div></div>
# <span></span>
# <div></div>
# <span></span>
# <div>
# <a
# href="#123123123123123131231312321312312312312312312312312313123123123123123"
# >123123123123</a
# >
# 123123
# </div>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)

View file

@ -1,12 +1,11 @@
"""Djlint tests specific to html.
"""Djlint tests for self closing tags.
run::
run:
pytest tests/test_html.py --cov=src/djlint --cov-branch \
pytest tests/test_html/test_selfclosing.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_selfclosing.py::test_self_closing_tags
"""

View file

@ -0,0 +1,138 @@
"""Djlint tests for single attribute per line.
Some tests may be from prettier.io's html test suite.
Where applicable this notice may be needed:
#### Prettier.io license ####
Copyright © James Long and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
run:
pytest tests/test_html/test_single_attribute_per_line.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_single_attribute_per_line.py::test_single_attribute_per_line
"""
# from typing import TextIO
# from click.testing import CliRunner
# from tests.conftest import reformat
# def test_single_attribute_per_line(runner: CliRunner, tmp_file: TextIO) -> None:
# # single-attribute-per-line: true
# html_in = (
# b"""
# <div data-a="1">
# Lorem ipsum dolor sit amet, consectetur adipiscing elit.
# </div>
# <div data-a="1" data-b="2" data-c="3">
# Lorem ipsum dolor sit amet, consectetur adipiscing elit.
# </div>
# <div data-a="Lorem ipsum dolor sit amet" data-b="Lorem ipsum dolor sit amet" data-c="Lorem ipsum dolor sit amet">
# Lorem ipsum dolor sit amet, consectetur adipiscing elit.
# </div>
# <div data-long-attribute-a="1" data-long-attribute-b="2" data-long-attribute-c="3">
# Lorem ipsum dolor sit amet, consectetur adipiscing elit.
# </div>
# <img src="/images/foo.png" />
# <img src="/images/foo.png" alt="bar" />
# <img src="/images/foo.png" alt="Lorem ipsum dolor sit amet, consectetur adipiscing elit." />
# """
# ).strip()
# html_out = (
# """
# <div data-a="1">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
# <div
# data-a="1"
# data-b="2"
# data-c="3"
# >
# Lorem ipsum dolor sit amet, consectetur adipiscing elit.
# </div>
# <div
# data-a="Lorem ipsum dolor sit amet"
# data-b="Lorem ipsum dolor sit amet"
# data-c="Lorem ipsum dolor sit amet"
# >
# Lorem ipsum dolor sit amet, consectetur adipiscing elit.
# </div>
# <div
# data-long-attribute-a="1"
# data-long-attribute-b="2"
# data-long-attribute-c="3"
# >
# Lorem ipsum dolor sit amet, consectetur adipiscing elit.
# </div>
# <img src="/images/foo.png" />
# <img
# src="/images/foo.png"
# alt="bar"
# />
# <img
# src="/images/foo.png"
# alt="Lorem ipsum dolor sit amet, consectetur adipiscing elit."
# />
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# # single-attribute-per-line: false
# html_in = (
# b"""
# <div data-a="1">
# Lorem ipsum dolor sit amet, consectetur adipiscing elit.
# </div>
# <div data-a="1" data-b="2" data-c="3">
# Lorem ipsum dolor sit amet, consectetur adipiscing elit.
# </div>
# <div data-a="Lorem ipsum dolor sit amet" data-b="Lorem ipsum dolor sit amet" data-c="Lorem ipsum dolor sit amet">
# Lorem ipsum dolor sit amet, consectetur adipiscing elit.
# </div>
# <div data-long-attribute-a="1" data-long-attribute-b="2" data-long-attribute-c="3">
# Lorem ipsum dolor sit amet, consectetur adipiscing elit.
# </div>
# <img src="/images/foo.png" />
# <img src="/images/foo.png" alt="bar" />
# <img src="/images/foo.png" alt="Lorem ipsum dolor sit amet, consectetur adipiscing elit." />
# """
# ).strip()
# html_out = (
# """
# <div data-a="1">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
# <div data-a="1" data-b="2" data-c="3">
# Lorem ipsum dolor sit amet, consectetur adipiscing elit.
# </div>
# <div
# data-a="Lorem ipsum dolor sit amet"
# data-b="Lorem ipsum dolor sit amet"
# data-c="Lorem ipsum dolor sit amet"
# >
# Lorem ipsum dolor sit amet, consectetur adipiscing elit.
# </div>
# <div
# data-long-attribute-a="1"
# data-long-attribute-b="2"
# data-long-attribute-c="3"
# >
# Lorem ipsum dolor sit amet, consectetur adipiscing elit.
# </div>
# <img src="/images/foo.png" />
# <img src="/images/foo.png" alt="bar" />
# <img
# src="/images/foo.png"
# alt="Lorem ipsum dolor sit amet, consectetur adipiscing elit."
# />
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)

View file

@ -0,0 +1,68 @@
"""Djlint tests for srcset.
Some tests may be from prettier.io's html test suite.
Where applicable this notice may be needed:
#### Prettier.io license ####
Copyright © James Long and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
run:
pytest tests/test_html/test_srcset.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_srcset.py::test_invalid
"""
# from typing import TextIO
# from click.testing import CliRunner
# from tests.conftest import reformat
# def test_invalid(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <img src="a"
# srcset="
# should-not-format 400w 100h,
# should-not-format 500w 200h
# "
# alt=""/>
# <img src="a"
# srcset="
# should-not-format ,, should-not-format 0q,,,
# "
# alt=""/>
# """
# ).strip()
# html_out = (
# """
# <img
# src="a"
# srcset="
# should-not-format 400w 100h,
# should-not-format 500w 200h
# "
# alt=""
# />
# <img
# src="a"
# srcset="
# should-not-format ,, should-not-format 0q,,,
# "
# alt=""
# />
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)

130
tests/test_html/test_svg.py Normal file
View file

@ -0,0 +1,130 @@
"""Djlint tests for svg.
Some tests may be from prettier.io's html test suite.
Where applicable this notice may be needed:
#### Prettier.io license ####
Copyright © James Long and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
run:
pytest tests/test_html/test_svg.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_svg.py::test_svg
"""
# from typing import TextIO
# from click.testing import CliRunner
# from tests.conftest import reformat
# def test_svg(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <!DOCTYPE html>
# <html>
# <head>
# <title>SVG</title>
# </head>
# <body>
# <svg width="100" height="100">
# <circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
# </svg>
# </body>
# </html>
# <svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
# <defs /> <style >
# polygon { fill: black }
# div {
# color: white;
# font:18px serif;
# height: 100%;
# overflow: auto;
# }
# </style>
# <g>
# <g><polygon points="5,5 195,10 185,185 10,195" />
# <text> Text</text></g>
# </g>
# <!-- Common use case: embed HTML text into SVG -->
# <foreignObject x="20" y="20" width="160" height="160">
# <!--
# In the context of SVG embeded into HTML, the XHTML namespace could be avoided, but it is mandatory in the context of an SVG document
# -->
# <div xmlns="http://www.w3.org/1999/xhtml">
# <p>
# 123
# </p>
# <span>
# 123
# </span>
# </div>
# </foreignObject>
# </svg>
# """
# ).strip()
# html_out = (
# """
# <!DOCTYPE html>
# <html>
# <head>
# <title>SVG</title>
# </head>
# <body>
# <svg width="100" height="100">
# <circle
# cx="50"
# cy="50"
# r="40"
# stroke="green"
# stroke-width="4"
# fill="yellow"
# />
# </svg>
# </body>
# </html>
# <svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
# <defs />
# <style>
# polygon {
# fill: black;
# }
# div {
# color: white;
# font: 18px serif;
# height: 100%;
# overflow: auto;
# }
# </style>
# <g>
# <g>
# <polygon points="5,5 195,10 185,185 10,195" />
# <text>Text</text>
# </g>
# </g>
# <!-- Common use case: embed HTML text into SVG -->
# <foreignObject x="20" y="20" width="160" height="160">
# <!--
# In the context of SVG embeded into HTML, the XHTML namespace could be avoided, but it is mandatory in the context of an SVG document
# -->
# <div xmlns="http://www.w3.org/1999/xhtml">
# <p>123</p>
# <span> 123 </span>
# </div>
# </foreignObject>
# </svg>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)

View file

@ -0,0 +1,41 @@
"""Djlint tests for symbol entities.
Some tests may be from prettier.io's html test suite.
Where applicable this notice may be needed:
#### Prettier.io license ####
Copyright © James Long and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
run:
pytest tests/test_html/test_symbol_entities.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_symbol_entities.py::test_symbol_entities
"""
# pylint: disable=C0116
from typing import TextIO
from click.testing import CliRunner
from tests.conftest import reformat
def test_symbol_entities(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
b"""<p>I will display &euro;</p>
<p>I will display &excl;</p>
<p>I will display &#8364;</p>
<p>I will display &#x20AC;</p>
""",
)
print(output.text)
assert output.exit_code == 0

View file

@ -1,13 +1,11 @@
"""Djlint tests specific to html.
"""Djlint tests for html code tag.
run::
run:
pytest tests/test_html.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \
pytest tests/test_html/test_tag_code.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_tag_code.py::test_code_tag
"""
# pylint: disable=C0116

View file

@ -1,13 +1,11 @@
"""Djlint tests specific to html.
"""Djlint tests for html dd tag.
run::
run:
pytest tests/test_html.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \
pytest tests/test_html/test_tag_dd.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_tag_dd.py::test_dd_tag
"""
# pylint: disable=C0116

View file

@ -1,13 +1,11 @@
"""Djlint tests specific to html.
"""Djlint tests for html details/summary tag.
run::
run:
pytest tests/test_html.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \
pytest tests/test_html/test_tag_details_summary.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_tag_details_summary.py::test_details_summary_tags
"""
# pylint: disable=C0116

View file

@ -1,13 +1,11 @@
"""Djlint tests specific to html.
"""Djlint tests for html dt tag.
run::
run:
pytest tests/test_html.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \
pytest tests/test_html/test_tag_dt.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_tag_dt.py::test_dt_tag
"""
# pylint: disable=C0116

View file

@ -1,12 +1,11 @@
"""Djlint tests specific to html.
"""Djlint tests for html figure tag.
run::
run:
pytest tests/test_html.py --cov=src/djlint --cov-branch \
pytest tests/test_html/test_tag_fig_caption.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_tag_fig_caption.py::test_figure_figcaption_tags
"""

View file

@ -1,12 +1,11 @@
"""Djlint tests specific to html.
"""Djlint tests for html hr tag.
run::
run:
pytest tests/test_html.py --cov=src/djlint --cov-branch \
pytest tests/test_html/test_tag_hr.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_tag_hr.py::test_hr_tag
"""

View file

@ -1,12 +1,11 @@
"""Djlint tests specific to html.
"""Djlint tests for html picture tag.
run::
run:
pytest tests/test_html.py --cov=src/djlint --cov-branch \
pytest tests/test_html/test_tag_picture.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_tag_picture.py::test_picture_source_img_tags
"""

View file

@ -1,13 +1,11 @@
"""Djlint tests specific to html.
"""Djlint tests for html pre tag.
run::
run:
pytest tests/test_html.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \
pytest tests/test_html/test_tag_pre.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_tag_pre.py::test_pre_tag
"""
# pylint: disable=C0116

View file

@ -1,12 +1,21 @@
"""Djlint tests specific to html.
"""Djlint tests for html script tags.
run::
Some tests may be from prettier.io's html test suite.
pytest tests/test_html.py --cov=src/djlint --cov-branch \
Where applicable this notice may be needed:
#### Prettier.io license ####
Copyright © James Long and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
run:
pytest tests/test_html/test_tag_script.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_tag_script.py::test_script_tag
"""
@ -70,3 +79,594 @@ def test_script_tag(runner: CliRunner, tmp_file: TextIO) -> None:
)
assert output.exit_code == 0
# def test_empty(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <script></script>
# """
# ).strip()
# html_out = (
# """
# <script></script>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_js(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <script type="text/javascript">
# var message = "Alert!";
# alert(message);
# </script>
# <script type="application/javascript">
# var message = "Alert!";
# alert(message);
# </script>
# <script>
# var message = "Alert!";
# alert(message);
# </script>
# <script type="text/babel">
# const someJS = 'this should be formatted'
# </script>
# <script type="module">
# import lib from './lib.js';
# function myFunction() { return 'foo'; }
# </script>
# """
# ).strip()
# html_out = (
# """
# <script type="text/javascript">
# var message = "Alert!";
# alert(message);
# </script>
# <script type="application/javascript">
# var message = "Alert!";
# alert(message);
# </script>
# <script>
# var message = "Alert!";
# alert(message);
# </script>
# <script type="text/babel">
# const someJS = "this should be formatted";
# </script>
# <script type="module">
# import lib from "./lib.js";
# function myFunction() {
# return "foo";
# }
# </script>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_simple(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <!DOCTYPE html>
# <html>
# <head>
# <title>Sample styled page</title>
# <script>alert('test');</script>
# <script>
# var message = "Alert!";
# alert(message);
# </script>
# </head>
# <body>
# <h1>Sample styled page</h1>
# <p>This page is just a demo.</p>
# </body>
# </html>
# """
# ).strip()
# html_out = (
# """
# <!DOCTYPE html>
# <html>
# <head>
# <title>Sample styled page</title>
# <script>
# alert("test");
# </script>
# <script>
# var message = "Alert!";
# alert(message);
# </script>
# </head>
# <body>
# <h1>Sample styled page</h1>
# <p>This page is just a demo.</p>
# </body>
# </html>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_single_script(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <script>alert('test');</script>
# <script>
# document.getElementById("demo").innerHTML = "Hello JavaScript!";
# </script>
# """
# ).strip()
# html_out = (
# """
# <script>
# alert("test");
# </script>
# <script>
# document.getElementById("demo").innerHTML = "Hello JavaScript!";
# </script>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_something_else(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <script type="text/template">
# <div>
# </div>
# </script>
# """
# ).strip()
# html_out = (
# """
# <script type="text/template">
# <div>
# </div>
# </script>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_template_literal(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <!DOCTYPE html>
# <html lang="en">
# <head>
# </head>
# <body>
# <script>
# function foo() {
# return \\`
# <div>
# <p>Text</p>
# </div>
# \\`;
# }
# </script>
# </body>
# </html>
# """
# ).strip()
# html_out = (
# """
# <!DOCTYPE html>
# <html lang="en">
# <head> </head>
# <body>
# <script>
# function foo() {
# return \\`
# <div>
# <p>Text</p>
# </div>
# \\`;
# }
# </script>
# </body>
# </html>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_typescript(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <script type="application/x-typescript">
# class Student {
# fullName: string;
# constructor(public firstName: string, public middleInitial: string, public lastName: string) {
# this.fullName = firstName + " " + middleInitial + " " + lastName;
# }
# }
# interface Person {
# firstName: string;
# lastName: string;
# }
# function greeter(person : Person) {
# return "Hello, " + person.firstName + " " + person.lastName;
# }
# let user = new Student("Jane", "M.", "User");
# document.body.innerHTML = greeter(user);
# </script>
# <script lang="ts">
# class Student {
# fullName: string;
# constructor(public firstName: string, public middleInitial: string, public lastName: string) {
# this.fullName = firstName + " " + middleInitial + " " + lastName;
# }
# }
# interface Person {
# firstName: string;
# lastName: string;
# }
# function greeter(person : Person) {
# return "Hello, " + person.firstName + " " + person.lastName;
# }
# let user = new Student("Jane", "M.", "User");
# document.body.innerHTML = greeter(user);
# </script>
# <script lang="tsx">
# class CommentBox extends React.Component<{ url: string, pollInterval: number}, CommentData> {
# constructor(){
# super()
# this.state = { data: [] };
# }
# fetchComments() {
# $.ajax({
# url: this.props.url,
# dataType: 'json',
# cache: false,
# success: (data) => this.setState({ data: data }),
# error: (xhr, status, err) => console.error(status, err)
# })
# }
# componentDidMount() {
# this.fetchComments();
# setInterval(this.fetchComments.bind(this), this.props.pollInterval);
# }
# render() {
# let handleCommentSubmit = (comment: { author: string, text: string }) => {
# console.warn('comment submitted!', comment);
# const updated = this.state.data.slice(0);
# updated.push(comment);
# this.setState({ data: updated });
# }
# return (
# <div className="commentBox">
# <h1>Comments</h1>
# <CommentList data={this.state.data}/>
# <CommentForm onCommentSubmit={handleCommentSubmit} />
# </div>
# );
# }
# }
# </script>
# """
# ).strip()
# html_out = (
# """
# <script type="application/x-typescript">
# class Student {
# fullName: string;
# constructor(
# public firstName: string,
# public middleInitial: string,
# public lastName: string
# ) {
# this.fullName = firstName + " " + middleInitial + " " + lastName;
# }
# }
# interface Person {
# firstName: string;
# lastName: string;
# }
# function greeter(person: Person) {
# return "Hello, " + person.firstName + " " + person.lastName;
# }
# let user = new Student("Jane", "M.", "User");
# document.body.innerHTML = greeter(user);
# </script>
# <script lang="ts">
# class Student {
# fullName: string;
# constructor(
# public firstName: string,
# public middleInitial: string,
# public lastName: string
# ) {
# this.fullName = firstName + " " + middleInitial + " " + lastName;
# }
# }
# interface Person {
# firstName: string;
# lastName: string;
# }
# function greeter(person: Person) {
# return "Hello, " + person.firstName + " " + person.lastName;
# }
# let user = new Student("Jane", "M.", "User");
# document.body.innerHTML = greeter(user);
# </script>
# <script lang="tsx">
# class CommentBox extends React.Component<
# { url: string; pollInterval: number },
# CommentData
# > {
# constructor() {
# super();
# this.state = { data: [] };
# }
# fetchComments() {
# $.ajax({
# url: this.props.url,
# dataType: "json",
# cache: false,
# success: (data) => this.setState({ data: data }),
# error: (xhr, status, err) => console.error(status, err),
# });
# }
# componentDidMount() {
# this.fetchComments();
# setInterval(this.fetchComments.bind(this), this.props.pollInterval);
# }
# render() {
# let handleCommentSubmit = (comment: { author: string; text: string }) => {
# console.warn("comment submitted!", comment);
# const updated = this.state.data.slice(0);
# updated.push(comment);
# this.setState({ data: updated });
# };
# return (
# <div className="commentBox">
# <h1>Comments</h1>
# <CommentList data={this.state.data} />
# <CommentForm onCommentSubmit={handleCommentSubmit} />
# </div>
# );
# }
# }
# </script>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_babel(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <script type="text/babel" data-presets="react" data-type="module">
# import { h,
# render } from 'https://unpkg.com/preact?module';
# render(
# <h1>Hello World!</h1>,
# document.body
# );
# </script>
# <script type="text/babel">
# <!--
# alert(1)
# -->
# </script>
# """
# ).strip()
# html_out = (
# """
# <script type="text/babel" data-presets="react" data-type="module">
# import { h, render } from "https://unpkg.com/preact?module";
# render(<h1>Hello World!</h1>, document.body);
# </script>
# <script type="text/babel">
# <!--
# alert(1);
# -->
# </script>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_legacy(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <script>
# <!--
# alert(1)
# -->
# </script>
# <script>
# <!--
# alert(2)
# //-->
# </script>
# """
# ).strip()
# html_out = (
# """
# <script>
# <!--
# alert(1);
# -->
# </script>
# <script>
# <!--
# alert(2);
# //-->
# </script>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_module(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <script type="module">
# import prettier from "prettier/standalone";
# import parserGraphql from "prettier/parser-graphql";
# prettier.format("query { }", {
# parser: "graphql",
# plugins: [
# parserGraphql],
# });
# </script>
# <script type="module">
# async function foo() {
# let x=10;while(x-->0)console.log(x)
# await(import('mod'))
# }
# </script>
# """
# ).strip()
# html_out = (
# """
# <script type="module">
# import prettier from "prettier/standalone";
# import parserGraphql from "prettier/parser-graphql";
# prettier.format("query { }", {
# parser: "graphql",
# plugins: [parserGraphql],
# });
# </script>
# <script type="module">
# async function foo() {
# let x = 10;
# while (x-- > 0) console.log(x);
# await import("mod");
# }
# </script>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_module_attributes(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <script src="foo.wasm" type="module" withtype="webassembly"></script>
# """
# ).strip()
# html_out = (
# """
# <script src="foo.wasm" type="module" withtype="webassembly"></script>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_script(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <script type="application/ld+json">
# { "json": true }
# </script>
# <script type="application/json">
# { "json":true }
# </script>
# <script type="importmap">
# { "json":true }
# </script>
# <script type="systemjs-importmap">
# { "json":true }
# </script><script type="invalid">
# { "json":false }
# </script>
# <script type="text/html">
# <div>
# <p>foo</p>
# </div>
# </script>
# <script
# async=""
# id=""
# src="/_next/static/development/pages/_app.js?ts=1565732195968"
# ></script><script></script>
# <!-- #8147 -->
# <script lang="vbscript">
# Function hello()
# End Function
# </script>
# <script lang="unknown">
# </script>
# """
# ).strip()
# html_out = (
# """
# <script type="application/ld+json">
# { "json": true }
# </script>
# <script type="application/json">
# { "json": true }
# </script>
# <script type="importmap">
# { "json": true }
# </script>
# <script type="systemjs-importmap">
# { "json": true }
# </script>
# <script type="invalid">
# { "json":false }
# </script>
# <script type="text/html">
# <div>
# <p>foo</p>
# </div>
# </script>
# <script
# async=""
# id=""
# src="/_next/static/development/pages/_app.js?ts=1565732195968"
# ></script>
# <script></script>
# <!-- #8147 -->
# <script lang="vbscript">
# Function hello()
# End Function
# </script>
# <script lang="unknown"></script>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)

View file

@ -1,12 +1,11 @@
"""Djlint tests specific to html.
"""Djlint tests for html small tag.
run::
run:
pytest tests/test_html.py --cov=src/djlint --cov-branch \
pytest tests/test_html/test_tag_small.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_tag_small.py::test_small_tag
"""

View file

@ -1,12 +1,11 @@
"""Djlint tests specific to html.
"""Djlint tests for html span tag.
run::
run:
pytest tests/test_html.py --cov=src/djlint --cov-branch \
pytest tests/test_html/test_tag_span.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_tag_span.py::test_span_tag
"""

View file

@ -1,93 +1,95 @@
"""Djlint tests specific to html.
"""Djlint tests for html textarea tag.
run::
run:
pytest tests/test_html.py --cov=src/djlint --cov-branch \
pytest tests/test_html/test_tag_textarea.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html.py::test_front_matter --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_tag_textarea.py::test_textarea_tag
"""
# pylint: disable=C0116
# from pathlib import Path
# from typing import TextIO
from pathlib import Path
from typing import TextIO
# from click.testing import CliRunner
from click.testing import CliRunner
# from src.djlint import main as djlint
# from tests.conftest import reformat, write_to_file
from src.djlint import main as djlint
from tests.conftest import reformat, write_to_file
# def test_textarea_tag(runner: CliRunner, tmp_file: TextIO) -> None:
# write_to_file(tmp_file.name, b"""<div><textarea>\nasdf\n asdf</textarea></div>""")
# runner.invoke(djlint, [tmp_file.name, "--reformat"])
# assert (
# Path(tmp_file.name).read_text(encoding="utf8")
# == """<div>
# <textarea>
# asdf
# asdf</textarea>
# </div>
# """
# )
# # check double nesting
# output = reformat(
# tmp_file,
# runner,
# b"""<div>
# <div class="field">
# <textarea>asdf</textarea>
# </div>
# </div>
# """,
# )
# assert output.exit_code == 0
def test_textarea_tag(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(tmp_file.name, b"""<div><textarea>\nasdf\n asdf</textarea></div>""")
runner.invoke(djlint, [tmp_file.name, "--reformat"])
assert (
Path(tmp_file.name).read_text(encoding="utf8")
== """<div>
<textarea>
asdf
asdf</textarea>
</div>
"""
)
# check double nesting
output = reformat(
tmp_file,
runner,
b"""<div>
<div class="field">
<textarea>asdf</textarea>
</div>
</div>
""",
)
# # check attributes
# output = reformat(
# tmp_file,
# runner,
# b"""<div>
# <div class="field">
# <textarea class="this"
# name="that">asdf</textarea>
# </div>
# </div>
# """,
# )
assert output.exit_code == 0
# assert (
# output.text
# == """<div>
# <div class="field">
# <textarea class="this" name="that">asdf</textarea>
# </div>
# </div>
# """
# )
# check attributes
output = reformat(
tmp_file,
runner,
b"""<div>
<div class="field">
<textarea class="this"
name="that">asdf</textarea>
</div>
</div>
""",
)
# def test_a_tag(runner: CliRunner, tmp_file: TextIO) -> None:
# output = reformat(
# tmp_file,
# runner,
# b"""<p>
# some nice text <a href="this">asdf</a>, ok
# </p>""",
# )
assert (
output.text
== """<div>
<div class="field">
<textarea class="this" name="that">asdf</textarea>
</div>
</div>
"""
)
# assert output.exit_code == 0
# # test added for https://github.com/Riverside-Healthcare/djLint/issues/189
# output = reformat(
# tmp_file,
# runner,
# b"""<a>
# <span>hi</span>hi</a>
# <div>
# <h4>{{ _("Options") }}</h4>
# </div>
# """)
def test_a_tag(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
b"""<p>
some nice text <a href="this">asdf</a>, ok
</p>""",
)
# assert output.exit_code == 0
assert output.exit_code == 0
# test added for https://github.com/Riverside-Healthcare/djLint/issues/189
output = reformat(
tmp_file,
runner,
b"""<a>
<span>hi</span>hi</a>
<div>
<h4>{{ _("Options") }}</h4>
</div>
""",
)
assert output.exit_code == 0

View file

@ -0,0 +1,927 @@
"""Djlint tests for tags.
Some tests may be from prettier.io's html test suite.
Where applicable this notice may be needed:
#### Prettier.io license ####
Copyright © James Long and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
run:
pytest tests/test_html/test_tags.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_tags.py::test_case_sensitive
"""
# from typing import TextIO
# from click.testing import CliRunner
# from tests.conftest import reformat
# def test_case_sensitive(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <CaseSensitive CaseSensitive="true">hello world</CaseSensitive>
# """
# ).strip()
# html_out = (
# """
# <CaseSensitive CaseSensitive="true">hello world</CaseSensitive>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_close_at_start(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <div>
# aaaaaaaaaa
# <a
# href="longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong"
# >bbbbbbbbbb</a
# >
# cccccccccc
# </div>
# <div>
# aaaaaaaaaa
# <a
# href="longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong"
# >bbbbbbbbbb</a
# >cccccccccc
# </div>
# """
# ).strip()
# html_out = (
# """
# <div>
# aaaaaaaaaa
# <a
# href="longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong"
# >bbbbbbbbbb</a
# >
# cccccccccc
# </div>
# <div>
# aaaaaaaaaa
# <a
# href="longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong"
# >bbbbbbbbbb</a
# >cccccccccc
# </div>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_custom_element(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <app-foo></app-foo>
# <app-bar></app-bar>
# """
# ).strip()
# html_out = (
# """
# <app-foo></app-foo>
# <app-bar></app-bar>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_opening_at_end(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <p
# >Want to write us a letter? Use our<a
# ><b
# ><a>mailing address</a></b
# ></a
# >.</p
# >
# <p
# >Want to write us a letter? Use our<a
# href="contacts.html#Mailing_address"
# ><b
# ><a>mailing address</a></b
# ></a
# >.</p
# >
# <p
# >Want to write us a letter? Use our<a
# href="contacts.html#Mailing_address"
# href1="contacts.html#Mailing_address"
# href2="contacts.html#Mailing_address"
# href3="contacts.html#Mailing_address"
# href4="contacts.html#Mailing_address"
# ><b
# ><a>mailing address</a></b
# ></a
# >.</p
# >
# """
# ).strip()
# html_out = (
# """
# <p>
# Want to write us a letter? Use our<a
# ><b><a>mailing address</a></b></a
# >.
# </p>
# <p>
# Want to write us a letter? Use our<a href="contacts.html#Mailing_address"
# ><b><a>mailing address</a></b></a
# >.
# </p>
# <p>
# Want to write us a letter? Use our<a
# href="contacts.html#Mailing_address"
# href1="contacts.html#Mailing_address"
# href2="contacts.html#Mailing_address"
# href3="contacts.html#Mailing_address"
# href4="contacts.html#Mailing_address"
# ><b><a>mailing address</a></b></a
# >.
# </p>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_option(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <select><option>Blue</option><option>Green</option><optgroup label="Darker"><option>Dark Blue</option><option>Dark Green</option></optgroup></select>
# <input list=colors>
# <datalist id=colors><option>Blue</option><option>Green</option></datalist>
# """
# ).strip()
# html_out = (
# """
# <select>
# <option>Blue</option>
# <option>Green</option>
# <optgroup label="Darker">
# <option>Dark Blue</option>
# <option>Dark Green</option>
# </optgroup>
# </select>
# <input list="colors" />
# <datalist id="colors">
# <option>Blue</option>
# <option>Green</option>
# </datalist>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_pre(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <pre>
# --------------------------------------------------------------------------------
# * * *
# ** ** ***
# ** ** *
# **** *** **** ******** ******** *** ****
# * *** * **** **** * *** ******** ******** *** *** **** **** *
# * **** ** **** * *** ** ** *** * *** ** ****
# ** ** ** * *** ** ** ** * *** **
# ** ** ** ** *** ** ** ** ** *** **
# ** ** ** ******** ** ** ** ******** **
# ** ** ** ******* ** ** ** ******* **
# ** ** ** ** ** ** ** ** **
# ******* *** **** * ** ** ** **** * ***
# ****** *** ******* ** ** *** * ******* ***
# ** ***** *** *****
# **
# **
# **
# --------------------------------------------------------------------------------
# </pre>
# <pre>
# Text in a pre element
# is displayed in a fixed-width
# font, and it preserves
# both spaces and
# line breaks
# </pre>
# <pre> Foo Bar </pre>
# <pre>
# Foo Bar
# </pre>
# <pre>Foo Bar
# </pre>
# <pre>
# Foo Bar</pre>
# <figure role="img" aria-labelledby="cow-caption">
# <pre>
# ___________________________
# < I'm an expert in my field. >
# ---------------------------
# \\ ^__^
# \\ (oo)\\_______
# (__)\\ )\\/\\
# ||----w |
# || ||
# ___________________________
# </pre>
# <figcaption id="cow-caption">
# A cow saying, "I'm an expert in my field." The cow is illustrated using preformatted text characters.
# </figcaption>
# </figure>
# <pre data-attr-1="foo" data-attr-2="foo" data-attr-3="foo" data-attr-4="foo" data-attr-5="foo" data-attr-6="foo">
# Foo Bar
# </pre>
# <div>
# <div>
# <div>
# <div>
# <pre>
# ______
# STRING
# ______
# </pre>
# </div>
# </div>
# </div>
# </div>
# <pre></pre>
# <pre><code #foo></code></pre>
# <details>
# <pre><!--Comments-->
# </pre></details>
# <details><pre>
# <!--Comments-->
# </pre>
# </details>
# <!-- #6028 -->
# <pre><br></pre>
# <PRE><HR></PRE>
# <pre><br/></pre>
# <PRE><HR/></PRE>
# <pre><br /></pre>
# <PRE><HR /></PRE>
# <pre><span></span></pre>
# <PRE><DIV></DIV></PRE>
# <pre><br/>long long long text long long long text long long long text long long long text <br></pre>
# <pre><br>long long long text long long long text long long long text long long long text <BR/></pre>
# """
# ).strip()
# html_out = (
# """
# <pre>
# --------------------------------------------------------------------------------
# * * *
# ** ** ***
# ** ** *
# **** *** **** ******** ******** *** ****
# * *** * **** **** * *** ******** ******** *** *** **** **** *
# * **** ** **** * *** ** ** *** * *** ** ****
# ** ** ** * *** ** ** ** * *** **
# ** ** ** ** *** ** ** ** ** *** **
# ** ** ** ******** ** ** ** ******** **
# ** ** ** ******* ** ** ** ******* **
# ** ** ** ** ** ** ** ** **
# ******* *** **** * ** ** ** **** * ***
# ****** *** ******* ** ** *** * ******* ***
# ** ***** *** *****
# **
# **
# **
# --------------------------------------------------------------------------------
# </pre>
# <pre>
# Text in a pre element
# is displayed in a fixed-width
# font, and it preserves
# both spaces and
# line breaks
# </pre>
# <pre> Foo Bar </pre>
# <pre>
# Foo Bar
# </pre>
# <pre>
# Foo Bar
# </pre>
# <pre> Foo Bar</pre>
# <figure role="img" aria-labelledby="cow-caption">
# <pre>
# ___________________________
# < I'm an expert in my field. >
# ---------------------------
# \\ ^__^
# \\ (oo)\\_______
# (__)\\ )\\/\\
# ||----w |
# || ||
# ___________________________
# </pre>
# <figcaption id="cow-caption">
# A cow saying, "I'm an expert in my field." The cow is illustrated using
# preformatted text characters.
# </figcaption>
# </figure>
# <pre
# data-attr-1="foo"
# data-attr-2="foo"
# data-attr-3="foo"
# data-attr-4="foo"
# data-attr-5="foo"
# data-attr-6="foo"
# >
# Foo Bar
# </pre>
# <div>
# <div>
# <div>
# <div>
# <pre>
# ______
# STRING
# ______
# </pre>
# </div>
# </div>
# </div>
# </div>
# <pre></pre>
# <pre><code #foo></code></pre>
# <details>
# <pre><!--Comments-->
# </pre>
# </details>
# <details>
# <pre>
# <!--Comments-->
# </pre>
# </details>
# <!-- #6028 -->
# <pre><br></pre>
# <pre><HR></pre>
# <pre><br/></pre>
# <pre><HR/></pre>
# <pre><br /></pre>
# <pre><HR /></pre>
# <pre><span></span></pre>
# <pre><DIV></DIV></pre>
# <pre><br/>long long long text long long long text long long long text long long long text <br></pre>
# <pre><br>long long long text long long long text long long long text long long long text <BR/></pre>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_tags(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <br/>
# <br />
# <br />
# <br
# />
# <br attribute-a />
# <br very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-attribute />
# <br attribute-a="value" />
# <br
# attribute-a="value"
# />
# <br very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-attribute="value" />
# <br very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-attribute="very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-value" />
# <br attribute-a="value" attribute-b="value" attribute-c="value" attribute-d="value" attribute-e="value" attribute-f="value" />
# <div>string</div>
# <div>very very very very very very very very very very very very very very very very long string</div>
# <div very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-attribute>string</div>
# <div very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-attribute="value">string</div>
# <div attribute="very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-value">string</div>
# <div attribute="value">very very very very very very very very very very very very very very very very long string</div>
# <div attribute="value" attributea="value" attributeb="value" attributec="value" attributed="value" attributef="value">string</div>
# <div attribute="value" attributea="value" attributeb="value" attributec="value" attributed="value" attributef="value">very very very very very very very very very very very very very very very very long string</div>
# <video width="320" height="240" controls>
# <source src="movie.mp4" type="video/mp4">
# <source src="movie.ogg" type="video/ogg">
# Your browser does not support the video tag.
# </video>
# <div><div>string</div></div>
# <div><div>string</div><div>string</div></div>
# <div><div><div>string</div></div><div>string</div></div>
# <div><div>string</div><div><div>string</div></div></div>
# <div><div></div></div>
# <div><div></div><div></div></div>
# <div><div><div><div><div><div><div>string</div></div></div></div></div></div></div>
# <div>
# <div>string</div>
# </div>
# <div>
# <div>string</div>
# </div>
# <div>
# <div>string</div>
# <div>string</div>
# </div>
# <ul
# >123<li
# class="foo"
# id="bar"
# >First</li
# >456<li
# class="baz"
# >Second</li
# >789</ul
# >
# <span>*<b>200</b></span>
# <img src="longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong" />123
# <div>123<meta attr/>456</div>
# <p>x<span a="b"></span></p>
# <p>x<meta a></p>
# <p>x<meta></p>
# <span></span>
# <label aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa></label> |
# <span></span>
# <br />
# <button xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# >12345678901234567890</button
# > <br /><br />
# <button bind-disabled="isUnchanged" on-click="onSave($event)"
# >Disabled Cancel</button
# >
# <br /><br />
# <button xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# >12345678901234567890</button
# > <br /><br />
# <button bind-disabled="isUnchanged" on-click="onSave($event)"
# >Disabled Cancel</button
# >
# <br /><br />
# <p>"<span [innerHTML]="title"></span>" is the <i>property bound</i> title.</p>
# <li>12345678901234567890123456789012345678901234567890123456789012345678901234567890</li>
# <div>
# <app-nav></app-nav>
# <router-outlet></router-outlet>
# <app-footer></app-footer>
# <app-nav [input]="something"></app-nav>
# <router-outlet></router-outlet>
# <app-footer></app-footer>
# <app-primary-navigation></app-primary-navigation>
# <router-outlet></router-outlet>
# <app-footer [input]="something"></app-footer>
# </div>
# <x:root><SPAN>tag name in other namespace should also lower cased</SPAN></x:root>
# <div>
# Lorem ipsum dolor sit amet, consectetur adipiscing elit,
# "<strong>seddoeiusmod</strong>".
# </div>
# <div>
# Lorem ipsum dolor sit amet, consectetur adipiscing elit,
# <strong>seddoeiusmod</strong>.
# </div>
# <span>
# <i class="fa fa-refresh fa-spin" />
# <i class="fa fa-refresh fa-spin" />
# <i class="fa fa-refresh fa-spin" />
# </span>
# <!-- #5810 -->
# <table><tr>
# </tr>
# </table><div>Should not insert empty line before this div</div>
# <!-- self-closing -->
# <span><input type="checkbox"/> </span>
# <span><span><input type="checkbox"/></span></span>
# <span><input type="checkbox"/></span>
# """
# ).strip()
# html_out = (
# """
# <br />
# <br />
# <br />
# <br />
# <br attribute-a />
# <br
# very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-attribute
# />
# <br attribute-a="value" />
# <br attribute-a="value" />
# <br
# very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-attribute="value"
# />
# <br
# very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-attribute="very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-value"
# />
# <br
# attribute-a="value"
# attribute-b="value"
# attribute-c="value"
# attribute-d="value"
# attribute-e="value"
# attribute-f="value"
# />
# <div>string</div>
# <div>
# very very very very very very very very very very very very very very very
# very long string
# </div>
# <div
# very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-attribute
# >
# string
# </div>
# <div
# very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-attribute="value"
# >
# string
# </div>
# <div
# attribute="very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-value"
# >
# string
# </div>
# <div attribute="value">
# very very very very very very very very very very very very very very very
# very long string
# </div>
# <div
# attribute="value"
# attributea="value"
# attributeb="value"
# attributec="value"
# attributed="value"
# attributef="value"
# >
# string
# </div>
# <div
# attribute="value"
# attributea="value"
# attributeb="value"
# attributec="value"
# attributed="value"
# attributef="value"
# >
# very very very very very very very very very very very very very very very
# very long string
# </div>
# <video width="320" height="240" controls>
# <source src="movie.mp4" type="video/mp4" />
# <source src="movie.ogg" type="video/ogg" />
# Your browser does not support the video tag.
# </video>
# <div><div>string</div></div>
# <div>
# <div>string</div>
# <div>string</div>
# </div>
# <div>
# <div><div>string</div></div>
# <div>string</div>
# </div>
# <div>
# <div>string</div>
# <div><div>string</div></div>
# </div>
# <div><div></div></div>
# <div>
# <div></div>
# <div></div>
# </div>
# <div>
# <div>
# <div>
# <div>
# <div>
# <div><div>string</div></div>
# </div>
# </div>
# </div>
# </div>
# </div>
# <div>
# <div>string</div>
# </div>
# <div>
# <div>string</div>
# </div>
# <div>
# <div>string</div>
# <div>string</div>
# </div>
# <ul>
# 123
# <li class="foo" id="bar">First</li>
# 456
# <li class="baz">Second</li>
# 789
# </ul>
# <span>*<b>200</b></span>
# <img
# src="longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong"
# />123
# <div>123<meta attr />456</div>
# <p>x<span a="b"></span></p>
# <p>x<meta a /></p>
# <p>x<meta /></p>
# <span></span>
# <label
# aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
# ></label>
# |
# <span></span>
# <br />
# <button xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>12345678901234567890</button>
# <br /><br />
# <button bind-disabled="isUnchanged" on-click="onSave($event)">
# Disabled Cancel
# </button>
# <br /><br />
# <button xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>12345678901234567890</button>
# <br /><br />
# <button bind-disabled="isUnchanged" on-click="onSave($event)">
# Disabled Cancel
# </button>
# <br /><br />
# <p>"<span [innerHTML]="title"></span>" is the <i>property bound</i> title.</p>
# <li>
# 12345678901234567890123456789012345678901234567890123456789012345678901234567890
# </li>
# <div>
# <app-nav></app-nav>
# <router-outlet></router-outlet>
# <app-footer></app-footer>
# <app-nav [input]="something"></app-nav>
# <router-outlet></router-outlet>
# <app-footer></app-footer>
# <app-primary-navigation></app-primary-navigation>
# <router-outlet></router-outlet>
# <app-footer [input]="something"></app-footer>
# </div>
# <x:root
# ><span>tag name in other namespace should also lower cased</span></x:root
# >
# <div>
# Lorem ipsum dolor sit amet, consectetur adipiscing elit,
# "<strong>seddoeiusmod</strong>".
# </div>
# <div>
# Lorem ipsum dolor sit amet, consectetur adipiscing elit,
# <strong>seddoeiusmod</strong>.
# </div>
# <span>
# <i class="fa fa-refresh fa-spin" />
# <i class="fa fa-refresh fa-spin" />
# <i class="fa fa-refresh fa-spin" />
# </span>
# <!-- #5810 -->
# <table>
# <tr></tr>
# </table>
# <div>Should not insert empty line before this div</div>
# <!-- self-closing -->
# <span><input type="checkbox" /> </span>
# <span
# ><span><input type="checkbox" /></span
# ></span>
# <span><input type="checkbox" /></span>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_tags2(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <div>before<noscript>noscript long long long long long long long long</noscript>after</div>
# <div>before<details><summary>summary long long long long </summary>details</details>after</div>
# <div>before<dialog open>dialog long long long long long long long long </dialog>after</div>
# <div>before<object data="horse.wav"><param name="autoplay" value="true"/><param name="autoplay" value="true"/></object>after</div>
# <div>before<meter min="0" max="1" low=".4" high=".7" optimum=".5" value=".2"></meter>after</div>
# <div>before<progress value=".5" max="1"></progress>after</div>
# """
# ).strip()
# html_out = (
# """
# <div>
# before<noscript>noscript long long long long long long long long</noscript
# >after
# </div>
# <div>
# before
# <details>
# <summary>summary long long long long</summary>
# details
# </details>
# after
# </div>
# <div>
# before
# <dialog open>dialog long long long long long long long long</dialog>
# after
# </div>
# <div>
# before<object data="horse.wav">
# <param name="autoplay" value="true" />
# <param name="autoplay" value="true" /></object
# >after
# </div>
# <div>
# before<meter
# min="0"
# max="1"
# low=".4"
# high=".7"
# optimum=".5"
# value=".2"
# ></meter
# >after
# </div>
# <div>before<progress value=".5" max="1"></progress>after</div>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_textarea(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <div>
# <div>
# <div>
# <div>
# <div>
# <div>
# <div>
# <div>
# <div>
# <div>
# <div>
# <div>
# <textarea rows="10" cols="45" name="text">
# String
# </textarea>
# </div>
# </div>
# </div>
# </div>
# </div>
# </div>
# </div>
# </div>
# </div>
# </div>
# </div>
# </div>
# <textarea></textarea>
# <div><textarea>lorem ipsum</textarea></div>
# """
# ).strip()
# html_out = (
# """
# <div>
# <div>
# <div>
# <div>
# <div>
# <div>
# <div>
# <div>
# <div>
# <div>
# <div>
# <div>
# <textarea rows="10" cols="45" name="text">
# String
# </textarea>
# </div>
# </div>
# </div>
# </div>
# </div>
# </div>
# </div>
# </div>
# </div>
# </div>
# </div>
# </div>
# <textarea></textarea>
# <div><textarea>lorem ipsum</textarea></div>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_unsupported(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <center></center>
# """
# ).strip()
# html_out = (
# """
# <center></center>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)

View file

@ -0,0 +1,50 @@
"""Djlint tests for text.
Some tests may be from prettier.io's html test suite.
Where applicable this notice may be needed:
#### Prettier.io license ####
Copyright © James Long and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
run:
pytest tests/test_html/test_text.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_text.py::test_tag_should_in_fill
"""
# from typing import TextIO
# from click.testing import CliRunner
# from tests.conftest import reformat
# def test_tag_should_in_fill(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <a-long-long-long-element>foo bar foo bar
# foo bar foo bar foo bar foo bar foo bar
# foo bar foo bar</a-long-long-long-element>
# <!-- The end tag should stay in 80 print width -->
# """
# ).strip()
# html_out = (
# """
# <a-long-long-long-element
# >foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo
# bar</a-long-long-long-element
# >
# <!-- The end tag should stay in 80 print width -->
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)

View file

@ -0,0 +1,784 @@
"""Djlint tests for whitespace.
Some tests may be from prettier.io's html test suite.
Where applicable this notice may be needed:
#### Prettier.io license ####
Copyright © James Long and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
run:
pytest tests/test_html/test_whitespace.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_whitespace.py::test_break_tags
"""
# from typing import TextIO
# from click.testing import CliRunner
# from tests.conftest import reformat
# def test_break_tags(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <a>Lorem</a>, ispum dolor sit <strong>amet</strong>.
# <div><a>Lorem</a>, ispum dolor sit <strong>amet</strong>.</div>
# <div><div><a>Lorem</a>, ispum dolor sit <strong>amet</strong>.</div></div>
# """
# ).strip()
# html_out = (
# """
# <a>Lorem</a>, ispum dolor sit <strong>amet</strong>.
# <div><a>Lorem</a>, ispum dolor sit <strong>amet</strong>.</div>
# <div>
# <div><a>Lorem</a>, ispum dolor sit <strong>amet</strong>.</div>
# </div>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_display_inline_block(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <button>Click here! Click here! Click here! Click here! Click here! Click here!</button>
# <button>
# Click here! Click here! Click here! Click here! Click here! Click here!
# </button>
# <div>
# <button>Click here! Click here! Click here! Click here! Click here! Click here!</button><button>Click here! Click here! Click here! Click here! Click here! Click here!</button>
# </div>
# <div>
# <button>Click here! Click here! Click here! Click here! Click here! Click here!</button>
# <button>Click here! Click here! Click here! Click here! Click here! Click here!</button>
# </div>
# <video src="brave.webm"><track kind=subtitles src=brave.en.vtt srclang=en label="English"><track kind=subtitles src=brave.en.vtt srclang=en label="English"></video>
# """
# ).strip()
# html_out = (
# """
# <button>
# Click here! Click here! Click here! Click here! Click here! Click here!
# </button>
# <button>
# Click here! Click here! Click here! Click here! Click here! Click here!
# </button>
# <div>
# <button>
# Click here! Click here! Click here! Click here! Click here! Click here!</button
# ><button>
# Click here! Click here! Click here! Click here! Click here! Click here!
# </button>
# </div>
# <div>
# <button>
# Click here! Click here! Click here! Click here! Click here! Click here!
# </button>
# <button>
# Click here! Click here! Click here! Click here! Click here! Click here!
# </button>
# </div>
# <video src="brave.webm">
# <track kind="subtitles" src="brave.en.vtt" srclang="en" label="English" />
# <track kind="subtitles" src="brave.en.vtt" srclang="en" label="English" />
# </video>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_display_none(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <!DOCTYPE html><HTML CLASS="no-js mY-ClAsS"><HEAD><META CHARSET="utf-8"><TITLE>My tITlE</TITLE><META NAME="description" content="My CoNtEnT"></HEAD></HTML>
# """
# ).strip()
# html_out = (
# """
# <!DOCTYPE html>
# <html class="no-js mY-ClAsS">
# <head>
# <meta charset="utf-8" />
# <title>My tITlE</title>
# <meta name="description" content="My CoNtEnT" />
# </head>
# </html>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_fill(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <p>
# <img
# src="/images/pansies.jpg"
# alt="about fedco bottom image"
# style="float: left;"
# /><strong>We are a cooperative</strong>, one of the few seed companies so organized
# in the United States. Because we do not have an individual owner or beneficiary,
# profit is not our primary goal. Consumers own 60% of the cooperative and worker
# members 40%. Consumer and worker members share proportionately in the cooperative&#8217;s
# profits through our annual patronage dividends.
# </p>
# """
# ).strip()
# html_out = (
# """
# <p>
# <img src="/images/pansies.jpg"
# alt="about fedco bottom image"
# style="float: left"
# /><strong>We are a cooperative</strong>, one of the few seed companies so
# organized in the United States. Because we do not have an individual owner or
# beneficiary, profit is not our primary goal. Consumers own 60% of the
# cooperative and worker members 40%. Consumer and worker members share
# proportionately in the cooperative&#8217;s profits through our annual
# patronage dividends.
# </p>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_inline_leading_trailing_spaces(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <span> 321 </span>
# <span> <a>321</a> </span>
# """
# ).strip()
# html_out = (
# """
# <span> 321 </span>
# <span> <a>321</a> </span>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_inline_nodes(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce cursus massa vel augue
# vestibulum facilisis in porta turpis. Ut faucibus lectus sit amet urna consectetur dignissim.
# Sam vitae neque quis ex dapibus faucibus at sed ligula. Nulla sit amet aliquet nibh.
# Vestibulum at congue mi. Suspendisse vitae odio vitae massa hendrerit mattis sed eget dui.
# Sed eu scelerisque neque. Donec <b>maximus</b> rhoncus pellentesque. Aenean purus turpis, vehicula
# euismod ante vel, ultricies eleifend dui. Class aptent taciti sociosqu ad litora torquent per
# conubia nostra, per inceptos himenaeos. Donec in ornare velit.</p>
# <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce cursus massa vel augue
# vestibulum facilisis in porta turpis. Ut faucibus lectus sit amet urna consectetur dignissim.
# Sam vitae neque quis ex dapibus faucibus at sed ligula. Nulla sit amet aliquet nibh.
# Vestibulum at congue mi. Suspendisse vitae odio vitae massa hendrerit mattis sed eget dui.
# Sed eu scelerisque neque. Donec <a href="#"><b>maximus</b></a> rhoncus pellentesque. Aenean purus turpis, vehicula
# euismod ante vel, ultricies eleifend dui. Class aptent taciti sociosqu ad litora torquent per
# conubia nostra, per inceptos himenaeos. Donec in ornare velit.</p>
# """
# ).strip()
# html_out = (
# """
# <p>
# Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce cursus massa
# vel augue vestibulum facilisis in porta turpis. Ut faucibus lectus sit amet
# urna consectetur dignissim. Sam vitae neque quis ex dapibus faucibus at sed
# ligula. Nulla sit amet aliquet nibh. Vestibulum at congue mi. Suspendisse
# vitae odio vitae massa hendrerit mattis sed eget dui. Sed eu scelerisque
# neque. Donec <b>maximus</b> rhoncus pellentesque. Aenean purus turpis,
# vehicula euismod ante vel, ultricies eleifend dui. Class aptent taciti
# sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Donec
# in ornare velit.
# </p>
# <p>
# Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce cursus massa
# vel augue vestibulum facilisis in porta turpis. Ut faucibus lectus sit amet
# urna consectetur dignissim. Sam vitae neque quis ex dapibus faucibus at sed
# ligula. Nulla sit amet aliquet nibh. Vestibulum at congue mi. Suspendisse
# vitae odio vitae massa hendrerit mattis sed eget dui. Sed eu scelerisque
# neque. Donec <a href="#"><b>maximus</b></a> rhoncus pellentesque. Aenean purus
# turpis, vehicula euismod ante vel, ultricies eleifend dui. Class aptent taciti
# sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Donec
# in ornare velit.
# </p>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_nested_inline_without_whitespace(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# (
# """
# <a href="/wiki/Help:IPA/English" title="Help:IPA/English">/<span style="border-bottom:1px dotted"><span title="/ˌ/: secondary stress follows">ˌ</span
# ><span title="/ɪ/: &#39;i&#39; in &#39;kit&#39;">ɪ</span
# ><span title="&#39;l&#39; in &#39;lie&#39;">l</span
# ><span title="/ə/: &#39;a&#39; in &#39;about&#39;">ə</span
# ><span title="/ˈ/: primary stress follows">ˈ</span
# ><span title="&#39;n&#39; in &#39;nigh&#39;">n</span
# ><span title="/ɔɪ/: &#39;oi&#39; in &#39;choice&#39;">ɔɪ</span></span>/</a>
# <span class="word"><span class="syllable"><span class="letter vowel">i</span><span class="letter consonant">p</span></span
# ><span class="syllable"><span class="letter consonant onset">s</span><span class="letter vowel">u</span><span class="letter consonant">m</span></span></span>
# """
# )
# .strip()
# .str.encode()
# )
# html_out = (
# """
# <a href="/wiki/Help:IPA/English" title="Help:IPA/English"
# >/<span style="border-bottom: 1px dotted"
# ><span title="/ˌ/: secondary stress follows">ˌ</span
# ><span title="/ɪ/: &#39;i&#39; in &#39;kit&#39;">ɪ</span
# ><span title="&#39;l&#39; in &#39;lie&#39;">l</span
# ><span title="/ə/: &#39;a&#39; in &#39;about&#39;">ə</span
# ><span title="/ˈ/: primary stress follows">ˈ</span
# ><span title="&#39;n&#39; in &#39;nigh&#39;">n</span
# ><span title="/ɔɪ/: &#39;oi&#39; in &#39;choice&#39;">ɔɪ</span></span
# >/</a
# >
# <span class="word"
# ><span class="syllable"
# ><span class="letter vowel">i</span
# ><span class="letter consonant">p</span></span
# ><span class="syllable"
# ><span class="letter consonant onset">s</span
# ><span class="letter vowel">u</span
# ><span class="letter consonant">m</span></span
# ></span
# >
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_non_breaking_whitespace(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = str.encode(
# """
# <!-- normal whitespaces -->
# <span>Nihil aut odit omnis. Quam maxime est molestiae. Maxime dolorem dolores voluptas quaerat ut qui sunt vitae error.</span>
# <!-- non-breaking whitespaces -->
# <span>Nihil aut odit omnis. Quam maxime est molestiae. Maxime dolorem dolores voluptas quaerat ut qui sunt vitae error.</span>
# <!-- non-breaking narrow whitespaces -->
# <span>Prix:32€</span>
# """
# ).strip()
# html_out = (
# """
# <!-- normal whitespaces -->
# <span
# >Nihil aut odit omnis. Quam maxime est molestiae. Maxime dolorem dolores
# voluptas quaerat ut qui sunt vitae error.</span
# >
# <!-- non-breaking whitespaces -->
# <span
# >Nihil aut odit omnis. Quam maxime est molestiae. Maxime dolorem dolores voluptas quaerat ut qui sunt vitae error.</span
# >
# <!-- non-breaking narrow whitespaces -->
# <span>Prix:32€</span>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_snippet_18(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = str.encode(
# """
# <div></div>
# """
# ).strip()
# html_out = (
# """
# <div></div>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_snippet_19(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = str.encode(
# """
# <div> </div>
# """
# ).strip()
# html_out = (
# """
# <div></div>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_snippet_20(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = str.encode(
# """
# <div> </div>
# """
# ).strip()
# html_out = (
# """
# <div></div>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_snippet_21(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = str.encode(
# """
# <div> </div>
# """
# ).strip()
# html_out = (
# """
# <div> </div>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_snippet_22(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = str.encode(
# """
# <span></span>
# """
# ).strip()
# html_out = (
# """
# <span></span>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_snippet_23(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = str.encode(
# """
# <span> </span>
# """
# ).strip()
# html_out = (
# """
# <span> </span>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_snippet_24(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = str.encode(
# """
# <span> </span>
# """
# ).strip()
# html_out = (
# """
# <span> </span>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_snippet_25(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = str.encode(
# """
# <span> </span>
# """
# ).strip()
# html_out = (
# """
# <span> </span>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_snippet_26(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = str.encode(
# """
# <img/><img/>
# """
# ).strip()
# html_out = (
# """
# <img /><img />
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_snippet_27(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = str.encode(
# """
# <img/> <img/>
# """
# ).strip()
# html_out = (
# """
# <img /> <img />
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_snippet_28(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = str.encode(
# """
# <img/> <img/>
# """
# ).strip()
# html_out = (
# """
# <img /> <img />
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_snippet_29(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = str.encode(
# """
# <img/> <img/>
# """
# ).strip()
# html_out = (
# """
# <img /> <img />
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_snippet_30(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = str.encode(
# """
# <i /> | <i />
# """
# ).strip()
# html_out = (
# """
# <i /> | <i />
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_snippet_31(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = str.encode(
# """
# <p><span>X</span> or <span>Y</span></p><p>X or Y</p>
# """
# ).strip()
# html_out = (
# """
# <p><span>X</span> or <span>Y</span></p>
# <p>X or Y</p>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_snippet_2005(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = str.encode(
# """
# <!-- U+2005 -->
# <div>before<span></span>afterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafter</div>
# <!-- U+005F -->
# <div>before<span>_</span>afterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafter</div>
# <!-- U+0020 -->
# <div>before<span> </span>afterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafter</div>
# """
# ).strip()
# html_out = (
# """
# <!-- U+2005 -->
# <div>
# before<span></span>afterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafter
# </div>
# <!-- U+005F -->
# <div>
# before<span>_</span>afterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafter
# </div>
# <!-- U+0020 -->
# <div>
# before<span
# > </span
# >afterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafterafter
# </div>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_snippet_2005_2(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = str.encode(
# """
# <!-- U+2005 -->
# <script type="text/unknown" lang="unknown">
# // comment
# // comment
# // comment
# // comment
# </script>
# <!-- U+005F -->
# <script type="text/unknown" lang="unknown">
# _ // comment
# // comment
# // comment
# // comment
# </script>
# <!-- U+0020 -->
# <script type="text/unknown" lang="unknown">
# // comment
# // comment
# // comment
# // comment
# </script>
# """
# ).strip()
# html_out = (
# """
# <!-- U+2005 -->
# <script type="text/unknown" lang="unknown">
# // comment
# // comment
# // comment
# // comment
# </script>
# <!-- U+005F -->
# <script type="text/unknown" lang="unknown">
# _ // comment
# // comment
# // comment
# // comment
# </script>
# <!-- U+0020 -->
# <script type="text/unknown" lang="unknown">
# // comment
# // comment
# // comment
# // comment
# </script>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_surrounding_linebreak(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <span>123</span>
# <span>
# 123</span>
# <span>123
# </span>
# <span>
# 123
# </span>
# <div>123</div>
# <div>
# 123</div>
# <div>123
# </div>
# <div>
# 123
# </div>
# """
# ).strip()
# html_out = (
# """
# <span>123</span>
# <span> 123</span>
# <span>123 </span>
# <span> 123 </span>
# <div>123</div>
# <div>123</div>
# <div>123</div>
# <div>123</div>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_table(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <table>
# <thead>
# <tr>
# <th>A</th>
# <th>B</th>
# <th>C</th>
# </tr>
# </thead>
# </table>
# <table><thead><tr><th>A</th><th>B</th><th>C</th></tr></thead></table>
# <table> <thead> <tr> <th> A </th> <th> B </th> <th> C </th> </tr> </thead> </table>
# <table>
# <thead>
# <tr>
# </tr>
# </thead>
# </table>
# """
# ).strip()
# html_out = (
# """
# <table>
# <thead>
# <tr>
# <th>A</th>
# <th>B</th>
# <th>C</th>
# </tr>
# </thead>
# </table>
# <table>
# <thead>
# <tr>
# <th>A</th>
# <th>B</th>
# <th>C</th>
# </tr>
# </thead>
# </table>
# <table>
# <thead>
# <tr>
# <th>A</th>
# <th>B</th>
# <th>C</th>
# </tr>
# </thead>
# </table>
# <table>
# <thead>
# <tr></tr>
# </thead>
# </table>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)
# def test_template(runner: CliRunner, tmp_file: TextIO) -> None:
# html_in = (
# b"""
# <template>
# <template>foo</template>
# </template>
# <template>
# <template>foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo</template>
# </template>
# """
# ).strip()
# html_out = (
# """
# <template>
# <template>foo</template>
# </template>
# <template>
# <template
# >foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo</template
# >
# </template>
# """
# ).strip()
# output = reformat(tmp_file, runner, html_in)

View file

@ -1,11 +1,21 @@
"""DjLint tests for yaml front matter.
Some tests may be from prettier.io's html test suite.
Where applicable this notice may be needed:
#### Prettier.io license ####
Copyright © James Long and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
run:
pytest tests/test_html/test_yaml.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html/test_yaml.py
pytest tests/test_html/test_yaml.py::test_custom_parser
"""
# pylint: disable=C0116
@ -36,10 +46,8 @@ invalid:
invalid:
---
<html>
<head>
</head>
<body>
</body>
<head></head>
<body></body>
</html>
"""
)
@ -61,10 +69,8 @@ hello: world
hello: world
---
<html>
<head>
</head>
<body>
</body>
<head></head>
<body></body>
</html>
"""
)
@ -80,3 +86,113 @@ layout: <div><div></div></div>
<div></div>""",
)
assert output.exit_code == 0
def test_custom_parser(runner: CliRunner, tmp_file: TextIO) -> None:
html_in = (
b"""
---mycustomparser
title: Hello
slug: home
---
<h1>
Hello world!</h1>
"""
).strip()
html_out = """---mycustomparser
title: Hello
slug: home
---
<h1>Hello world!</h1>
"""
output = reformat(tmp_file, runner, html_in)
assert output.text == html_out
def test_empty(runner: CliRunner, tmp_file: TextIO) -> None:
html_in = (
b"""
---
---
<h1>
Hello world!</h1>
"""
).strip()
html_out = """---
---
<h1>Hello world!</h1>
"""
output = reformat(tmp_file, runner, html_in)
assert output.text == html_out
def test_empty_2(runner: CliRunner, tmp_file: TextIO) -> None:
html_in = (
b"""
---
---
<div>
---
</div>
"""
).strip()
html_out = """---
---
<div>---</div>
"""
output = reformat(tmp_file, runner, html_in)
assert output.text == html_out
def test_issue_9042_no_empty_line(runner: CliRunner, tmp_file: TextIO) -> None:
html_in = (
b"""
---
layout: foo
---
Test <a
href="https://djlint.com">abc</a>.
"""
).strip()
html_out = """---
layout: foo
---
Test <a href="https://djlint.com">abc</a>.
"""
output = reformat(tmp_file, runner, html_in)
assert output.text == html_out
def test_issue_9042(runner: CliRunner, tmp_file: TextIO) -> None:
html_in = (
b"""
---
layout: foo
---
Test <a
href="https://djlint.com">abc</a>.
"""
).strip()
html_out = """---
layout: foo
---
Test <a href="https://djlint.com">abc</a>.
"""
output = reformat(tmp_file, runner, html_in)
assert output.text == html_out