mirror of
https://github.com/Hopiu/djLint.git
synced 2026-05-20 02:41:51 +00:00
test(html tests): restructured tests
This commit is contained in:
parent
eec497d043
commit
a124a4dd6d
19 changed files with 949 additions and 614 deletions
101
tests/test_html/test_attributes.py
Normal file
101
tests/test_html/test_attributes.py
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
"""Djlint tests specific to html.
|
||||
|
||||
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 \
|
||||
--cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
|
||||
"""
|
||||
# pylint: disable=C0116
|
||||
from typing import TextIO
|
||||
|
||||
from click.testing import CliRunner
|
||||
|
||||
from tests.conftest import reformat
|
||||
|
||||
|
||||
def test_long_attributes(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<input type="text" class="class one class two" disabled="true" value="something pretty long goes here"
|
||||
style="width:100px;cursor: text;border:1px solid pink"
|
||||
required="true" />""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 1
|
||||
|
||||
assert (
|
||||
output.text
|
||||
== """<input type="text"
|
||||
class="class one class two"
|
||||
disabled="true"
|
||||
value="something pretty long goes here"
|
||||
style="width:100px;cursor: text;border:1px solid pink"
|
||||
required="true"/>
|
||||
"""
|
||||
)
|
||||
|
||||
# check styles
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<div class="my long classes"
|
||||
required="true"
|
||||
checked="checked"
|
||||
data-attr="some long junk"
|
||||
style="margin-left: 90px;
|
||||
display: contents;
|
||||
font-weight: bold;
|
||||
font-size: 1.5rem;">
|
||||
""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
|
||||
# check styles when tag is first
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<div>
|
||||
<div style="margin-left: 90px;
|
||||
display: contents;
|
||||
font-weight: bold;
|
||||
font-size: 1.5rem;"
|
||||
data-attr="stuff"
|
||||
class="my long class goes here">
|
||||
</div>
|
||||
</div>
|
||||
""",
|
||||
)
|
||||
assert output.exit_code == 0
|
||||
|
||||
|
||||
def test_ignored_attributes(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<div
|
||||
class="a long list of meaningless classes"
|
||||
id="somthing_meaning_less_is_here"
|
||||
required
|
||||
checked="checked"
|
||||
json-data='{"menu":{"header":"SVG Viewer","items":[{"id":"Open"}]}}'>
|
||||
</div>""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 1
|
||||
print(output.text)
|
||||
assert (
|
||||
output.text
|
||||
== """<div class="a long list of meaningless classes"
|
||||
id="somthing_meaning_less_is_here"
|
||||
required
|
||||
checked="checked"
|
||||
json-data='{"menu":{"header":"SVG Viewer","items":[{"id":"Open"}]}}'>\n</div>
|
||||
"""
|
||||
)
|
||||
40
tests/test_html/test_aurelia.py
Normal file
40
tests/test_html/test_aurelia.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
"""Djlint tests specific to aurelia.
|
||||
|
||||
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_aurelia.py --cov=src/djlint --cov-branch \
|
||||
--cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
poetry run pytest tests/test_html/test_aurelia.py::test_aurelia
|
||||
|
||||
"""
|
||||
# pylint: disable=C0116
|
||||
from typing import TextIO
|
||||
|
||||
from click.testing import CliRunner
|
||||
|
||||
from tests.conftest import reformat
|
||||
|
||||
|
||||
def test_aurelia(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<template>
|
||||
<i class.bind="icon"></i>
|
||||
</template>
|
||||
""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
39
tests/test_html/test_comments.py
Normal file
39
tests/test_html/test_comments.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
"""Djlint tests specific to html.
|
||||
|
||||
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 \
|
||||
--cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
|
||||
"""
|
||||
# pylint: disable=C0116
|
||||
from pathlib import Path
|
||||
from typing import TextIO
|
||||
|
||||
from click.testing import CliRunner
|
||||
|
||||
from src.djlint import main as djlint
|
||||
from tests.conftest import write_to_file
|
||||
|
||||
|
||||
def test_html_comments_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""<div>\n <!-- asdf--><!--\n multi\nline\ncomment--></div>""",
|
||||
)
|
||||
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
|
||||
assert (
|
||||
Path(tmp_file.name).read_text(encoding="utf8")
|
||||
== """<div>
|
||||
<!-- asdf--><!--
|
||||
multi
|
||||
line
|
||||
comment-->
|
||||
</div>
|
||||
"""
|
||||
)
|
||||
|
|
@ -1,609 +0,0 @@
|
|||
"""Djlint tests specific to html.
|
||||
|
||||
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 \
|
||||
--cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
|
||||
"""
|
||||
# pylint: disable=C0116
|
||||
from pathlib import Path
|
||||
from typing import TextIO
|
||||
|
||||
from click.testing import CliRunner
|
||||
|
||||
from src.djlint import main as djlint
|
||||
from tests.conftest import reformat, write_to_file
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def test_code_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<ol>
|
||||
<li>
|
||||
<code>a</code> b
|
||||
</li>
|
||||
</ol>""",
|
||||
)
|
||||
assert output.exit_code == 0
|
||||
|
||||
|
||||
def test_pre_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
# added for https://github.com/Riverside-Healthcare/djLint/issues/187
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""{% if a %}
|
||||
<div>
|
||||
<pre><code>asdf</code></pre>
|
||||
<pre><code>asdf
|
||||
</code></pre>
|
||||
<!-- other html -->
|
||||
<h2>title</h2>
|
||||
</div>
|
||||
{% endif %}""",
|
||||
)
|
||||
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>
|
||||
# """,
|
||||
# )
|
||||
|
||||
# assert output.exit_code == 0
|
||||
|
||||
# # check attributes
|
||||
# output = reformat(
|
||||
# tmp_file,
|
||||
# runner,
|
||||
# b"""<div>
|
||||
# <div class="field">
|
||||
# <textarea class="this"
|
||||
# name="that">asdf</textarea>
|
||||
# </div>
|
||||
# </div>
|
||||
# """,
|
||||
# )
|
||||
|
||||
# assert (
|
||||
# output.text
|
||||
# == """<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.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
|
||||
|
||||
|
||||
def test_script_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""<div>\n <script>console.log();\n console.log();\n\n </script>\n</div>""",
|
||||
)
|
||||
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
|
||||
assert (
|
||||
Path(tmp_file.name).read_text(encoding="utf8")
|
||||
== """<div>
|
||||
<script>console.log();
|
||||
console.log();
|
||||
|
||||
</script>
|
||||
</div>
|
||||
"""
|
||||
)
|
||||
|
||||
# check script includes
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<script src="{% static 'common/js/foo.min.js' %}"></script>""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<script>
|
||||
$("#x").do({
|
||||
dataBound: function () {
|
||||
this.tbody.append($("<td colspan=2'>X</td>"));
|
||||
},
|
||||
});
|
||||
</script>
|
||||
""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
|
||||
# check bad template tags inside scripts
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<script>{{missing_space}}</script>\n""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
|
||||
|
||||
def test_html_comments_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""<div>\n <!-- asdf--><!--\n multi\nline\ncomment--></div>""",
|
||||
)
|
||||
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
|
||||
assert (
|
||||
Path(tmp_file.name).read_text(encoding="utf8")
|
||||
== """<div>
|
||||
<!-- asdf--><!--
|
||||
multi
|
||||
line
|
||||
comment-->
|
||||
</div>
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def test_long_attributes(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<input type="text" class="class one class two" disabled="true" value="something pretty long goes here"
|
||||
style="width:100px;cursor: text;border:1px solid pink"
|
||||
required="true" />""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 1
|
||||
|
||||
assert (
|
||||
output.text
|
||||
== """<input type="text"
|
||||
class="class one class two"
|
||||
disabled="true"
|
||||
value="something pretty long goes here"
|
||||
style="width:100px;cursor: text;border:1px solid pink"
|
||||
required="true"/>
|
||||
"""
|
||||
)
|
||||
|
||||
# check styles
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<div class="my long classes"
|
||||
required="true"
|
||||
checked="checked"
|
||||
data-attr="some long junk"
|
||||
style="margin-left: 90px;
|
||||
display: contents;
|
||||
font-weight: bold;
|
||||
font-size: 1.5rem;">
|
||||
""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
|
||||
# check styles when tag is first
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<div>
|
||||
<div style="margin-left: 90px;
|
||||
display: contents;
|
||||
font-weight: bold;
|
||||
font-size: 1.5rem;"
|
||||
data-attr="stuff"
|
||||
class="my long class goes here">
|
||||
</div>
|
||||
</div>
|
||||
""",
|
||||
)
|
||||
assert output.exit_code == 0
|
||||
|
||||
|
||||
def test_small_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""<small>text</small>""",
|
||||
)
|
||||
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
assert (
|
||||
Path(tmp_file.name).read_text(encoding="utf8")
|
||||
== """<small>text</small>
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def test_dd_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""<dd>text</dd>""",
|
||||
)
|
||||
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
assert (
|
||||
Path(tmp_file.name).read_text(encoding="utf8")
|
||||
== """<dd>
|
||||
text
|
||||
</dd>
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def test_hr_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<div>
|
||||
<div>
|
||||
<hr>
|
||||
</div>
|
||||
</div>
|
||||
""",
|
||||
)
|
||||
assert output.exit_code == 0
|
||||
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<div>
|
||||
<div>
|
||||
<hr />
|
||||
</div>
|
||||
</div>
|
||||
""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
|
||||
|
||||
# def test_span_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
# write_to_file(
|
||||
# tmp_file.name,
|
||||
# b"""<span class="icon has-text-grey is-large "><i class="fas fa-lg fa-star"></i></span>""",
|
||||
# )
|
||||
# runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
# assert (
|
||||
# Path(tmp_file.name).read_text(encoding="utf8")
|
||||
# == """<span class="icon has-text-grey is-large "><i class="fas fa-lg fa-star"></i></span>
|
||||
# """
|
||||
# )
|
||||
|
||||
# # issue #171, span is an inline tag
|
||||
# output = reformat(
|
||||
# tmp_file,
|
||||
# runner,
|
||||
# b"""<div class="hi">
|
||||
# <div class="poor">
|
||||
# <p class="format">
|
||||
# <strong>H</strong>ello stranger, <strong>do not wrap span</strong>, <strong>pls</strong>.
|
||||
# <span class="big">H</span>ello stranger, <strong>do not wrap span</strong>, <span class="big">pls</span>.
|
||||
# </p>
|
||||
# </div>
|
||||
# </div>""",
|
||||
# ) # noqa: E501
|
||||
# assert output.exit_code == 0
|
||||
|
||||
|
||||
def test_dt_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""<dt>text</dt>""",
|
||||
)
|
||||
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
assert (
|
||||
Path(tmp_file.name).read_text(encoding="utf8")
|
||||
== """<dt>
|
||||
text
|
||||
</dt>
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def test_details_summary_tags(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""<details><summary>summary</summary>body</details>""",
|
||||
)
|
||||
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
assert (
|
||||
Path(tmp_file.name).read_text(encoding="utf8")
|
||||
== """<details>
|
||||
<summary>
|
||||
summary
|
||||
</summary>
|
||||
body
|
||||
</details>
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def test_figure_figcaption_tags(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""<figure><img src="" alt=""><figcaption>caption</figcaption></figure>""",
|
||||
)
|
||||
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
assert (
|
||||
Path(tmp_file.name).read_text(encoding="utf8")
|
||||
== """<figure>
|
||||
<img src="" alt="">
|
||||
<figcaption>
|
||||
caption
|
||||
</figcaption>
|
||||
</figure>
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def test_ignored_attributes(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<div
|
||||
class="a long list of meaningless classes"
|
||||
id="somthing_meaning_less_is_here"
|
||||
required
|
||||
checked="checked"
|
||||
json-data='{"menu":{"header":"SVG Viewer","items":[{"id":"Open"}]}}'>
|
||||
</div>""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 1
|
||||
print(output.text)
|
||||
assert (
|
||||
output.text
|
||||
== """<div class="a long list of meaningless classes"
|
||||
id="somthing_meaning_less_is_here"
|
||||
required
|
||||
checked="checked"
|
||||
json-data='{"menu":{"header":"SVG Viewer","items":[{"id":"Open"}]}}'>\n</div>
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def test_picture_source_img_tags(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""\
|
||||
<picture><source media="(max-width:640px)"
|
||||
srcset="image.jpg"><img src="image.jpg" alt="image"></picture>""",
|
||||
)
|
||||
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
assert (
|
||||
Path(tmp_file.name).read_text(encoding="utf8")
|
||||
== """<picture>
|
||||
<source media="(max-width:640px)" srcset="image.jpg">
|
||||
<img src="image.jpg" alt="image">
|
||||
</picture>
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def test_ignored_block(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<!-- <span> -->
|
||||
<div><p><span></span></p></div>
|
||||
<!-- <div> -->
|
||||
""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 1
|
||||
|
||||
assert (
|
||||
output.text
|
||||
== """<!-- <span> -->
|
||||
<div>
|
||||
<p>
|
||||
<span></span>
|
||||
</p>
|
||||
</div>
|
||||
<!-- <div> -->
|
||||
"""
|
||||
)
|
||||
|
||||
# check custom ignore tag {# djlint:off #} {# djlint:on #}
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<!-- djlint:off -->
|
||||
<div><p><span></span></p></div>
|
||||
<!-- djlint:on -->
|
||||
{# djlint:off #}
|
||||
<div><p><span></span></p></div>
|
||||
{# djlint:on #}
|
||||
{% comment %} djlint:off {% endcomment %}
|
||||
<div><p><span></span></p></div>
|
||||
{% comment %} djlint:on {% endcomment %}
|
||||
{{ /* djlint:off */ }}
|
||||
<div><p><span></span></p></div>
|
||||
{{ /* djlint:on */ }}
|
||||
{{!-- djlint:off --}}
|
||||
<div><p><span></span></p></div>
|
||||
{{!-- djlint:on --}}
|
||||
""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""{# djlint: off #}<meta name="description" content="{% block meta_content %}Alle vogelkijkhutten van Nederland{% endblock %}">{# djlint:on #}
|
||||
""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
|
||||
# check script tag
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<script>
|
||||
<div><p><span></span></p></div>
|
||||
</script>
|
||||
""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
|
||||
assert (
|
||||
"""<script>
|
||||
<div><p><span></span></p></div>
|
||||
</script>
|
||||
"""
|
||||
in output.text
|
||||
)
|
||||
|
||||
# check inline script includes
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<html>
|
||||
<head>
|
||||
<link href="{% static 'foo/bar.css' %}" rel="stylesheet"/>
|
||||
<!--JS-->
|
||||
<script src="{% static 'foo/bar.js' %}"></script>
|
||||
</head>
|
||||
</html>
|
||||
""",
|
||||
)
|
||||
print(output.text)
|
||||
assert output.exit_code == 0
|
||||
|
||||
|
||||
def test_style_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<style>
|
||||
{# override to fix text all over the place in media upload box #}
|
||||
.k-dropzone .k-upload-status {
|
||||
color: #a1a1a1;
|
||||
}
|
||||
</style>
|
||||
""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<style>
|
||||
.k-dropzone .k-upload-status {
|
||||
color: #a1a1a1;
|
||||
}
|
||||
</style>
|
||||
""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
|
||||
# check style includes
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<link href="{% static 'common/js/foo.min.js' %}"/>""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
|
||||
|
||||
def test_self_closing_tags(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""<p><span>Hello</span> <br /><input /><link /><img /><source /><meta /> <span>World</span></p>""",
|
||||
)
|
||||
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
assert (
|
||||
Path(tmp_file.name).read_text(encoding="utf8")
|
||||
== """<p>
|
||||
<span>Hello</span>
|
||||
<br />
|
||||
<input />
|
||||
<link />
|
||||
<img />
|
||||
<source />
|
||||
<meta />
|
||||
<span>World</span>
|
||||
</p>
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def test_void_self_closing_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""<p><span>Hello</span> <br><input><link><img><source><meta> <span>World</span></p>""",
|
||||
)
|
||||
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
assert (
|
||||
Path(tmp_file.name).read_text(encoding="utf8")
|
||||
== """<p>
|
||||
<span>Hello</span>
|
||||
<br>
|
||||
<input>
|
||||
<link>
|
||||
<img>
|
||||
<source>
|
||||
<meta>
|
||||
<span>World</span>
|
||||
</p>
|
||||
"""
|
||||
)
|
||||
151
tests/test_html/test_ignored.py
Normal file
151
tests/test_html/test_ignored.py
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
"""Djlint tests specific to html.
|
||||
|
||||
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 \
|
||||
--cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
|
||||
"""
|
||||
# pylint: disable=C0116
|
||||
|
||||
from typing import TextIO
|
||||
|
||||
from click.testing import CliRunner
|
||||
|
||||
from tests.conftest import reformat
|
||||
|
||||
|
||||
def test_ignored_block(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<!-- <span> -->
|
||||
<div><p><span></span></p></div>
|
||||
<!-- <div> -->
|
||||
""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 1
|
||||
|
||||
assert (
|
||||
output.text
|
||||
== """<!-- <span> -->
|
||||
<div>
|
||||
<p>
|
||||
<span></span>
|
||||
</p>
|
||||
</div>
|
||||
<!-- <div> -->
|
||||
"""
|
||||
)
|
||||
|
||||
# check custom ignore tag {# djlint:off #} {# djlint:on #}
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<!-- djlint:off -->
|
||||
<div><p><span></span></p></div>
|
||||
<!-- djlint:on -->
|
||||
{# djlint:off #}
|
||||
<div><p><span></span></p></div>
|
||||
{# djlint:on #}
|
||||
{% comment %} djlint:off {% endcomment %}
|
||||
<div><p><span></span></p></div>
|
||||
{% comment %} djlint:on {% endcomment %}
|
||||
{{ /* djlint:off */ }}
|
||||
<div><p><span></span></p></div>
|
||||
{{ /* djlint:on */ }}
|
||||
{{!-- djlint:off --}}
|
||||
<div><p><span></span></p></div>
|
||||
{{!-- djlint:on --}}
|
||||
""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""{# djlint: off #}<meta name="description" content="{% block meta_content %}Alle vogelkijkhutten van Nederland{% endblock %}">{# djlint:on #}
|
||||
""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
|
||||
# check script tag
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<script>
|
||||
<div><p><span></span></p></div>
|
||||
</script>
|
||||
""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
|
||||
assert (
|
||||
"""<script>
|
||||
<div><p><span></span></p></div>
|
||||
</script>
|
||||
"""
|
||||
in output.text
|
||||
)
|
||||
|
||||
# check inline script includes
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<html>
|
||||
<head>
|
||||
<link href="{% static 'foo/bar.css' %}" rel="stylesheet"/>
|
||||
<!--JS-->
|
||||
<script src="{% static 'foo/bar.js' %}"></script>
|
||||
</head>
|
||||
</html>
|
||||
""",
|
||||
)
|
||||
print(output.text)
|
||||
assert output.exit_code == 0
|
||||
|
||||
|
||||
def test_style_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<style>
|
||||
{# override to fix text all over the place in media upload box #}
|
||||
.k-dropzone .k-upload-status {
|
||||
color: #a1a1a1;
|
||||
}
|
||||
</style>
|
||||
""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<style>
|
||||
.k-dropzone .k-upload-status {
|
||||
color: #a1a1a1;
|
||||
}
|
||||
</style>
|
||||
""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
|
||||
# check style includes
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<link href="{% static 'common/js/foo.min.js' %}"/>""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
64
tests/test_html/test_selfclosing.py
Normal file
64
tests/test_html/test_selfclosing.py
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
"""Djlint tests specific to html.
|
||||
|
||||
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 \
|
||||
--cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
|
||||
"""
|
||||
# pylint: disable=C0116
|
||||
from pathlib import Path
|
||||
from typing import TextIO
|
||||
|
||||
from click.testing import CliRunner
|
||||
|
||||
from src.djlint import main as djlint
|
||||
from tests.conftest import write_to_file
|
||||
|
||||
|
||||
def test_self_closing_tags(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""<p><span>Hello</span> <br /><input /><link /><img /><source /><meta /> <span>World</span></p>""",
|
||||
)
|
||||
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
assert (
|
||||
Path(tmp_file.name).read_text(encoding="utf8")
|
||||
== """<p>
|
||||
<span>Hello</span>
|
||||
<br />
|
||||
<input />
|
||||
<link />
|
||||
<img />
|
||||
<source />
|
||||
<meta />
|
||||
<span>World</span>
|
||||
</p>
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def test_void_self_closing_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""<p><span>Hello</span> <br><input><link><img><source><meta> <span>World</span></p>""",
|
||||
)
|
||||
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
assert (
|
||||
Path(tmp_file.name).read_text(encoding="utf8")
|
||||
== """<p>
|
||||
<span>Hello</span>
|
||||
<br>
|
||||
<input>
|
||||
<link>
|
||||
<img>
|
||||
<source>
|
||||
<meta>
|
||||
<span>World</span>
|
||||
</p>
|
||||
"""
|
||||
)
|
||||
32
tests/test_html/test_tag_code.py
Normal file
32
tests/test_html/test_tag_code.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
"""Djlint tests specific to html.
|
||||
|
||||
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 \
|
||||
--cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
|
||||
"""
|
||||
# pylint: disable=C0116
|
||||
|
||||
from typing import TextIO
|
||||
|
||||
from click.testing import CliRunner
|
||||
|
||||
from tests.conftest import reformat
|
||||
|
||||
|
||||
def test_code_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<ol>
|
||||
<li>
|
||||
<code>a</code> b
|
||||
</li>
|
||||
</ol>""",
|
||||
)
|
||||
assert output.exit_code == 0
|
||||
35
tests/test_html/test_tag_dd.py
Normal file
35
tests/test_html/test_tag_dd.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
"""Djlint tests specific to html.
|
||||
|
||||
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 \
|
||||
--cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
|
||||
"""
|
||||
# pylint: disable=C0116
|
||||
from pathlib import Path
|
||||
from typing import TextIO
|
||||
|
||||
from click.testing import CliRunner
|
||||
|
||||
from src.djlint import main as djlint
|
||||
from tests.conftest import write_to_file
|
||||
|
||||
|
||||
def test_dd_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""<dd>text</dd>""",
|
||||
)
|
||||
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
assert (
|
||||
Path(tmp_file.name).read_text(encoding="utf8")
|
||||
== """<dd>
|
||||
text
|
||||
</dd>
|
||||
"""
|
||||
)
|
||||
38
tests/test_html/test_tag_details_summary.py
Normal file
38
tests/test_html/test_tag_details_summary.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
"""Djlint tests specific to html.
|
||||
|
||||
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 \
|
||||
--cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
|
||||
"""
|
||||
# pylint: disable=C0116
|
||||
from pathlib import Path
|
||||
from typing import TextIO
|
||||
|
||||
from click.testing import CliRunner
|
||||
|
||||
from src.djlint import main as djlint
|
||||
from tests.conftest import write_to_file
|
||||
|
||||
|
||||
def test_details_summary_tags(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""<details><summary>summary</summary>body</details>""",
|
||||
)
|
||||
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
assert (
|
||||
Path(tmp_file.name).read_text(encoding="utf8")
|
||||
== """<details>
|
||||
<summary>
|
||||
summary
|
||||
</summary>
|
||||
body
|
||||
</details>
|
||||
"""
|
||||
)
|
||||
35
tests/test_html/test_tag_dt.py
Normal file
35
tests/test_html/test_tag_dt.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
"""Djlint tests specific to html.
|
||||
|
||||
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 \
|
||||
--cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
|
||||
"""
|
||||
# pylint: disable=C0116
|
||||
from pathlib import Path
|
||||
from typing import TextIO
|
||||
|
||||
from click.testing import CliRunner
|
||||
|
||||
from src.djlint import main as djlint
|
||||
from tests.conftest import write_to_file
|
||||
|
||||
|
||||
def test_dt_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""<dt>text</dt>""",
|
||||
)
|
||||
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
assert (
|
||||
Path(tmp_file.name).read_text(encoding="utf8")
|
||||
== """<dt>
|
||||
text
|
||||
</dt>
|
||||
"""
|
||||
)
|
||||
38
tests/test_html/test_tag_fig_caption.py
Normal file
38
tests/test_html/test_tag_fig_caption.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
"""Djlint tests specific to html.
|
||||
|
||||
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 \
|
||||
--cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
|
||||
"""
|
||||
# pylint: disable=C0116
|
||||
from pathlib import Path
|
||||
from typing import TextIO
|
||||
|
||||
from click.testing import CliRunner
|
||||
|
||||
from src.djlint import main as djlint
|
||||
from tests.conftest import write_to_file
|
||||
|
||||
|
||||
def test_figure_figcaption_tags(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""<figure><img src="" alt=""><figcaption>caption</figcaption></figure>""",
|
||||
)
|
||||
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
assert (
|
||||
Path(tmp_file.name).read_text(encoding="utf8")
|
||||
== """<figure>
|
||||
<img src="" alt="">
|
||||
<figcaption>
|
||||
caption
|
||||
</figcaption>
|
||||
</figure>
|
||||
"""
|
||||
)
|
||||
45
tests/test_html/test_tag_hr.py
Normal file
45
tests/test_html/test_tag_hr.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
"""Djlint tests specific to html.
|
||||
|
||||
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 \
|
||||
--cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
|
||||
"""
|
||||
# pylint: disable=C0116
|
||||
from typing import TextIO
|
||||
|
||||
from click.testing import CliRunner
|
||||
|
||||
from tests.conftest import reformat
|
||||
|
||||
|
||||
def test_hr_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<div>
|
||||
<div>
|
||||
<hr>
|
||||
</div>
|
||||
</div>
|
||||
""",
|
||||
)
|
||||
assert output.exit_code == 0
|
||||
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<div>
|
||||
<div>
|
||||
<hr />
|
||||
</div>
|
||||
</div>
|
||||
""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
38
tests/test_html/test_tag_picture.py
Normal file
38
tests/test_html/test_tag_picture.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
"""Djlint tests specific to html.
|
||||
|
||||
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 \
|
||||
--cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
|
||||
"""
|
||||
# pylint: disable=C0116
|
||||
from pathlib import Path
|
||||
from typing import TextIO
|
||||
|
||||
from click.testing import CliRunner
|
||||
|
||||
from src.djlint import main as djlint
|
||||
from tests.conftest import write_to_file
|
||||
|
||||
|
||||
def test_picture_source_img_tags(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""\
|
||||
<picture><source media="(max-width:640px)"
|
||||
srcset="image.jpg"><img src="image.jpg" alt="image"></picture>""",
|
||||
)
|
||||
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
assert (
|
||||
Path(tmp_file.name).read_text(encoding="utf8")
|
||||
== """<picture>
|
||||
<source media="(max-width:640px)" srcset="image.jpg">
|
||||
<img src="image.jpg" alt="image">
|
||||
</picture>
|
||||
"""
|
||||
)
|
||||
36
tests/test_html/test_tag_pre.py
Normal file
36
tests/test_html/test_tag_pre.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
"""Djlint tests specific to html.
|
||||
|
||||
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 \
|
||||
--cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
|
||||
"""
|
||||
# pylint: disable=C0116
|
||||
from typing import TextIO
|
||||
|
||||
from click.testing import CliRunner
|
||||
|
||||
from tests.conftest import reformat
|
||||
|
||||
|
||||
def test_pre_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
# added for https://github.com/Riverside-Healthcare/djLint/issues/187
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""{% if a %}
|
||||
<div>
|
||||
<pre><code>asdf</code></pre>
|
||||
<pre><code>asdf
|
||||
</code></pre>
|
||||
<!-- other html -->
|
||||
<h2>title</h2>
|
||||
</div>
|
||||
{% endif %}""",
|
||||
)
|
||||
assert output.exit_code == 0
|
||||
72
tests/test_html/test_tag_script.py
Normal file
72
tests/test_html/test_tag_script.py
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
"""Djlint tests specific to html.
|
||||
|
||||
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 \
|
||||
--cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
|
||||
"""
|
||||
# pylint: disable=C0116
|
||||
from pathlib import Path
|
||||
from typing import TextIO
|
||||
|
||||
from click.testing import CliRunner
|
||||
|
||||
from src.djlint import main as djlint
|
||||
from tests.conftest import reformat, write_to_file
|
||||
|
||||
|
||||
def test_script_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""<div>\n <script>console.log();\n console.log();\n\n </script>\n</div>""",
|
||||
)
|
||||
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
|
||||
assert (
|
||||
Path(tmp_file.name).read_text(encoding="utf8")
|
||||
== """<div>
|
||||
<script>console.log();
|
||||
console.log();
|
||||
|
||||
</script>
|
||||
</div>
|
||||
"""
|
||||
)
|
||||
|
||||
# check script includes
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<script src="{% static 'common/js/foo.min.js' %}"></script>""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<script>
|
||||
$("#x").do({
|
||||
dataBound: function () {
|
||||
this.tbody.append($("<td colspan=2'>X</td>"));
|
||||
},
|
||||
});
|
||||
</script>
|
||||
""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
|
||||
# check bad template tags inside scripts
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<script>{{missing_space}}</script>\n""",
|
||||
)
|
||||
|
||||
assert output.exit_code == 0
|
||||
33
tests/test_html/test_tag_small.py
Normal file
33
tests/test_html/test_tag_small.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
"""Djlint tests specific to html.
|
||||
|
||||
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 \
|
||||
--cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
|
||||
"""
|
||||
# pylint: disable=C0116
|
||||
from pathlib import Path
|
||||
from typing import TextIO
|
||||
|
||||
from click.testing import CliRunner
|
||||
|
||||
from src.djlint import main as djlint
|
||||
from tests.conftest import write_to_file
|
||||
|
||||
|
||||
def test_small_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""<small>text</small>""",
|
||||
)
|
||||
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
assert (
|
||||
Path(tmp_file.name).read_text(encoding="utf8")
|
||||
== """<small>text</small>
|
||||
"""
|
||||
)
|
||||
48
tests/test_html/test_tag_span.py
Normal file
48
tests/test_html/test_tag_span.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
"""Djlint tests specific to html.
|
||||
|
||||
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 \
|
||||
--cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
|
||||
"""
|
||||
# pylint: disable=C0116
|
||||
from pathlib import Path
|
||||
from typing import TextIO
|
||||
|
||||
from click.testing import CliRunner
|
||||
|
||||
from src.djlint import main as djlint
|
||||
from tests.conftest import reformat, write_to_file
|
||||
|
||||
|
||||
def test_span_tag(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
write_to_file(
|
||||
tmp_file.name,
|
||||
b"""<span class="icon has-text-grey is-large "><i class="fas fa-lg fa-star"></i></span>""",
|
||||
)
|
||||
runner.invoke(djlint, [tmp_file.name, "--reformat"])
|
||||
assert (
|
||||
Path(tmp_file.name).read_text(encoding="utf8")
|
||||
== """<span class="icon has-text-grey is-large "><i class="fas fa-lg fa-star"></i></span>
|
||||
"""
|
||||
)
|
||||
|
||||
# issue #171, span is an inline tag
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<div class="hi">
|
||||
<div class="poor">
|
||||
<p class="format">
|
||||
<strong>H</strong>ello stranger, <strong>do not wrap span</strong>, <strong>pls</strong>.
|
||||
<span class="big">H</span>ello stranger, <strong>do not wrap span</strong>, <span class="big">pls</span>.
|
||||
</p>
|
||||
</div>
|
||||
</div>""",
|
||||
) # noqa: E501
|
||||
assert output.exit_code == 0
|
||||
93
tests/test_html/test_tag_textarea.py
Normal file
93
tests/test_html/test_tag_textarea.py
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
"""Djlint tests specific to html.
|
||||
|
||||
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 \
|
||||
--cov-report xml:coverage.xml --cov-report term-missing
|
||||
|
||||
|
||||
"""
|
||||
# pylint: disable=C0116
|
||||
# from pathlib import Path
|
||||
# from typing import TextIO
|
||||
|
||||
# from click.testing import CliRunner
|
||||
|
||||
# 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
|
||||
|
||||
# # check attributes
|
||||
# output = reformat(
|
||||
# tmp_file,
|
||||
# runner,
|
||||
# b"""<div>
|
||||
# <div class="field">
|
||||
# <textarea class="this"
|
||||
# name="that">asdf</textarea>
|
||||
# </div>
|
||||
# </div>
|
||||
# """,
|
||||
# )
|
||||
|
||||
# assert (
|
||||
# output.text
|
||||
# == """<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.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
|
||||
|
|
@ -9,13 +9,12 @@ run:
|
|||
|
||||
"""
|
||||
# pylint: disable=C0116
|
||||
from pathlib import Path
|
||||
from typing import TextIO
|
||||
|
||||
from click.testing import CliRunner
|
||||
|
||||
from src.djlint import main as djlint
|
||||
from tests.conftest import reformat, write_to_file
|
||||
from tests.conftest import reformat
|
||||
|
||||
|
||||
def test_invalid(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
output = reformat(
|
||||
|
|
@ -30,7 +29,9 @@ invalid:
|
|||
|
||||
<html><head></head><body></body></html>""",
|
||||
)
|
||||
assert output.text == """---
|
||||
assert (
|
||||
output.text
|
||||
== """---
|
||||
invalid:
|
||||
invalid:
|
||||
---
|
||||
|
|
@ -41,6 +42,7 @@ invalid:
|
|||
</body>
|
||||
</html>
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def test_valid(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
|
|
@ -53,7 +55,9 @@ hello: world
|
|||
---
|
||||
<html><head></head><body></body></html>""",
|
||||
)
|
||||
assert output.text == """---
|
||||
assert (
|
||||
output.text
|
||||
== """---
|
||||
hello: world
|
||||
---
|
||||
<html>
|
||||
|
|
@ -63,6 +67,8 @@ hello: world
|
|||
</body>
|
||||
</html>
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def test_more(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
output = reformat(
|
||||
|
|
|
|||
Loading…
Reference in a new issue